Skip to content

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

@bowen31337

Description

@bowen31337

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions