Skip to content

[WRONG BRANCH] fix(cursor): preserve malformed buffered tool args - #276

Closed
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-empty-arguments-from-malformed-tool-calls
Closed

[WRONG BRANCH] fix(cursor): preserve malformed buffered tool args#276
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-empty-arguments-from-malformed-tool-calls

Conversation

@luvs01

@luvs01 luvs01 commented Aug 13, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Cursor previously buffered incremental argsTextDelta and, when a completion arrived with no structured map, treated an incomplete JSON buffer as empty arguments, which the bridge serialized as {} and caused malformed/truncated arguments to be silently accepted downstream instead of failing-closed.

Description

  • Change resolveCompletedArgs to preserve the buffered argsTextDelta when it is non-empty but not complete JSON, so malformed/truncated argument blobs are forwarded instead of being conflated with a genuinely no-arg call.
  • Update the inline documentation to explain the new fail-closed intent for malformed buffered text.
  • Add a focused regression test preserves incomplete streamed args when completion has no argument map in tests/cursor-protobuf-events.test.ts to verify the adapter emits the buffered truncated text at completion.
  • Files modified: src/adapters/cursor/protobuf-events.ts, tests/cursor-protobuf-events.test.ts.

Testing

  • Ran bun test tests/cursor-protobuf-events.test.ts, which passed (34 passed, 0 failed).
  • Ran bun run typecheck (tsc --noEmit), which completed cleanly.
  • Ran bun run privacy:scan, which passed.
  • Ran git diff --check (no whitespace or diff issues found).

Codex Task

Summary by CodeRabbit

  • Bug Fixes

    • Preserved incomplete streamed tool-call arguments instead of replacing them with empty content.
    • Continued to normalize complete JSON arguments while keeping empty output only for calls without arguments.
  • Tests

    • Added regression coverage for incomplete tool-call argument streams, including successful completion without errors.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2f5d8aaf-4d3c-4be6-850d-e698cf84a33f

📥 Commits

Reviewing files that changed from the base of the PR and between 1193075 and 0233e50.

📒 Files selected for processing (2)
  • src/adapters/cursor/protobuf-events.ts
  • tests/cursor-protobuf-events.test.ts

📝 Walkthrough

Walkthrough

The change preserves incomplete streamed tool-call arguments when completion provides no structured argument map. A regression test verifies deferred start emission, the preserved argument delta, and the tool-call end event.

Changes

Cursor tool argument handling

Layer / File(s) Summary
Preserve buffered arguments and cover incomplete streams
src/adapters/cursor/protobuf-events.ts:338-346, tests/cursor-protobuf-events.test.ts:312-335
resolveCompletedArgs now retains malformed or incomplete buffered JSON instead of replacing it with an empty string. Complete JSON and structured argument maps keep their existing behavior. The regression test verifies the emitted start, partial argument text, and end events.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Mergeability Score: ⚪ Minimal · up to 0233e

This localized change preserves malformed buffered tool arguments instead of converting them to empty arguments, with focused tests and validation passing; no actionable merge-blocking risk remains.

Suggested reviewers: lidge-jun, wibias, ingwannu

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving malformed buffered Cursor tool arguments.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-empty-arguments-from-malformed-tool-calls

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

@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 13, 2026
@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@github-actions github-actions Bot changed the title fix(cursor): preserve malformed buffered tool args [WRONG BRANCH] fix(cursor): preserve malformed buffered tool args Aug 13, 2026
@github-actions
github-actions Bot marked this pull request as draft August 13, 2026 02:12

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0233e50917

ℹ️ 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 name = mcpWireNameFromArgs(args);
if (isCompleteJson(buffered)) return normalizeJsonText(buffered, name, state);
return "";
return buffered;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject whitespace-only buffered arguments

When argsTextDelta contains only whitespace and completion has no argument map, returning the truthy buffer does not fail closed: toolCallArgumentsUsable trims it and accepts it as an empty no-arg call, while closeCurrentToolCall preserves the original whitespace instead of substituting {}. The response is therefore marked completed with arguments: " ", which is not valid JSON and can make the echoed call fail on the next turn. Reject whitespace-only non-empty buffers as malformed rather than forwarding them.

AGENTS.md reference: src/AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

@luvs01 luvs01 closed this Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant