fix(server): a new worktree thread's agent starts on its renamed branch #34781
main fromrefs/pull/34781/head·merged by juliusmarminge View on GitHubThreadLaunchService.prepareInBackground forked the branch-name generation and git branch -m into a background fiber (branchRename) and then dispatched prepared-run.release without waiting for it, so the agent's turn (and its session-start git status) ran on the temporary t3/ branch while the rename landed seconds later. The fix joins the rename fiber (Fiber.join(branchRename)) right before the setup is marked uncancellable and the run is released. The rename still runs concurrently with fetch/setup-script work, so no extra latency beyond the rename itself. The fiber already catches and logs all rename failures, so the join cannot fail the launch; a failed rename just leaves the placeholder branch as today. A cancel during the wait interrupts the parent fiber, and the existing onError path interrupts the rename fiber and cleans up the worktree. No new regex or parser.
Fixes pingdotgg/t3code#33397
Reproduction on main#
Commit ddc4f57602 (origin/main). Started T3CODE_DEV_SEED=0 vp run dev:server --home-dir <scratch> --no-seed, made a one-commit git repo, t3 project add <repo>, then t3 thread start . 'Run git branch --show-current and tell me what branch your session-start git status said' --worktree main --provider claudeAgent --model <cheapest Claude> --wait. The agent replied that its session-start git status said t3/244e0c25 and git branch --show-current also printed t3/244e0c25. Branch reflog: 06:06:10 created from main as t3/244e0c25; 06:06:23 'renamed refs/heads/t3/244e0c25 to refs/heads/t3/report-current-and-start-branch'. Orchestration events show provider-session.attached at 06:06:11, about 12 s before the rename. So the agent ran its whole turn on the placeholder branch, while the thread ended up on the semantic name. A unit test on branch factory/repro-33397 (ThreadLaunchService.test.ts, 'starts the agent of a new worktree thread only after its branch is renamed') fails on main 3 of 3 times. A local check that joins the rename fiber before the release makes the file pass 52 of 52.
Evidence#
On each commit: start a fresh unseeded real server, add a one-commit repository, and start an agent with --worktree main --wait, asking it to run git branch --show-current and report its session-start branch. Then inspect the branch reflog and persisted events.
Base: the session attached at 06:23:29.203, and the actual git tool returned t3/da3c3f1e at 06:23:35.218. The final branch update to t3/report-session-start-branch occurred at 06:23:38.203—nine seconds after attachment.
Head: the final branch update to t3/t3/fe21a4a1 occurred at 06:24:16.615, before session attachment at 06:24:16.672. Both the actual git tool output and the agent's startup-context report matched that final name.
The following images and videos are renderings of recorded CLI stdout, with the persisted event timeline appended after the turn. Private paths and the model identifier are redacted.
| Before | After |
|---|---|
![]() | ![]() |
| ddc4f57602 | e981f23f3e |
| Recording · Transcript · Events | Recording · Transcript · Events |
Reproduction driver · Event extraction script
AI-assisted; verified with the tests and tools listed above.
Not shown:
- No push or PR creation was performed; proof covers the startup branch mismatch that causes it.
- Web, desktop, and mobile presentation were not captured. The manual CLI route exercised real provider startup because the scenario replay emits canned tool output and its launcher disables real branch-name generation.
- Branch-name quality was not assessed: the head generator selected t3/t3/fe21a4a1. The verified behavior is that rename completed before session attachment and the agent used the final name.
Tests#
vp test run src/orchestration-v2/ThreadLaunchService.test.ts -t 'only after its branch is renamed' without the fix: 1 failed (reproduces). vp test run src/orchestration-v2/ThreadLaunchService.test.ts with the fix: 52/52 passed. vp run check:changed: format, lint, knip, typecheck (3 packages), tests (2 files) all pass.
Not in this change#
- Did not reproduce end to end with a real provider turn; relied on the repro branch's unit test, which fails on main and passes with the fix.
AI-assisted; verified with the tests and tools listed above.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅ Codex Live turn messages 1 1 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅ Claude Live turn messages 1 1 0 (0.0%) 8 ✅ Baseline:
5c6f2f1· PR result:e981f23· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
No actionable comments were generated in the recent review.
Walkthrough
-
Thread preparation now waits for an in-progress worktree branch rename before continuing to agent startup. A test checks that the run is not released while branch-name generation is pending.
Changes: Worktree branch rename
Layer / File(s) Summary Preparation and release timing
apps/server/src/orchestration-v2/ThreadLaunchService.ts,apps/server/src/orchestration-v2/ThreadLaunchService.test.tsprepareInBackgroundwaits for an in-progress branch rename before continuing. A test checks that the run is not released while renaming is pending.Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Low
Possibly related PRs
- pingdotgg/t3code#31052: Changes the same preparation behavior and tests that the run remains unreleased until branch naming completes.
Suggested labels:
bugfixSuggested reviewers:
maria-rcks,t3dotgg,macroscopeapp
Merge Risk:
Minimal · up toe981f-
New worktree threads now wait for the branch rename to finish before the agent starts, so the agent sees the final branch name. No actionable merge-blocking risk remains.
Pre-merge checks:
4-
Check name Status Explanation Title check The title states the main change: a new worktree thread's agent now starts on the renamed branch instead of the temporary placeholder branch. It matches the joined branch-rename fix in ThreadLaunchSer… Linked Issues check [ #33397] The issue requires that the agent session see the final semantic branch name when a new worktree thread starts. The reviewed head adds `if (branchRename !== null) yield* Fiber.join(branchRena…Out of Scope Changes check The whole-PR change set has two files. The service change is a two-line join with a comment, and it directly implements the #33397requirement. The test file adds a single regression test for the same…Description check The description is long and detailed. It explains the problem (the agent's run was released before the forked branch rename finished, so the agent saw the temporary t3/ branch), the change (joinin… Full details: Title check
-
Explanation
The title states the main change: a new worktree thread's agent now starts on the renamed branch instead of the temporary placeholder branch. It matches the joined branch-rename fix in ThreadLaunchService.ts and the related test. The conventional commit format is used, and the wording is specific.
Full details: Linked Issues check
-
Explanation
[
#33397] The issue requires that the agent session see the final semantic branch name when a new worktree thread starts. The reviewed head addsif (branchRename !== null) yield* Fiber.join(branchRename);inprepareInBackgroundofapps/server/src/orchestration-v2/ThreadLaunchService.ts, beforesetupTracker.markUncancellable(threadId)and before the agent run is released. The agent run therefore starts only after the rename fiber completes. The added test inThreadLaunchService.test.tsasserts that the release does not occur while the branch still has its temporary name. The PR does not add end-to-end verification with a real provider turn. The unit test is the only automated evidence. The reviewed diff for the service file was read directly. The test file change was taken from the summary and was not independently read.
Full details: Out of Scope Changes check
-
Explanation
The whole-PR change set has two files. The service change is a two-line join with a comment, and it directly implements the
#33397requirement. The test file adds a single regression test for the same ordering behavior. No unrelated changes are present. The PR description states that no new regex or parser was added, and the diff is consistent with that statement.
Full details: Description check
-
Explanation
The description is long and detailed. It explains the problem (the agent's run was released before the forked branch rename finished, so the agent saw the temporary t3/<id> branch), the change (joining the rename fiber before setup is marked uncancellable and the run is released), and the verification (a unit test that fails on main and passes with the fix, a 52/52 test run, a repro on main with a before/after comparison, and a check:changed run). It follows the template's Problem, Change, and Verification sections. The Scope and approval section is weak. It links issue
#33397with 'Fixes', but it does not link a maintainer approval comment or explain approval for the change. The objectives text says the issue is directly linked, so the link exists. The description also cites a commit hash and media files, which is acceptable. The title is not present in the provided text, so the conventional commit title cannot be checked.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: factory/issue-33397
- File: .coderabbit.config.ts
- Commit: e981f23
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
e85eb5bc-a74d-47fe-987e-03ea550119fb
Commits-
Reviewing files that changed from the base of the PR and between 5c6f2f1229514881a18af286b8a63e15ab4bef70 and e981f23f3e175d88555b45cf1c4b5d307e0ad67a.
Files selected for processing: 2-
apps/server/src/orchestration-v2/ThreadLaunchService.test.tsapps/server/src/orchestration-v2/ThreadLaunchService.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
-
-
juliusmarminge merged this8212aaa
juliusmarminge closed this
Sign in to join this conversation.


Approvability#
Verdict: Approved at
e981f23Macroscope's review found this PR approvable — New worktree agents now wait for the existing branch rename to finish before starting, aligning their branch with the thread’s displayed name. The change is limited to startup sequencing and retains existing cancellation and error handling.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).