carlos / platform Public

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 under a.mu, never call begin, never touch inflight or lastActive, never wake. They are cancelled synchronously before any stop: beginStopLocked, installProcLocked on 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 : ping heartbeats, 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: 30000 over 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_streams counters 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.

Human

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.

Commits 26
Discussions 1 1 open
Tasks 3/6 done

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