Skip to content

Subagent tool: sessionID not clearly marked as optional in serialized JSON schema #55503

Closed

Description

@throny

Problem

The subagent tool's sessionID parameter is correctly defined as optional in the TypeScript source (Schema.optionalKey(SessionSchema.ID)), but some models do not reliably infer optionality from the serialized JSON schema. They see sessionID in properties and treat it as required, filling it with garbage values like "sesh" or "sesh_omit_should_not_be_here".

This results in Subagent session not found errors that confuse the model, which then retries with more garbage values in a loop.

Evidence

  • Source: packages/core/src/tool/plugin/subagent.ts line 40 — Schema.optionalKey(SessionSchema.ID)
  • Serialization: packages/ai/src/tool.ts — Schema.toJsonSchemaDocument() produces a JSON schema where sessionID is in properties but not in required
  • The serialized schema is technically correct, but some models do not check the required array and instead pattern-match "fill in all properties"

Expected Behavior

Models should omit sessionID when starting a new subagent. The tool description already says "Calls without a sessionID start a new conversation," but models ignore this.

Actual Behavior

Models fill sessionID with fabricated values, causing Subagent session not found errors. Explicit user prompts to omit the field do not reliably fix the behavior.

Suggested Fix

Add explicit "optional": true to the serialized JSON schema for sessionID, background, model, and agent in the subagent tool definition. Alternatively, add a stronger hint in the tool description (e.g., "IMPORTANT: Do NOT include sessionID unless continuing a previous subagent").

Environment

  • OpenCode version: latest (desktop)
  • Model: third-party model with weaker JSON schema adherence

Activity

  1. opencode-agent commented on Oct 14, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report, @throny! Your request is to make it clearer to models that sessionID (and the other optional subagent parameters) should be left out when starting a new subagent. Some models, like aqua/gpt-6-luna, fill it in with made-up values and then loop on Subagent session not found.

    The current schema already marks sessionID as optional: it is left out of required, and its description says calls without it start a new conversation. So this is a model-compatibility improvement rather than a bug. Also, "optional": true isn't a JSON Schema keyword, so a stronger warning in the description is the more likely way to help. Maintainers will consider it.

    In the meantime, the plugin session context hook can change each tool's description and input schema before the request is sent. A small plugin could add a firmer "do not pass sessionID unless continuing a previous subagent" line to the subagent tool for that model.

    Related: #53615 (another change to the subagent tool's wording for the model).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions