fix(server): thread snapshot returns empty HTTP 400 when an AskUserQuestion entry has no question text
Version: v0.0.42 (stock npm install); the same code is on current main and the v0.0.43 nightly/preview tags as of 2026-09-26.
Repro
In a Claude thread, the model calls AskUserQuestion with an entry that has header and options but no question text (Claude rejects the call and the agent retries). The same shape also appears transiently when a streamed tool.updated for AskUserQuestion holds input.questions: [{}] because header streams before question.
From then on GET /api/orchestration/threads/:id returns HTTP 400 with an empty body; the web and mobile clients never load the thread ("waiting for input" / loading forever), while every other thread is fine. The WebSocket thread snapshot path fails the same way.
Server trace:
HttpApiSchemaError: Body … SchemaError: Expected JSON value at ["thread"]["activities"][N]["payload"]
Root cause
projectQuestionToolInput (packages/shared/src/toolActivity.ts) maps each question to { question: asTrimmedString(...) }, which yields { question: undefined } when there is no text. OrchestrationThreadActivity.payload is Schema.Unknown, and the HttpApi JSON codec rejects undefined, so one bad activity fails the whole snapshot. Because the failed call's tool.completed row is kept, the thread stays unloadable permanently.
Proposed fix
Leave the key out when there is no text:
// packages/shared/src/toolActivity.ts, projectQuestionToolInput
text === undefined ? {} : { question: text }
with a toStrictEqual regression test. Clients already read record(question)?.question, so a missing key is handled. It may also be worth making projectActivityPayload JSON-safe in general (drop undefined values) so a single malformed activity can never make a thread unloadable.
Possibly related symptom: #10418.
Found and patched with Claude Opus 5.5 via Claude Code; a one-commit local build with this change fixes it here.
Confirmed on current main (0.0.42). Not a duplicate of #10418. That report is the same “this thread never finishes loading” symptom after a snapshot failure, but the cause there was an unconfirmed disk-full path. Nothing else open matches this encode failure.
projectQuestionToolInput in packages/shared/src/toolActivity.ts always emits { question: asTrimmedString(...) }. asTrimmedString returns undefined when the entry has no question text, including a streamed questions: [{}] and a finished AskUserQuestion call that only has header and options. Object.keys still sees that key, and Schema.Unknown rejects it as “Expected JSON value” on the payload itself, which is why the trace stops at ["thread"]["activities"][N]["payload"]. HttpApiSchemaError for the response body is rendered as an empty 400.
Stored rows are fine. Inserts use JSON.stringify, which drops undefined, and item.completed persists the raw tool input. The bad value is created again on every read: listProjectedThreadActivities projects the payload, then both GET /api/orchestration/threads/:threadId and the WebSocket snapshot/live events project it again. A rejected call’s tool.completed row therefore keeps the thread unloadable. A later update that includes question text recovers a purely mid-stream failure.
The proposed change is the right fix: omit question when there is no text. Clients already read it with record(question)?.question, and that field exists only so the work log can match the tool row to the canonical question. A toStrictEqual regression on the projected questions array is enough. No database rewrite is needed; threads that are already stuck load again once the projection stops emitting undefined. A general “drop every undefined in projectActivityPayload” pass is a separate change and is not required to fix this.
[!NOTE] 🤖 GPT-6.1-Sol responding on behalf of Theo
This issue should be resolved in the next nightly build by Orchestrator v2 (#2829).
Please try that nightly. If the problem still exists, open a new issue with the nightly version you tested and steps to reproduce it.