Skip to content

feat(core): deterministic session log replay with synced watermark - #35040

Merged
kitlangton merged 3 commits into
v2from
log-synced
Jul 3, 2026
Merged

kitlangton merged 3 commits into
v2from
log-synced

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Summary

Replay durable Session logs through a fixed pre-captured watermark and emit log.synced exactly once, replacing the old log.caught_up moving-boundary marker. This makes reconnect-safe log replay deterministic while preserving live tail delivery for events committed during replay.

Changes

  • packages/schema: rename EventLog.CaughtUp / log.caught_up to EventLog.Synced / log.synced, update marker docs, and cover optional seq encoding.
  • packages/core: add bounded readAfter { through, limit }, LayerOptions.logReadPageSize defaulting to 512, pull-driven paged replay, once-only synced marker, and isCaughtUp -> isSynced.
  • packages/protocol: update the Session log SSE union and route description to the log.synced contract.
  • packages/client and packages/sdk-next: update marker-related tests without regenerating generated client trees.
  • specs/v2: document the marker rename, deterministic watermark replay, and generated-client integration timing.

Decisions

  • D4: keep aggregateID on log.synced for consistency with envelopes, hints, and core aggregate APIs.
  • D5: omit seq when the captured watermark is empty (-1).
  • D5: emit the marker once for the captured watermark.
  • D5: expose LayerOptions.logReadPageSize, default 512.
  • D5: defer session.get watermark and generalized aggregate log API.

Closes #35015
Part of #35021

Test Plan

  • packages/schema: bun typecheck passed.
  • packages/core: bun typecheck passed.
  • packages/core: bun run test -- test/event.test.ts test/session-log.test.ts test/session-create.test.ts test/session-prompt.test.ts passed.
  • packages/protocol: bun typecheck passed.
  • packages/client: bun typecheck passed.
  • packages/client: bun run test -- test/effect.test.ts test/promise.test.ts passed.
  • packages/sdk-next: bun typecheck passed.
  • packages/sdk-next: bun run test -- test/embedded.test.ts passed.
  • Worktree root: bunx prettier --check packages/client/test/effect.test.ts packages/client/test/promise.test.ts packages/core/src/event.ts packages/core/src/session.ts packages/core/test/event.test.ts packages/core/test/session-create.test.ts packages/core/test/session-log.test.ts packages/core/test/session-prompt.test.ts packages/protocol/src/groups/session.ts packages/schema/src/event-log.ts packages/schema/src/event.ts packages/schema/test/event.test.ts packages/sdk-next/test/embedded.test.ts specs/v2/schema-changelog.md specs/v2/session.md passed.
  • Push hook: bun turbo typecheck passed.

Generated client regeneration intentionally happens at integration time per the audit merge protocol; generated trees are untouched on this branch.

@kitlangton
kitlangton merged commit 57e9e97 into v2 Jul 3, 2026
6 checks passed
@kitlangton
kitlangton deleted the log-synced branch July 3, 2026 01:38
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant