Skip to content

fix(agent-session): drop JSON-shaped prompt suggestions instead of showing raw JSON in the composer - #51559

Merged
nwparker merged 1 commit into
mainfrom
bugbash/issue-51512
Nov 28, 2026
Merged

nwparker merged 1 commit into
mainfrom
bugbash/issue-51512

Conversation

@nwparker

@nwparker nwparker commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Sometimes Claude or Codex has no guess for your next message and says so with a small piece of machine data, {"suggestion":null}. Orca treated that as the guess itself and put it in the message box. Now Orca throws away any guess that is machine data instead of a sentence.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​14 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​14
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​31 $\color{#cf222e}{\Huge{\mathbf{−}}}$​21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10

What Changed

  • Before: the composer could show {"suggestion":null} (or other JSON) as an editable prompt suggestion after a turn finished.
  • After: a suggestion that is a JSON object or array is dropped, so no suggestion is shown in that case. Normal suggestions, including ones that contain braces or brackets in a sentence ({x} still fails, fix the [WIP] test), still appear.
  • Mechanism: Claude (withClaudePromptSuggestions) and Codex (readSampleText) each had their own trim + 1000-character check. Both now call one shared readPromptSuggestionText in src/main/native-chat/agent-session-wire/publication/subscribers/agent-session-prompt-suggestion-text.ts. It trims, keeps the same 1000-character cap, and returns null when the text starts with { or [ and parses as JSON. Codex's NO_PREDICTION sentinel check is unchanged.

Why

The sampler's "no guess" reply sometimes comes back as a JSON payload instead of empty text or NO_PREDICTION, and both providers passed it straight to the composer. Dropping it at the one place where suggestion text is read fixes it for both providers. Only text that actually parses as JSON is dropped, so a real prompt that happens to start with a brace is not lost. Because the cap and trim rules now live in one place, the two providers can't drift apart.

Linked Issue

Fixes #51512

Visual Proof

N/A. The fix is a main-process filter on the suggestion text, and the result is that no suggestion is shown. The before/after evidence is a probe test run on main versus this branch: on main, 14 of 29 cases fail (Codex and Claude both pass {"suggestion":null}, {"suggestion": null}, padded variants, {}, [], [null] and {"suggestion":"fix it"} to the composer). On this branch all 29 pass.

Testing

  • Repro: fed {"suggestion":null} and other JSON payloads through the Codex sample reader and the Claude prompt-suggestion handler on main. Both published the raw JSON as a suggestion.

  • Verification: the same probe passes on this branch (29/29). Added agent-session-prompt-suggestion-text.test.ts, which covers dropping a padded JSON payload and keeping a prompt that contains braces and brackets. The Codex and Claude turn suites still pass.

  • Static gates: oxlint (default, anti-slop, code-quality native plugins), ast-grep, oxfmt and the changed-code quality gate all pass on the touched files.

  • Platforms: macOS (unit level). The change is pure string handling with no platform-specific code.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

Performance

None that matters. This runs once per finished turn, when a suggestion arrives, not on a hot path. Microbenchmark, old vs new per call: typical sentence 4.3 ns vs 7.2 ns, JSON payload 4.3 ns vs 86 ns. The adversarial worst case is a 1000-character brace- or bracket-led string that forces a full JSON.parse, which costs about 2.9 to 5.6 µs. That is far below a 16 ms frame. There is no new I/O, subprocess, polling, or renderer or store work, so there is no per-tab fanout.

Risk

Level: Low

The riskiest part: a real suggestion that is itself valid JSON (for example the model suggesting a bare [1, 2]) is now dropped. The user would just see no suggestion for that turn. Back it out with a plain revert.

Review

Reported by flowke

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security, cross-platform, remote SSH, mobile and backwards compatibility: no impact. This is a main-process text filter and no wire shapes change.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…owing raw JSON in the composer

Claude and Codex prompt suggestions now pass through one shared reader that
trims the text, enforces the existing 1000-character cap, and drops any
suggestion that parses as a JSON object or array (such as a sampler's
`{"suggestion":null}` for "no guess"), so the composer never shows it as
editable text.

Fixes #51512
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

A shared helper now trims prompt-suggestion text and rejects non-string, empty, oversized, or valid JSON input. Claude and Codex use the helper instead of local trimming and length checks. Tests cover a JSON null-suggestion payload and text containing braces or brackets.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 8b615

This change stops raw JSON payloads such as a null suggestion from showing up as editable prompt text in Claude and Codex sessions. Ordinary sentences containing braces or brackets are still suggested. The change is small and contained, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: JSON-shaped prompt suggestions are dropped so raw JSON no longer appears in the composer. It follows the fix(scope) convention, is specific, and matches the raw summar…
Linked Issues check Passed [#51512] requires that internal suggestion data not appear as literal text in the composer. At head, the new helper readPromptSuggestionText in agent-session-prompt-suggestion-text.ts returns `nul…
Out of Scope Changes check Passed All changed files relate to the issue objective. The new shared helper implements the JSON-payload filter. codex-composer-predictions.ts and claude-open-turn.ts replace their local trim and length…
Description check Passed The description covers every required section of the template: ELI5, What Changed, Why, Linked Issue (Fixes #51512), Visual Proof (N/A with a reason and probe evidence), Testing with checkboxes, Perfo…
Full details: Title check

Explanation

The title names the main change: JSON-shaped prompt suggestions are dropped so raw JSON no longer appears in the composer. It follows the fix(scope) convention, is specific, and matches the raw summary and objectives. Minor issue: at 99 characters it is slightly long.

Full details: Linked Issues check

Explanation

[#51512] requires that internal suggestion data not appear as literal text in the composer. At head, the new helper readPromptSuggestionText in agent-session-prompt-suggestion-text.ts returns null when trimmed text starts with { or [ and JSON.parse succeeds. The reported payload {"suggestion":null} therefore yields no suggestion. Codex readSampleText in codex-composer-predictions.ts now calls this helper and keeps the NO_PREDICTION check. Per the PR summary, claude-open-turn.ts also calls the helper before storing a suggestion, so both providers share the filter. The helper keeps the empty-text and 1000-character limits, and ordinary prose with braces or brackets still passes. The PR adds a unit test file for these cases. The exact trigger in the issue is unknown, so this assessment covers the reported payload path only. No non-coding requirements exist in the issue.

Full details: Out of Scope Changes check

Explanation

All changed files relate to the issue objective. The new shared helper implements the JSON-payload filter. codex-composer-predictions.ts and claude-open-turn.ts replace their local trim and length checks with that helper, which removes duplicate logic and keeps the 1000-character cap. The test file covers the new helper. The known side effect is that a valid JSON suggestion such as [1, 2] is now dropped. The PR description states this tradeoff, and it follows directly from the requested filter, so it is not an unrelated change.

Full details: Description check

Explanation

The description covers every required section of the template: ELI5, What Changed, Why, Linked Issue (Fixes #51512), Visual Proof (N/A with a reason and probe evidence), Testing with checkboxes, Performance (a concrete reason with measurements), Risk with level Low and a revert plan, AI Disclosure, the Agent skill upstream boundary, Notes, and Checklist. The author states the mechanism, the 1000-character cap, and the trade-off of dropping valid JSON suggestions. The only unchecked item is the full pnpm lint, typecheck, test, and build run, and the author says CI covers that. The template's AI Disclosure section is left blank, which is non-critical for this check.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ca89c87a-7249-4456-b687-140444702ab8
Commits

Reviewing files that changed from the base of the PR and between bafaabd and 8b615f1.

Files selected for processing: 4

  • src/main/claude/structured/turns/claude-open-turn.ts
  • src/main/codex/structured/turns/codex-composer-predictions.ts
  • src/main/native-chat/agent-session-wire/publication/subscribers/agent-session-prompt-suggestion-text.test.ts
  • src/main/native-chat/agent-session-wire/publication/subscribers/agent-session-prompt-suggestion-text.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@nwparker
nwparker merged commit 0dd4244 into main Nov 28, 2026
56 of 57 checks passed
@nwparker
nwparker deleted the bugbash/issue-51512 branch November 28, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Composer intermittently displays raw {"suggestion":null} JSON

1 participant