Skip to content

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
mainfrom
feat/orchestrator-auto-topic-routing
Closed

feat(orchestrator): auto-derive topic for session reuse so same-theme children converge without manual --topic#1727
wqymi wants to merge 2 commits into
mainfrom
feat/orchestrator-auto-topic-routing

Conversation

@wqymi

@wqymi wqymi commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add deriveTopic() helper that automatically derives stable topic keys from operation context (PR numbers in task text, directory basename)
  • Auto-derive topic in session create branch when op.topic is not set, enabling same-theme child sessions to auto-reuse without the LLM having to pass --topic manually
  • Support __fresh__ sentinel to opt out of auto-routing when a caller truly needs isolation

Design

The deriveTopic(op) function extracts stable topic keys from two signals (in priority order):

  1. PR numbers in task text: matches #1234, PR 1234, pull/1234, issue #123 patterns
  2. Directory basename: normalized to lowercase-hyphenated format (e.g., /path/to/my-appauto: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: Add deriveTopic() helper and FRESH_SENTINEL constant
  • packages/opencode/src/tool/session.ts:652-661: Auto-derive topic in create branch before find-or-reuse
  • packages/opencode/src/tool/session.ts:1173: Export deriveTopic and FRESH_SENTINEL for testing
  • packages/opencode/test/derive-topic.test.ts: Comprehensive tests for deriveTopic

Behavior

Input Derived Topic
task: "Fix #1234" auto:pr-1234
task: "PR 5678: implement" auto:pr-5678
task: "fix bug", dir: "/path/to/my-app" auto:dir-my-app
task: "Fix #1234", dir: "/path/to/my-app" auto:pr-1234 (PR wins)
task: "fix bug" undefined (no auto-route)
topic: "__fresh__" undefined (opt-out)

wqymi added 2 commits July 15, 2026 22:15
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
wqymi force-pushed the feat/orchestrator-auto-topic-routing branch from 6f2aa9e to 8afbefd Compare July 15, 2026 14:16
@wqymi

wqymi commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #1741 (Orchestrator route-first redesign). #1727 只是 topic 字符串匹配的止血;#1741 从根上把路由改为 AI-routes-from-injected-roster,不再需要 topic 这个 create-key。Closing as superseded.

@wqymi wqymi closed this Jul 17, 2026
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