edge-held-streams-432
Edge-held event streams (#432)
A browser EventSource opened with carlos_hold=1 on a hibernating instance is held by the edge while the instance sleeps and resumed with Last-Event-ID when something else wakes it. A held stream never counts as activity and never wakes anything, so a page left open no longer keeps an instance awake.
Design rev 3 (docs/superpowers/specs/2026-10-28-edge-held-streams-design.md) and plan rev 2 (docs/superpowers/plans/2026-10-28-edge-held-streams.md), both approved by Paul 2026-11-02 (discussion 432). origin/main merged first (9f2ac42d); the plan's interfaces held, with one addition: the wake hook also fires at the two fence lifts main added (recoveryprobe, seed exclusion).
What changes
- Activator (
internal/activator/heldlegs.go):AdmitHeldLeg/HeldAdmissible/SetHeldWakeHook. Legs are admitted and registered in one step undera.mu, never callbegin, never touchinflightorlastActive, never wake. They are cancelled synchronously before any stop:beginStopLocked,installProcLockedon a generation change, every entry removal, and the claim producer's pre-stop. Workers are refused held legs up front. - Edge (
internal/edge/heldstream.go,sse.go,edge.go): marked requests are classified once after lookup (non-stream marked requests to a hibernating route get 400 before login/gate handling); the hold branch sits after the password gate. One stream task per browser relays whole SSE events from legs served through the route's own proxy, writes bare: pingheartbeats, reopens on the wake hook or a 25 s tick, turns a first-leg 3xx into 204, passes other non-200s through, and closes on a reopen refusal. Caps 64/host, 4096/box (retry: 30000over cap), 1 h max hold, short-leg backoff. Marked requests never touch the shared cache or asset catch on any edge; reload closes streams for hosts no longer managed here; marked HA requests use only the in-memory holder decision. - Status:
held_streamscounters in the box snapshot (additive).
Tests
Randomized lifecycle simulation (edge, 300 seeds), swap simulation with held-leg invariants I4/I5 (activator), go/types guard over every stop transition and a static check that the held path never reaches activity, 12 production-wired witnesses with a real activator, edge and SSE child (sleep, wake, resume across two sleeps, drain under 2 s, overlap swap, stop/admit race, expired session, forwarded headers and signing, cookie scoping, edge restart), tunnel-hub cache witnesses, marked login POST 400, byte-for-byte marker strip.
Also on this branch, test-only: run_cutover_witness_test.go had a pre-existing race (it released the CLI before its activation checks); it failed this branch's CI twice, reproduced 3/3 with an injected delay, and is fixed (0fa5468c).
Review
Astra per-task reviews of Tasks 1, 2, 5, 6 (each closed with fix rounds), whole-branch review R1: READY AFTER FIXES, fixes re-reviewed, census approved (docs/superpowers/notes/census-proposal-edge-held-streams.md). Findings in docs/superpowers/reviews/ASTRA-FINDINGS-edge-held-streams-branch-R1*.md; follow-ups in docs/superpowers/notes/edge-held-streams-followups.md (region-HA cold holder cache before HA ships; close idle edge-to-child connections at stop).
Not in this branch: the app-author docs page (plan Task 9) is in copy review with Paul and lands as its own branch.
Switch-on: live as soon as an app sends the marker. First user: Rastrillo's live.js.
Design for #432: the edge holds a browser's SSE stream (opted in with the URL marker carlos_hold=1) while its instance sleeps, and reopens it with Last-Event-ID when the instance wakes. The stream never counts as activity and never wakes anything. Spec rev 3 in docs/superpowers/specs/2026-10-28-edge-held-streams-design.md; Astra round 2 READY AFTER FIXES, P2s applied. Waiting on Paul's approval before the implementation plan.
Discussions 1 open
Tasks 3/6 done
- Design spec rev 1 Done
- Astra review (max 3 rounds) Done
- Paul approves the design Done
- Implementation plan Started
- Build Not started
Activity
- claude agent, operated by paul@keymail.dev replied to Hold a browser's SSE stream at the edge while an instance sleeps, and resume it on wake
- claude agent, operated by paul@keymail.dev replied to Hold a browser's SSE stream at the edge while an instance sleeps, and resume it on wake
- claude agent, operated by paul@keymail.dev replied to Hold a browser's SSE stream at the edge while an instance sleeps, and resume it on wake
- claude agent, operated by paul@keymail.dev pushed 0fa5468c0 cutover witness: check the drain state before releasing the CLI
- claude agent, operated by paul@keymail.dev pushed fe8b69c73 edge-held-streams: branch review findings and follow-up list (#432)
- claude agent, operated by paul@keymail.dev pushed 35efd9879 activator: deterministic startup-wait witness for held admission (#432)
- claude agent, operated by paul@keymail.dev pushed 40de96387 census: refresh edge-held streams proposal after review fixes (#432)
- claude agent, operated by paul@keymail.dev pushed 0bbc108d1 edge, activator: held-stream whole-branch review fixes (#432)
- claude agent, operated by paul@keymail.dev pushed e8e38fa68 census: edge-held streams proposal (#432)
- claude agent, operated by paul@keymail.dev pushed 0ece5cf99 activator: production-wired witnesses for held streams with a real child (#432)
- claude agent, operated by paul@keymail.dev pushed c9bcf63de edge, status: held-stream counters in the box snapshot (#432)
- claude agent, operated by paul@keymail.dev pushed edba0ba19 edge: held-stream dispatch review fixes (#432)
- claude agent, operated by paul@keymail.dev pushed e8cc11284 edge: held-stream review fixes (#432)
- claude agent, operated by paul@keymail.dev pushed 85f8d00a9 edge: classify carlos_hold requests and hold them after the gate (#432)
- claude agent, operated by paul@keymail.dev pushed 63cc9cf70 edge: the held-stream task (#432)
- claude agent, operated by paul@keymail.dev pushed 1595be9f7 activator: held-leg guard takes only actState's own constants (#432)
- claude agent, operated by paul@keymail.dev pushed 21241fbec activator: held-leg guard and sim fixes from task 2 review (#432)
- claude agent, operated by paul@keymail.dev pushed 535b75ddb edge: SSE block reader for held streams (#432)
- claude agent, operated by paul@keymail.dev pushed 829b1ff13 edge: held-leg methods on the Activator seam; countingWriter unwraps (#432)
- claude agent, operated by paul@keymail.dev pushed 1d0619cfa activator: guard held-leg transitions; simulate held legs in swaps (#432)
- claude agent, operated by paul@keymail.dev pushed dca7aaa4d activator: refuse held legs on worker entries (#432)
- claude agent, operated by paul@keymail.dev pushed f2a684b71 activator: cancel held legs before a claim producer's stop (#432)
- claude agent, operated by paul@keymail.dev pushed 991e7b42d activator: held-leg admission, registry and synchronous cancellation (#432)
- claude agent, operated by paul@keymail.dev pushed 9f2ac42d3 Merge remote-tracking branch 'origin/main' into edge-held-streams-432-1
- claude agent, operated by paul@keymail.dev replied to Hold a browser's SSE stream at the edge while an instance sleeps, and resume it on wake
- claude agent, operated by paul@keymail.dev pushed ae6eb493f edge-held-streams: plan rev 2 after Astra plan round 1 (#432)
- task updated: Implementation plan
- task updated: Paul approves the design
- claude agent, operated by paul@keymail.dev pushed cd61c9d94 edge-held-streams: implementation plan (#432)
- task updated: Astra review (max 3 rounds)