Skip to content

feat(sse): detect sequence gaps and stale events#910

Closed
luoye520ww wants to merge 2 commits into
KunAgent:developfrom
luoye520ww:codex/sse-gap-detection
Closed

feat(sse): detect sequence gaps and stale events#910
luoye520ww wants to merge 2 commits into
KunAgent:developfrom
luoye520ww:codex/sse-gap-detection

Conversation

@luoye520ww

Copy link
Copy Markdown
Collaborator

Problem

The sequenced SSE contract can identify order, but the consumer still needs a deterministic decision before projecting an event. Applying an event after a missing sequence can corrupt the renderer projection and make reconnect recovery non-deterministic.

Scope

This PR adds a pure sequence detector on top of #902. It does not change the SSE transport, renderer reducer, replay route, or cursor persistence.

Changes

  • Classify events as accepted, duplicate, out-of-order, gap, or old-stream.
  • Return the expected sequence and a new cursor only for contiguous events.
  • Keep the previous cursor for duplicates, stale events, gaps, and stream changes.
  • Validate event metadata with the shared sequenced event schema before classification.

Safety

  • Gap detection is fail-closed for projection: callers can stop and perform bounded replay or authoritative reload.
  • No input event mutates the caller-owned cursor.
  • The detector does not claim cross-thread isolation because the current event contract has no thread field.

Typecheck

npm.cmd run typecheck

Passed.

Tests

npm.cmd exec vitest run src/shared/sse-gap.test.ts
npm.cmd run lint
npm.cmd run build
git diff --check

Passed: 6 sequence decision tests; root typecheck, lint, and build passed; diff check passed.

Review performed

  • Sequence boundary correctness
  • Duplicate and stale event behavior
  • Stream replacement behavior
  • Cursor immutability
  • Contract validation and PR scope

Non-goals

  • SSE transport changes
  • Renderer reducer integration
  • Bounded replay or authoritative reload
  • Persistent resume cursors

Dependency

Depends on #902 for SequencedRuntimeEvent. After #902 merges, rebase this branch onto develop and drop dependency commits.

@luoye520ww

Copy link
Copy Markdown
Collaborator Author

Superseded by consolidated IPC/SSE reliability PR #945, which passed Typecheck, Linux, macOS, and Windows packaged checks. Closing this duplicate to keep the review surface focused.

@luoye520ww luoye520ww closed this Jul 14, 2026
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