Skip to content

Conversation

@shuv1337
Copy link
Collaborator

@shuv1337 shuv1337 commented Dec 31, 2025

Summary

  • Merges upstream sst/opencode#6478
  • Adds parallel subtask execution support via Promise.all()
  • Fixes model inheritance for subtasks with proper parent context restoration
  • Adds command.execute.before plugin hook for pre-execution logic
  • Improves model resolution with proper fallback chain

Changes

SubtaskPart Schema Extension (message-v2.ts)

  • Added model, parentAgent, parentModel fields to track parent context

Parallel Subtask Execution (prompt.ts)

  • Refactored subtask handling to execute concurrently via Promise.all()
  • Parent agent/model context now restored after subtask completion
  • Added command.execute.before hook trigger before command execution
  • Updated extra parameter in resolveTools to use empty object

Model Resolution Fix (task.ts, prompt.ts)

  • Improved model resolution with proper priority chain:
    1. Command frontmatter model
    2. Agent model
    3. Session model
    4. Default model
  • lastModel() now returns undefined if no session model found
  • Callers updated to handle undefined with fallback to Provider.defaultModel()

New Plugin Hook (plugin/index.ts)

  • Added command.execute.before hook for intercepting command execution

SDK Types (types.gen.ts)

  • Updated Part type and SubtaskPartInput with new fields

Testing

  • All 407 unit tests pass
  • TypeScript build passes across all packages

Related

Greptile Summary

This PR merges upstream sst/opencode#6478 which adds parallel subtask execution, model inheritance fixes, and a new plugin hook. It also includes fork-specific improvements for the hosted environment (welcome screen, server persistence, CORS for *.shuv.ai).

Key Changes

Core Subtask Improvements:

  • Parallel execution: Subtasks now execute concurrently via Promise.all() instead of sequentially
  • Model inheritance: Added model, parentAgent, parentModel fields to SubtaskPart schema to properly restore session context after subtask completion
  • Model resolution: Fixed fallback chain - extraModel → agentModel → msgModel → defaultModel
  • Plugin hook: New command.execute.before hook allows plugins to intercept command execution

Fork-Specific Features:

  • Welcome screen: New component for server connection with health checks and saved server management
  • Server persistence: Active server URL now persisted across sessions (storage key server.v4)
  • CORS support: Added *.shuv.ai domain to allowed origins
  • UI refinements: Reordered header buttons (ThemePicker before FontPicker)

Potential Concerns

  1. extra parameter change (prompt.ts:622): Changed from { model: input.model } to empty object {}. The model is now only passed to subtasks via extra: { model: task.model }. Verify regular tool calls don't rely on ctx.extra.model

  2. Parallel subtask race conditions: Multiple subtasks creating messages/parts concurrently could potentially create ordering issues if they share state

  3. PR scope: Mixing upstream merge with unrelated UI/CORS changes makes it harder to isolate regressions. Consider splitting into separate PRs in the future

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk - mostly upstream code with good test coverage
  • Score reflects well-tested upstream changes (407 tests passing) with clear architectural improvements. Deducted one point for: (1) extra parameter change in resolveTools that removes model context and needs verification, (2) parallel execution introducing potential race conditions in message creation, and (3) mix of upstream merge with unrelated UI/CORS changes making it harder to isolate issues
  • Pay close attention to packages/opencode/src/session/prompt.ts for the extra: {} change and parallel subtask execution logic

Important Files Changed

Filename Overview
packages/opencode/src/session/message-v2.ts Added model, parentAgent, and parentModel fields to SubtaskPart schema for context tracking
packages/opencode/src/session/prompt.ts Refactored subtask execution to run in parallel via Promise.all(), added parent context restoration, command.execute.before hook, and fixed model resolution chain
packages/opencode/src/tool/task.ts Improved model resolution with proper fallback chain: extraModel → agentModel → msgModel → defaultModel
packages/plugin/src/index.ts Added command.execute.before hook for pre-execution plugin logic
packages/opencode/src/server/cors.ts Extracted CORS logic to dedicated module with support for shuv.ai domain
packages/app/src/components/welcome-screen.tsx New welcome screen component for server connection with health checks and saved server management

Sequence Diagram

sequenceDiagram
    participant User
    participant Session
    participant Plugin
    participant Prompt
    participant TaskTool
    participant Subtask1
    participant Subtask2

    User->>Session: Send message with command
    Session->>Prompt: Process command
    Prompt->>Plugin: Trigger command.execute.before hook
    Plugin-->>Prompt: Hook complete
    
    Note over Prompt: Filter subtasks from other tasks
    Prompt->>Prompt: subtasks = tasks.filter(type === "subtask")
    Prompt->>Prompt: Store parent context (agent, model)
    
    Note over Prompt,Subtask2: Execute all subtasks in parallel via Promise.all()
    
    par Parallel Execution
        Prompt->>TaskTool: executeSubtask(task1)
        TaskTool->>Subtask1: Execute with task1.model
        Subtask1-->>TaskTool: Result
        TaskTool-->>Prompt: Complete
    and
        Prompt->>TaskTool: executeSubtask(task2)
        TaskTool->>Subtask2: Execute with task2.model
        Subtask2-->>TaskTool: Result
        TaskTool-->>Prompt: Complete
    end
    
    Note over Prompt: All subtasks complete
    Prompt->>Prompt: Restore parent context
    Prompt->>Session: Create synthetic user message
    Note over Session: agent = parentAgent ?? lastUser.agent<br/>model = parentModel ?? lastUser.model
    Session-->>User: Continue with restored context
Loading

The variant field was accidentally removed during a cherry-pick that fixed
plugin commands. This restores variant support in PromptInput, CommandInput,
and the corresponding message/command handlers.
Move CORS origin validation to cors.ts for better testability and add
support for *.shuv.ai domain alongside *.opencode.ai.
…nvironments

- Persist active server selection across sessions (server.v4 storage)
- Add WelcomeScreen for hosted environments when server connection fails
- Add connection state machine (connecting/ready/needs_config/error)
- Add hosted environment detection utilities
- Add REVIEW_PANE constants for centralized width configuration
- Enforce max review pane width ratio (33% of viewport)
- Handle window resize to maintain width constraints
- Add empty state UI when no files to review
- Move Theme/Font pickers before Review and Terminal toggles
- Add clarifying comments for button groups
…ce, command.execute.before hook

Merges changes from sst#6478:
- Add parallel subtask execution via Promise.all()
- Fix model inheritance for subtasks with parent context restoration
- Add command.execute.before plugin hook for pre-execution logic
- Improve model resolution with proper fallback chain:
  command frontmatter > agent model > session model > default model
- Extend SubtaskPart schema with model, parentAgent, parentModel fields
- Update task tool to use ctx.extra.model for model override

Closes #225
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

16 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

messageID: input.processor.message.id,
callID: options.toolCallId,
extra: { model: input.model },
extra: {},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: check that tools still work correctly - extra changed from { model: input.model } to empty object {}

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/opencode/src/session/prompt.ts
Line: 622:622

Comment:
**style:** check that tools still work correctly - `extra` changed from `{ model: input.model }` to empty object `{}`

How can I resolve this? If you propose a fix, please make it concise.

Copy link

@spoons-and-mirrors spoons-and-mirrors Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is volontary, no value should be forced into extra at this stage, fallbacks resolve properly.

feeding model: input.model will override agent's configured model on any main session use of the task tool (eg, main session uses sonnet, calls an 'explore' agent configured with haiku -> we want haiku for that task tool. With model: input.model we would get the main session (sonnet) as the explore subagent's model.

@shuv1337 shuv1337 merged commit 6bc91e2 into integration Dec 31, 2025
2 of 4 checks passed
@shuv1337 shuv1337 deleted the feat/merge-upstream-6478 branch December 31, 2025 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants