Repository navigation
Gate 7: resumable leaf sessions (crash mid-run → resume → verdict) - #11
Conversation
realProduceVerdict now persists the leaf session to Redis under env.sessionId (BufferedRedisBackend drains continuously) and wires flush + checkpoint extensions. Re-invoking the same sessionId resumes from the durable log (openFromCheckpoint) instead of starting fresh — unifying §2.4 retry with §7 gate-7 resume. submit_verdict also writes a durable 'verdict' custom entry, so a session that crashed after submitting recovers the verdict without re-running the agent (verdictFromCustomEntry). Unit-tested helper + durable-write; live path in the smoke. Signed-off-by: Paolo Dettori <[email protected]>
The resumable path uses env.sessionId as the Pi session id, but the spec's '<run_id>/<item_id>' convention contains a slash, which fails Pi's id validation (alphanumeric + .-_ , alphanumeric ends). Add toSessionId() to map the envelope id deterministically (slash -> dash, trim to alphanumeric ends) and use it for the session id, Redis keying, and verdict recovery. Unit-tested. Signed-off-by: Paolo Dettori <[email protected]>
Dispatches a leaf, confirms the session persisted to Redis, force-kills the harness pod mid-run, then re-invokes the same sessionId — asserting the session resumes from the durable log and still produces its verdict (MVP spec §7 gate 7). Live: 9/9 checks pass on kind sh-knative. Signed-off-by: Paolo Dettori <[email protected]>
pdettori
left a comment
There was a problem hiding this comment.
Self-review (cannot APPROVE own PR). Clean, well-structured implementation of gate 7 (resumable leaf sessions). The resume logic is solid: fast-path verdict recovery from the durable log, checkpoint-based session restore, and belt-and-suspenders post-prompt recovery. toSessionId sanitization and verdictFromCustomEntry validation are both correct with good edge-case test coverage. The live smoke (claim 6) covers the full crash → resume → verdict path convincingly.
One nit below (non-blocking). Ready for external review.
| // Durable, resumable session keyed by the (sanitized) session id. BufferedRedisBackend drains | ||
| // writes continuously, so a mid-run crash preserves progress up to the last drained entry. | ||
| const sid = toSessionId(env.sessionId); | ||
| const store = new RedisSessionBackend<FileEntry>(config?.redisUrl ?? "redis://localhost:6379"); |
There was a problem hiding this comment.
nit: store (RedisSessionBackend) is never explicitly disconnected after use. Under Knative (process dies after request) this is fine, but if realProduceVerdict were ever called in a long-lived process it would leak connections. Worth a store.disconnect?.() in the finally block if the backend exposes one — or a comment noting the Knative lifecycle assumption.
Summary
Implements MVP spec §7 gate 7 (resume) — the documented stretch — completing the leaf-session verification gate end-to-end. A leaf session killed mid-run now resumes via the M5 durable log and still produces its verdict.
Builds on #10 (Task 6). Plan:
docs/superpowers/plans/2026-06-26-mvp-leaf-session-contract.md§7.What's here
runLeafis now resumable.realProduceVerdictpersists the session to Redis under the envelopesessionId(BufferedRedisBackend, which drains continuously so a mid-run crash preserves progress), wiringflushExtension+checkpointExtensionalongsidesubmitVerdictExtension+k8sSandboxExtension. Re-invoking the samesessionIdresumes from the durable log (openFromCheckpoint, falling back to full reconstruction) instead of starting fresh — unifying §2.4 retry with §7 gate-7 resume.submit_verdictalso appends averdictcustom session entry (same pattern as the checkpoint marker). On resume, if that entry already exists the verdict is recovered from the log and the agent is not re-run (covers a crash after submitting); otherwise the session re-prompts and completes (covers a crash before submitting).verdictFromCustomEntryis unit-tested.<run_id>/<item_id>id contains a slash, which fails Pi's session-id validation when used as the actual session id.toSessionId()maps it deterministically (slash → dash, trim to alphanumeric ends); unit-tested.Verification — MVP spec §7, live on Kind
sh-knativeLEAF_LIVE_SMOKE=1 bash deploy/knative/leaf-smoke.sh→ 9/9 checks pass, 0 fail. New Claim 6:All prior claims (workspace isolation, fan-out, structured output, model routing, failure path, idempotency, scale-to-zero) still pass.
Unit tests: full harness suite green (63 passed, 2 live-gated skipped).
Behavior note
Re-invoking a
sessionIdnow resumes the existing session rather than starting fresh — consistent with §2.4 ("retry = re-invoke") and required for gate 7. A genuinely fresh re-run uses a newsessionId.Assisted-By: Claude Code