sanad: worker runtime p0 — walking skeleton (deploy, invoke, trace, pause) - #4
Merged
Conversation
…nts, runs, invoke tokens
…ed gate, itok route
…ker mode + keep_warm
…ndjson passthrough
…ainment + keep-warm probe
…busy-run coverage
…ping, parse failure
… transitions, honest invoke errors
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.
What this is
The worker-runtime P0 walking skeleton — deploy a worker-agent bundle, invoke it synchronously as an ephemeral budgeted run, stream its journal, persist its trace, pause it. Spec and plan live on
worker-agents-prd:docs/superpowers/specs/2026-08-13-worker-runtime-design.md+docs/superpowers/plans/2026-08-13-worker-runtime-p0-walking-skeleton.md.Locked decisions this implements: run-per-invoke (ephemeral soul, fresh session = the trace); machine per (workspace, env) reusing the Fargate wake machinery, subprocess-per-run; DB run rows + S3 traces via presigned URLs; one accountable owner per agent (deploy-blocked without one);
ReturnOutputtool as the interface contract (nudge locally, fail-fastno_outputin cloud); budgets clamped machine-side.The three stacks
sanad-web — worker tables (workspaces/agents/versions/deployments/runs/invoke tokens/machines) + migrations 0006–0007;
itok_invoke tokens (quota at mint); agent registry with stable-ownership upsert, deployment supersede rule, version-ancestry check; per-(workspace,env) machine wake with boot-compatible task env +keep_warm; sync invoke route (NDJSON passthrough, idempotency keys, 120s wake bound, honest 4xx passthrough,storage_unconfiguredpre-wake guard); completion ingest with pricing rollup; status-guarded lost-run reaper with maintained staleness signal; runs read APIs; minimal/agentspages + per-agent OpenAPI.kimi CLI —
kimi_cli/worker/assembly (worker.yaml sidecar, derived agent spec preserving base tools,ReturnOutputstop-turn tool shared verbatim by both runtimes);sanad agent dev(local ephemeral run, exit-code contract 0/1/3/4);sanad agent deploy/runs/logs/pause/resumeagainst the real route contracts.terminal-server —
RunRunner(one-turn wire subprocess, token budget with status-guarded trip, defensive telemetry parsing); gated/internal/worker/*routes (fail-closedWORKER_ENABLED, bundle containment hardened against traversal/degenerate/conflicting keys, budget clamps, symmetric spawn cleanup); gzip trace upload via presigned PUT + completion report + registry drop; keep-warm idle probe.Parity evidence (DX-4):
tests_e2e/test_worker_parity.pyruns the same bundle throughsanad agent devand the real cloud RunRunner — identical output document, full event sequence observed, mutation-tested non-vacuous.Tests
540 passing on this exact tree: 306 sanad-web (vitest, incl. contract tests for the invoke/complete/openapi routes), 201 terminal-server, 33 CLI worker + e2e (dev + parity). Every task landed through TDD with an independent review + fix loop; a final whole-branch review (cross-task seams, security posture, run lifecycle) drove one last hardening wave (reaper staleness maintenance, guarded run-state transitions, idempotency-key clearing on infra failures, machine-4xx passthrough).
Before first staging deploy
SANAD_RUNS_BUCKET; grant thesanad-workspace-taskrole PUT (and the control plane GET) onruns/*— unset bucket now fails closed pre-wake withstorage_unconfigured.CRON_SECRETand schedulePOST /api/internal/cron/reap-runs.WORKER_ENABLED=1/KEEP_WARMinjected at task launch.Sign-off wanted
MODEL_PRICINGnumbers are placeholders (kimi-k3: $0.60/MTok in, $2.50/MTok out) — flag before anything billing-visible.Fast-follows (tracked in the branch ledger, none merge-blocking)
Drizzle meta snapshots 0003–0005 backfill (chip open); test-strengthening (supersede WHERE assertion, outside-work-dir bundle case, missing-agent.yaml case);
live_run_ids()accessor instead of_runsreach-in; keepWarm live-flip to a running machine; per-wakeensureAccessPointlatency;/agentsNav link; explicitKIMI_DISABLE_TELEMETRYin the e2e env; the 7 auto-fixable pre-existing ruff errors blocking repo-widemake check;storage_unconfiguredkeeps its idempotency key (revisit with retry UX).