[WRONG BRANCH] fix(cursor): avoid quadratic replay cost by tracking entry index and bounding replay window - #348
Conversation
|
✅ Deterministic PR hygiene checks passed. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
⏳ DRAFT
What to do
Its title has been prefixed with |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d16b150861
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const replayStart = externalModel | ||
| ? Math.max(0, replayEnd - CURSOR_EXTERNAL_REPLAY_MESSAGE_LIMIT) | ||
| : 0; |
There was a problem hiding this comment.
Align the capped replay window to a complete turn
When more than 4,096 messages follow the most recent historical user message, this cutoff starts on an assistant/tool-result entry. The later complete-turn selector requires a user root, so with the history constructed by the new test (old turn, 4,101 assistant messages, then the active user), it rejects the orphaned suffix and sends only the system root; the external model receives the active “continue” action with none of the conversation being continued. Anchor the bounded suffix at a user/developer boundary, or explicitly retain the preceding user message, so limiting construction cannot erase all replay context.
Useful? React with 👍 / 👎.
Motivation
entries.indexOf(...)for every duplicate, creating attacker-controlled O(k·r) CPU behavior that could stall the server event loop.rawMessagesbefore pruning, so large attacker-controlled histories could trigger the quadratic path before any size limits applied.Description
lastReplayEntryis replaced bylastReplayEntryIndexand duplicate replacements update the known index directly to make each dedupe operation O(1).CURSOR_EXTERNAL_REPLAY_MESSAGE_LIMIT = 4096and limit the synchronous replay construction to the newest bounded suffix for external wire models so replay processing is bounded before later wire-size pruning.bounds replay construction before processing an oversized historytotests/cursor-repetition-breaker.test.tsthat verifies oversized histories outside the bounded replay window do not trigger the severe repetition note.Testing
bun test tests/cursor-repetition-breaker.test.tsand all 6 tests passed.bun run typecheck(TS check) which completed without errors.bun run test; the repository-wide suite ran many tests and reported unrelated failures/timeouts in other subsystems, so only the focused regression and typecheck were relied on to validate this scoped fix.Codex Task