Skip to content

fix(session): order messages across ID rollover - #40432

Closed
HudsonGri wants to merge 1 commit into
anomalyco:devfrom
HudsonGri:agent/fix-message-id-rollover
Closed

fix(session): order messages across ID rollover#40432
HudsonGri wants to merge 1 commit into
anomalyco:devfrom
HudsonGri:agent/fix-message-id-rollover

Conversation

@HudsonGri

Copy link
Copy Markdown

Summary

  • order session messages by persisted creation time, with ID only as a same-millisecond tie-breaker
  • use the same comparator for loop completion and pending compaction/subtask selection
  • add a rollover fixture with IDs immediately before and after the 48-bit timestamp boundary
  • prove SQLite pagination already preserves chronological storage order across the boundary

Why

Ascending IDs encode Date.now() * 0x1000 + counter into six bytes. The timestamp prefix wraps every 2^36 ms. At the next boundary, 2026-08-14T11:19:55.136Z, a newer ID sorts lexically before an older ID. Long-lived sessions can therefore select the wrong latest user/assistant and fail the loop-exit check.

Verification

  • bun test test/session/message-v2.test.ts test/session/messages-pagination.test.ts (89 pass)
  • bun run typecheck

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Aug 4, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search results, no duplicate PRs were found that are addressing the same issue as PR #40432. While there are some related PRs about session message ordering (like #38798 "order messages by time so the run loop can terminate" and #40099 "finish prompt loop by parent link"), none appear to be duplicates of this specific PR which focuses on fixing the ID rollover issue with 48-bit timestamp boundaries.

No duplicate PRs found

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Aug 4, 2026
@github-actions github-actions Bot closed this Aug 4, 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