feat(core): add experimental subagent context forking by rekram1-node · Pull Request #47576 · anomalyco/opencode · GitHub
Skip to content

feat(core): add experimental subagent context forking - #47576

Open
rekram1-node wants to merge 4 commits into
v2from
subagent-fork
Open

feat(core): add experimental subagent context forking#47576
rekram1-node wants to merge 4 commits into
v2from
subagent-fork

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Issue for this PR

No linked issue.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Subagents currently start with fresh history. Setting experimental.subagent_fork: true registers an optional fork parameter that copies parent history before the assistant message spawning the child. The internal fork method accepts an optional parentID to record ownership using the existing creation and fork events. Forks inherit the source session's defaults; the subagent tool then sets its title, agent, and model through existing session methods before prompting. Public event schemas are unchanged. The only public schema addition is the config flag.

With the flag absent or false, the registered tool uses the original input schema, description, and fresh-session behavior. It contains no fork parameter or prompting to enable the experiment. Config updates reload the registered schema through the existing config observer.

When enabled, passing both fork and sessionID returns an error. Omitting fork or passing false keeps fresh-session behavior. Forked children receive a short instruction to use inherited history as context and perform their assigned task. The parameter description and child instruction are intentionally brief.

How did you verify your code works?

  • The latest focused run passed all 60 tests across session-create and tool-subagent. Fork replay covers absent ownership, ownership by the source, and a separate owner, while preserving the source history and defaults. Coverage includes registration and model-visible schemas for missing/false/true config values, unchanged default wording and execution, conflicting arguments, inherited tool calls/results in the child's model request, history boundaries, continuation, and fresh sessions.
  • Additional core coverage passed across config/entry-observer, session-compaction, session-instructions, session-runner-message, and config normalization. 18 schema tests passed across config, events, and event manifests.
  • Tests used Bun 1.4.2. Core typechecking, formatting, and Effect simplification checks passed; Oxlint reported no errors. The pre-push typecheck passed all 33 packages. Client config types were regenerated.
  • The broader schema contract-hygiene test has an unrelated existing failure: integration.ts:62,68 uses Schema.Any. Those lines and the failing test are unchanged from the base.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.

1 participant