transport-log-stream-sse: honor ?after query as the resume cursor for source-driven reconnects #855

Closed
opened 2026-08-25 20:22:18 +00:00 by matou-build-agent · 2 comments

Symptom

dashboard-log-stream-source (#810) is the ONLY EventSource construction site and it owns reconnect + resume backfill with an injected timer (it closes the follow and opens a fresh one, rather than relying on the browser's native auto-reconnect). A freshly-constructed browser EventSource cannot set a request header, so its source-driven reconnect/resume carries its ring cursor as a query param ?after=<seq> on GET /api/v1/logs/stream/{scope}.

The merged SSE route (transport-log-stream-sse, #808) reads the reconnect cursor only from the Last-Event-ID header (lastEventID(r) in internal/controlapi/logstream.go). It ignores ?after. So:

  • The browser's native transient reconnect (same EventSource instance) works — it re-sends Last-Event-ID and the hub backfills.
  • The source's own reconnect after stream lost, and its resume/visibility backfill (a fresh EventSource), send no Last-Event-ID header, so the route treats them as a fresh subscribe (afterSeq 0) and replays the ring tail instead of backfilling the gap after the last held Seq. Client-side dedup (#810 dedups on Seq) keeps this correct-but-wasteful — no duplicate line renders — but it is not a true gap-backfill.

Proposed fix

In lastEventID(r) (or a small wrapper), fall back to the after query parameter when the Last-Event-ID header is absent: afterSeq = header ?? query("after") ?? 0. A one-line-ish change plus a route test; the header stays authoritative when present (native reconnect), the query covers source-driven reconnect.

Found while

Building #810 (observability:dashboard-log-stream-source). #810 is complete and green against its fake-EventSource seam; this only affects the live production wiring against the real route. Filed rather than edited because the route is the transport-log-stream-sse slice (#808), not #810 (CLAUDE.md rule 3 — stay in scope).

## Symptom `dashboard-log-stream-source` (#810) is the ONLY `EventSource` construction site and it **owns reconnect + resume backfill** with an injected timer (it closes the follow and opens a fresh one, rather than relying on the browser's native auto-reconnect). A freshly-constructed browser `EventSource` cannot set a request header, so its source-driven reconnect/resume carries its ring cursor as a query param `?after=<seq>` on `GET /api/v1/logs/stream/{scope}`. The merged SSE route (`transport-log-stream-sse`, #808) reads the reconnect cursor **only** from the `Last-Event-ID` header (`lastEventID(r)` in `internal/controlapi/logstream.go`). It ignores `?after`. So: - The browser's **native** transient reconnect (same EventSource instance) works — it re-sends `Last-Event-ID` and the hub backfills. - The source's **own** reconnect after *stream lost*, and its **resume**/visibility backfill (a fresh EventSource), send no `Last-Event-ID` header, so the route treats them as a fresh subscribe (afterSeq 0) and replays the ring tail instead of backfilling the gap after the last held Seq. Client-side dedup (#810 dedups on Seq) keeps this correct-but-wasteful — no duplicate line renders — but it is not a true gap-backfill. ## Proposed fix In `lastEventID(r)` (or a small wrapper), fall back to the `after` query parameter when the `Last-Event-ID` header is absent: `afterSeq = header ?? query("after") ?? 0`. A one-line-ish change plus a route test; the header stays authoritative when present (native reconnect), the query covers source-driven reconnect. ## Found while Building #810 (`observability:dashboard-log-stream-source`). #810 is complete and green against its fake-EventSource seam; this only affects the live production wiring against the real route. Filed rather than edited because the route is the `transport-log-stream-sse` slice (#808), not #810 (CLAUDE.md rule 3 — stay in scope).
Author
Member

swarm-claim host=elitebook-distributed-server-03 run=10097
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=elitebook-distributed-server-03 run=10097 (automated multi-host claim — lowest live claim id works this ticket)
Author
Member

close-report for #855 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 855,
  "status": "success",
  "commits": [
    "7d491ed"
  ],
  "changed_files": [
    "internal/controlapi/logstream.go",
    "internal/controlapi/logstream_integration_test.go",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "go test ./internal/controlapi/",
      "exit_code": 0
    },
    {
      "command": "go vet ./internal/controlapi/",
      "exit_code": 0
    }
  ],
  "criteria": {
    "lastEventID falls back to ?after query when Last-Event-ID header absent (afterSeq = header ?? query(after) ?? 0)": "internal/controlapi/logstream.go lastEventID() now reads r.URL.Query().Get(\"after\") when the header is empty; commit 7d491ed",
    "header stays authoritative when present (native reconnect)": "TestLogStream_LastEventIDHeaderWinsOverAfterQuery — with both set, afterSeq=7 from the header (green)",
    "source-driven reconnect ?after covered by a route test": "TestLogStream_SourceDrivenReconnectCarriesAfterQueryCursor — ?after=11, no header, follows with afterSeq=11 (green)"
  },
  "summary": "The SSE log-stream route now honours ?after=<seq> as the resume cursor when Last-Event-ID is absent, so source-driven EventSource reconnects (#810) get a true gap-backfill instead of a ring-tail replay.",
  "blockers": []
}
**close-report** for #855 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 855, "status": "success", "commits": [ "7d491ed" ], "changed_files": [ "internal/controlapi/logstream.go", "internal/controlapi/logstream_integration_test.go", "STATUS.md" ], "tests": [ { "command": "go test ./internal/controlapi/", "exit_code": 0 }, { "command": "go vet ./internal/controlapi/", "exit_code": 0 } ], "criteria": { "lastEventID falls back to ?after query when Last-Event-ID header absent (afterSeq = header ?? query(after) ?? 0)": "internal/controlapi/logstream.go lastEventID() now reads r.URL.Query().Get(\"after\") when the header is empty; commit 7d491ed", "header stays authoritative when present (native reconnect)": "TestLogStream_LastEventIDHeaderWinsOverAfterQuery — with both set, afterSeq=7 from the header (green)", "source-driven reconnect ?after covered by a route test": "TestLogStream_SourceDrivenReconnectCarriesAfterQueryCursor — ?after=11, no header, follows with afterSeq=11 (green)" }, "summary": "The SSE log-stream route now honours ?after=<seq> as the resume cursor when Last-Event-ID is absent, so source-driven EventSource reconnects (#810) get a true gap-backfill instead of a ring-tail replay.", "blockers": [] } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/idss#855
No description provided.