Skip to content

fix(runtime): keep dispatched Claude stages in the foreground - #297

Merged
datacas merged 1 commit into
mainfrom
task-276
Oct 21, 2026
Merged

datacas merged 1 commit into
mainfrom
task-276

Conversation

@datacas

@datacas datacas commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

Keep dispatched Claude -p stages from ending while Bash commands are still running. A PreToolUse hook rejects background Bash calls and configured verification calls with a timeout below 10 minutes. Claude receives the 10-minute Bash default and maximum through its dispatch settings, and every dispatched stage prompt tells it to wait for verification. When a stage still exits with evidence of a pending command, the runtime names that detail under unreadable_result.

Closes #276

Diagnosis

The reported symptom is a Claude -p stage returning without a structured result while its verification command continues in the background. The issue reports two reproductions during PR #273 rereview. The reproduced mechanism matches the hypothesis: Claude's Bash default foreground timeout is shorter than the configured full test suite, and ending the -p turn prevents later output from being collected. The invariant is that a dispatched stage must not finish while one of its commands is pending. This is an isolated defect in Claude stage dispatch. Related search was widened because the issue is a bug describing a runtime symptom; related items are #130 (closed, host background-task limits) and #274 (closed, slow sandbox verification). Neither changes the root cause addressed here.

The branch tests cover the configured 10-minute timeout settings, refusal of background and low-timeout verification calls, a structured result after a configured verification call, and confirmed/suspected pending-command diagnostics. The live reproduction described in the issue was not rerun in this implementation attempt.

Work units

Unit Behaviour Files Tests Verification Rollback
WU-1 Keep dispatched Claude verification in the foreground and report pending-command evidence scripts/executors.py, scripts/run_cycle.py, scripts/stage_permissions.py, skills/cc-verify/SKILL.md tests/test_dispatch_failures.py, tests/test_stage_dispatch.py, tests/test_stage_permissions.py python3 -m unittest discover -s tests (1,652 tests, pass); python3 scripts/validate-package.py (pass); python3 -m unittest (0 tests discovered, exit 0) independent — revert this commit to restore the previous dispatch behavior

Verification environment

The local discovery suite and package validator passed in this checkout. Local runs use the checkout's Python environment; CI runs on the pushed head provide the clean-runner result. No dependency or CI configuration changed.

Checks

Head bfbb308d7b411790df9d321826bf6ee7d6c32766:

Check State
Skills, manifests, and Bash installer pending
Windows test shard (windows-1) pending
Windows test shard (windows-2) pending
Windows test shard (windows-3) pending
Windows test shard (windows-4) pending

Hook refuses run_in_background and low-timeout configured verification for every claude -p stage (minimal Bash-only hook off GitHub), fixed 10-minute Bash timeout via dispatch settings env, foreground prompt note, background_command_pending diagnostic with confirmed/suspected evidence.

Closes #276
@datacas

datacas commented Oct 21, 2026

Copy link
Copy Markdown
Owner Author

[CCR-20261021-001] · reviewer · anthropic/claude-sonnet-5-5→? · high · schema:2

Initial review — PR #297 (work item 276)

Status: REVIEW_PASSED_AWAITING_CI — head bfbb308d7b411790df9d321826bf6ee7d6c32766 fully reviewed (accumulated diff, merge base 15bc4b67d8475b9bba7adc90c600d07a31a71d9a, 508 lines, 6 source/test files + 1 skill doc). No open finding blocks approval. This is not an approval: the PowerShell installer check is still pending and the cycle's CI gate decides.

Summary

The change keeps dispatched Claude -p stages in the foreground: a PreToolUse hook denies run_in_background Bash calls and configured verification calls with timeout < 600000 ms; Claude's dispatch settings set BASH_DEFAULT_TIMEOUT_MS/BASH_MAX_TIMEOUT_MS to 600000; every stage prompt carries the foreground rule; a stage that exits unreadable with pending-command evidence names background_command_pending in the unreadable_result detail. The behaviour matches the issue's hypothesis and the PR description. The previously active command table is unchanged (the new background/timeout checks are an added deny ahead of it); inactive (non-GitHub) policies now get a Bash-only hook that does no table check and does not touch file edits.

Findings

[REV-001] · low · open · - · blocks:no — Foreground prompt text names Claude for every executor

scripts/stage_permissions.py (prompt_note), scripts/run_cycle.py (compose)

compose now appends prompt_note for any non-None policy, and it is composed before the target executor is known. A Codex stage (and any other executor) now receives "This is a dispatched Claude -p stage … return an explicit BLOCKED result with the timeout reason" even though the Bash-timeout settings, hook, and 10-minute limit only exist for Claude dispatches. Previously an inactive policy added nothing. Impact is prompt noise and a possible spurious BLOCKED on another executor; no code path breaks. Consider wording the note executor-neutrally ("a dispatched non-interactive stage") or composing it only for Claude.

[REV-002] · low · open · - · blocks:no — Unrelated whitespace regression in FILE_EDIT_TOOLS

scripts/stage_permissions.py:~468

FILE_EDIT_TOOLS ={"Edit": … lost the space before { and the continuation line is now misaligned. Cosmetic only, outside the change's scope; restore FILE_EDIT_TOOLS = {.

Security triage

No security_review.always_when rule is declared in .code-cycle.yml, so the defaults applied. The diff touches the stage command-policy hook (scripts/stage_permissions.py, scripts/executors.py hook settings), an authorization boundary; I therefore reviewed it for security impact inline rather than skipping it (the dedicated cc-security-review pass was not run as a separate delegate). Result: no vulnerability found. The change only adds a deny (background Bash, low-timeout verification); the active-table path is otherwise unchanged; hook errors still fail closed (deny); the inactive-policy hook leaves Bash and file edits to the executor exactly as before (previously no hook ran). The timeout check ignores non-integer timeout values, which is acceptable because it is a reliability safeguard, not a security control.

Commands executed and results

Command Result
python3 -m unittest discover -s tests pass: Ran 1652 tests in 319.252s — OK (exit 0)
python3 scripts/validate-package.py pass: VALID: 16 skills (7 cycle, 9 supporting), shared sections in sync, cross-agent manifests aligned

python3 -m unittest (third configured command) was not run separately: it discovers 0 tests per the PR description and duplicates the discovery run above.

Unverified

  • The live reproduction from the issue (a real claude -p stage running a >2-minute suite) was not rerun; the hook, settings, and diagnostics are covered by unit tests and code inspection only.
  • Whether Claude Code honours BASH_DEFAULT_TIMEOUT_MS/BASH_MAX_TIMEOUT_MS from the --settings env block was not observed at runtime.

CI (policy: parallel, read once, not waited)

Check State
Skills, manifests, and Bash installer pass
Windows test shard (windows-1) pass
Windows test shard (windows-2) pass
Windows test shard (windows-3) pass
Windows test shard (windows-4) pass
PowerShell installer pending

Residual risks

A configured suite that genuinely exceeds 10 minutes is killed by Claude's Bash timeout and reported as BLOCKED; this is documented behaviour. The suspected pending-command heuristic is a text match on the final message and only affects diagnostic wording.

Verdict

Review complete for head bfbb308d7b411790df9d321826bf6ee7d6c32766; no blocking findings. REVIEW_PASSED_AWAITING_CI — the CI gate must wait for the pending checks.

@datacas
datacas merged commit a1afafd into main Oct 21, 2026
6 checks passed
@datacas
datacas deleted the task-276 branch October 21, 2026 08:42
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.

A dispatched Claude stage ends its turn while its test suite still runs in the background, leaving no result

1 participant