Skip to content

Show the reason the agent gave for stopping - #16

Merged
datacas merged 2 commits into
mainfrom
feat/reported-reason
Sep 21, 2026
Merged

datacas merged 2 commits into
mainfrom
feat/reported-reason

Conversation

@datacas

@datacas datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner

Why

A canary stopped with this and nothing else:

datacas/code-cycle-toolkit 15: HUMAN_INTERVENTION
  implement cheap_coder    codex   succeeded
  stopped: the implement reported BLOCKED

The agent had explained itself in its own structured block. That explanation died with the process, so finding out what it said cost three more dispatches. The status was recorded correctly and the one thing an operator needs in order to act was dropped.

Now:

  stopped: the implement reported BLOCKED
  reason:  GitHub authentication is invalid and the GitHub API is unreachable

Scope

CycleReport.reason is taken from the block's error, summary, blocking_reason or reason, in that order — error first, because that is what a blocked skill fills in while summary may describe the run rather than the failure. It is whitespace-collapsed to one line so the report stays readable at a glance.

It travels with every ending, not only the bad ones: a run that reached APPROVED still said something about how.

Two things it deliberately is not

It is not stored. Telemetry holds references, counts and closed-vocabulary tokens — not prose. A test writes a reason containing a credential-shaped sentence and asserts no row anywhere contains it, while the BLOCKED status is still recorded.

It is not a fact. The same canary reported "GitHub authentication is invalid and the GitHub API is unreachable" — and from the same sandbox, the same directory, minutes later, gh api user returned datacas, gh issue view 15 returned the issue, and gh auth status showed a valid token. The agent's report was well-formed and wrong.

Showing it is what made that checkable. Believing it would have sent somebody to read a status page. So nothing branches on it, and a test asserts a completed stage still completes however alarming the prose beside it is.

Tests

Nine. The reason reaches the operator and appears in the report; error wins over summary; a block without one behaves exactly as before; an unreadable block has no reason to give; a multi-line reason stays on one line; a non-string, empty or whitespace reason is not a reason; the prose never reaches the store; and the reason decides nothing.

One of them found a real gap while being written: the reason was attached only where a stage stopped, so a cycle that reached APPROVED carried none. That is why it now travels with every ending.

Verification

  • python3 -m unittest discover -s tests — Ran 399 tests ... OK (was 390).
  • python3 scripts/validate-package.py — VALID. Its privacy scan caught a real repository name in one of the new tests; replaced with owner/api.

After this

Canary 4, one run. If it blocks again the reason will be on screen without paying for a second call, and only then is it worth investigating why cc-implement-issue declares itself blocked. Issue #15 stays open until that is settled.

A canary stopped with `the implement reported BLOCKED` and nothing else. The
agent had explained itself in its own structured block -- and that explanation
died with the process, so working out what it said cost three more dispatches.
The status was recorded correctly; the one thing an operator needs to act was
dropped.

CycleReport now carries the reason from the block's error, summary,
blocking_reason or reason, and prints it under the status. It travels with every
ending rather than only the bad ones: a run that finished still said something
about how.

Two things it deliberately is not. It is not stored: telemetry holds references
and counts, and a test asserts the prose never reaches a row. And it is not a
fact -- the same canary reported "GitHub authentication is invalid and the
GitHub API is unreachable" while gh returned the user, the issue and the remote
from the same sandbox, the same directory, minutes later. Showing it is what
made that checkable; believing it would have sent somebody to read a status
page. Nothing branches on it, asserted by a test.

Nine tests. One of them found a real gap while being written: the reason was
only attached where a stage stopped, so a cycle that reached APPROVED carried
none.
@datacas

datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner Author

Review summary

Reviewed PR 16 at head 791e064bec7ec1206fcff9dbf8e3d86bb0d8a4f5 against base 0343e31afed7bb9fa8a5fcbfba10e03248e163cd. The accumulated change adds operator-visible reasons from structured agent results, keeps those reasons out of telemetry, and adds focused tests and documentation. The PR body references open throwaway issue #15, but no closing issue is linked through GitHub metadata.

The core reporting behavior works, but the new output path treats untrusted agent prose as terminal-safe text. That creates one blocking security finding.

Findings

[REV-001] · medium · open · blocks:yes — Untrusted reason text reaches the terminal unsanitized

File: scripts/run_cycle.py, line 187 (rendered at line 234)

Reported.reason accepts any non-empty string from the agent’s error, summary, blocking_reason, or reason fields and only collapses whitespace. CycleReport.explain() then interpolates that value directly into the CLI report. ANSI and other terminal control characters are not whitespace, so they survive into operator-visible output.

I reproduced this with an agent reason containing \x1b[31mspoofed\x1b[0m; the rendered report still contained both ESC characters. A compromised or instruction-injected agent response could therefore recolor, erase, or spoof terminal output seen by the operator.

Sanitize C0/ANSI control sequences before rendering, or encode the reason for terminal-safe display. Keep the existing whitespace normalization and add a regression test covering escape sequences (and preferably a reasonable display-length limit).

Security triage and audit

Sensitive change: the diff adds a trust boundary from agent-provided structured output into operator-facing observability. The security audit reviewed this path and confirmed REV-001. No secrets were exposed during the review.

Verification

Preflight succeeded with Python 3.10.12 and PyYAML available. No database, service, migration, or port prerequisite is required by this repository’s verification workflow.

Executed:

  • python3 -m unittest tests.test_run_cycle.ReportedReasonTests -v — 9 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 399 tests in 13.651s, OK.
  • git diff --check origin/main...HEAD — passed.
  • Focused terminal-control reproduction — confirmed ESC characters remain in CycleReport.explain() output, as described in REV-001.

Live Codex/Claude dispatches were not run in this environment; the repository’s fake-agent and installed-runtime tests were available and passed.

CI

All current PR checks are 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

The reason remains intentionally unpersisted, which limits telemetry and database exposure. Until terminal sanitization is added, operator-facing reports must be treated as capable of containing terminal control sequences.

Verdict

CHANGES_REQUESTED — resolve REV-001 before approval.

The reason an agent gives is printed into an operator's terminal report, and
collapsing whitespace did not make it safe: an escape is not whitespace, so
\x1b[31m survived intact. An agent -- compromised, injected, or merely odd --
could recolour, erase or forge the lines around its own. Reproduced: ESC, BEL
and backspace all reached the rendered report.

The executor's own `detail` had the same hole one line over. It is stderr from
a CLI, exactly as untrusted, printed to the same screen, and it now goes
through the same function.

Control bytes are removed rather than escape sequences recognised. Without ESC
such a sequence is inert text, and that claim holds without keeping a grammar
in step with every terminal that might read the output. The text is also cut to
500 characters: a reason is one line of a report, not a page of it.

Seven tests, five failures and two errors against the previous version. One
asserts every C0 control and DEL is gone by building the string from the
character codes, rather than listing the three that happened to be reproduced.
@datacas

datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner Author

Resolution summary

Reproduced against 791e064 before editing, fixed in a531025.

[REV-001] · medium · resolved · valid · blocks:yes — Untrusted reason text reaches the terminal unsanitized

Valid, and the flaw is precisely in the reasoning I used when I wrote it: I treated " ".join(value.split()) as normalisation, and str.split() only knows whitespace. An escape is not whitespace. Reproduced with the reported payload plus two more controls:

reason repr: '\x1b[31mspoofed\x1b[0m\x07 and \x08\x08\x08gone'
ESC in rendered: True | BEL: True | BS: True

The same hole existed one line over, and the finding did not name it. _why() interpolates result.detail, which is the executor's own stderr or stdout — exactly as untrusted, printed to the same screen:

detail path carries ESC: True

Fixing only the reported instance would have left its twin in place, so both now go through one readable().

Why bytes rather than sequences

I remove every C0 control and DEL instead of recognising ANSI sequences. Without ESC, [31mspoofed[0m is inert text, and that claim holds for any terminal — whereas a sequence matcher has to stay in step with CSI, OSC, DCS and whatever a given emulator also acts on. The visible leftovers are honest: they show the agent sent something odd rather than hiding it.

Also added, as the finding suggested: a 500-character cut with an ellipsis. A reason is one line of a report, not a page of it.

Regression tests

Seven, and against 791e064 the file gives FAILED (failures=5, errors=2); against a531025, OK.

  • the reported payload reaches neither reason nor the rendered report, while spoofed survives as text;
  • every C0 control and DEL is removed — the test builds the string from chr(code) over the whole range rather than listing the three that happened to be reproduced;
  • the executor's detail is cleaned too, through a dispatch that fails with an escape in its stderr;
  • a 4,000-character reason is cut to the limit and ends in an ellipsis;
  • a reason made only of control characters is no reason at all.

Verification

  • Before: ESC, BEL and BS all present in report.explain(); detail likewise.
  • After: reason: '[31mspoofed[0m and gone', no ESC/BEL/BS anywhere in the rendered report, detail likewise, long reason capped at 501 characters including the ellipsis.
  • python3 -m unittest discover -s tests — Ran 404 tests ... OK (was 399).
  • python3 scripts/validate-package.py — VALID.
  • CI on a531025 — all four checks pass, none pending, failed, cancelled or skipped.

Sensitivity triage

This is the security fix, so the audit was repeated against the change itself. It removes characters from strings on their way to stdout and executes nothing new; the reason still never reaches the store, still decides nothing, and the cleaning applies to both untrusted sources. No further finding.

Residual risks

The guarantee is "no control bytes", not "no misleading text". An agent can still write a plausible and false sentence — this PR exists because one did — and the cleaning does nothing about that. That is why the reason is displayed as a claim and nothing branches on it.

Unchanged from the PR body: issue #15 is still open and the IMPLEMENTED → review → verdict chain is still unvalidated live. Canary 4 comes next, and it now costs one run rather than four.

Status: RESOLVED — REV-001 closed at a531025.

@datacas

datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner Author

Re-review summary

Reviewed PR 16 at head a5310256e313f7e90f44a51f930608841c1662e6 against base 0343e31afed7bb9fa8a5fcbfba10e03248e163cd. The previous review covered head 791e064bec7ec1206fcff9dbf8e3d86bb0d8a4f5; the intervening commit addresses its terminal-output finding.

The accumulated change still confines the agent-provided reason to operator-facing reporting: it is not stored in telemetry and does not affect routing or verdict decisions. The new fix applies the same terminal-safe cleaning to executor detail, removes every C0 control and DEL byte while preserving readable text, and caps the displayed reason at 500 characters.

Findings

[REV-001] · medium · resolved · valid · blocks:yes — Untrusted reason text reaches the terminal unsanitized

The finding is resolved in scripts/run_cycle.py. readable() removes C0 controls and DEL, which removes ESC from ANSI sequences before rendering, collapses the remaining text to one line, and limits it to 500 characters. The executor detail path now uses the same helper. The reason remains display-only and is not written to telemetry.

Validation covered the prior ESC/BEL/backspace reproduction, every C0 code plus DEL, executor detail, control-only input, and the length limit. No new findings were identified.

Security triage and audit

This remains a sensitive trust-boundary change because agent output and executor diagnostics reach operator-facing terminal output. The current audit found no new execution, persistence, authorization, secret-exposure, or injection sink. The cleaned value is only rendered; it is not evaluated, dispatched, used for routing, or stored.

Verification

  • python3 -m unittest tests.test_run_cycle.ReportedReasonTests -v — 14 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 404 tests in 12.770s, OK.
  • git diff --check origin/main...HEAD — passed.
  • Runtime control-byte reproduction — ESC, BEL, and backspace absent from CycleReport.explain(); all C0/DEL bytes removed; 4,000-character input capped at 501 characters including the ellipsis.

Live Codex/Claude dispatches were not run in this environment; the repository's fake-agent and installed-runtime tests were available and passed.

CI

All four current check runs for a531025 are completed successfully, with no pending, failed, cancelled, or skipped checks:

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

Residual risk

The displayed reason remains an unverified agent claim and can still be misleading as prose; it is intentionally not treated as a fact. The existing PR-body reference to open issue #15 is unchanged and does not add a finding in this review.

Verdict

APPROVED — REV-001 is resolved and verified; no open blocking findings remain.

@datacas
datacas merged commit 45e341b into main Sep 21, 2026
4 checks passed
@datacas
datacas deleted the feat/reported-reason branch September 21, 2026 22:27
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