Repository navigation
fix(agent-session): drop JSON-shaped prompt suggestions instead of showing raw JSON in the composer - #51559
Conversation
…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
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
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.What Changed
{"suggestion":null}(or other JSON) as an editable prompt suggestion after a turn finished.{x} still fails, fix the [WIP] test), still appear.withClaudePromptSuggestions) and Codex (readSampleText) each had their own trim + 1000-character check. Both now call one sharedreadPromptSuggestionTextinsrc/main/native-chat/agent-session-wire/publication/subscribers/agent-session-prompt-suggestion-text.ts. It trims, keeps the same 1000-character cap, and returnsnullwhen the text starts with{or[and parses as JSON. Codex'sNO_PREDICTIONsentinel 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 onmain. 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
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)