Skip to content

fix(cursor): consolidate quarantine and replay allocation fixes - #5507

Merged
lidge-jun merged 6 commits into
devfrom
codex/260922-bundle-cursor-replay
Sep 22, 2026
Merged

lidge-jun merged 6 commits into
devfrom
codex/260922-bundle-cursor-replay

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Sep 22, 2026

Copy link
Copy Markdown
Owner

Summary

Bound Cursor output quarantine to 8 KiB while preserving reasoning order, leading-marker classification, and upstream error visibility. Retain independent adjacent echo findings, including call IDs on a marker's own line. Replace duplicate replay roots by their recorded index and avoid oversized UTF-8 allocations while restoring invocation arguments.

This bundle carries the following contributions from @luvs01 in three ordered contribution commits, followed by a dev merge and a focused contract-regression follow-up:

Original PR Reviewed source head Coverage
#5476 51c12285e729169d146682521f268116cda2a9cd Superseded in full, with same-line diagnostic and upstream-error regressions. Its combined predecessors are carried once.
#5474 f4eab495c382a49cc69301b2baf4aa8e5143ee30 Partial: constant-time duplicate replacement only. The 4,096-message raw cutoff is deferred because it can discard the initiating instruction before replay pruning. Long-history regressions preserve instruction and invocation fidelity. Do not close the original as fully completed.
#5458 60bb62f81f130cdee436c5fffbf5dc87a8fc9284 Superseded in full: bounded UTF-8 probing and single-serialization restoration. Existing newest-first, checkpoint-offset, output-elision and final encoded-cost behavior stays covered.

The external root envelope remains 192 roots / 512 KiB, with 2 KiB invocation admission followed by spare-budget restoration. Full history traversal remains; this PR does not claim a total request CPU or heap bound. Quarantine classifies only bounded leading windows and flushes when its retained-output budget is exhausted.

Original PR closure remains a maintainer action after proving inclusion on dev. No native stack or dependent PR chain is used.

Verification

  • Local checks: NOT RUN. The owner prohibited local tests, typecheck, builds, dependency installation, and runtime/service execution. Commits and push bypass hooks as requested.
  • Static review covered the combined protobuf changes, checkpoint offsets, cap accounting, UTF-8 truncation, event ordering, error visibility, and contributor attribution. git diff --check passed.
  • Added regressions for adjacent/split same-line markers, reasoning release before upstream errors below and above the cap, long collapsed replay turns, long trailing result runs, and impossible restoration allocation/serialization.
  • No test was skipped, no timeout or platform gate was relaxed, and no file-size limit was increased. Existing test files remain in their registered domains.
  • Merged dev 6c2f7676dcedba21bdbacf4fb84a7b2c286d1ee6 after feat(desktop): native macOS usage panel and release regression fixes #5490 landed; the shared CI, test runner, layout registries, and management route have no lane-local modifications. Final exact-head hosted CI is pending. Original-head CI is historical evidence only; it does not verify this combined branch.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Co-authored-by: luvs01 27862058+luvs01@users.noreply.github.com

Summary by CodeRabbit

  • Bug Fixes
    • Improved Cursor output handling for oversized responses, preserving valid content while preventing excessive buffering.
    • Improved detection and attribution of repeated or corrupted output markers during retries.
    • Preserved output ordering and terminal errors when processing large or interrupted responses.
    • Improved handling of long repeated conversation history and oversized tool-call arguments.

lidge-jun and others added 3 commits September 22, 2026 18:21
Carries #5476, including same-line marker attribution and upstream-error ordering regressions.

Co-authored-by: luvs01 <27862058+luvs01@users.noreply.github.com>
Partially carries #5474. Preserve complete-history turn and invocation fidelity; defer the raw-message cutoff because it can discard the initiating instruction. Add long-history regression coverage.

Co-authored-by: luvs01 <27862058+luvs01@users.noreply.github.com>
Carries #5458. Reuse serialized arguments, probe UTF-8 length within the remaining envelope budget, and preserve final encoded-cost validation.

Co-authored-by: luvs01 <27862058+luvs01@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration

Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 76d5640e-2078-4911-b660-511cb8b646b0

📥 Commits

Reviewing files that changed from the base of the PR and between 8ffbf97 and c01b874.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 24d0babc-8a73-4a38-b4c6-2acf677c3fea

📥 Commits

Reviewing files that changed from the base of the PR and between 6c2f767 and 8ffbf97.

📒 Files selected for processing (7)
  • src/adapters/cursor.ts
  • src/adapters/cursor/envelope-echo.ts
  • src/adapters/cursor/protobuf-request.ts
  • structure/providers/cursor.md
  • tests/providers/cursor/cursor-envelope-echo-retry.test.ts
  • tests/providers/cursor/cursor-repetition-breaker.test.ts
  • tests/providers/cursor/cursor-tool-result-invocation.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Cursor recovery now bounds held output and detector input, attributes corruption to separate marker windows, preserves replay entry positions, and performs bounded UTF-8 checks for invocation arguments. Tests cover oversized frames, marker attribution, long repetition runs, and restoration limits.

Changes

Cursor midstream recovery

Layer / File(s) Summary
Midstream corruption attribution
src/adapters/cursor/envelope-echo.ts:133-245, tests/providers/cursor/cursor-envelope-echo-retry.test.ts:99-157
CursorMidstreamEchoObserver tracks multiple corruption windows. New markers settle prior windows, and findings are capped when created. Tests cover adjacent, clean, duplicate, split, and same-line markers.
Bounded output quarantine
src/adapters/cursor.ts:51,319-439, src/adapters/cursor/envelope-echo.ts:79,276-280,345, structure/providers/cursor.md:197-219, tests/providers/cursor/cursor-envelope-echo-retry.test.ts:352-521
The output guard limits retained bytes to 8 KiB, bounds sniffer input to 512 and 2,048 UTF-16 characters, classifies text before the aggregate cap, and releases oversized events directly. Tests cover retry classification, ordering, flush behavior, and bounded matches.

Cursor replay encoding

Layer / File(s) Summary
Bounded replay encoding
src/adapters/cursor/protobuf-request.ts:314-347,953-999,1074-1082, structure/providers/cursor.md:119-120, tests/providers/cursor/cursor-repetition-breaker.test.ts:79-104, tests/providers/cursor/cursor-tool-result-invocation.test.ts:606-635
Replay replacement uses recorded entry positions. UTF-8 truncation and length checks stop at configured bounds. Invocation restoration reuses serialized arguments and skips growth that cannot fit. Tests cover 4,100-entry runs and oversized argument serialization.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~30 minutes

Change: Bug fix

Possibly related PRs

  • lidge-jun/opencodex#4929: Adds the earlier Cursor midstream envelope-echo observer and replay cleanup that this change further bounds and refines.
  • lidge-jun/opencodex#4900: Introduces the Cursor echo recovery path that this change hardens.
  • lidge-jun/opencodex#2651: Adds the repetition breaker whose replay-root indexing and long-run behavior this change updates.

Merge Risk: ⚪ Minimal · up to 8ffbf

The implementation bounds Cursor quarantine and replay argument materialization while preserving marker attribution and event ordering; no concrete production-impacting defect is identified, so the PR is mergeable.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 6 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies Cursor fixes and accurately summarizes the two main change areas: quarantine handling and replay allocation.
Full details: Docstring Coverage

Explanation

Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 6 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

lidge-jun and others added 2 commits September 22, 2026 18:26
Document the intentional per-frame prefix boundary and verify late matches pass through without corrective retry while leading-match regressions remain intact.

Co-authored-by: luvs01 <27862058+luvs01@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@lidge-jun
lidge-jun marked this pull request as ready for review September 22, 2026 09:29
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner September 22, 2026 09:29
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-22T09:33:39.447124Z 8ffbf97 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added the bug Something isn't working label Sep 22, 2026
@lidge-jun

Copy link
Copy Markdown
Owner Author

리뷰 · 우선순위 58 / 80

이 PR은 Cursor 어댑터에서 출력을 잠깐 붙잡아 두는 격리(quarantine)와 과거 대화를 다시 만드는 재생(replay) 경로를 한꺼번에 고칩니다. 모델이 한 번에 아주 큰 글·생각 조각을 보내도 격리 버퍼가 8 KiB를 넘기지 않게 막고, 앞부분만 보고 echo/라우팅 환각을 판별한 뒤에도 순서는 유지합니다. 중간 echo 진단은 서로 가까운 마커를 각각 따로 기록하고, 마커 줄에 있는 call-id도 그 마커 몫으로 잡습니다. 재생 쪽에서는 같은 내용이 반복될 때 indexOf로 다시 찾지 않고 기록해 둔 위치로 바로 갈아끼우며, 잘린 도구 인자 복원은 UTF-8 길이를 예산 안에서만 재고 큰 배열을 만들지 않습니다. base는 dev이고 #5476·#5458은 사실상 전부, #5474는 중복 치환만 부분 반영입니다.

라인 - src/adapters/cursor.ts echo/라우팅 환각 throw 직전: guardHeld = []만 비우고 guardHeldBytes는 그대로 둡니다. 지금은 runOnce가 다시 돌아가서 큰 문제는 아니지만, 숫자와 배열이 어긋날 수 있는 자리입니다.
라인 - PR 본문 Verification: 로컬 테스트·타입체크·빌드를 돌리지 않았다고 명시되어 있습니다. 이번 헤드(8ffbf97) CI가 실질 검증 게이트입니다.
라인 - #5474 원본의 4096 raw-message cutoff는 의도적으로 빠졌습니다. 긴 히스토리에서 첫 지시문이 잘릴 수 있어서인데, 원본 PR을 “다 끝남”으로 닫으면 그 이슈가 사라집니다.

메인테이너의 판단이 필요한 지점

피드 앞부분만(echo 512자, 라우팅 2048자) 보고 교정 재시도를 걸고, 그 뒤에 오는 매칭은 그냥 통과시키는 경계가 제품으로 괜찮은지. 구조 문서와 회귀 테스트에는 이미 박혀 있습니다. 원본 PR 닫기는 포함이 dev에 증명된 뒤 메인테이너가 하면 됩니다. #5476·#5458은 닫아도 되고, #5474는 부분 반영이니 열린 채로 두는 편이 맞습니다.

너의 추천

CI(특히 cursor 관련 테스트 샤드) 통과를 보고 머지하세요. 머지 후 #5476·#5458은 닫고, #5474는 cutoff 후속 이슈를 남기거나 원본을 열린 채로 두세요. throw 경로의 guardHeldBytes 리셋은 작은 후속 정리로 충분합니다.

이 댓글은 grok-bot이 작성했습니다

@lidge-jun
lidge-jun marked this pull request as ready for review September 22, 2026 17:02
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant