The issue is that the task tool is being filtered out with the message [SESSION] Tool filtered out: task. This prevents sub-sessions from being created in normal mode.
The parentId field in the session might be set to an empty string "" or the string "undefined" instead of being actually undefined. This causes isMainSession() to return false, which filters out the task tool.
Updated agent-config.ts to properly check for all falsy values:
export function isSubAgentSession(
_sessionId: string,
parentId?: string,
): boolean {
// Sub-agent sessions have a parent session ID
// Check for actual value, not just undefined
// Also check for string "undefined" which might come from serialization
return (
parentId !== undefined &&
parentId !== null &&
parentId !== "" &&
parentId !== "undefined"
)
}Added comprehensive logging to trace the issue:
console.log("[AGENT-CONFIG] getAllowedTools:", {
sessionId,
parentId,
parentIdType: typeof parentId,
parentIdTruthy: !!parentId,
parentIdLength: typeof parentId === "string" ? parentId.length : "N/A",
isMainSession: isMain,
willGetAllTools: isMain,
})Added logging when tools are filtered:
if (!isAllowed) {
console.log("[SESSION] Tool filtered out:", toolName)
continue // Skip tools that aren't allowed
}-
Start OpenCode:
dgmo run -
Monitor Console Output:
- Look for
[AGENT-CONFIG] getAllowedTools:logs - Check the
parentIdvalue and type - Verify
isMainSession: truefor main sessions - Confirm no
[SESSION] Tool filtered out: taskmessage
- Look for
-
Create a Task:
Create 3 agents to analyze this codebase -
Check Sub-Sessions:
- Press
/sub-sessionin TUI - Should see the 3 created agents
- Tree view should show hierarchy
- Press
-
Verify Storage:
# Check for new sub-session files find ~/.local/share/opencode/project/*/storage/session/sub-sessions/ -name "*.json" -mmin -5
[SESSION] Tool filtering check: {
sessionID: "ses_xxx",
parentID: undefined,
parentIDType: "undefined",
parentIDValue: "undefined",
isMainSession: true
}
[AGENT-CONFIG] getAllowedTools: {
sessionId: "ses_xxx",
parentId: undefined,
parentIdType: "undefined",
parentIdTruthy: false,
parentIdLength: "N/A",
isMainSession: true,
willGetAllTools: true
}
[AGENT-CONFIG] Main session detected, returning ALL_TOOLS including task
[SUB-SESSION DEBUG] Creating sub-session: { ... }
[SUB-SESSION DEBUG] Writing to: session/sub-sessions/ses_yyy
[SUB-SESSION DEBUG] Sub-session created successfully
- No
[SESSION] Tool filtered out: taskmessage -
isMainSession: truein logs - Sub-sessions created successfully
- Sub-sessions appear in /sub-session dialog
- Tree view shows parent-child relationships
- Files created in correct project directory
-
Check Session Creation: Verify how the main session is created. It should use
Session.create()without any parameters. -
Check Session Storage: Look at the session info file to see if parentID is stored:
jq . ~/.local/share/opencode/project/*/storage/session/info/ses_*.json | grep -A2 -B2 parentID
-
Force Fix: If parentID is incorrectly set, you can manually update the session:
// In session creation if (!parentID) { delete result.parentID // Ensure it's undefined, not empty string }
The fix is successful when:
- Task tool is available without
/agentscommand - Sub-sessions are created and stored
- Sub-sessions appear in the TUI dialog
- No error messages in console
- Consistent behavior across sessions
This implementation ensures that main sessions are properly identified and receive all tools, including the task tool, enabling sub-session creation in normal mode.