Skip to content

Conversation

@konard
Copy link
Contributor

@konard konard commented Feb 1, 2026

Summary

Fixes the ZodError ("No matching discriminator") that crashes the session when a tool execution fails or is aborted.

  • Root cause: Commit 7748404 changed status: 'error' to status: 'failed' in processor.ts, but the Zod schema ToolStateError defines the valid status as z.literal('error'). This mismatch causes the z.discriminatedUnion('status', [...]) validation to reject the data when Session.updatePart() is called.
  • Fix: Revert to status: 'error' in all 3 places in processor.ts and 1 place in event-handler.js, aligning with the Zod schema and upstream OpenCode.
  • Verified: Upstream OpenCode uses status: 'error' consistently.

Changes

  • js/src/session/processor.ts: Change 'failed''error' in tool-error handler and cleanup loop (3 changes)
  • js/src/cli/event-handler.js: Change 'failed''error' in tool state check (1 change)
  • docs/case-studies/issue-149/: Full case study with timeline reconstruction, root cause analysis, and incident log
  • js/.changeset/fix-tool-state-zod-error.md: Changeset for patch release

Fixes #149

Test plan

  • Unit tests pass (bun test - session-usage, json-standard-unit, socket-retry, timeout-retry, stream-timeout)
  • Lint and format checks pass (npm run check)
  • Pre-commit hooks pass
  • Manual test: trigger a tool error and verify no ZodError is thrown
  • Verify tool error events are properly output in CLI

This PR was created automatically by the AI issue solver

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #149
@konard konard self-assigned this Feb 1, 2026
… processor

The Zod schema ToolStateError defines status as z.literal('error'), but
processor.ts was using 'failed' in three places, causing ZodError with
"No matching discriminator" when tools fail or are aborted. This was
introduced in commit 7748404 and diverges from upstream OpenCode.

Fixes #149

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title [WIP] ZodError fix: ZodError in session processor for tool error status Feb 1, 2026
@konard konard marked this pull request as ready for review February 1, 2026 13:18
@konard
Copy link
Contributor Author

konard commented Feb 1, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $5.522514 USD
  • Calculated by Anthropic: $4.254565 USD
  • Difference: $-1.267949 (-22.96%)
    📎 Log file uploaded as Gist (883KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard konard merged commit c5ad97b into main Feb 1, 2026
8 checks passed
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.

ZodError

2 participants