fix(ask_user_question): recover from stringified questions array, add example shape#177
Conversation
… example shape to description Reported failure mode: smaller / older models (Qwen3, Minimax variants, some open-weights routes) JSON-encode the entire `questions` array as a string instead of emitting it as a native array literal. validateToolParams threw with "Parameter \"questions\" must be an array" — useless feedback since the model HAD sent the array, just stringified. Three changes, layered: 1. Silent coercion in validateToolParams. If `questions` is a string that parses as JSON, parse it and continue. Logs a debugLogger.warn so the signal stays visible — silent coercion would mask a real upstream regression if model behavior shifts. Catches ~all of the user-reported failures without a retry round-trip. 2. Example shape added to the tool description. Models replicate concrete examples better than they synthesize from abstract schemas with 3 levels of nesting. Placeholder text is clearly labeled as shape-only so models don't cargo-cult the example values into their actual questions. 3. Sharper error message for the residual case (non-JSON garbage in the string slot): "Pass `questions` as a real array literal, not a JSON-encoded string." Clear, specific, tells the model exactly which strategy to drop. Considered but rejected: - Schema relaxation (allow `options: string[]`, default multiSelect): API change, breaks downstream `option.description` consumers (dialog UI, ACP renderer), premature without data showing #1+#2 are insufficient. Tests updated with two new cases: stringified-array coercion, non-JSON string error path. 5319 core / 0 fail; lint + typecheck clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Review rate limit: 3/5 reviews remaining, refill in 18 minutes and 22 seconds. Comment |
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
Why
Reported failure mode: smaller / older models (Qwen3, Minimax variants, some open-weights routes) JSON-encode the entire `questions` array as a string instead of emitting it as a native array literal. `validateToolParams` then threw with the unhelpful `Parameter "questions" must be an array` — and the model retried with the same wrong format because the error didn't tell it what was actually wrong.
Self-review of the proposed plan rejected one option:
What
```diff
packages/core/src/tools/askUserQuestion.ts
```
Plus an example shape block in the tool description (with placeholder text so models don't cargo-cult literal values) and an explicit "questions is a real array. Do NOT JSON-encode it as a string." instruction.
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests
Documentation