feat(orchestrator): auto-derive topic for session reuse so same-theme children converge without manual --topic - #1727
Closed
wqymi wants to merge 2 commits into
Closed
feat(orchestrator): auto-derive topic for session reuse so same-theme children converge without manual --topic#1727wqymi wants to merge 2 commits into
wqymi wants to merge 2 commits into
Conversation
Add automatic topic routing for the session tool so same-theme child sessions are auto-reused without the LLM having to pass --topic manually. Changes: - Add deriveTopic() helper that extracts stable topic keys from: * PR numbers in task text (e.g., #1234, PR 1234, pull/1234) * Directory basename (normalized to lowercase-hyphenated) - Auto-derive topic in create branch when op.topic is not set - Support __fresh__ sentinel to opt out of auto-routing - Export deriveTopic and FRESH_SENTINEL for testing - Add comprehensive tests for deriveTopic The derived topic is prefixed with 'auto:' to avoid collision with explicit topics. PR numbers take precedence over directory signals. Same inputs always produce the same topic key for stable reuse.
The previous implementation guessed topics via regex on task text (PR numbers #1234/PR 1234/pull/1234) and directory basename. This is fragile and wrong: task text mentioning '#1234' misroutes; same-dir different-theme tasks wrongly merge; genuinely-related tasks without a PR number split. Remove deriveTopic's regex/basename logic entirely. Topic is now ONLY set when the caller explicitly passes it (op.topic). When absent, a fresh session is always created — no silent misrouting. Design choice (A): topic stays OPTIONAL in schema, but the harness no longer guesses. If you want reuse, pass an explicit --topic/topic; otherwise you get a fresh session. This is deterministic and caller-controlled. Changes: - Remove deriveTopic function (regex + basename logic) - Remove FRESH_SENTINEL constant - Remove auto-routing fallback in create branch - Remove exports for testing - Delete test/derive-topic.test.ts - Update topic schema description to clarify contract - Keep find-or-reuse machinery (if op.topic) unchanged
wqymi
force-pushed
the
feat/orchestrator-auto-topic-routing
branch
from
July 15, 2026 14:16
6f2aa9e to
8afbefd
Compare
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
deriveTopic()helper that automatically derives stable topic keys from operation context (PR numbers in task text, directory basename)op.topicis not set, enabling same-theme child sessions to auto-reuse without the LLM having to pass--topicmanually__fresh__sentinel to opt out of auto-routing when a caller truly needs isolationDesign
The
deriveTopic(op)function extracts stable topic keys from two signals (in priority order):#1234,PR 1234,pull/1234,issue #123patterns/path/to/my-app→auto:dir-my-app)The derived topic is prefixed with
auto:to avoid collision with explicit topics. PR numbers take precedence over directory signals. Same inputs always produce the same topic key for stable reuse.Changes
packages/opencode/src/tool/session.ts:196-245: AddderiveTopic()helper andFRESH_SENTINELconstantpackages/opencode/src/tool/session.ts:652-661: Auto-derive topic in create branch before find-or-reusepackages/opencode/src/tool/session.ts:1173: ExportderiveTopicandFRESH_SENTINELfor testingpackages/opencode/test/derive-topic.test.ts: Comprehensive tests for deriveTopicBehavior
task: "Fix #1234"auto:pr-1234task: "PR 5678: implement"auto:pr-5678task: "fix bug", dir: "/path/to/my-app"auto:dir-my-apptask: "Fix #1234", dir: "/path/to/my-app"auto:pr-1234(PR wins)task: "fix bug"undefined(no auto-route)topic: "__fresh__"undefined(opt-out)