fix(cursor): bound frame copying and preserve context boundaries - #432
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Cursor concatenated the entire incomplete Connect frame for every network fragment: a deterministic 1 MiB/1 KiB-chunk regression copied 538 MB. Separately, transcript rows cached relative paths across cwd changes. The follow-up audit also needed to distinguish duplicate protocol representations from actual duplicated model context. Fixes #431.
Value
Large fragmented responses incur linear copying, and switching child working directories cannot show stale relative paths. Context regression coverage prevents a misleading optimization from deleting required history or substituting generated-token counts for context usage.
Approach
Use a five-byte header plus one bounded payload buffer for fragmented frames, borrowing contiguous payload slices for synchronous decode. Preserve the 16 MiB limit, EOF errors and existing MCP handoff boundaries. Include cwd in the bounded transcript cache key. Verify both Cursor history trees, compacted-context rebuilding and Pi's zero-usage estimation boundary without changing the protocol or usage policy.
Validation
bun run checkpassed. The defaultbun run testattempt was interrupted during severe host scheduling delay; its log is retained. The complete repository-discovered suite then passed at Node file concurrency 2: 1455 passed, one platform skip; Vitest 30/30. Final-head CI passed on84cc307e9af5c8fac0824619ab00814c19d7af5c: Node 22.19.0, Node 24 and Windows, including standard repository checks/tests and package smoke coverage. Two independent code reviews found no actionable issues. Deterministic regressions cover byte-copy growth, all split positions, empty/coalesced frames, retained buffers, frame limits, production truncated EOF, cwd warm/cold equivalence, history pairing and compacted rebuilds. No paid provider calls or user runtime changes.Impact
No model tools, permissions, settings or persisted schema change. A fragmented frame now reserves its declared payload size (up to the existing 16 MiB cap) once its validated header arrives, instead of repeated incremental allocations. Model history and token accounting remain unchanged: upstream evidence identifies JSON root history as model input and native turns as UI state; local duplication is not proof of doubled model context. The separate viewport rewrite #327 remains outside this batch because its existing 512-item measurement does not establish severe lag and its invalidation contract needs separate review.
Investigation. Fixed base:
69a7e5f19b4db3e32b7ad6abc81884edf767b2e3.