Skip to content

Verification gate: a thread only goes green once its verify command exits 0 (#296) - #331

Merged
currentbits merged 11 commits into
mainfrom
coder/verification-loop-agents-must-prove-thei-3f9cdf
Aug 17, 2026
Merged

currentbits merged 11 commits into
mainfrom
coder/verification-loop-agents-must-prove-thei-3f9cdf

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Closes the implementation for #296. Today a thread lands done because the agent said it was done. This adds a verification stage distinct from review: the run has to prove it.

Shape

A thread carries a verifyCommand (a shell string, e.g. npm test). When it is set, a run that would land done instead runs that command in the thread's worktree — after the turn checkpoint, so the evidence pins to a sha that already exists.

  • Exit 0 → the thread goes green and the VerifyResult is stored as evidence.
  • Non-zero → the thread does not go green. The agent is handed a structured bundle as a new turn: the command, exit code or timeout, the checkpoint sha, "fix attempt N of M", the log tail, and an instruction to state a root-cause hypothesis, fix the cause, and re-run the command itself. Up to MAX_FIX_ATTEMPTS (2) hand-backs, after which the thread lands failed with a lastError naming the command — which badges the sidebar and arms "Retry turn".
  • Unarmed (no command) → nothing changes; runs settle exactly as they do today.

Why no new ThreadStatus

A verifying thread stays working. The ask is a gate, not a fourth colour, and a new status would have meant touching every switch in the sidebar, settle and waiting logic for no user-visible gain. It is still working — it just has to finish the proof before it can claim it is done.

What changed

  • electron/verify.js (new) — the engine. Spawns under /bin/sh -c, detached, 10-minute timeout escalating through killTree, log tail capped in flight and at rest, plus buildFixPrompt for the failure bundle. Never rejects: "could not run the tests" is a verification failure like any other, not a crash of the run lifecycle.
  • electron/runner.js — the gate lives in afterSuccessfulTurn, the single choke point every provider (generic, claude, codex, kimi, opencode, workflow) lands through, so no provider path can settle around it. Fix turns are delivered exactly the way orchestrator wake-ups already are, including the catch that lands failed when a turn cannot be delivered at all.
  • electron/store.js / services.js / ipc.js — persistence for verifyCommand and verify, plus threads:setVerifyCommand and threads:runVerify (a manual "Verify now" that rejects while a run is active).
  • src/shared/ipc.ts — the VerifyResult contract: outcome, exit code, timed-out flag, log tail, pinned sha, duration, attempt.
  • Environment tab — a Verification card: the command input, a Verify now button, and the evidence (pass/fail, exit or timed out, duration, age, short sha) with the log collapsed on a pass and expanded on a failure, since a pass needs no reading and a failure is the whole point.

Review notes

Three defects were caught reviewing the slices before merge, each fixed in its own commit:

  • The retry bound was off by one, so the agent got one fix turn while the prompt told it "attempt 1 of 2" — the gate was misreporting its own budget.
  • runStartedAt is cleared at the run terminal, so flipping back to working for the command left the sidebar showing "Working" with no elapsed time for however long the suite ran.
  • The HEAD lookup used execFileSync, blocking the main process on a git call every gated turn — the same freeze the PR refresher was rewritten to avoid. Now async, sharing the helper the services layer already uses.

Tests

core 38/38 · renderer 795/795 · memory 122/122 · electron 918/919. The single electron failure is the pre-existing web-integration reconnect test, unchanged from main's baseline.

Not in scope

Embedded-browser click-through (#155) and screenshots/videos as run artifacts (#244) both depend on unlanded work; evidence here is the command's log tail. VerifyResult is where artifact ids attach once #244 has somewhere to put them. Thread goals declaring required outputs up front (#238) would replace the single command with a contract without changing the gate's shape.

  • PR created by the Claude Code agent

Willem and others added 10 commits August 17, 2026 18:02
Shared contract so the backend, runner and UI can be built in parallel:

- ipc.ts: ThreadInfo.verifyCommand / .verify, VerifyResult, and the
  threads.setVerifyCommand / threads.runVerify channels.
- electron/verify.js: the engine — normalizeCommand, tailLog,
  runVerifyCommand (spawn + timeout + killTree + capped log tail) and
  buildFixPrompt (the structured failure bundle handed to the fixer).
- devCoder/wireClient: dev-twin and wire client kept in sync.

No gate is armed yet; runner wiring and persistence land next.

Co-Authored-By: Claude Opus 5 <[email protected]>
…into coder/fork-verification-loop-agents-must-prove-d668f4
…into coder/fork-verification-loop-agents-must-prove-e15d93
…yNow IPC

Store migration and createThread default the gate to unarmed. The setter
normalizes via the shared engine and does not bump updatedAt. runVerifyNow
stores VerifyResult evidence (runId "manual") and refuses an active run.
A thread with verifyCommand no longer lands done on the agent's word.
afterSuccessfulTurn runs the command after the checkpoint, stores the
VerifyResult as evidence, and either goes green, hands a fix turn back,
or lands failed once MAX_FIX_ATTEMPTS is exhausted.
…into coder/verification-loop-agents-must-prove-thei-3f9cdf
Two fixes on the merged runner gate:

- The hand-back bound was `attempt + 1 < MAX_FIX_ATTEMPTS`, so the agent
  got one fix turn while buildFixPrompt told it "Fix attempt 1 of 2".
  Now `attempt < MAX_FIX_ATTEMPTS` — the prompt's count is the real one.
- runStartedAt is cleared at the run terminal, so flipping the thread back
  to "working" for the verify command left the sidebar showing "Working"
  with no elapsed time. Restamp on entry, clear on every settle path.

Co-Authored-By: Claude Opus 5 <[email protected]>
Let a thread declare its prove-it command and read the latest evidence
on the Environment tab. Emptying the field disarms the gate.
…into coder/verification-loop-agents-must-prove-thei-3f9cdf
The runner slice grew its own worktreeHeadSha using execFileSync, which
blocks the main process for a git call on every gated turn — the freeze
the PR refresher was rewritten to avoid. Use the async gitTryAsync helper
the services slice already reaches for.

Co-Authored-By: Claude Opus 5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

…op-agents-must-prove-thei-3f9cdf

# Conflicts:
#	src/wireClient.ts
@currentbits
currentbits merged commit 9bc04e8 into main Aug 17, 2026
1 check failed
@currentbits
currentbits deleted the coder/verification-loop-agents-must-prove-thei-3f9cdf branch October 3, 2026 16:07
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