Feature design: verification-failure self-correction loop #174
Labels
No labels
4-29
bug
documentation
duplicate
enhancement
flow improvement
good first issue
help wanted
invalid
investigating
issue-agent
issue-agent-blocked
issue-agent-complete
issue-agent-pr-open
issue-agent-runner-nelsonlaptop
issue-agent-runner-nelsonpc
issue-agent-runner-nelsonpc-user
issue-agent-running
needs-verification
next to do
question
queue
recon
relics-stats-onboarding
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
romaine-life/spirelens#174
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
When the issue-agent's own verification phase aborts with a fixable failure, the agent should re-enter the implementation phase automatically with the verification artifact as feedback, rather than dumping the diagnostic and waiting for a human to re-trigger or comment. This is the loop that defines "agentic" in the modern sense — AlphaCode, Devin, Cursor agent mode, Aider all have some form of it.
This issue is a design doc, not an implementation. Phasing at the bottom calls out an MVP slice that's useful on its own.
This is the prerequisite for the PR-comment-driven revise loop in #173 — the verification-failure loop covers self-correction before a PR is opened, the comment loop covers human-in-the-loop iteration after. Build this one first; both are useful, but a non-self-correcting agent escalates fixable failures to the human and never gets the work done.
Concrete trigger that motivates this
Run 25178505492 on issue #142 aborted with
claimed_result_not_observed: the verification phase honestly readvigor gained: 88from the screenshot and the wrapper rejected it (the newexpected_textcontract from #172 working as designed). The agent's ownissue-agent-verification.mdeven sketched the likely root cause:That's enough information for an implementation re-attempt to plausibly fix the bug. Today the run just aborts. This is exactly the gap the self-correction loop closes.
What's already in place
The schema is half-supported by today's contracts:
retryable: true|falsefield — designed exactly for this.unit_tests_failed,target_evidence_missing,claimed_result_not_observed,screenshot_not_relevantscenario_setup_failed,mcp_state_mismatch,game_state_unreachable,metadata_unavailable,mcp_capability_missingvalidation_plan_impossible,change_too_large,requires_architecture_change-test-plan,-implementation,-verification) already get distinct names — adding a-attempt{N}suffix is mechanical.What's missing
Workflow loop control. After verification, the wrapper has to branch on
(status, abort_reason, retryable, attempt < max_attempts). If retryable + impl-fixable + budget-left, jump back to implementation with the verification artifact as additional input. Today the workflow is a strict DAG.Implementation prompt awareness of priors. "You've tried this before, here's what failed and why" — the agent must read the prior attempt's
verification.json,evidence_results,observed_text, andabort_reason, and produce a different implementation. Without this it'll just repeat the same code. The prompt needs an explicit "do not produce the same change as last attempt" rule plus structured access to the prior attempt's artifacts.Iteration ledger. Each attempt needs distinct artifacts (
-attempt1,-attempt2, etc.), and the PR description / final summary needs to show the trail: "attempt 1 failed at unit_tests_failed (test X failed because Y), attempt 2 fixed X but failed verification at target_evidence_missing, attempt 3 passed."Test-plan revision (defer to v2). Sometimes the test plan is wrong, not the implementation (e.g. an unrealistic
expected_textthat the implementation can't physically satisfy because the contract was loose-translated wrong). The pure implementation-loop can't fix that — needs an escalation: after N implementation retries against the same test plan, escalate to a plan-revision phase. More complex; leave for v2.Budget caps. Per-attempt budget envelope (existing
MaxBudgetUsdper phase) plus a per-run cumulative ceiling. Today's $15-per-phase cap × up to 4 phases × multiple attempts can blow up cost. Default cumulative cap proposal: $25 per issue (3-4 attempts at typical phase costs)."Same vs new branch" decision. Each attempt could push another commit to the same branch (preserving history) or rebase (clean diff). Recommendation: same branch, additive commits — that's how a real engineer would work, and it gives the next attempt's prompt access to the diff history of prior attempts as additional context.
MVP slice
Cleanest first cut:
max_implementation_attemptsworkflow input (default2).verification.json. Ifstatus=abort && retryable=true && abort_reason ∈ {unit_tests_failed, target_evidence_missing, claimed_result_not_observed, screenshot_not_relevant}ANDattempt < max, set an env flag and re-run implementation + verification with the prior verification artifact in the prompt.prior_verification.jsonexists, read it first; treat itsabort_reasonandnotesas your top priority. Do not produce the same change as last attempt — diff what you write against the existing branch and reject if identical." rule.-attempt{N}suffix (path or filename — TBD).Estimate: ~2 days at our recent pace.
Full feature
Cross-cutting
Get-ExitCodeTextandGet-ClaudeCostSummaryaggregations need to roll up across attempts.max_attemptsattempts fail, the run aborts cleanly. Issue gets a comment with the trail. No PR opened.Risks
max_attempts=5and watch a single issue eat $50. The default cap should be conservative.Decisions to make before starting
max_implementation_attempts(proposal: 2).max_implementation_attemptsas a per-issue label (e.g.agent-max-attempts:3) or only as a workflow-default input.Closing during repository issue cleanup. If this becomes active work again, we can reopen or recreate it as a fresh, specific task.