Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a new worktree thread's agent starts on its renamed branch #34781

Mergedjuliusmarmingemerged 0 commits intomain fromrefs/pull/34781/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

ThreadLaunchService.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.

BeforeAfter
Before: agent uses placeholder branchAfter: agent uses final branch
ddc4f57602e981f23f3e
Recording · Transcript · EventsRecording · 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

    2. Approvability

      Verdict: Approved at e981f23

      Macroscope'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).
    3. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded21.5 KiB21.5 KiB0 B (0.0%)24.4 KiB✅
      CodexLive turn messages110 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages110 (0.0%)8✅

      Baseline: 5c6f2f1 · PR result: e981f23 · Source CI: success

      Scenario 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.

    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      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.ts
      prepareInBackground waits 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: bugfix

      Suggested reviewers: maria-rcks, t3dotgg, macroscopeapp

      Merge Risk: Minimal · up to e981f

      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: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe 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 checkPassed[#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 checkPassedThe whole-PR change set has two files. The service change is a two-line join with a comment, and it directly implements the #33397 requirement. The test file adds a single regression test for the same…
      Description checkPassedThe 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 adds if (branchRename !== null) yield* Fiber.join(branchRename); in prepareInBackground of apps/server/src/orchestration-v2/ThreadLaunchService.ts, before setupTracker.markUncancellable(threadId) and before the agent run is released. The agent run therefore starts only after the rename fiber completes. The added test in ThreadLaunchService.test.ts asserts 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 #33397 requirement. 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/&lt;id&gt; 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 #33397 with '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

      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.ts
      • apps/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.

    5. juliusmarminge merged this8212aaa

    6. juliusmarminge closed this

Sign in to join this conversation.