FACTORY_OUTCOME: COMPLETED I built the two-pass engine: targeted intake, cheap screening, deeper qualification for survivors only, then automatic shortlisting. No step needs a human. The acceptance check passes: `python3 -m unittest tests.test_autonomous_qualification -v` ran 29 tests, all OK. I did not migrate the live database (it is still at schema version 2) and did not run any live leads. **How a run works** (`app/autonomous_qualification.py`, `QualificationEngine(...).run(candidates)`) 1. **Intake:** a company becomes a candidate only if it matches the campaign targeting and has a dated signal that names it, with a real source URL. Companies that fail are not stored; the report lists them with reason codes such as `no_dated_signal` or `outside_geography`. If too many arrive, the extra ones are put off, not stored. 2. **Pass 1 (cheap screening):** each candidate becomes SCREENED or REJECTED with a reason code from the config. This pass can fill in an unknown country, size or sector. 3. **Pass 2 (deeper qualification):** this runs only on companies that passed screening. Every scoring dimension is stored with its weight, score, points, cited signals and explanation. Each company ends up QUALIFIED, REJECTED, or held as SCREENED with a reason such as `needs_more_evidence` or `evidence_not_supported`. The thresholds come from the campaign config. 4. **Shortlist:** qualified companies move to SHORTLISTED automatically, using the config's ranking and per-run cap. Each gets a handoff record for the presales stage, with `human_approval_required=false` and `outreach_authorized=false`. Companies that don't make the cut stay QUALIFIED with `below_shortlist_cutoff` or `shortlist_capacity`. - **Evidence:** source-confirmed ("SUPPORTED") evidence is enough; human verification is never required. If the AI cites a signal that doesn't exist, the answer is rejected and nothing is cached. **Failures, re-runs and limits** - **Nothing waits for a person:** held records are asked again only when their signals or the config change. An AI failure leaves the record where it was, stores the error, and it is retried on the next run. `monitor()` shows every record with its state, reason codes and last error. - **Re-runs cost nothing if nothing changed:** each AI answer is stored per company, pass, input and config version. An unchanged re-run makes no AI calls and records no state changes. A crashed run picks up from the stored answers, and repeating a finished run's ID just returns its report. - **New signals:** a rejected company is readmitted only if its rejection reason is not marked final in the config. - **Resource limits:** each call counts against the run's call, token and wall-clock limits, and retries are capped. Each AI call runs in a separate process that is killed at its deadline. Work over budget is put off with its state unchanged, the run is marked `BUDGET_EXHAUSTED`, and the shortlist step still runs. - **Human override (optional):** an override needs a named person and a reason, and is logged permanently. `force_reject`, `force_shortlist` and `remove_from_shortlist` stick across runs; `restore` and `requalify` hand the record back to the automatic flow. **Storage:** I added migration 3 in `app/migrations.py`. It adds four new tables: runs, the current state of each company, the state history, and the stored AI answers. The database blocks edits and deletions of the history and the stored answers. Existing tables are untouched. **Files** - `app/autonomous_qualification.py`, `tests/test_autonomous_qualification.py`, `docs/autonomous-qualification.md` (new) - `app/migrations.py`, `tests/test_migrations.py` (the migration list now includes migration 3), `docs/storage-schema.md` (changed) **Full suite:** 381 tests, 3 failures, none caused by this change: - The `test_e2e` scheduler test still expects `NOT_DUE` but gets `DUE`, the same failure the last task reported. - `test_mobile_ui…test_pages_and_assets` expects a company ID in the page title, but the leads page doesn't show it. It fails the same way when I remove migration 3. - The third was the migration test that expected only migrations 1–2; I updated it and it now passes. **Not done yet, for the next task:** - Apply migration 3 to `data/leads.db` (`python3 -m app.migrations`). - Connect the screening and qualification passes to real AI models. - Convert the research workflow's output (`claims`) into this engine's input (`signals`). - Re-check shortlisted or qualified companies when new signals arrive. Today they are only reported as `revalidation_pending`. - Make the UI read from the new tables.