Files
ai-engineering/docs/local-server-sse.md
T
bquarkz 9a555cb3c6
build / jvm (push) Waiting to run
build / native (macos-15, macos-arm64) (push) Waiting to run
build / native (ubuntu-24.04, linux-x86_64) (push) Waiting to run
build / native (windows-2025, windows-x86_64) (push) Waiting to run
Test / Tests and coverage
Intrepid/AI Engineering/pipeline/head This commit looks good
feat: add per-project native server and SSE command streaming
Keep Spring in a persistent project server with lightweight clients, managed start/stop, bounded SSE subscriptions, cursor recovery and durable mutation outcomes. Preserve SQLite authority and transaction limits, and document reproducible native measurements.

Validation: 269 tests, 11 pipeline scenarios, full native/SSE smoke, native package verification and 17 installer tests passed. Implements WRK-000E / DEC-0001 / DEC-0002.
2026-11-22 23:08:47 +00:00

3.5 KiB

SSE for pending invocations

WRK-000E / DEC-0002 / PLN-0002 replaces repeated status requests with an event subscription. POST /execute still admits one UUID/fingerprint exactly once under the existing recovery contract. A terminal response stays ordinary JSON. Otherwise the client opens GET /requests/UUID/events, authenticated with the same private instance/protocol headers, and consumes text/event-stream as UTF-8.

Frames have id, event and JSON data fields. The ID is a job generation UUID and monotonic sequence joined by :. The payload contains the request id, event cursor/kind, stdoutOffset/stderrOffset, incremental stdout/stderr, state, exit code, input sequence, input requirement and cancellation flag. Output offsets count UTF-16 characters, matching Java writers and the existing JSON response.

Kinds are snapshot, stdout, stderr, progress, input-required, completed and unknown. Output events carry deltas; state events carry no additional output. A snapshot contains the complete retained output from offset zero. Its terminal state can also represent a job that finished before subscription. Terminal events follow durable receipt publication; UNKNOWN retains the existing ambiguous-outcome semantics. Transient progress history is not a durable execution log.

Last-Event-ID resumes within a generation. Replay is limited to 128 events and 256 Ki characters; output events use chunks of at most 16 Ki characters. A missing, expired, future or different-generation cursor gets an explicit snapshot. The client verifies previously received output before appending a snapshot suffix; gaps or differing prefixes are errors, never silently accepted or replayed mutations. After a crash only durable terminal output or an explicit UNKNOWN result is available.

Publishers wake waiting subscribers when state/output changes. Waiting and replay selection occur under the job monitor; socket writes happen after it is released. No stream retains a database transaction or publication lock. An open subscription does not itself count as job activity. Disconnecting it neither cancels the operation nor resubmits /execute; input and cooperative cancellation remain explicit POSTs.

GET /requests/UUID remains for inspection and recovery, rather than periodic monitoring by the updated client. SSE is additive to local HTTP protocol 1; the existing build-identity/drain lifecycle still selects matching client/server builds. Engineering contract 4 and canonical SQLite memory are unchanged.

The CLI allows three reconnect attempts with 100/200/400 ms backoff and a five-second stream read timeout. A normal stream disconnect resumes from its last committed cursor; an uncertain input response or a changed server instance also inspects the durable result once. Input already read from stdin is retained with its sequence. Neither stream exhaustion nor disconnection automatically cancels the job.

The dedicated stream executor admits at most 16 subscriptions per project and two per job. Heartbeats run every second; a socket write blocked for two seconds is interrupted, closing its JDK SocketChannel. This detaches the subscriber and leaves the job recoverable. Drain allows one second for terminal delivery once no jobs remain, then closes remaining streams. These timers do not extend server idle time.

Reference: SSE specification.

Native observations and reproduction commands: SSE results.