Repository navigation
fix(agent-status): questions over 16 KB show their card with every option - #31632
Conversation
The shared normalizer cut interactivePrompt at 16,000 characters as plain text, so a longer question became invalid JSON and every client dropped its card. Shorten only the presentation text inside the JSON instead, keeping every option label, using the compaction the WSL relay already had (now in the shared normalizer, which the relay calls).
…on mobile A compacted live question and its transcript copy differ in text, so a dismissed card reopened when status cleared before the tool result. Key the dismissal on a prefix every copy keeps. Mobile's transcript budget also dropped every option of a question over 4,000 characters; compact it with the same shared function instead. Log the case where the labels alone are over the status cap.
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
c8cc79db-0770-4a9b-b088-a13657cc5ad0
📒 Files selected for processing: 6
src/main/runtime/rpc/methods/native-chat-rpc-block-sanitize.test.tssrc/main/runtime/rpc/methods/native-chat-rpc-block-sanitize.tssrc/shared/agent-status-field-normalization.tssrc/shared/agent-status-types.test.tssrc/shared/native-chat-ask.tssrc/wsl-guest/agent-hook-envelope-publication.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
| let low = 1 | ||
| let high = prompt.length | ||
| let fitted: string | null = null | ||
| while (low <= high) { | ||
| const mid = Math.floor((low + high) / 2) | ||
| const candidate = promptAtLimit(mid) | ||
| if (fits(candidate)) { | ||
| fitted = candidate | ||
| low = mid + 1 | ||
| } else { | ||
| high = mid - 1 | ||
| } | ||
| } | ||
| return fitted |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Guard fitInteractivePrompt against a throw from deeply nested JSON.
normalizeInteractivePromptField now parses and recursively compacts any oversized interactivePrompt. JSON.parse accepts very deep nesting. compactInteractivePromptValue recurses without a depth limit, so a nested prompt larger than the cap can overflow the stack with a RangeError.
The previous normalizer only sliced the string and could not throw. A RangeError now escapes normalizeInteractivePromptField. parseAgentStatusPayload catches it and returns null, which drops the whole status payload instead of only the prompt. assertJsonTextStructureWithinLimits checks only the outer payload text. It does not limit the nesting inside the prompt string.
Catch the failure inside fitInteractivePrompt and return null. The caller then uses its existing plain-truncation fallback.
🛡️ Proposed fix
- while (low <= high) {
- const mid = Math.floor((low + high) / 2)
- const candidate = promptAtLimit(mid)
- if (fits(candidate)) {
- fitted = candidate
- low = mid + 1
- } else {
- high = mid - 1
- }
- }
- return fitted
+ try {
+ while (low <= high) {
+ const mid = Math.floor((low + high) / 2)
+ const candidate = promptAtLimit(mid)
+ if (fits(candidate)) {
+ fitted = candidate
+ low = mid + 1
+ } else {
+ high = mid - 1
+ }
+ }
+ } catch {
+ // Why: a pathologically nested prompt can overflow the recursive compaction; treat it as unfittable.
+ return null
+ }
+ return fitted📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let low = 1 | |
| let high = prompt.length | |
| let fitted: string | null = null | |
| while (low <= high) { | |
| const mid = Math.floor((low + high) / 2) | |
| const candidate = promptAtLimit(mid) | |
| if (fits(candidate)) { | |
| fitted = candidate | |
| low = mid + 1 | |
| } else { | |
| high = mid - 1 | |
| } | |
| } | |
| return fitted | |
| let low = 1 | |
| let high = prompt.length | |
| let fitted: string | null = null | |
| try { | |
| while (low <= high) { | |
| const mid = Math.floor((low + high) / 2) | |
| const candidate = promptAtLimit(mid) | |
| if (fits(candidate)) { | |
| fitted = candidate | |
| low = mid + 1 | |
| } else { | |
| high = mid - 1 | |
| } | |
| } | |
| } catch { | |
| // Why: a pathologically nested prompt can overflow the recursive compaction; treat it as unfittable. | |
| return null | |
| } | |
| return fitted |
Fixes #16931
What users saw
If an agent asked a question with a serialized prompt over 16,000 characters (for example a Grok
ask_user_questionwith a long body), the pane went to waiting, but no question card or options appeared on the desktop or the phone. Nothing explained why.Now
The card shows with every option. If the question text is too long to fit, its end is cut off.
On mobile, the transcript copy of a question over about 4,000 characters also kept its options. Before, it lost all of them.
Root cause
normalizeInteractivePromptFieldcutinteractivePromptat 16,000 characters as plain text. Every status payload goes through it: local hooks, SSH/WSL relay ingest and IPC. So an oversized prompt reached every client as invalid JSON, and each parser returned null without saying so.Change
question,header,description,detail,summary) and never touches option labels. That compaction now lives in the shared normalizer asfitInteractivePrompt. The normalizer uses it, and the relay calls the same function with its frame budget.Known limits
[agent-status] interactivePrompt of N chars cannot fit…. No real agent sends labels that long.tool_inputhalf of the issue does not exist in current code. Nothing in the hook path cutstool_inputat 128 KB. The nearest limits are two:Verified
agent-status-types.test.ts: an oversized question still parses with its labels.native-chat-rpc-block-sanitize.test.ts: mobile keeps the options, and the status, desktop transcript and mobile transcript copies share one dismiss key.UserPromptSubmitplusPreToolUseAskUserQuestion hook with a 21K question, posted to the app's hook server, and the pane was switched to chat view. The transcript held only the user turn, so the card had to come from live status.Visual Proof
Before (main): the pane waits with no question card.
(screenshot removed: contained real product data)
After: the question card shows, with both options under the shortened question.
(screenshot removed: contained real product data)