Skip to content

fix(agent-status): questions over 16 KB show their card with every option - #31632

Merged
AmoabaKelvin merged 2 commits into
mainfrom
large-question-cards
Oct 22, 2026
Merged

AmoabaKelvin merged 2 commits into
mainfrom
large-question-cards

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​59 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​59
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​129 $\color{#cf222e}{\Huge{\mathbf{−}}}$​58 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​71

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_question with 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

normalizeInteractivePromptField cut interactivePrompt at 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

  • Normalizer. The WSL relay already had a compaction that keeps the JSON valid. It shortens only presentation text (question, header, description, detail, summary) and never touches option labels. That compaction now lives in the shared normalizer as fitInteractivePrompt. The normalizer uses it, and the relay calls the same function with its frame budget.
  • Mobile transcript. Mobile's RPC sanitizer had a generic 4,000-character tool-input budget that dropped every option of a long question. Question tool calls now use the same compaction.
  • Dismiss key. The live copy and the transcript copy are now shortened to different lengths. The dismiss key therefore reads a 200-character prefix of the presentation text, so a dismissed card no longer reopens when the transcript copy takes over.

Known limits

  • Labels alone over 16,000 characters cannot fit. That case keeps today's plain cut, so answer detection stays fail-closed, and it now logs [agent-status] interactivePrompt of N chars cannot fit…. No real agent sends labels that long.
  • An older host still cuts the prompt before it is sent. That goes away once the host updates.
  • The 128 KB tool_input half of the issue does not exist in current code. Nothing in the hook path cuts tool_input at 128 KB. The nearest limits are two:
    • The hook listener's 128K structural-token limit. It rejects the whole request rather than cutting it.
    • Native chat's 16 KB running-preview bound for ACP/Pi tool calls. That is not the hook card path.

Verified

  • Focused tests fail on main and pass here:
    • 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.
  • The relay, native-chat dismiss and mobile prompt tests pass.
  • Ran hidden dev builds of main and of this branch. Each got a real Claude UserPromptSubmit plus PreToolUse AskUserQuestion 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.
    • On main, the stored prompt was 16,000 characters that do not parse, and no card appeared.
    • On this branch, the stored prompt is 16,000 characters that do parse, and the card shows both options.

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)

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.
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Shared prompt fitting now shortens selected presentation fields while preserving option labels when a valid candidate fits. Status normalization and envelope publication use the shared helper. Mobile RPC sanitization fits recognized ask prompts before generic sanitization. Dismissal keys use bounded question text, headers, and option descriptions. Tests cover prompt parseability, option retention, and matching dismissal identities.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to 60eeb

Pathologically nested questions can lose their status update, and some dismissed question cards can reappear on mobile. These are bounded risks, but the prompt failure is worth fixing before merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 35.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title is concise, specific, and accurately describes the main change: oversized agent-status questions now display their cards and retain all answer options.
Description check Passed The description is mostly complete. It explains the user impact, root cause, implementation, known limits, linked issue, testing results, and before/after visual proof. It does not reproduce every tem…
Linked Issues check Passed [#16931] The shared normalizer now compacts oversized valid interactive-prompt JSON by shortening only presentation fields and preserving option labels. The WSL relay applies the same fitting logic to…
Out of Scope Changes check Passed All changed production code supports [#16931]. The shared fitter, relay integration, mobile integration, regression tests, and dismiss-key update preserve interactive question cards and their identity…
Full details: Description check

Explanation

The description is mostly complete. It explains the user impact, root cause, implementation, known limits, linked issue, testing results, and before/after visual proof. It does not reproduce every template heading or checklist item, but it provides the required decision-making information.

Full details: Linked Issues check

Explanation

[#16931] The shared normalizer now compacts oversized valid interactive-prompt JSON by shortening only presentation fields and preserving option labels. The WSL relay applies the same fitting logic to its frame budget. Mobile transcript sanitization applies the same logic before the generic budget. Tests cover parseability, option retention, and shared dismissal identity. The repository evidence supplied with this PR identifies no current 128 KB tool_input truncation in the hook-card path; that path rejects an over-limit request instead. The PR logs when option labels alone cannot fit, so that remaining case is no longer silent.

Full details: Out of Scope Changes check

Explanation

All changed production code supports [#16931]. The shared fitter, relay integration, mobile integration, regression tests, and dismiss-key update preserve interactive question cards and their identity across live and transcript copies. No unrelated production behavior is demonstrated.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • 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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c8cc79db-0770-4a9b-b088-a13657cc5ad0
📥 Commits

Reviewing files that changed from the base of the PR and between 7a06b65 and 60eebc5.

📒 Files selected for processing: 6
  • src/main/runtime/rpc/methods/native-chat-rpc-block-sanitize.test.ts
  • src/main/runtime/rpc/methods/native-chat-rpc-block-sanitize.ts
  • src/shared/agent-status-field-normalization.ts
  • src/shared/agent-status-types.test.ts
  • src/shared/native-chat-ask.ts
  • src/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.

Comment on lines +223 to +236
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 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.

Suggested change
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

@AmoabaKelvin
AmoabaKelvin merged commit b174776 into main Oct 22, 2026
51 checks passed
@AmoabaKelvin
AmoabaKelvin deleted the large-question-cards branch October 22, 2026 00:08
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.

Interactive prompt cards can be dropped silently by tool_input (128KB) and interactivePrompt (16KB) truncation

1 participant