# Review by Linus Torvalds (Round 1)

Now I have a thorough picture. Let me write the review.

---

VERDICT: request-changes

FINDINGS:
- [src/colonyos/cli.py:1427]: Imports `run_phase_sync` from `colonyos.orchestrator` but never uses it — then re-imports from `colonyos.agent` on line 1497 as `_run_phase`. Dead import. This is the kind of sloppy "I copy-pasted and didn't clean up" that tells me nobody actually read the code after writing it.
- [src/colonyos/cli.py:1425]: Imports private function `_extract_run_id_from_url` from `colonyos.ci`. If you need it in the public interface, drop the underscore. If it's an implementation detail, it shouldn't be used from outside the module. Pick one.
- [src/colonyos/cli.py:1503]: `hasattr(config, "get_model")` — this is defensive coding against your own code. `ColonyConfig` always has `get_model`. Remove the conditional and just call `config.get_model(Phase.CI_FIX)`. If your type isn't stable enough to rely on, you have bigger problems.
- [src/colonyos/cli.py:1530-1555]: The `--wait` logic for last-attempt vs non-last-attempt is duplicated. Two near-identical blocks of poll → check → return. Extract a common function or restructure the loop so it doesn't branch on `attempt >= max_retries` with copy-pasted code.
- [src/colonyos/orchestrator.py:1261-1268]: PR number extraction from deliver artifacts does `import re as _re` inline. Just import `re` at the top of the file like a normal person. The file already uses regex — I checked. Inline imports for stdlib modules scoped to a single function are cargo-cult "optimization" that accomplishes nothing except making the code harder to read.
- [src/colonyos/orchestrator.py:1340-1342]: `import subprocess as _sp` inline. Same problem. Use the module-level import.
- [src/colonyos/orchestrator.py:1252,1299]: Both `_run_ci_fix_loop` and `ci_fix` CLI command have identical logic for collecting failed check logs and building the prompt. This is textbook duplication. Extract a helper like `_collect_ci_failure_context(checks, repo_root, log_char_cap)` and use it in both places.
- [src/colonyos/cli.py:1559-1591]: `_save_ci_fix_run_log` manually serializes `RunLog` to JSON. The `_save_run_log` in orchestrator.py presumably does the same thing. Don't invent a second serialization path — reuse the existing one or explain why you can't.
- [src/colonyos/ci.py]: FR16 (validate `gh` auth) is not implemented as a pre-flight check in the CLI command. The PRD says: "Validate `gh` CLI is authenticated (same pattern as `doctor.py`). On failure, direct user to `colonyos doctor`." The fetch will eventually fail with an opaque error, but the PRD asked for an explicit up-front check.
- [tests/test_orchestrator.py]: Task 7.1 claims tests were written for the orchestrator CI fix loop integration, but the diff only shows a single line change (updating the Phase ordering assertion). No actual test for `_run_ci_fix_loop` or its integration in `run()`. The task checkbox is checked but the work wasn't done.
- [tests/test_cli.py]: Task 6.1 lists many test cases (failed checks with mocked agent, error cases for uncommitted changes, behind remote, gh not authenticated, PhaseResult recording). Only three tests exist: help output, all-checks-pass, and invalid PR ref. The stated scope of testing was not delivered.

SYNTHESIS:
The architectural skeleton is right — `ci.py` as a clean module mirroring `github.py`, config dataclass, instruction template, orchestrator integration gated by config. The data structures make sense. But the implementation has the unmistakable smell of code that was written once and never reviewed: dead imports, private functions used across module boundaries, duplicated logic in the CLI and orchestrator that should share a helper, a second serialization path for RunLog that shouldn't exist, and inline stdlib imports for no reason. Worst of all, the test coverage claims don't match reality — the orchestrator integration test and most CLI edge-case tests simply don't exist despite being checked off in the task file. I don't ship code with lying checkboxes. Fix the duplication, clean up the imports, write the tests you said you wrote, and implement FR16.