You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
task tool crashes with "messages.map is not a function" whenever session.messages returns a non-2xx (normalizeSDKResponse preferResponseOnMissingData yields non-array) #6912
When the HTTP call fails with a non-2xx status, the hey-api SDK resolves (does not throw) with { error, request, response } — there is no data key. With preferResponseOnMissingData: true, normalizeSDKResponse then returns the raw response object, which is truthy and not an array. Callers (findNearestMessageWithFieldsFromSDK → findNearestMessageWithFieldsFromMessages, findFirstMessageWithAgentFromSDK, findMessageContextFromSDK) pass it straight into messages.map(...) → the crash above.
The task tool hits this on every dispatch via executeBackground → resolveMessageContext (sqlite backend → SDK path), which is why task delegation fails 100% while the rest of the session keeps working.
The same latent crash exists anywhere an array-expecting call site uses preferResponseOnMissingData: true (e.g. the todo fetch paths) — any non-2xx from session.messages/session.todo (401, 404, 502, ...) turns into a TypeError instead of graceful degradation.
Trigger in my environment (for completeness)
opencode serve 1.18.18 with OPENCODE_SERVER_PASSWORD set, plus a system HTTP_PROXY whose no_proxy used CIDR notation (127.0.0.0/8). Bun's fetch does not match CIDR entries in NO_PROXY (filed as oven-sh/bun#39352), so the plugin's loopback API calls were routed through the proxy and came back 502. Fixing the proxy env makes the crash disappear — but the missing array guard means any transient non-2xx will crash the task tool the same way.
Same symptom, different trigger: anomalyco/opencode#33114 (task() fails with messages.map is not a function over WSL).
Suggested fix
Guard the array contract after normalization, e.g. in fetchSDKMessages:
constmessages=normalizeSDKResponse(response,emptyMessages,{preferResponseOnMissingData: true});if(!Array.isArray(messages)){log2("[hook-message-injector] SDK message fetch returned non-array",{ sessionID });returnnull;}returnmessages;
(and the same Array.isArray check for the other preferResponseOnMissingData: true array call sites), so a failed SDK fetch degrades to the existing null fallback path instead of crashing the tool call.
Activity