feat(loop): enforce driver one-shot contract — post-exit verify + debris classifier + tests (#111) - #118
Merged
Conversation
…sifier (#111) Two incident classes wedged the autonomous PR loop: a driver backgrounding its orchestrator and ending its turn early left half-born feat/issue-N-* branches with a phantom rc=0 ledger success (issues #91/#92), while a naive "delete debris" fix risked destroying gates-green, unpushed work (recovered manually as PR #117 for issue #107). loop-daemon.sh: run_driver now forces CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS=0 (overridable) on the driver spawn so a backgrounded orchestrator fails fast instead of half-completing. After every advance-verdict driver exits (skipping timeouts/spawn-errors), verify_and_classify_post_exit queries an open PR for the issue via bot-gh.sh, corrects a naive `result=exit rc=0` to `result=phantom rc=0` when none exists, and calls the new pure-git classify_debris (empty / publishable / half-done / absent) to decide whether cleanup is safe. Only the provably `empty` + no-PR case is ever destructive (branch + worktree deleted); publishable/half-done work is always left untouched. A failed/ offline bot-gh.sh degrades to `verify=skipped` and takes no action. Adds 47 new/updated assertions across loop-daemon.test.sh (classifier unit checks + full-fixture phantom/Case-A-delete/Case-C-safety/offline-degrade scenarios) and loop-event.test.sh (regression guard for the one-shot contract clauses in both the advance and feedback driver prompts).
robercano
approved these changes
Jul 15, 2026
This was referenced Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
First scoped slice of #111. The autonomous PR loop was wedged twice by drivers that ended their headless one-shot turn without a published result:
feat/issue-N-*branches,rc=0phantom success in the ledger, census read the local branches asin_flightand skipped the issues.This slice adds post-exit verification and a debris CLASSIFIER (not a blind deleter) at the driver post-exit boundary in the daemon.
Changes (all within
.claude/, module: harness)run_driverexportsCLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS=0(overridable) so backgrounded work dies loudly instead of half-completing.classify_debris <branch> <worktree_dir>(pt 2): deterministic, pure-git, network-free →empty | publishable | half-done(absentfor a missing branch). Shares states with Loop: failure classification + crash-resume for dead workers (the recovery half of loop-health) #98's classifier.verify_and_classify_post_exit(pt 1): foradvance issue=Nverdicts with a non-timeout rc, queries GitHub viabot-gh.shfor the issue's open PR; recordspr=<n>; rewritesresult=exit rc=0→result=phantomwhen rc=0 but no PR exists. Offline/failedbot-gh.shdegrades toverify=skippedwith zero destructive action.empty+ no PR +feat/issue-N-*branch → delete branch + worktree (action=deleted). This is the only destructive path, reachable solely on the provably-empty state.publishable/half-doneare never deleted (half-done→resumable).result=… [pr=…] [debris=…] [action=…];run_driver's return-code contract is preserved.Tests
loop-event.test.sh(23→29): regression guards asserting the ADVANCE and FEEDBACK driver prompts contain the three one-shot contract clauses (foreground-only spawn, "do NOT end your turn until the work product exists on GitHub", delete-debris-on-failure) — guards hotfix d37e951.loop-daemon.test.sh(22→47): behavioralCLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS=0assert; phantom (rc=0 + no PR →result=phantom);classify_debrisunit tests (empty/publishable/half-done/absent, real git fixtures); Case A actual branch+worktree deletion; Case C safety (nothing deleted, branch survives,resumable); offlinebot-gh.sh→verify=skipped.Gates
.claude/self/gates.json: build / lint / test (checks.sh + smoke-fanout) all green. Reviewer lenses (correctness=opus, tests=sonnet, consensus=all) both APPROVE; the tests reviewer mutation-tested the Case A/C/phantom assertions to confirm they bite.Deferred (follow-ups)
publishable; execution deferred.claude --resume— belongs to Loop: failure classification + crash-resume for dead workers (the recovery half of loop-health) #98 by the issue's scope note.half-doneworktrees (currently recorded/resumable, never auto-committed).Closes #111