Skip to content

Merge upstream PR #6478: Parallel subtasks, model inheritance, and command.execute.before hook #225

@shuv1337

Description

@shuv1337

Summary

Merge sst/opencode#6478 into our fork. This PR combines three related improvements to slash commands and subtask handling:

  1. Parallel subtask execution - Slash commands can spawn multiple subagents concurrently
  2. Model inheritance fix - Proper model/agent context restoration after subtask completion
  3. New plugin hook - command.execute.before for plugin extensibility

Problem/Context

Currently, subtasks execute sequentially and lose parent session context (agent/model) after completion. This limits the power of slash commands and plugins. The upstream PR addresses these issues by:

  • Allowing parallel subtask execution via Promise.all()
  • Tracking parent agent/model in SubtaskPart schema
  • Adding command.execute.before hook for pre-execution plugin logic
  • Fixing model resolution chain: Command Frontmatter → Agent → Session → Default

This also enables the subtask2 plugin which provides advanced slash command capabilities like multi-step workflows and parallel model comparison (A/B testing with different models).

Acceptance Criteria

  • All changes from upstream PR add command.execute.before hook + allow parallel subtasks + fix model inheritance anomalyco/opencode#6478 are merged
  • SubtaskPart schema includes model, parentAgent, and parentModel fields
  • Subtasks execute in parallel when multiple are queued
  • Parent agent/model context is restored after subtask completion
  • command.execute.before hook is available in plugin system
  • Model inheritance follows correct priority: command → agent → session → default
  • Existing tests pass
  • Manual testing confirms subtask behavior works correctly

Implementation Details

Files Modified

File Changes
packages/opencode/src/session/message-v2.ts Add model, parentAgent, parentModel to SubtaskPart schema
packages/opencode/src/session/prompt.ts Refactor subtask handling for parallel execution, fix model inheritance
packages/opencode/src/tool/task.ts Update model resolution to use ctx.extra.model
packages/plugin/src/index.ts Add command.execute.before hook type
packages/sdk/js/src/v2/gen/types.gen.ts Update generated types for SubtaskPart

Key Code Changes

Parallel Subtask Execution (prompt.ts):

// Filter subtasks from other task types
const subtasks = tasks.filter((t) => t.type === "subtask")
const otherTasks = tasks.filter((t) => t.type !== "subtask")

// Execute all subtasks in parallel
await Promise.all(subtasks.map(executeSubtask))

Model Inheritance Fix (prompt.ts):

// Restore parent context after subtask
agent: subtasks[0]?.parentAgent ?? lastUser.agent,
model: subtasks[0]?.parentModel ?? lastUser.model,

New Plugin Hook (index.ts):

"command.execute.before"?: (
  input: { command: string; sessionID: string; arguments: string },
  output: { parts: Part[] },
) => Promise<void>

Related PRs (Merged into anomalyco#6478)

Tasks

  • Fetch upstream changes from sst/opencode
  • Cherry-pick or merge PR add command.execute.before hook + allow parallel subtasks + fix model inheritance anomalyco/opencode#6478 commits
  • Resolve any conflicts with fork-specific changes
  • Verify SubtaskPart schema changes in message-v2.ts
  • Verify prompt.ts parallel execution logic
  • Verify task.ts model resolution changes
  • Verify plugin hook additions
  • Run bun test in packages/opencode
  • Manual test: Create subtask command and verify parallel execution
  • Manual test: Verify model inheritance works correctly
  • Update fork sync documentation if needed

External References

Notes

  • PR stats: +193 additions, -130 deletions across 5 files
  • The PR is currently OPEN in upstream
  • Consider waiting for upstream merge or merge early if we need the functionality

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions