Repository navigation
Add human-gate (gate-while-idle, Archetype B) to the leaf-session backend - #14
Merged
Merged
Conversation
added 20 commits
June 28, 2026 12:36
Design for the last unbuilt leaf-session archetype: a single leaf session pauses mid-pipeline awaiting an external human decision, parks in durable state with the pod scaled to zero, and resumes with the decision injected, preserving context across one or more gates. Decisions: agent-declared gate via a request_approval tool with external decision authority + re-invocation (charter G1/G2); continuation-prompt resume (well-formed transcript, no Pi-internals dependency); decisionRef file transport + re-invoke-by-sessionId trigger; no harness-side timeout (park indefinitely). gateId-keyed durable gate-request/gate-decision entries make multi-gate replay and double-resume idempotent. paused acks the queue (parked work); runLeaf writes the gate marker. Reuses M4/M5 + the async queue/marker/KEDA substrate unchanged. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Match the codebase resume idiom: realProduceVerdict re-seeds via session.prompt() on every invocation (openFromCheckpoint loads context but does not auto-run a turn). The gate continuation is re-derived from the durable gate-decision entry and re-seeded each resume, idempotent exactly like the existing initial-prompt verdict resume. Replaces the earlier 'replayed durable turn' wording. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Bite-sized TDD tasks for Archetype B: gate.ts pure logic (types, decision validation, computeGateState, decideSeed), request_approval tool, gate-marker I/O, classifyOutcome paused/aborted, runLeaf gate front-end + marker, status endpoint awaiting_approval, and a gated live smoke. Each task ends with an independently testable deliverable; the realProduceVerdict wiring and live smoke are verified on the Kind sh-knative cluster per the existing convention. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…ncy) Signed-off-by: Paolo Dettori <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…rompt gate instruction Signed-off-by: Paolo Dettori <[email protected]>
…continue) Signed-off-by: Paolo Dettori <[email protected]>
…arker Signed-off-by: Paolo Dettori <[email protected]>
…rt/idempotent) Signed-off-by: Paolo Dettori <[email protected]>
…rio + dynamic gateId Signed-off-by: Paolo Dettori <[email protected]>
…pod-poll best-effort) The idempotent re-invoke hits the verdict fast-path (M5 recovery, no agent/model call), so the leaf-job pod Running window is sub-second and a 5s poll may miss it. Document that pod observation is best-effort (a hard-fail would be flaky); the real proof is the terminal-state-unchanged assertions (done stable, verdict identical, exactly 1 result file). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
The smoke seeded inputs (heredoc) and the decision file (pipe) through oexec, which runs kubectl exec WITHOUT -i, so local stdin was never forwarded to the pod and cat wrote empty files -> runLeaf returned bad_inputs and the gate never fired. Add an oexec_i (-i) helper for the four stdin-fed writes; non-stdin calls keep using oexec. Verified the -i seeding writes the expected 82-byte inputs JSON into the pod. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ict instruction In the require_approval turn buildLeafPrompt was instructing BOTH request_approval AND submit_verdict, so the model (haiku) took the simpler path and submitted a verdict directly, never gating. The gated branch now instructs request_approval as the first-and-only action and withholds the verdict instruction (delivered later by the approve continuation). Unit test asserts the gated prompt omits the submit_verdict token. Full harness suite 115(+2 skip) green. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…gate) Live testing showed the model (haiku) ignores the prompt and calls submit_verdict directly in the pre-gate turn, bypassing the gate. Make require_approval a hard guarantee: in realProduceVerdict the submit_verdict extension is registered only when the agent has passed at least one gate (a gate-decision exists, or is being applied this turn). In the pre-gate turn the only structured-output tool is request_approval, so the gate cannot be bypassed. Non-gated items are unaffected (allowVerdict is true when require_approval is false). Harness suite 115(+2 skip) green; typecheck clean. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
bash parses ${1:-{}} as ${1:-{} followed by a literal }, so when an
extra-json arg was passed (Claim 3+) the value got a trailing } and jq
--argjson rejected it as invalid JSON. Claim 1 only worked by
coincidence (unset -> {}). Use an explicit local default instead.
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
pdettori
added a commit
that referenced
this pull request
Jun 28, 2026
Address human-gate (#14) review follow-ups
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.
Summary
Archetype B — human-gate ("gate-while-idle") for the leaf-session backend, the last unbuilt archetype. A single leaf session can pause mid-pipeline awaiting an external human decision, park in durable state with the pod scaled to zero, and resume with the decision injected — across one or more gates — before a verdict. Additive: every existing path (sync
/run-leaf, async enqueue, cron-dispatch,leaf-queue, KEDAScaledJob,submit_verdict, the leaf-job runner) is unchanged; a leaf that never gates behaves exactly as today.Spec:
docs/specs/2026-06-28-human-gate-design.md· Plan:docs/superpowers/plans/2026-06-28-human-gate.mdHow it works
request_approval({summary, proposed_action})tool → durablegate-requestentry (monotonicgateId) →runLeafwrites anawaiting_approvalgate marker to<resultRef>.gate→ session parks.decisionReffile ({gateId, action: approve|reject|abort, feedback?}) and re-invokes the samesessionId(sync or async).runLeafresumes from the durable log, records agate-decisionentry, and re-seeds a continuation prompt (approve/reject) or returnsaborted.gateId-keyed entries make multi-gate sequences, stale decisions, double-resume, and crash-mid-resume idempotent (effectively-once).require_approvalitems thesubmit_verdicttool is withheld until a gate decision exists, so the gate cannot be bypassed even if the model ignores the prompt.Design decisions (spec §1): agent-declared gate with external decision/re-invocation (charter G1/G2); continuation-prompt resume (no tool-result injection);
decisionReffile transport; no harness-side timeout (orchestrator owns deadlines); decision actions approve/reject/abort. Auto-approve mode is explicitly not built.Verification
@sh/harness115 passed (2 skipped),@sh/knative-server29 passed,gate.ts19 tests.deploy/knative/leaf-gate-smoke.sh, all 6 claims PASS): pause (marker, no verdict) → scale-to-zero while parked → resume-approve → idempotent re-invoke → reject (agent re-gatedgateId 1→ approve → done; multi-gate) → abort.Deferred follow-ups (non-blocking; final review confirmed none block merge)
processOnecosmetically labelspaused/abortedas"failed"(onlyidle/retrydrive the loop; ack is correct).realProduceVerdict.proposed_actionrejection test; shape-validatereadGateMarkerif external marker producers are ever added.Assisted-By: Claude Code