FACTORY_OUTCOME: COMPLETED ## Сводка для владельца Итог: вердикт R1 — FAIL (условный): код, хеши, additive-миграция, замороженное согласование, CAS/идемпотентность и режим PARKED подтверждены; найден один блокирующий дефект владельческих действий. Проблемы: после PASS владелец не может изменить требования (revise) или остановить (hold) — запрос возвращает успех (303), но ничего не меняется; плюс 3 некритичных замечания. Production не пострадал: миграция безопасна, режим PARKED, циклов 0. Решение: принять итог FAIL и поручить минимальную правку (≈10 строк) с повторной проверкой; миграция уже применена и откат не нужен; включение функции и рестарт сервисов по-прежнему не разрешены. # R1 independent review — automatic review cycles Reviewer: independent task FR-AUTO-REVIEW-R1-REVIEW, 2026-11-29. No code edited, no production writes, no restart. Production DB was opened only read-only (`mode=ro`); all tests/copy checks used temporary DBs and fake executors. Real-CLI tests (`test_errors_timeout_and_auth_preflight`, `test_execution_edits_real_workspace_and_contract`) were excluded and not run. ## Verdict: **FAIL** (one blocking defect; everything else PASS) The defect is small, local, disabled-by-default, and does not endanger production in PARKED mode, but it breaks an owner control that the design (§3.4, §8 downgrade preflight, row 2 of the transition table) relies on. R1 should not be accepted as complete until fixed and re-tested. ## Blocking finding **B-1. Owner `revise`/`hold` on a PASSED cycle is a silent no-op.** - Code: `control_plane/review_cycles.py:437` — `c['state']=='PASSED' and trigger!='accept'` ⇒ `outcome='STALE_OUTCOME'`. This branch is meant for *late worker outcomes* but also catches owner (non-worker) triggers `stop` and `change_requirements`. `console/owner_decisions.py:36-41` does not check the returned outcome, so the route returns 303. - Reproduced (temporary DB, probe outside the repo): approve → producer → independent PASS → `can_accept` true; POST `/tasks/{id}/decision` action=`revise` ⇒ HTTP **303**, cycle stays `PASSED`, `version` 2→2, task stays `COMPLETED`, instruction unchanged; only a `STALE_OUTCOME` transition row is written. - Impact: a PASSED checkpoint task (status REVIEW) or completed task cannot be revised/held via the cycle; legacy guard (`guard_edit`) also blocks any other edit path, so the only way out is `accept`. Contradicts design §8 (downgrade requires owner to "accept, supersede or cancel" an unresolved cycle) and gives the owner a false success. - Minimal correction: (1) at line 437 apply the stale rule to `worker` triggers only, and let non-worker `change_requirements` (→ SUPERSEDED, task PLANNED) and `stop` through when state is PASSED and no live execution; (2) in `decide()` raise 409 if the returned transition `outcome` is `STALE_OUTCOME`; (3) add a test in `test_review_cycles_r1.py` for revise and hold after PASS (state, task status, instruction, HTTP code). ## Non-blocking findings (recommendations, not required for R1 verdict) 1. **Mutation reason masked by stop/park** (`review_cycles.py:439` precedes `:492`). Reproduced: reviewer result with `files_changed`+`forbidden_action` while `stop_requested=1` ⇒ cycle `STOPPED/MANUAL_STOP`, execution left `COMPLETED` (not `REJECTED_MUTATION`). Safe outcome (stopped, can't accept, resume needs fresh baseline and clears acceptance), but the mutation evidence/reason is lost. Suggest evaluating `integrity_violation` before the stop/park branch for REVIEW-phase workers. 2. **Stale reviewer outcome with mutation is record-only** (`:437`): a late reviewer from an older revision that mutated files will not stop the cycle. Mitigated because `can_accept` recomputes the producer manifest, but R2/R3 should treat integrity violations in stale outcomes as a stop. 3. **No CANCELLED producer**: state exists in the CHECK constraint and design, but no code path sets it. Needed by the design's downgrade path; defer to R3/R4 but track. 4. Owner `accept` after `PASSED` keeps cycle state `PASSED` (task `ACCEPTED`); fine, noted for UI work. ## Evidence checked **Hashes.** All 11 files in `r1-evidence/source-sha256.json` re-hashed now: byte counts and SHA-256 **all match** current sources (db.py 52c1e93b…, review_cycles.py 6819ab07…, test_review_cycles_r1.py fac29bca…, etc.). No git history exists (`.git` is an empty directory), so no historical diff was possible and none is claimed. **Fresh test runs (this review, temp DBs, fake executors):** | Run | Result | |---|---| | `test_review_cycles_r1.py` + `test_runtime.py::test_migration_is_additive_and_repeatable` | **45 passed** (44 R1 + 1 migration), 115 s | | `legacy_probe.py` (runtime/approved_runtime/supervisor/verification/owner_decisions minus the 13 listed) | **56 passed, 13 deselected, 15 subtests passed**, 151 s | | Two probes (B-1 and finding 1) | both reproduce defects above | Report numbers (44/56/15) are reproduced. Report's safe adapter subset (21 passed) and the interrupted adapter run were taken from its logs, not re-run; the report discloses the real-CLI mock defect honestly (no model result is claimed). **Design v4 conformance (code read in full: `review_cycles.py`, `review_cycle_schema.sql`, `db.py`, owner_decisions, approval hook):** - *Additive migration*: PASS. New columns via `MIGRATIONS` with defaults; tables `CREATE IF NOT EXISTS`; `init_db` idempotent. Copy tests (see below) preserved all row counts. - *Frozen approval*: PASS. Snapshot+cycle inserted inside the `approve_task` transaction after `approved_at` is set; snapshot has BEFORE UPDATE/DELETE abort triggers and a digest over all fields; task inputs/attachments/dependencies frozen by triggers while cycle is ACTIVE/STOPPED/PASSED; `snapshot_valid` re-checks digest, requirement attachments (full streaming SHA-256), workspace and contract. Resource paths and contract paths cannot escape workspace; contract paths are a floor. CORAL/L-IT cannot enable cycles. - *CAS/idempotency*: PASS. `cycle_apply` requires an open transaction, uses savepoint, `version` CAS, unique `idem_key`; duplicates return the stored transition; stale outcomes don't advance version or overwrite recorded evidence. - *Acceptance*: PASS. `can_accept` needs latest producer of current revision/snapshot, durable passed verification with matching hash and contract, unchanged manifest, independent completed PASS (different executor), clean integrity record, no live execution, no validated BLOCKING finding. Owner accept can't bypass it; legacy tasks unchanged. - *Findings*: PASS. Stable identity `criterion|target`; BLOCKING requires valid criterion/target and contained evidence/recorded test else downgraded; PASS evaluated before no-progress; disputes need evidence; 2nd UPHELD / 2 persisted remediations stop. - *Mutation stop/resume*: PASS with finding 1–2. Integrity violation ⇒ STOPPED, `REJECTED_MUTATION`, findings not applied, acceptance cleared, no auto-resume; resume owner-only, ceiling 5, needs reacquisition flag + fresh baseline equal to current files, then re-executes in the same spent revision. - *Legacy parity*: PASS. Legacy tokens/routes unchanged for non-cycle tasks; supervisor adds only `CYCLE_MANAGED` for rows with a cycle; dispatcher claim fence retained (no cycle launch path exists yet, as R1 scope intends). - *Disabled by default*: PASS. Settings default `enabled=False`; control row defaults `PARKED`; `effective_mode` is PARKED unless both durable `ON` **and** env `AI_FACTORY_REVIEW_CYCLE=1`; approval raises Conflict if enabled settings but parked. - Scope: R2–R6 absence is not counted against R1. ## Pre-migration compatibility failure and rollout ordering (owner revision) **What failed.** The first broad legacy run was 55 passed / 14 failed. One failure was `test_migration_is_additive_and_repeatable`: the test simulates a pre-R1 DB by `ALTER TABLE … DROP COLUMN`, and SQLite refuses to drop a column referenced by the new trigger `cycle_task_inputs`. **Assessment: a test-fixture artifact, not a real upgrade defect.** The fixture fix (drop that trigger first, as a pre-R1 DB wouldn't have it, then let `init_db` recreate it) is legitimate and the test now passes. Side note: those triggers do prevent `DROP COLUMN` on guarded task columns, so a future physical rollback by dropping columns would also need to drop triggers; the design's rollback is PARKED mode with code retained, so this is not a problem. **Real-DB upgrade proof (my own copy test, temp files only).** `init_db()` twice on (a) `backups/factory-pre-r1-20261129-082817.db` and (b) the old `factory.db.bak-20261013-1754-pre-contract`: both succeed, all table row counts unchanged, `integrity_check` ok, `foreign_key_check` empty, control mode `PARKED`. So both a recent and a much older schema upgrade cleanly. **Production state observed read-only.** `data/factory.db`: R1 tables/triggers/columns present; `review_cycle_control.mode = PARKED`; `review_cycles` = 0, `cycle_snapshots` = 0; integrity_check ok; 252 tasks (same as backup). Backup `backups/factory-pre-r1-20261129-082817.db` (sha256 a2b6e28c…d8f6a1) predates the migration (it contains no R1 tables), passes integrity_check, has 341 executions vs 342 live (one new execution since, expected). Backup was taken before the migration — ordering correct. Design §8 asks for `sqlite3 .backup`; I cannot tell from files which method was used (size 24297472 incl. WAL content suggests a consistent backup, but unproven) — a recommendation to record the method. **Rollout ordering.** Console and dispatcher have run since 2026-11-28 07:08 and the supervisor since 2026-10-17, i.e. they are **old code** (R1 sources were modified 2026-11-29). They kept operating after the migration (console POSTs at 08:28:31 returned 303; dispatcher/supervisor ticks continue at 08:29–08:30). That is consistent with design: old code ignores new tables, all new columns have defaults, and the new triggers fire only for tasks with an open cycle (none). So the sequence *backup → copy test → additive migration → old code keeps running, PARKED* is safe. Cautions for the next step: (1) do **not** restart until B-1 is fixed, because the restarted code will bring in the owner-decision path with the defect; (2) after restart `AI_FACTORY_REVIEW_CYCLE` is unset ⇒ still PARKED regardless of DB; (3) no dispatcher path can launch a cycle yet (R3), so turning mode ON would be inert and misleading — keep PARKED; (4) restart only in an authorized idle window per design §8; this review authorizes nothing. ## Attribution of the 13 legacy failures (no historical checkout claimed) The report's `legacy-known-failures.json` lists 13 node IDs: 8 fallback/executor-expectation (runtime, approved_runtime, supervisor) and 5 UI/template (4 in owner_decisions, 1 monitor template). I verified: (a) the 56-test remainder passes; (b) `legacy-hooks-bypassed.log` shows the same 13 failing with the R1 hooks (`current/freeze_approval/guard_edit/guard_project_inputs`) replaced by no-ops; (c) failure messages are expectation mismatches (`'deepseek'` lists vs `claude-code`, `None != 'nemotron'`, `'totals' is undefined`, missing "Technical details" in English markup) that match the known outdated DeepSeek/text-only expectation debt from FR-EXECUTOR-VERIFY. Caveat, accurately stated: this shows the failures are **not caused by the four hooks**; it does not isolate the other R1 edits (supervisor fence, owner token, DB migration) nor prove they pre-date R1 (no checkout), and it does not equate them to the "12 legacy tests" of the earlier note (13 ≠ 12; one is unexplained and should be triaged). The attribution is "reproduces without R1 hooks; consistent with legacy expectation debt", not "proven pre-existing". ## Recommendations (separate from verdict) - After the B-1 fix, re-run the 45-test set plus the new revise/hold-after-PASS test and the 56-test legacy remainder; re-hash the changed files and update `source-sha256.json`. - Record the backup method and a post-migration `integrity_check` result in the rollout notes. - Triage the 13th legacy failure vs the 12 known ones; keep the real-CLI mock defect as separate debt (patch `subprocess.Popen` in those two tests). - Keep PARKED and the env flag off until R3 wiring exists; do not restart before B-1 is fixed. ## Not verified Real HTTP server behaviour (tests call handlers directly), real executors/E2E, dispatcher recovery, physical isolation — all R2–R6 scope. Production was inspected read-only and not exercised.