Skip to content

Read what the agent said, not what the CLI printed - #14

Merged
datacas merged 2 commits into
mainfrom
feat/agent-output
Sep 21, 2026
Merged

datacas merged 2 commits into
mainfrom
feat/agent-output

Conversation

@datacas

@datacas datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner

What the canary found

One real cycle against Codex and Claude, ~20 céntimos, and it located three defects that 372 passing tests did not. All three come from the same root: the fakes printed the structured block as plain text, and the real CLIs do not.

1. Normalized agent output, per adapter

Claude wraps its reply in one JSON object under result. Codex wraps its in NDJSON agent_message items. The driver was reading raw stdout, so it found ORCHESTRATION_RESULT and then failed to parse the block, because the newlines and quotes were still \n and \" inside a JSON string:

"result": "...ORCHESTRATION_RESULT\n{\n  \"skill\": \"cc-initial-review\",\n  \"status\": \"BLOCKED\", ..."

The reviewer had done its job perfectly — it reported BLOCKED and explained that CANARY-1 matched no issue or PR. The driver recorded "no structured verdict".

Each adapter now unwraps its own format into agent_output, and the driver reads that. It does not learn what result or item.completed mean, and neither does the next executor added.

Both extractors were written against live captures, not by assumption, and those captures are the fixtures (tests/fakes/codex_output.ndjson, tests/fakes/claude_output.json, identifiers replaced). The observed Codex shape:

{"type":"item.completed","item":{"id":"item_0","type":"agent_message","text":"ORCHESTRATION_RESULT\n..."}}

When an adapter does not recognise its own envelope it returns the output unchanged rather than some filtered part of it — returning only what it recognised would silently drop the rest.

2. Presence and readability, not one None

read_structured_result now returns a Reported carrying three distinguishable answers: readable, present-but-unreadable, absent. Collapsing them meant a cycle recorded "no verdict" for a run that was explicitly blocked.

A status outside the store's vocabulary is treated as no status rather than carried to record_verdict, where it would raise and end the run without its closing row — a failure this driver has already made once.

3. Functional stop semantics

outcome=succeeded was not wrong, and it has not been changed. The canary's implement row said succeeded and the clone had no commits and no modified files: the call returned, the work did not happen. Two facts about different layers, which the store already keeps in separate columns.

What was wrong is that the cycle continued. Now a stage whose own report is not a completion stops it:

CLI rc=0                        → outcome = succeeded   (unchanged)
ORCHESTRATION_RESULT BLOCKED    → status  = BLOCKED, recorded
                                → cycle stops, no review dispatched

COMPLETES states what each role must report to continue — IMPLEMENTED, RESOLVED/PARTIALLY_RESOLVED, APPROVED/CHANGES_REQUESTED. PARTIALLY_RESOLVED continues because the re-review is what judges how much was resolved. Every stop condition now lives in one advance() rather than being repeated per stage: a condition repeated four times is one that will be missing from the fourth.

first_pass_rate() is untouched — it already counts only reviews with a terminal verdict, so a blocked implementation never enters the sample.

Tests

387 (was 373). The ones that matter:

  • the block survives the envelope: escaped in the fixture, parseable after unwrapping, CHANGES_REQUESTED recovered;
  • a dispatch carries what the agent said, with the events stripped;
  • an unrecognised envelope passes through whole;
  • an implementation reporting BLOCKED stops the cycle with zero reviewer dispatches, while its dispatch row still reads succeeded and the reported status is recorded beside it;
  • a status the store cannot hold does not reach it, and the closing row is still written;
  • installed level: the fake agents now write their CLI's real envelope, so tests/test_installed_cycle.py exercises the exact shape the canary broke on — including the blocked-implement case end to end, and Codex reporting no model at all, which the live run showed and the test now asserts instead of pretending otherwise.

Verification

  • python3 -m unittest discover -s tests — Ran 387 tests ... OK.
  • python3 scripts/validate-package.py — VALID.
  • Both extractors run against the live captures: Codex yields the block alone; Claude's result yields text whose block parses.

After this

Repeat the canary. The acceptance criterion is no longer "three rows" but: a real implement produces a readable structured result; if IMPLEMENTED, a real review follows with a readable verdict; if BLOCKED, that is recorded and no review appears. Only then does counting to ten start.

A canary against the real CLIs found three things no fake could. The driver read
the raw stdout of each executor as if it were the reply. Claude wraps its reply
in one JSON object under `result`, so the block arrived with its newlines and
quotes still escaped: read_structured_result located ORCHESTRATION_RESULT and
then failed to parse it, and a review that had correctly reported BLOCKED was
recorded as no verdict at all. Codex wraps its reply in NDJSON `agent_message`
items, the same problem one format further away. The fakes had printed the block
as plain text, so every test passed while nothing worked.

Each adapter now unwraps its own envelope into agent_output and the driver reads
that. Neither the driver nor the next executor to be added learns what `result`
or `item.completed` mean. Both extractors were written against live captures,
not by assumption, and those captures are the fixtures. The fake agents write
their CLI's envelope too, so the installed cycle exercises the real shape --
including Codex reporting no model at all, which a live run showed and the test
now asserts instead of pretending otherwise.

Second: a structured result now distinguishes readable, present-but-unreadable,
and absent. One None for all three meant a cycle recorded "no verdict" for a run
that was explicitly blocked. A status outside the store's vocabulary is treated
as no status rather than carried to record_verdict, where it would raise and end
the run without its closing row.

Third, and the one that matters for the data: a dispatch that returned is not a
stage that worked. The canary had Codex exit 0 having changed nothing -- the
work item did not exist -- and the cycle went on to review it. Those are two
facts about different layers and the store already keeps them in separate
columns, so outcome stays `succeeded` and the reported status is recorded beside
it. What changed is that a stage whose own report is not a completion stops the
cycle. Every stop condition now lives in one place rather than being repeated
per stage; one repeated four times is one that will be missing from the fourth.
@datacas

datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner Author

Review summary

Reviewed the accumulated diff from origin/main to 367d4b7ec9ee444182294a48f45972ed54df13d5 for PR 14, covering the executor output adapters, cycle-driver stop semantics, fake CLI envelopes, tests, documentation, and skill text. The scope matches the PR description and the repository has no linked issue or prior review threads.

The change fixes the reported envelope-parsing and functional-stop defects, but the normalized output path still drops valid results from sufficiently long agent responses. That is a blocking correctness issue for the cycle driver.

Findings

[REV-001] · high · open · blocks:yes — Structured results can be lost after output truncation

File: scripts/executors.py, line 352

NativeAdapter.dispatch() unwraps the complete agent response, then stores only self.agent_output(stdout)[-8000:]. read_structured_result() subsequently searches only that truncated string. If an agent emits a valid ORCHESTRATION_RESULT block followed by more than 8,000 characters, the opening delimiter is discarded and the cycle treats the response as absent: it records no functional status and stops with HUMAN_INTERVENTION, even though the agent reported a valid completion.

I reproduced this with a successful Codex-shaped item.completed response containing a valid IMPLEMENTED block followed by 9,000 characters. The observed result was agent_output_chars=8000, reported_present=False, and reported_status=None.

Preserve the full normalized text for structured-result parsing, or locate and extract the structured block before applying a bounded diagnostic-output limit. Keep any truncation separate from the authoritative result path.

Security triage

Sensitive change: the diff handles executor authentication evidence, subprocess execution, environment-derived credential paths, and untrusted CLI output parsing. The security audit reviewed those trust boundaries and found no confirmed security vulnerability in the changed code. No secrets were exposed in the review.

Verification

Executed:

  • python3 scripts/validate-package.py — VALID: 12 skills (6 cycle, 6 supporting), shared sections in sync, cross-agent manifests aligned.
  • python3 -m unittest discover -s tests -v — Ran 387 tests in 8.514s, OK.
  • git diff --check origin/main...HEAD — passed.
  • Focused runtime reproduction of the truncation case — failed as described in REV-001.

The repository’s preflight had Python 3.10.12 and PyYAML available. A live Codex/Claude dispatch was not rerun because this review environment does not provide a configured live provider session; the fake-envelope and installed-runtime coverage did run.

CI

All four reported PR checks completed successfully:

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

The remote CI gates are green, but they do not cover a response whose structured block is followed by more than 8,000 characters.

Residual risk

The new live-envelope fixtures and installed-cycle tests cover the normal Codex and Claude response shapes. Long or unusually verbose successful responses remain at risk until the bounded-output parsing path is corrected.

Verdict

CHANGES_REQUESTED — resolve REV-001, then rerun the focused regression and full suite.

agent_output was capped at 8000 characters, so a reply that carried on past its
own structured block lost the block's opening delimiter with the tail. The cycle
then recorded a completed stage as having reported nothing, and stopped with
HUMAN_INTERVENTION on a run the agent had finished. Reproduced: a valid
IMPLEMENTED block followed by 9000 characters gave agent_output of exactly 8000,
present=False, status=None.

Two different jobs shared one string. The tail in artifacts is diagnostic and
stays cut to 4000; agent_output is the authoritative result path and is now
whole. It costs nothing to keep -- the full stdout is already in memory at that
point -- and a limit on it is a silent deletion of valid results.

Three tests: a long reply keeps its result, the diagnostic tail stays bounded
while the parsed text does not, and the same case end to end through the cycle.
Two of them fail against the previous version.
@datacas

datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner Author

Resolution summary

Reproduced against 367d4b7 before editing, fixed in 5538dcd.

[REV-001] · high · resolved · valid · blocks:yes — Structured results can be lost after output truncation

Valid, and self-inflicted: the [-8000:] was introduced by this very PR. Reproduced exactly as reported — a valid IMPLEMENTED block followed by 9,000 characters gave agent_output of exactly 8000 characters, present=False, status=None. A stage the agent had completed would have been recorded as having reported nothing and stopped the cycle with HUMAN_INTERVENTION.

Worth naming the shape of the mistake, because it is the one this PR was fixing one layer up: two different jobs were sharing one string.

  • artifacts["stdout"] is diagnostic — what a person reads afterwards. Bounding it keeps a result small, and it stays cut to 4,000.
  • agent_output is the authoritative result path — what the caller parses its answer out of. A limit on it is a silent deletion of valid results.

So it is now kept whole. That costs nothing: the complete stdout is already in memory at that point, and agent_output is transient — read once by whoever drives the stage and never stored.

Also worth saying plainly: the case is not exotic. A block followed by a summary, next steps or a closing paragraph is what an agent ordinarily writes, and my original comment claimed truncating "after" unwrapping was the safe order. It was safe against cutting the envelope mid-token, and unsafe against exactly this.

Regression tests

Three, two of which fail against the previous version (verified by restoring scripts/executors.py from 367d4b7: Ran 125 tests … FAILED (failures=2), OK with the fix):

  • a reply that keeps talking past its own block keeps its result — agent_output is the full length and still contains the delimiter;
  • the diagnostic tail stays bounded at 4,000 while the parsed text does not, so the fix cannot be "fixed" later by removing both limits;
  • the same case end to end through run_cycle: the implement stage reports IMPLEMENTED, the review follows, and the row carries the status.

The third one passes both ways by design — it pins the bound that must stay.

Verification

  • Before: agent_output chars: 8000 of 9089, present: False, status: None.
  • After: agent_output chars: 9089 of 9089, artifacts stdout chars: 4000, present: True, status: IMPLEMENTED.
  • python3 -m unittest discover -s tests — Ran 390 tests ... OK (was 387).
  • python3 scripts/validate-package.py — VALID.
  • CI on 5538dcd — all four checks pass, none pending, failed, cancelled or skipped.

Sensitivity triage

Agreeing with the review's audit. The change removes a truncation from a transient string and executes nothing new; no data crosses a boundary it did not cross before. No audit finding.

Residual risks

The live fixtures cover one response shape per CLI, captured from real runs. A provider changing its envelope would not be caught by these tests — it would be caught by the next canary, which is what found this class of defect in the first place. The canary rerun is still pending and is the acceptance criterion for this work, not the suite.

Status: RESOLVED — REV-001 closed at 5538dcd.

@datacas

datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner Author

Re-review summary

Re-reviewed the accumulated diff from origin/main to 5538dcd3decd085abacdf1be8e72cd5d65b3cc40, including the change since the previous reviewed head 367d4b7ec9ee444182294a48f45972ed54df13d5. The latest commit separates the authoritative normalized agent_output from the bounded human-facing diagnostic tail in artifacts and adds focused regression coverage.

No new findings were identified.

Previous finding

[REV-001] · high · resolved · blocks:yes — Structured results can be lost after output truncation

File: scripts/executors.py, line 356

Corrected and verified by execution. agent_output is now kept whole, while only artifacts["stdout"] is limited to 4,000 characters. The original reproduction — a valid IMPLEMENTED block followed by 9,000 characters — now produced agent_output_chars=9086, diagnostic_stdout_chars=4000, reported_present=True, and reported_status=IMPLEMENTED.

Current accumulated review

The full merge-base diff remains in scope: executor envelope extraction, structured-result classification, functional cycle stop semantics, installed fake-agent behavior, telemetry-facing stage recording, documentation, and tests. The latest fix is consistent with the stated design: diagnostic output is bounded, but the caller’s authoritative result is not.

Security triage

Sensitive change: the reviewed files handle executor authentication evidence, subprocess execution, environment-derived credential paths, and untrusted CLI output parsing. The security audit found no confirmed vulnerability in the current accumulated diff. No secrets were exposed. The PR has no sensitive-area labels.

Verification

Preflight found Python 3.10.12 and PyYAML available; no database, service, migration, or port prerequisite was required for this repository’s test workflow.

Executed:

  • Original truncation reproduction — passed after the fix: the structured result remained readable while the diagnostic tail stayed bounded.
  • python3 -m unittest tests.test_executors.AgentOutputTests tests.test_run_cycle.FunctionalStopTests -v — 15 tests, OK.
  • python3 scripts/validate-package.py — VALID: 12 skills (6 cycle, 6 supporting), shared sections in sync, cross-agent manifests aligned.
  • python3 -m unittest discover -s tests -v — Ran 390 tests in 8.182s, OK.
  • git diff --check origin/main...HEAD — passed.

An authenticated live Codex/Claude dispatch was not rerun in this environment; the live-envelope fixtures and installed-runtime tests cover the observed provider shapes.

CI

Current PR checks are all completed successfully, with no pending, failed, cancelled, or skipped gates:

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

Residual risk

Provider behavior outside the captured Codex and Claude envelope shapes remains an external integration risk, but an unrecognized envelope is deliberately passed through and results are now no longer truncated before parsing.

Verdict

APPROVED — REV-001 is resolved and verified; no open finding blocks approval.

@datacas
datacas merged commit 0343e31 into main Sep 21, 2026
4 checks passed
@datacas
datacas deleted the feat/agent-output branch September 21, 2026 21:46
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