Skip to content

approvals: implement the lifecycle that outlives the run (ADR-0029) - #12

Merged
glaborie merged 9 commits into
mainfrom
feat/approval-resume
Nov 8, 2026
Merged

glaborie merged 9 commits into
mainfrom
feat/approval-resume

Conversation

@glaborie

@glaborie glaborie commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Implements ADR-0029 (#11). Six commits, one per layer.

The invariant, tested first: a deferred policy raises before _run_tool on every path, including the parallel one. The run ends pending_approval with RunResult.pending carrying the id, and the tool has not run — test_a_deferred_approval_stops_before_the_tool_runs asserts the side-effect counter is empty.

How resume works: resume_run(spec, run_id, approved=…, approver=…) refuses an unknown run, a subagent, a run that is not suspended, an already-answered approval, and one whose stored arguments no longer match their SHA-256 digest (an edited request cannot become a different approval). It then records the verdict once under BEGIN IMMEDIATE, rebuilds the transcript from log.messages() + the system prompt, re-runs on_tool_call — the post-transform arguments are deliberately never logged (ADR-0025), so this is how resume recovers what would have executed — executes only the calls with no tool_result, and re-enters the same step engine at first_step = model calls + 1.

That last part is the riskiest edit: the step loop moved out of run_agent into _drive(...), which both run_agent and resume_run call. It was lifted verbatim by script, and the 379 pre-existing tests still pass unchanged.

Surfaces: harness approvals / harness approve <manifest> <id> [--deny] [--as NAME] (a suspended run exits 3), and GET /api/approvals / POST /api/approvals/{id} behind the existing bearer token.

Honest limits, all in the ADR and the threat model:

  • approver is a self-declared label. Authority is possession of the channel (token or terminal); the harness has no accounts and no doc claims an identity.
  • Silence expires into a denial at RIGGING_APPROVAL_TTL_S (24h default), even if the caller says yes.
  • Root runs only; a suspending subagent is a different problem.
  • Two Langfuse traces share one run_id after resume — OTLP cannot hold a span across processes.
  • The wall-clock budget restarts at resume; waiting for a human is not the run's time.

17 tests added (11 lifecycle, 2 CLI, 1 service, plus the route-list update). ruff + mypy --strict clean; 390 offline tests green.

@glaborie
glaborie merged commit 60461e0 into main Nov 8, 2026
6 checks passed
@glaborie
glaborie deleted the feat/approval-resume branch November 8, 2026 11:14
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