Skip to content

Heads up: opencode titlecase() crash when task() called without subagent_type (workaround inside) #1948

@bkataru

Description

@bkataru

Summary

When using oh-my-opencode with opencode v1.2.6, the process crashes with a TypeError in certain conditions — specifically when a model calls the task() tool without providing subagent_type.

This is primarily an opencode bug, but it's worth noting here because oh-my-opencode's multi-model orchestration (especially Sisyphus with models like Qwen 3.5, GLM-4.7) increases the frequency of task() calls, making the crash more likely to surface.

The Error

TypeError: undefined is not an object (evaluating 'str3.replace')
      at titlecase (src/util/locale.ts:3:12)
      at task (src/cli/cmd/run.ts:170:24)
      at loop (src/cli/cmd/run.ts:472:15)

What Triggers It

opencode/run.ts:170 calls Locale.titlecase(info.input.subagent_type) with no null check. When a model omits subagent_type from its task() call (valid per schema), titlecase(undefined) throws.

In TypeScript project directories, models orchestrated by oh-my-opencode's Sisyphus agent tend to delegate via task() more aggressively, often without subagent_type — reliably reproducing the crash.

Attempted Workaround: disabled_hooks

Adding "disabled_hooks": ["category-skill-reminder"] to oh-my-opencode.json does not fully fix this — even with the hook disabled, the models themselves generate task() calls without subagent_type. The hook was only one trigger.

Upstream Issue

Filed as: anomalyco/opencode#14169

The fix is a simple null guard in src/util/locale.ts:

function titlecase(str: string | undefined): string {
    if (!str) return "";
    return str.replace(/\b\w/g, (c) => c.toUpperCase());
}

Workaround Until Fixed

A same-size binary patch can be applied to the compiled opencode binary. Full details, patch script, and verification results here:

https://gist.github.com/bkataru/27caa1aeb746efb06f83127cfcc586b0

Suggestion for oh-my-opencode

If possible, when oh-my-opencode generates a task() call (e.g. via the category-skill-reminder hook or Sisyphus orchestration), ensuring subagent_type is always included would prevent this crash path regardless of the opencode version.

Environment

Component Version
opencode v1.2.6 (anomalyco fork)
oh-my-opencode v3.7.3
Models Qwen 3.5-397B, GLM-4.7, MiniMax M2.1 (NVIDIA NIM)
OS Linux (Ubuntu 24.04)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions