Skip to content

Wire the recorder into a cycle somebody can run - #12

Merged
datacas merged 2 commits into
mainfrom
feat/cycle-wiring
Sep 21, 2026
Merged

datacas merged 2 commits into
mainfrom
feat/cycle-wiring

Conversation

@datacas

@datacas datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner

Why

CycleRecorder shipped in #10 with no caller outside its own tests. The guarantee it enforces — route, dispatch and record as one operation, with no path through it that does only part — therefore applied to nothing, and telemetry had zero productive rows however many cycles ran.

What this adds

scripts/run_cycle.py: probe the executors once, label the work before routing anything, then implement → review → (resolve → rereview)* with every stage going through recorder.stage().

python3 ~/.code-cycle/runtime/run_cycle.py \
  --repo owner/name --task API-7 --difficulty 2 --verifiability auto

It decides nothing: no cost model, no learning, no rule that changes itself from an outcome. Those stay where they are until there is something measured to move them with.

It does not infer a verdict. A review's outcome is read from the structured result the driver explicitly asks the executor to emit — opt-in on request in every review skill, so a documented capability rather than a hopeful one — and never from an exit code or from prose. When the block is absent the cycle stops and records that the verdict is unknown. A guess would be indistinguishable from data forever after, and the point of this instrument is to be believed later.

Orca is named as the exception. Its dispatch returns a started worker and a dispatchId, not a finished stage, so a cycle routed there stops after the dispatch rather than treating absent output as failure.

One fix to the recorder

CycleRecorder now takes the probe map and passes it to every dispatch. Without it dispatch() probed all executors again on each call, so an availability could change between two stages with nothing recording that it had — which is exactly what cc-orchestrator tells a run not to do, and it was the runtime doing it.

The acceptance criterion is an installed layout, not scripts/

tests/test_installed_cycle.py installs the toolkit into a temporary home, puts fake agent binaries on PATH, starts the entrypoint the way a person would, and then opens telemetry.sqlite to read what the run left behind. No provider, no network, no credential: the agents are a script that prints what a real one prints, including the resolved model the way each real CLI reports it.

It covers four scenarios:

  1. the healthy cycle — implement → review → APPROVED, five rows, ending READY_FOR_MANUAL_MERGE;
  2. a second round after CHANGES_REQUESTED — nine rows, iteration going 0,0,0,0,1,1,1,1,1, with the findings counts the reviewer reported;
  3. a review that emits no structured block — the cycle stops, exit 1, final status HUMAN_INTERVENTION;
  4. the scenario the fallback exists for — the fake Codex reports an exhausted window from a real subprocess, the recorder reroutes once, and all three facts survive in SQLite: the abandoned Codex attempt with missing_capability=operating_quota, the fallback decision with used_fallback=1, and what Claude then did.

Found while writing it

The request the driver composes contains the words ORCHESTRATION_RESULT, so an executor that echoes its own prompt puts a decoy earlier in the stream. Reading forwards parsed the prompt and reported no verdict; the block is now read from the end. The fake agent echoes its prompt precisely so this stays covered.

Verification

  • python3 -m unittest discover -s tests — Ran 330 tests ... OK (was 322).
  • python3 scripts/validate-package.py — VALID.
  • A real run by hand from an installed layout: implement cheap_coder codex succeeded, review reviewer claude succeeded, READY_FOR_MANUAL_MERGE, five rows in SQLite with requested and resolved models matching.

What is still not done

Nothing reads the recorded rows back automatically; first_pass_rate() reaches the cost model only when someone passes it. The sequence from here is: one canary cycle against a real provider, then normal use until MINIMUM_SAMPLE = 10, then compare the observed rate against the conservative 0.0 — and only then consider wiring it in.

CycleRecorder shipped with no caller outside its tests. The guarantee it
enforces -- route, dispatch and record as one operation, with no path that does
only part -- therefore applied to nothing, and the telemetry store had zero
productive rows however many cycles ran.

run_cycle.py is that sequence, written once: probe the executors, label the work
before routing anything, then implement -> review -> (resolve -> rereview)* with
every stage going through recorder.stage(). It decides nothing. No cost model,
no learning, no rule that changes itself from an outcome.

It does not infer a verdict either. A review's outcome is read from the
structured result the driver explicitly asks the executor to emit, which every
review skill documents as opt-in on request, and never from an exit code or from
prose. When the block is absent the cycle stops and says the verdict is unknown:
a guess would be indistinguishable from data forever after. Orca is named out
loud as the case where the dispatch returns a started worker rather than a
finished stage, so a cycle routed there stops after the dispatch.

The probe map is now taken once and handed to the recorder, which passes it to
every dispatch. Without it each dispatch probed again on its own, so an
availability could change between two stages with nothing recording that it had
-- exactly what the orchestration contract tells a run not to do.

The acceptance criterion is from an installed layout, not from scripts/:
install into a temporary home, put fake agent binaries on PATH, start the
entrypoint as a person would, then open telemetry.sqlite and read the rows. It
covers the healthy cycle, a second round after CHANGES_REQUESTED, a review that
reports no verdict, and the scenario the fallback exists for -- Codex reporting
an exhausted window, the recorder rerouting once, and all three facts surviving
in SQLite: the abandoned attempt, the fallback decision, and what the fallback
did.

One thing found while writing the driver: the request it composes contains the
word ORCHESTRATION_RESULT, so an executor that echoes its own prompt puts a
decoy earlier in the stream. Reading forwards parsed the prompt and reported no
verdict, so the block is now read from the end.
@datacas

datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner Author

Initial review — PR #12

Summary

I reviewed the accumulated diff from 8472b8c59fc8ede350dd5f711e842123b5307fb4 to ae8a0692d6b4bab6447edbaa14547192e2a152bb across all 10 changed files. The new installed-cycle wiring is covered by passing tests and CI, but the runtime has two correctness gaps around asynchronous Orca dispatches and malformed structured results.

[REV-001] · high · open · blocks:yes — An asynchronous Orca dispatch is treated as completed work

Path: scripts/run_cycle.py, line 192

run_cycle() advances to the next role whenever StageOutcome.succeeded is true. Orca's successful worker-start result means that a worker was launched and includes a dispatchId; it does not mean that the implementation stage finished or produced a reviewable result. Because this branch does not recognize Orca's asynchronous result, the cycle can immediately run a review and eventually return READY_FOR_MANUAL_MERGE for work that is still running.

I reproduced this with an Orca-shaped successful dispatch followed by a successful Claude-shaped review: the report contained ['implement', 'review'] and ended with READY_FOR_MANUAL_MERGE.

Please stop and record the asynchronous dispatch as a human/external follow-up state when the result carries an Orca dispatchId (or expose an explicit asynchronous result flag), rather than advancing to review.

[REV-002] · medium · open · blocks:no — Non-object structured output crashes the driver

Path: scripts/run_cycle.py, line 227

read_structured_result() accepts any JSON value, but _verdict() assumes the result is a mapping and calls .get(). A valid delimited block containing a JSON string, number, or other non-object therefore raises AttributeError and bypasses recorder.close(), instead of being treated as an unknown/malformed result and recorded as HUMAN_INTERVENTION.

I reproduced this with ORCHESTRATION_RESULT\n"APPROVED"\nEND_ORCHESTRATION_RESULT; the cycle raised AttributeError: 'str' object has no attribute 'get'.

Please require isinstance(payload, dict) before returning/consuming the parsed result and route malformed blocks through the existing unknown-verdict stop path.

Security triage

This is a sensitive change because it launches local agent CLIs, accepts a caller-provided working directory, and processes agent output. The scoped security audit found no confirmed vulnerability: subprocesses are invoked with argument arrays rather than a shell, the working directory is passed explicitly to the child process, and the changed code does not persist credentials or transcript prose in telemetry. The two findings above are correctness/reliability findings, not security findings.

Verification

  • python3 scripts/validate-package.py — passed (VALID).
  • python3 -m unittest discover -s tests -v — passed, 330 tests.
  • python3 -m unittest tests.test_installed_cycle tests.test_cycle -q — passed, 29 tests.
  • python3 -m compileall -q scripts tests — passed.
  • git diff --check origin/main...HEAD — passed.
  • Targeted Orca-shaped and malformed-result harnesses — both reproduced the issues above.

CI

All checks currently reported for head ae8a0692d6b4bab6447edbaa14547192e2a152bb passed:

  • Skills, manifests, and Bash installer — passed (2 runs).
  • PowerShell installer — passed (2 runs).

Unverified items and residual risk

No live Orca worker or real provider was available in this review; the asynchronous path was validated with an adapter-shaped execution harness and the installed fake-agent path was exercised end to end. Until REV-001 is fixed, a configured Orca route can advance the workflow before implementation completion. Until REV-002 is fixed, malformed model output can terminate a run without its closing telemetry row.

Verdict

CHANGES_REQUESTED — REV-001 blocks approval. REV-002 should also be fixed before relying on the CLI as a durable cycle runner.

The driver documented that Orca returns a receipt rather than a result, and then
advanced on DispatchOutcome.SUCCEEDED like every other executor. A cycle routed
to Orca ran its review against work still being written and could reach
READY_FOR_MANUAL_MERGE for an implementation that had not finished. The claim
was in the docstring and nothing in the code enforced it.

The distinction is now carried, not narrated. Adapter.completes_work states what
a backend is, OrcaAdapter declares False, and the dispatch wrapper applies it to
every result, so an adapter cannot report finished work it only launched by
forgetting a keyword. Every stage in the driver stops on it, naming the
reference the work continues under, and the cycle still closes itself so the
stop leaves its row.

The wrapper also stopped rebuilding its result field by field. It now uses
dataclasses.replace and sets only the two things this layer knows that the
adapter does not; listing the rest again is how a new field gets dropped.

Second finding, same commit: a delimited block holding a JSON string or number
parsed cleanly, was returned as a result, and raised AttributeError on the first
.get -- ending the run before its closing row. read_structured_result now
requires an object, and a malformed block takes the existing unknown-verdict
path.

Both reproduced first: an Orca-shaped run reached READY_FOR_MANUAL_MERGE with
roles ['implement', 'review'], and a block containing "APPROVED" raised. After
the fix the first stops at implement with the dispatchId in the reason and a
coordinate row, and the second stops with no structured verdict.
@datacas

datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner Author

Resolution summary

Both findings reproduced against ae8a069 before any edit, fixed in abb1921.

[REV-001] · high · resolved · valid · blocks:yes — An asynchronous Orca dispatch is treated as completed work

Valid, and the uncomfortable part is that this PR's own docstring already said "Orca is a start, not a finish" while the code advanced on DispatchOutcome.SUCCEEDED like any other executor. The claim was narrated and nothing enforced it — the same failure this instrument exists to catch, in the instrument again.

Reproduced: an Orca-shaped successful dispatch followed by a successful review gave ['implement', 'review'] ending READY_FOR_MANUAL_MERGE, exactly as reported.

Fixed by carrying the distinction rather than describing it:

  • Adapter.completes_work states what a backend is. OrcaAdapter declares False, with the reason next to it: worker-start returns once the worker is alive, and the stage finishes later and elsewhere.
  • DispatchResult.asynchronous carries it on the result.
  • dispatch() applies the class declaration to every successful result, so an adapter cannot report finished work it only launched by forgetting a keyword at one return statement. A blocked Orca dispatch started nothing and stays False.
  • Every stage in the driver stops on it — implement, review, resolve and rereview — naming the reference the work continues under, and recorder.close() still runs so the stop leaves its row.

I chose the adapter declaration over sniffing artifacts["dispatchId"], which the finding offered as an alternative: the dispatch id is Orca's receipt format, and a second definition of "asynchronous" living in the driver would drift from the first. One statement, applied in one place, tested against the real OrcaAdapter.

Also fixed while in there: dispatch() rebuilt its result field by field, so a new field on DispatchResult had to be remembered in a second place or it was silently dropped on the way out — which is precisely what would have happened to asynchronous. It now uses dataclasses.replace and sets only the two things that layer knows and the adapter does not.

[REV-002] · medium · resolved · valid · blocks:no — Non-object structured output crashes the driver

Valid and reproduced: ORCHESTRATION_RESULT\n"APPROVED"\nEND_ORCHESTRATION_RESULT raised AttributeError: 'str' object has no attribute 'get', which ended the run before recorder.close() — so the one case where the record matters most left no closing row.

read_structured_result() now returns the payload only when it is an object. A block holding a string or a number is delimited, parseable and not a result; returning it hands the caller something that merely looks like one. Malformed blocks take the existing unknown-verdict path and the cycle stops with HUMAN_INTERVENTION and its coordinate row.

Regression tests

tests/test_run_cycle.py (new, 9 tests) covers the driver's own decisions in process:

  • a stage that only started does not advance the cycle, and the fallback executor is never dispatched;
  • the stop reason names the reference (D-7);
  • the cycle still closes itself, and the started dispatch is still recorded as a row;
  • a review that only started produces no verdict;
  • a block holding a string, and one holding a number, are not results;
  • a malformed block stops the cycle instead of ending it, with the closing row present;
  • an echoed prompt containing the words ORCHESTRATION_RESULT does not shadow the real block.

tests/test_executors.py gains five: the real OrcaAdapter reports asynchronous on a successful receipt, a native success does not, an adapter that declares completes_work = False but forgets the keyword is still corrected by the wrapper, a blocked dispatch stays False, and the wrapper preserves detail, artifacts, resolved model and policy across its replace.

Verification

  • Before: ['implement', 'review'] READY_FOR_MANUAL_MERGE; AttributeError.
  • After: ['implement'], HUMAN_INTERVENTION, reason implement was started on codex as D-7 and finishes elsewhere; this cycle cannot see its result, rows [('implement', None), ('coordinate', 'HUMAN_INTERVENTION')]; the malformed block stops with no structured verdict.
  • python3 -m unittest discover -s tests — Ran 344 tests ... OK (was 330).
  • python3 scripts/validate-package.py — VALID.
  • CI on abb1921 — all four checks pass, none pending, failed, cancelled or skipped.

Sensitivity triage

Unchanged in kind and narrower in effect: the diff adds a stop condition and a type check, executes nothing new, and passes no new data to a subprocess. Agreeing with the review's triage, these are correctness findings; no audit finding.

Residual risks

No live Orca worker has still never been started end to end — the asynchronous contract is verified against the real adapter with an injected runner and a real receipt payload, not against a running worker. Collecting an Orca stage's result after the fact remains out of scope: this driver stops and says where the work went, it does not follow it.

One thing noticed while triaging and deliberately left alone: CycleRecorder routes with profiles=None, so code_cycle.profiles from .code-cycle.yml never reaches routing. That is not one of these findings and changing it here would widen the PR; it needs its own change.

Status: RESOLVED — REV-001 and REV-002 closed at abb1921.

@datacas

datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner Author

Re-review — PR #12

Scope and change since the previous review

The previous review covered ae8a0692d6b4bab6447edbaa14547192e2a152bb. This re-review covers the complete accumulated diff against main at current head abb1921c5b435047c72b2ee72117894fa65d8dc5, including the fix commit and its new executor/driver regression tests.

The fix commit adds an explicit asynchronous-dispatch signal to DispatchResult, makes the executor wrapper preserve and derive that signal, stops every cycle stage that only started work elsewhere, and rejects non-object structured-result payloads before verdict handling.

Previous findings

[REV-001] · high · resolved · valid · blocks:yes — An asynchronous Orca dispatch is treated as completed work

Status: corrected and verified by execution.

OrcaAdapter now declares that worker-start does not complete the stage, successful Orca receipts set DispatchResult.asynchronous, and run_cycle() stops before advancing to the next role. The stop reason includes the dispatch reference and recorder.close() writes the HUMAN_INTERVENTION coordinate row.

Independent reproduction with an Orca-shaped successful dispatch produced only ['implement'], dispatched no reviewer, and returned HUMAN_INTERVENTION with the D-7 reference. The new tests also exercise the real OrcaAdapter receipt and the wrapper propagation path.

[REV-002] · medium · resolved · valid · blocks:no — Non-object structured output crashes the driver

Status: corrected and verified by execution.

read_structured_result() now returns a payload only when it is a dictionary. A delimited string or numeric JSON value therefore reaches the existing “no structured verdict” stop path instead of calling .get() on the wrong type.

Independent reproduction with ORCHESTRATION_RESULT\n"APPROVED"\nEND_ORCHESTRATION_RESULT returned HUMAN_INTERVENTION, reported no structured verdict, and left a closing coordinate row with that status.

Current accumulated review

No new findings. The changed executor wrapper preserves the adapter result fields while applying readiness and asynchronous state, and blocked dispatches remain non-asynchronous. The known .code-cycle.yml profile-loading limitation remains outside this PR's scope as documented in the resolution record.

Security triage and audit

The change remains sensitive because it launches local agent CLIs and handles working-directory and agent-result data. The scoped security audit found no confirmed vulnerability: no new shell execution or credential persistence was introduced, subprocess arguments remain structured, and the new state is control-flow metadata rather than sensitive output.

Verification

  • python3 -m unittest tests.test_run_cycle tests.test_executors -q — passed, 90 tests.
  • python3 -m unittest discover -s tests -v — passed, 344 tests.
  • python3 scripts/validate-package.py — passed (VALID).
  • python3 -m compileall -q scripts tests — passed.
  • git diff --check origin/main...origin/feat/cycle-wiring — passed.
  • Original REV-001 and REV-002 reproductions — both now pass with the corrected stop/record behavior.

CI

All current checks for abb1921c5b435047c72b2ee72117894fa65d8dc5 passed; none are pending, failed, cancelled, skipped, or missing:

  • Skills, manifests, and Bash installer — passed (2 runs).
  • PowerShell installer — passed (2 runs).

Unverified items and residual risk

No live Orca worker or real provider was started. The asynchronous contract was verified against the real adapter with an injected receipt runner, and the installed fake-agent cycle remains covered end to end. Following an asynchronous worker after dispatch remains outside this driver's scope; it records the handoff and stops rather than claiming completion.

Verdict

APPROVED — both previous findings are resolved and verified, no new blocking finding is open, and all required checks pass at the reviewed head.

@datacas
datacas merged commit d29f405 into main Sep 21, 2026
4 checks passed
@datacas
datacas deleted the feat/cycle-wiring branch September 21, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant