Skip to content

fix(diagnostics): let client sessions restart after five minutes - #800

Merged
nixuuu merged 1 commit into
devfrom
fix/diagnostics-session-window
Nov 15, 2026
Merged

nixuuu merged 1 commit into
devfrom
fix/diagnostics-session-window

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 15, 2026

Copy link
Copy Markdown
Member

Cause

ClientDiagnostics.submit() (apps/gateway/src/diagnostics/clients.ts) keeps the retired sessions of each sender+source channel so it can ignore replays. A third new session raised ResourceExhausted("Diagnostics session limit reached"). The comment said "twice within its five-minute lease", but:

  • the lease never expired while the client kept submitting, because state.last is refreshed on every batch and channels are only evicted after 300 s with no batches;
  • retired was never trimmed.

So after the third page reload (each reload starts a new session; desktop uses crypto.randomUUID()), every batch from that sender got HTTP 429 (gateway-errors.ts maps ResourceExhausted to 429). This lasted until the client stopped submitting for five minutes, and that client's diagnostics were lost. In the desktop renderer it shows up as POST /api/diagnostics/submit 429 once a minute.

Fix

  • Retired sessions now carry their retirement time, and entries older than five minutes are dropped, giving a real sliding window. At most two new sessions are accepted per channel in any five minutes; a third still gets ResourceExhausted.
  • A retired session stays ignored until its window ends. After that, replays are still blocked: the window (300 s) is longer than the batch freshness tolerance in both directions (±120 s, so 240 s in total). Any batch accepted before the retirement is already rejected as stale by then.
  • Memory accounting is unchanged: the fixed 1 KiB per-channel reservation already covers at most two retired entries. #restored checkpoints don't use retired.
  • The client is unchanged. It already swallows submit errors (.catch(() => {})). The console line is the browser's own network log. With this fix a 429 is only a short, rate-limited condition, so a client backoff isn't clearly needed.
  • docs/diagnostics.md now describes the restart window (in Polish).

Fixes: #569 (the PR that added the session limit)

Verification

Ran locally:

  • bun run check:tmp ./tests/integration/diagnostics-clients.test.ts: 11 pass. The new test fails on the old code with Diagnostics session limit reached and passes with the fix. It covers:
    • a reload every three minutes over 24 minutes keeps being accepted;
    • a third restart within five minutes is still limited;
    • a retired session is still ignored inside its window;
    • a stale replay after the window is rejected.
  • apps/gateway typecheck, plus oxlint and oxfmt on the edited files.

Left to CI: the full gate (gen:check, repo-wide typecheck/lint/format, all test shards, builds).

Copy audit: not applicable, no UI text changes.

🤖 Generated with Claude Code

Retired client sessions were never pruned, and the sender lease never
expired while the client kept submitting every minute. After the third
reload, every batch from that sender got ResourceExhausted (HTTP 429)
until it stopped submitting for five minutes. Retirements now carry a
timestamp and expire after a sliding five-minute window. A retired
session stays ignored until its window ends.

Fixes: #569

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nixuuu
nixuuu enabled auto-merge (squash) November 15, 2026 08:25
@nixuuu
nixuuu merged commit fb4896a into dev Nov 15, 2026
11 checks passed
@nixuuu
nixuuu deleted the fix/diagnostics-session-window branch November 15, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant