Bug: TypeError in session prompt handling and workflow timeout with free models #7000

Open
opened 2026-02-16 18:05:52 -05:00 by yindo · 2 comments
Owner

Originally created by @bowen31337 on GitHub (Jan 20, 2026).

Originally assigned to: @thdxr on GitHub.

Bug Report: TypeError in session prompt handling and workflow timeout issues with free models

Summary

There are two critical issues affecting the OpenCode server's functionality:

  1. TypeError in session prompt handling (src/session/prompt.ts:1597)
  2. Workflow engine timeout with free models (e.g., minimax-m2.1-free)

Issue 1: TypeError in command handling

Description

When sending requests to the OpenCode server via REST API, certain command formats trigger a TypeError.

Error Message

TypeError: undefined is not an object (evaluating 'command3.agent')
    at command2 (src/session/prompt.ts:1597:23)
    at processTicksAndRejections (native:7:39)

Steps to Reproduce

  1. Start the OpenCode server:
opencode serve --port 54321
  1. Create a session:
curl -X POST http://localhost:54321/session \
  -H "Content-Type: application/json" \
  -d '{}'
# Response: {"id": "ses_xxx", ...}
  1. Send a command request:
curl -X POST "http://localhost:54321/session/{SESSION_ID}/command" \
  -H "Content-Type: application/json" \
  -d '{
    "messageID": "msg-test-001",
    "model": "opencode/minimax-m2.1-free",
    "agent": "",
    "command": "bash",
    "arguments": "echo \"test\""
  }'

Expected Result

The command should be processed and executed.

Actual Result

{"name":"UnknownError","data":{"message":"TypeError: undefined is not an object (evaluating 'command3.agent')\n    at command2 (src/session/prompt.ts:1597:23)\n    at processTicksAndRejections (native:7:39)"}}

Environment

  • OpenCode version: 1.1.25
  • Platform: macOS (Darwin)
  • Server port: 54321

Root Cause Analysis

The error occurs in src/session/prompt.ts at line 1597 when accessing the agent property. The code appears to be accessing a property on an undefined object, likely due to improper null checking or object structure validation.


Issue 2: Workflow timeout with free models

Description

The OpenCode workflow engine terminates prematurely when using free models (like minimax-m2.1-free) that have longer response times (90+ seconds).

Steps to Reproduce

  1. Start the OpenCode server:
opencode serve --port 54321
  1. Run a workflow with a free model:
uv run oac run ./project --model "opencode/minimax-m2.1-free" --spec templates/rest-api.md

Expected Result

The workflow should wait for the LLM response (up to the configured timeout, e.g., 600s) before proceeding.

Actual Result

[INFO] Waiting for LLM response... (15s elapsed, timeout: 600.0s)
[INFO] Waiting for LLM response... (30s elapsed, timeout: 600.0s)
[INFO] Waiting for LLM response... (45s elapsed, timeout: 600.0s)
[INFO] Workflow state: complete

The workflow completes at ~45 seconds even though:

  • Timeout is configured for 600s
  • The minimax-m2.1-free model takes 90+ seconds for responses
  • The LLM is still processing

Environment

  • Model: opencode/minimax-m2.1-free
  • Timeout configured: 600s
  • Actual completion time: ~45s
  • Platform: macOS (Darwin)

Root Cause Analysis

The workflow engine appears to have a hardcoded or misconfigured short-circuit timeout that triggers before the LLM response is received. This may be related to the streaming response handling or the way the workflow engine tracks request progress.


Workarounds

For Issue 1 (TypeError)

Use the OpenCode CLI directly instead of REST API:

opencode run "Your request" --model "opencode/minimax-m2.1-free"

For Issue 2 (Timeout)

Use a faster (paid) model instead of free models:

uv run oac run ./project --model "anthropic/claude-sonnet-4-20250514"

Impact

  • Issue 1: Blocks programmatic access via REST API, affecting SDK integrations
  • Issue 2: Makes free models unusable for autonomous workflows
  • Combined Impact: Users cannot build automated workflows using free models through the REST API

Suggested Fixes

For Issue 1

Add proper null checking and validation for the agent property in src/session/prompt.ts:1597:

// Before
const agent = command3.agent;

// After  
const agent = command3?.agent ?? "";

For Issue 2

  • Review the workflow timeout configuration logic
  • Ensure the timeout is based on the actual LLM response, not an internal stream timeout
  • Consider adding model-specific timeout adjustments for known slow models

Additional Context

  • Free models (minimax-m2.1-free, glm-4.7-free) are important for users without API keys
  • These models are documented as having longer response times (up to 600s recommended timeout)
  • The OpenCode CLI works correctly, suggesting the issue is specific to REST API handling

Related Files

  • src/session/prompt.ts (line 1597)
  • Workflow engine timeout configuration
  • REST API command handler

Test Data

Session ID for Issue 1 Reproduction

ses_4221056f2ffeIrtlGp2cVyOrLK

LLM Response Time Data

  • Simple query: ~90s (minimax-m2.1-free)
  • Complex query: >120s (minimax-m2.1-free)

Severity

  • Issue 1: High - Blocks programmatic access
  • Issue 2: High - Makes free models unusable for automation

Contact

For questions or additional context, please reach out.


Bug Report Version: 1.0
Date: 2026-01-21
OpenCode Version: 1.1.25

Originally created by @bowen31337 on GitHub (Jan 20, 2026). Originally assigned to: @thdxr on GitHub. # Bug Report: TypeError in session prompt handling and workflow timeout issues with free models ## Summary There are two critical issues affecting the OpenCode server's functionality: 1. **TypeError in session prompt handling** (`src/session/prompt.ts:1597`) 2. **Workflow engine timeout with free models** (e.g., minimax-m2.1-free) ## Issue 1: TypeError in command handling ### Description When sending requests to the OpenCode server via REST API, certain command formats trigger a TypeError. ### Error Message ``` TypeError: undefined is not an object (evaluating 'command3.agent') at command2 (src/session/prompt.ts:1597:23) at processTicksAndRejections (native:7:39) ``` ### Steps to Reproduce 1. Start the OpenCode server: ```bash opencode serve --port 54321 ``` 2. Create a session: ```bash curl -X POST http://localhost:54321/session \ -H "Content-Type: application/json" \ -d '{}' # Response: {"id": "ses_xxx", ...} ``` 3. Send a command request: ```bash curl -X POST "http://localhost:54321/session/{SESSION_ID}/command" \ -H "Content-Type: application/json" \ -d '{ "messageID": "msg-test-001", "model": "opencode/minimax-m2.1-free", "agent": "", "command": "bash", "arguments": "echo \"test\"" }' ``` ### Expected Result The command should be processed and executed. ### Actual Result ``` {"name":"UnknownError","data":{"message":"TypeError: undefined is not an object (evaluating 'command3.agent')\n at command2 (src/session/prompt.ts:1597:23)\n at processTicksAndRejections (native:7:39)"}} ``` ### Environment - OpenCode version: 1.1.25 - Platform: macOS (Darwin) - Server port: 54321 ### Root Cause Analysis The error occurs in `src/session/prompt.ts` at line 1597 when accessing the `agent` property. The code appears to be accessing a property on an undefined object, likely due to improper null checking or object structure validation. --- ## Issue 2: Workflow timeout with free models ### Description The OpenCode workflow engine terminates prematurely when using free models (like minimax-m2.1-free) that have longer response times (90+ seconds). ### Steps to Reproduce 1. Start the OpenCode server: ```bash opencode serve --port 54321 ``` 2. Run a workflow with a free model: ```bash uv run oac run ./project --model "opencode/minimax-m2.1-free" --spec templates/rest-api.md ``` ### Expected Result The workflow should wait for the LLM response (up to the configured timeout, e.g., 600s) before proceeding. ### Actual Result ``` [INFO] Waiting for LLM response... (15s elapsed, timeout: 600.0s) [INFO] Waiting for LLM response... (30s elapsed, timeout: 600.0s) [INFO] Waiting for LLM response... (45s elapsed, timeout: 600.0s) [INFO] Workflow state: complete ``` The workflow completes at ~45 seconds even though: - Timeout is configured for 600s - The minimax-m2.1-free model takes 90+ seconds for responses - The LLM is still processing ### Environment - Model: opencode/minimax-m2.1-free - Timeout configured: 600s - Actual completion time: ~45s - Platform: macOS (Darwin) ### Root Cause Analysis The workflow engine appears to have a hardcoded or misconfigured short-circuit timeout that triggers before the LLM response is received. This may be related to the streaming response handling or the way the workflow engine tracks request progress. --- ## Workarounds ### For Issue 1 (TypeError) Use the OpenCode CLI directly instead of REST API: ```bash opencode run "Your request" --model "opencode/minimax-m2.1-free" ``` ### For Issue 2 (Timeout) Use a faster (paid) model instead of free models: ```bash uv run oac run ./project --model "anthropic/claude-sonnet-4-20250514" ``` --- ## Impact - **Issue 1**: Blocks programmatic access via REST API, affecting SDK integrations - **Issue 2**: Makes free models unusable for autonomous workflows - **Combined Impact**: Users cannot build automated workflows using free models through the REST API --- ## Suggested Fixes ### For Issue 1 Add proper null checking and validation for the `agent` property in `src/session/prompt.ts:1597`: ```typescript // Before const agent = command3.agent; // After const agent = command3?.agent ?? ""; ``` ### For Issue 2 - Review the workflow timeout configuration logic - Ensure the timeout is based on the actual LLM response, not an internal stream timeout - Consider adding model-specific timeout adjustments for known slow models --- ## Additional Context - Free models (minimax-m2.1-free, glm-4.7-free) are important for users without API keys - These models are documented as having longer response times (up to 600s recommended timeout) - The OpenCode CLI works correctly, suggesting the issue is specific to REST API handling --- ## Related Files - `src/session/prompt.ts` (line 1597) - Workflow engine timeout configuration - REST API command handler --- ## Test Data ### Session ID for Issue 1 Reproduction ``` ses_4221056f2ffeIrtlGp2cVyOrLK ``` ### LLM Response Time Data - Simple query: ~90s (minimax-m2.1-free) - Complex query: >120s (minimax-m2.1-free) --- ## Severity - **Issue 1**: High - Blocks programmatic access - **Issue 2**: High - Makes free models unusable for automation --- ## Contact For questions or additional context, please reach out. --- **Bug Report Version**: 1.0 **Date**: 2026-01-21 **OpenCode Version**: 1.1.25
Author
Owner

@github-actions[bot] commented on GitHub (Jan 20, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #6573: Sessions hang indefinitely when Task tool spawns subagents via REST API (opencode serve) - Similar REST API issue with command handling and session state
  • #6792: Task Tool Timeouts & Early Termination in Multi-Agent Conductor Pattern - Similar timeout issue where tasks return session_id prematurely instead of completing
  • #9437: Agent.get() returns undefined without error handling, causing crash - Related undefined handling issue that causes TypeError when accessing agent properties

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 20, 2026): This issue might be a duplicate of existing issues. Please check: - #6573: Sessions hang indefinitely when Task tool spawns subagents via REST API (opencode serve) - Similar REST API issue with command handling and session state - #6792: Task Tool Timeouts & Early Termination in Multi-Agent Conductor Pattern - Similar timeout issue where tasks return session_id prematurely instead of completing - #9437: Agent.get() returns undefined without error handling, causing crash - Related undefined handling issue that causes TypeError when accessing agent properties Feel free to ignore if none of these address your specific case.
Author
Owner

@wlioi commented on GitHub (Feb 5, 2026):

Related: Another TypeError in prompt.ts (#12336)

I reported a similar TypeError issue (#12336) that also occurs in src/session/prompt.ts, but at a different location.

Comparison

Your Issue (#9733): Line 1597, command3.agent undefined
My Issue (#12336): Line 704, schema._zod.def undefined

Common Pattern

Both issues suggest src/session/prompt.ts has multiple locations missing defensive null checking.

Refs:

  • #12336: Bug: Zod TypeError when loading custom tools
  • #12269: tool.registry test fails on CI
@wlioi commented on GitHub (Feb 5, 2026): ## Related: Another TypeError in prompt.ts (#12336) I reported a similar TypeError issue (#12336) that also occurs in src/session/prompt.ts, but at a different location. ### Comparison Your Issue (#9733): Line 1597, command3.agent undefined My Issue (#12336): Line 704, schema._zod.def undefined ### Common Pattern Both issues suggest src/session/prompt.ts has multiple locations missing defensive null checking. Refs: - #12336: Bug: Zod TypeError when loading custom tools - #12269: tool.registry test fails on CI
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7000