subagent: ^ses-only sessionID schema lets mangled IDs pass, then fails as "session not found"
Summary
Model-emitted sessionID arguments for the subagent tool that are truncated or mangled pass the tool's schema validation because it only checks the ^ses prefix. The call then fails at session lookup with Subagent session not found: <value>, which reads as if the session no longer exists. Agents consequently conclude that healthy child sessions were destroyed, and retrying cannot help because the malformed value is emitted deterministically.
Observed on two different orchestrator models: GLM-5.3 Flash (2026-11-17, first noticed on v2.3.0) and Step 5 Preview (nvidia/stepfun-ai/step-5-preview, 2026-11-23, on v2.3.2).
Environment
- opencode version: 2.3.2 (first observed on 2.3.0 on 2026-11-17; re-verified on 2.3.2 on 2026-11-23)
- OS: Linux 7.2.15-1-omarchy (linux x64), Arch-based Omarchy
- Terminal: TERM=xterm-256color, COLORTERM=truecolor
- Shell: /usr/bin/bash
- Install/channel: latest
- Active plugins:
./plugins/repo-map,./plugins/subagent-id-guard(local guard plugin — see Additional Context; the underlying schema/lookup behavior is independent of it)
Reproduction
- Dispatch a subagent with the
subagenttool (nosessionIDargument) and let the child finish. The child session stays alive and idle; the dispatch result returns its ID, e.g.sessionID: ses_df8cd0687ffeGEZIpOEgFhwvcn. - Call the
subagenttool again to continue that child, passing thesessionIDargument. - When the model's emitted value is truncated/mangled — e.g. the literal
sesinstead of the full ID above — the call passes schema validation (^sesprefix check) and fails withSubagent session not found: ses.
Deterministic case measured on 2026-11-23: Step 5 Preview emitted the literal ses on 8 of 8 continuation attempts. Earlier observation (2026-11-17, GLM-5.3 Flash, before any guard plugin existed): the same call failed with the underlying Subagent session not found: ses error after first emitting "ses \n" and then "ses" three times in a row.
Expected Behavior
A sessionID that cannot be a real session ID should be rejected at validation time with an error that says the argument is corrupted — not pass validation and then imply the session is gone. A stricter schema (real IDs are ses_ + 26 alphanumeric, so ^ses_[A-Za-z0-9]{20,}$ would be safe) and/or a lookup error that distinguishes "malformed ID" from "session not found" would both prevent agents from drawing the wrong conclusion.
Actual Behavior
The subagent tool accepts any value starting with ses, then fails with Subagent session not found: <mangled value>. The message describes the symptom as a missing session, so agents treat healthy sessions as destroyed.
Additional Context
- Frequency: deterministic per affected model; two models across two days; started in v2.3.0 and persists on v2.3.2.
- Workaround (local plugin, not a fix): a plugin hooking
tool.execute.before/tool.execute.afterthat (a) trims whitespace damage fromsessionID, (b) rejects values not matching^ses_[A-Za-z0-9]{21,}$with an instructive, self-correcting error, and (c) auto-repairs a truncated value that is a strict prefix of exactly one child session dispatched in the current server process (ambiguous prefixes are rejected with the candidate IDs listed). This makes the failure mode actionable but does not fix the underlying acceptance of malformed IDs. - Possibly related: the dispatch result returns the child sessionID as plain text inside the tool output (
sessionID: ses_...) rather than as a structured field, which makes faithful copying harder for models. A structuredsessionIDfield in the tool result would likely reduce the rate of mangled arguments. - No secrets in this report; session IDs are local identifiers. Full local write-up (reproduction, verification, limits):
~/Documents/Documentaties/general/opencode/OpenCode_Subagent_Id_Guard.sumdin our docs (not part of this repo).
Thanks for the detailed report and the workaround write-up!
I think this is a duplicate of #59293. That issue has the same Subagent session not found: ses failure. Its comments trace it to the same cause: the session ID schema only checks that the value starts with ses (Schema.isStartingWith("ses") in packages/schema/src/session-id.ts), so a bare ses passes validation, and the tool then returns Subagent session not found: <value> with whatever value it received. People there also propose the same stricter pattern (^ses_[0-9A-Za-z]{26}$), and the data includes nvidia/stepfun-ai/step-5-preview and v2.3.0.
Related issues, ordered by likelihood:
- #59293: the same
Subagent session not found: sesfailure with the same cause and proposed fix - #58019: problems caused by the
^sespattern on the subagentsessionIDschema (the fix proposed in #58053 is^ses.*$, which comments in #59293 point out still matchesses) - #55504: models filling in the optional
sessionIDparameter
On your note about a structured field: in the code I read, the tool's output already has a sessionID field next to the text output.
I'm closing this issue now as a duplicate of #59293. Please add your details there: the v2.3.2 data point, the 8/8 Step 5 Preview result, the GLM-5.3 Flash "ses \n" observation and your guard plugin. If you think this isn't the same problem, reply here and the issue will reopen.