Skip to content

feat(worktree): one side-branch checkout per self-mode repo (#1443) - #1465

Merged
SaulMoro merged 1 commit into
Tencent:mainfrom
Walternater:fix/1443-one-side-branch-checkout
Oct 28, 2026
Merged

SaulMoro merged 1 commit into
Tencent:mainfrom
Walternater:fix/1443-one-side-branch-checkout

Conversation

@Walternater

@Walternater Walternater commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A kind: self team installed at user scope and the project partition of the same repository compute different side-branch worktree paths:

  • user scope: ~/.teamai/reports-wt
  • project scope: ~/.teamai/projects/<slug>/reports-wt

#1445 made eviction symmetric so either pull could take the branch back, but the underlying split remains: every alternating pull moves both checkouts, and the two scopes use separate lock files, so they can evict a checkout the other scope is using. This is the follow-up the issue asks for (option 1).

Fix

One side-branch checkout per kind: self repository, for both scopes and every checkout:

  • New runtime seam. LocalConfig.branchHome is resolved when the config loads, from the repository's shared project anchor (resolveAnchors → resolvePartitionDir, so a pre-feat(partition): encode the full project path into the data-home slug #546 partition is adopted): <partition>/side-branches. It is runtime-only: never read from YAML and dropped by serializeLocalConfig, like dataHome.
  • getWorktreeDir follows it. For self mode both scopes return <branchHome>/reports-wt / <branchHome>/learnings-wt, and the lock path beside each checkout follows, so both scopes share one checkout and one lock per branch. No anchor (outside git) keeps today's ~/.teamai fallback.
  • Loaders attach it. loadLocalConfig, loadLocalConfigForScope, readConfigFrom (including the dry-run self-heal preview), initSelfRepo and bootstrapSelfRepo.
  • The dashboard uses the loader. dashboard/workspaces.ts read the user config with its own parser, so it never got branchHome and its report writer recreated ~/.teamai/reports-wt; it now calls loadLocalConfigForScope('user', …, { dryRun: true }).
  • A side-branches/ subdirectory keeps installs apart. A git-mode team clone in the same partition (a nested team repo) keeps its own checkouts as siblings of the clone, directly under the partition (<partition>/reports-wt). Self mode's subdirectory means the two never claim the same path, whichever installed first.
  • Upgrade. The first pull removes a checkout left in ~/.teamai/, in a legacy <checkout>/.teamai/, or at the partition root (the pre-teamai-reports checkout conflict between user scope and project scope of the same single-repo (kind: self) team repo (variant not covered by #808) #1443 project layout), and now takes the lock beside that old checkout first, so a command still using it is never deleted from under.
  • Readers follow. Hook ownership (isOwnCheckout) recognises the shared checkouts; reports, learnings, dashboard, scorers and viz go through getWorktreeDir.
  • Files stay put. Config, state, usage and the learnings queue keep their per-scope locations (~/.teamai/… for user scope, the partition for project scope). Only the two side-branch checkouts and their locks move.
  • No new command or flag. Design note and a [Unreleased] → 💥 Breaking Changes line in CHANGELOG.md cover the move. The changelog says 0.28.0 run after the upgrade cannot publish reports or learnings from either scope; they stay queued locally (the user-scope user-usage.jsonl, the partition's usage.jsonl, and the pending-learnings queues) until an upgraded pull sends them.

Testing

  • npx tsc --noEmit, npm run lint (oxlint, changed files).
  • New unit file src/__tests__/branch-home-1443.test.ts — 6 passed: both scopes, a linked worktree and the pre-feat(partition): encode the full project path into the data-home slug #546 partition resolve one checkout and lock; branchHome is never saved; a git-mode sibling in the same partition is left alone; a held old lock blocks the takeover and releasing it lets the next call take over.
  • New dashboard case in dashboard-workspaces.test.ts pins that the user workspace loads branchHome.
  • New e2e src/__tests__/e2e/single-side-branch-1443.test.ts — 2 tests, real CLI:
    1. both checkouts start in ~/.teamai/; the first pull --verbose moves them into side-branches/, usage from the user scope and then the project scope both reach teamai-reports, a queued learning is published, a git-mode sibling at <partition>/reports-wt survives, alternating pulls print no removed the old checkout again, per-scope config/state/usage stay, and teamai doctor exits 0.
    2. both checkouts start at the partition root (the older project layout); the user pull takes them over, and both end in side-branches/.
      Both fail on main, pass here (control run).
  • Rebased onto current main (4d3d1f15), including fix(init): refuse --scope user in single-repo mode #1455 and fix(status): surface unconfirmed automatic reports #1462; the two conflicting loader/serializer hunks were merged with main's member-settings changes.
  • Related unit files: 380 passed, 11 skipped (branch-home-1443, dashboard-workspaces, branch-worktree-scope-eviction, branch-worktree-retire, single-repo-mode, status-list, hook-handlers, git-hook, init, migrate, reports-votes-owner, learnings-publish).
  • The three changed e2e files (self-mode-worktrees-808, single-side-branch-1443, init-registration-result): 32/33. The one failure (publishes from both checkouts …, worktreeDir pruning at line 313) also fails on origin/main in this environment, verified by switching to base; it passes in CI.
  • Pre-existing local failures also reproduced on origin/main and not caused by this change: workflow-local-driver setup timeouts, workflow-skill-driver killed-runner pid, workflow-workspace submodule ignore, env-exec YAML message.

Real CLI, after npm run build, fresh HOME:

### A. start from ~/.teamai
user pull exit=0
  [debug] [learnings] removed the old checkout at <home>/.teamai/learnings-wt
  [debug] [reports] removed the old checkout at <home>/.teamai/reports-wt
home ~/.teamai/*wt: 0
partition root *wt: 0
partition side-branches: 2
removals on alternating pulls: 0
git-mode checkout kept: yes

### B. start from the partition root
before: partition root *wt=2 side-branches=0
user pull exit=0
  [debug] [reports] removed the old checkout at <partition>/reports-wt
  [debug] [learnings] removed the old checkout at <partition>/learnings-wt
home ~/.teamai/*wt: 0
partition root *wt: 0
partition side-branches: 2

A held old lock on the ~/.teamai layout:

# ~/.teamai/.reports-lock held by a live process
reports worktree unavailable: <home>/.teamai/reports-wt is being updated by another teamai command
  (its lock <home>/.teamai/.reports-lock is held). teamai keeps that checkout at
  <partition>/side-branches/reports-wt, shared by every checkout of this repo.
old reports-wt still there: yes
# lock released, next pull:
[reports] removed the old checkout at <home>/.teamai/reports-wt
old reports-wt after release: no

Fixes #1443.

@Walternater
Walternater force-pushed the fix/1443-one-side-branch-checkout branch from 8b67e06 to ed0b0d1 Compare October 27, 2026 14:50
@github-actions

Copy link
Copy Markdown

No confident findings in the specified PR diff.

The PR description satisfies the testing requirement: it records a representative real-CLI verification after npm run build, including checkout migration and alternating user/project pulls.

Review was read-only; I did not run, build, or install anything from the PR.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

@Walternater Thanks, the main fix works. We ran the built CLI at ed0b0d1 on a self-mode repo with a user-scope and a project-scope install:

  • One move. From either starting place, the first pull moves the checkouts once, and later alternating pulls in both scopes remove nothing. All events from both scopes reach teamai-reports exactly once, the queued learning is published, and doctor exits 0. main still removes and recreates both checkouts on every pull.
  • The move is safe. An unpushed commit is pushed, an uncommitted file is refused and kept, and a held old lock refuses until it is released. A half-finished move recovers, and a second run moves nothing.
  • Mixed with 0.28.0, both orders. Every event is delivered once, and the checkout never moves back.

Three changes before this is approved:

  • [P1 blocking] The dashboard moves the checkout back. src/dashboard/workspaces.ts:24 reads the user config with its own parser, so it never gets branchHome. One GET /api/workflows?workspace=user recreates teamai-reports at ~/.teamai/reports-wt, and the next pull prints removed the old checkout again. #1443 names the dashboard under "Every reader follows", and the body says it is covered. Loading the user workspace with loadLocalConfigForScope('user', undefined, { dryRun: true }), or applying withBranchHome in configAt, would fix it. A dashboard step in the e2e would pin it.

  • [P1 blocking] A different team in the same repo now shares the checkout. Take a user-scope self install of repo X and a project-scope install of another team repo Y inside X. Y keeps its clone at <partition of X>/team-repo, so its checkouts are at <partition of X>/{reports,learnings}-wt, and X's branchHome now points at the same two paths. Whichever creates a path first owns it, and the other is refused on every pull. In our run, X's 3 usage events stayed in user-usage.jsonl, and Y could not publish learnings. On main both deliver. #1443 lists this under "Keep apart". The warning also says "left by an install in another mode", and following its git worktree remove advice only hands the path to the other install. Two ways out:

    • Give self-mode side branches their own subdirectory of the partition, which git-mode clones never use. We'd prefer this one, because it doesn't depend on which install came first.
    • Attach branchHome only when the partition holds no install, or a kind: self install of the same repository. That is smaller, but it breaks if Y installs later.

    Either way, please add the case to the e2e.

  • [P1 blocking] A Breaking Changes line in CHANGELOG. This moves stored data on first use, so it needs a line under [Unreleased] → 💥 Breaking Changes, for example:

    A single-repo (kind: self) team keeps one teamai-reports and one teamai-learnings checkout per repository, in its project partition (~/.teamai/projects/<slug>/), for the user scope too. The first command after the upgrade removes the user-scope checkouts in ~/.teamai/reports-wt and ~/.teamai/learnings-wt. Their commits stay on the branch; a checkout with uncommitted changes is kept and named. teamai 0.28.0 run on the same machine afterwards cannot publish user-scope reports; they stay in ~/.teamai/user-usage.jsonl until an upgraded pull sends them (for #1443).

Non-blocking:

  • [P3 nit] The body's record starts only from ~/.teamai; #1443 asked for both starts. Our run from the partition passes.

Once the first two are fixed, nothing else from #1443's acceptance criteria remains, so the body can say Fixes #1443.

CI review: we disagree with "no findings", because of the three items above.

Verified at ed0b0d1: tsc and lint pass. The full unit suite and 14 e2e files (98 tests) on the changed paths pass. The new tests fail on the baseline and pass here, also under a symlinked TMPDIR. Not run here: the outside-git fallback, and Windows (CI passes).

@SaulMoro
SaulMoro self-requested a review October 27, 2026 15:25
@Walternater
Walternater force-pushed the fix/1443-one-side-branch-checkout branch from ed0b0d1 to 9f33728 Compare October 27, 2026 15:41
@github-actions

Copy link
Copy Markdown

No confident findings in the specified PR diff. The earlier pass raised no findings, so there are none to mark resolved.

The PR description satisfies the testing requirement: it records representative real-CLI verification after npm run build, covering migration from both old layouts and alternating user/project pulls.

Review was read-only; I did not run, build, or install anything from the PR.

@Walternater
Walternater force-pushed the fix/1443-one-side-branch-checkout branch from 9f33728 to 2428ab4 Compare October 27, 2026 16:27
@github-actions

Copy link
Copy Markdown

No confident findings in the specified PR diff. Earlier passes raised no findings, so there are none to mark resolved.

The PR description satisfies the testing requirement: it records representative real-CLI verification after npm run build, covering migration from both old layouts and alternating user/project pulls.

Review was read-only; I did not run, build, or install anything from the PR.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

@Walternater Thanks, two of the three are fixed. With the built CLI at 2428ab4:

  • Dashboard. After a dashboard request on the user workspace, both checkouts stay under side-branches/, and the next pull removes nothing.
  • Keep apart. The subdirectory works in all three orders: Y first, X first, and X from the 0.28.0 layout with Y added later. Nothing is refused, every event is delivered, and doctor passes.
  • 0.28.0, both orders. Every event reaches teamai-reports, and queued learnings from both scopes publish.
  • The move itself. An unpushed commit is pushed, an untracked file is kept, and a held lock is respected. A second run moves nothing.
  • CI fixtures. 2428ab4 fixes the self-mode-worktrees-808 and init-registration-result fixtures that broke at 9f33728. All 33 tests in those files pass here.

One change is still open, and it's our mistake:

  • [P1 blocking] The CHANGELOG line understates what 0.28.0 loses. The sentence we suggested says 0.28.0 "cannot publish user-scope reports". With the checkouts under side-branches/, 0.28.0 run after an upgraded pull cannot publish reports or learnings from either scope. Nothing is lost, because the next upgraded pull sends all of it. Please replace the last sentence with:

    teamai 0.28.0 run on the same machine afterwards cannot publish reports or learnings from either scope; they stay queued locally (~/.teamai/user-usage.jsonl, the partition's usage.jsonl, and the pending-learnings queues) until an upgraded pull sends them.

Non-blocking:

  • [P3 nit] The comment at src/__tests__/e2e/self-mode-worktrees-808.test.ts:823-825 describes a git-mode leftover under side-branches/, which can no longer happen. "A checkout of another repository where self mode keeps its own" would fit.
  • [P3 nit] Two doc comments in src/types.ts still say the checkouts sit directly in the partition.
  • [P3 nit] The body's testing notes about self-mode-worktrees-808 are out of date.

CI review: we disagree with "no findings", because of the CHANGELOG sentence.

Verified at 2428ab4: tsc and lint pass. The unit files and the changed e2e files pass; the unit suite's only failures were timeouts under load, and those files pass when run alone. Not run here: Windows.

@Walternater

Copy link
Copy Markdown
Collaborator Author

@SaulMoro all three P1s are addressed on 2428ab45; CI is fully green (6 Lint & Test, 3 E2E shards, Windows, Build).

  1. Dashboard moves the checkout back — dashboard/workspaces.ts now loads the user workspace with loadLocalConfigForScope('user', undefined, { dryRun: true }), so its config carries branchHome. A new case in dashboard-workspaces.test.ts pins the shared path.
  2. Different team in the same repo — self mode now keeps the side-branch checkouts in <partition>/side-branches/, which a git-mode clone in the same partition (siblings <partition>/reports-wt) never uses. The e2e creates a git-mode-looking <partition>/reports-wt before alternating pulls and asserts it survives; a unit case covers the same split.
  3. Breaking Changes — CHANGELOG.md has the [Unreleased] → 💥 Breaking Changes entry: user-scope checkouts in ~/.teamai/, a legacy <checkout>/.teamai/, and a pre-teamai-reports checkout conflict between user scope and project scope of the same single-repo (kind: self) team repo (variant not covered by #808) #1443 partition-root checkout move on the first command; commits stay on the branch, dirty checkouts are kept and named, and 0.28.0 afterwards cannot publish user-scope reports.

Also from the review:

  • the e2e now covers both starting layouts (from ~/.teamai/ and from the partition root), and the body's real-CLI record includes both;
  • the existing self-mode-worktrees-808 and init-registration-result e2e cases were updated to the new side-branches/ location (they were the two shard failures on the previous head).

Could you take another look at 2428ab45? Fixes #1443 is in the body.

@github-actions

Copy link
Copy Markdown

No confident findings in the specified PR diff. Earlier passes raised no findings, so there are none to mark resolved.

The PR description satisfies the testing requirement: it records representative real-CLI verification after npm run build, covering migration from both old layouts and alternating user/project pulls.

Review was read-only; I did not run, build, or install anything from the PR.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

Approving at a78a027. The CHANGELOG line now says what 0.28.0 loses: run after an upgraded pull, it cannot publish reports or learnings from either scope, and they stay queued until an upgraded pull sends them. The test comment and the src/types.ts doc comments are updated.

The rebase onto main resolves cleanly: withBranchHome wraps the new applyConfigOverlays and applyMachineSettings calls, and serializeLocalConfig drops branchHome next to the new overlay field. #1477 also changes src/config.ts and src/hook-handlers.ts after this branch's base, so we checked a merge with current main. tsc and lint pass there, and so do the config, types, self-mode, dashboard-workspaces, hook-handlers and doctor test files (34 files, 737 tests).

From the earlier rounds at 2428ab4, checked with the built CLI:

  • both 0.28.0 layouts migrate;
  • an unpushed commit is pushed, an untracked file is kept, and a held lock is respected;
  • a second run moves nothing;
  • the dashboard keeps both checkouts under side-branches/;
  • the subdirectory case works in every order;
  • every event reaches teamai-reports with 0.28.0 in both orders.

Thanks for seeing this through.

@jeff-r2026 Breaking for the next tag: a kind: self team's user-scope teamai-reports / teamai-learnings checkouts move into the repository's partition (side-branches/), and 0.28.0 run afterwards on the same machine queues reports and learnings instead of publishing them. See CHANGELOG.

…1443)

A user-scope `kind: self` install and the repo's project partition computed
different reports/learnings worktree paths, so whichever pulled second could
take the branch but the other could never take it back. Tencent#1445 made eviction
symmetric; each alternating pull still moved both checkouts and the two
scopes used separate locks.

Resolve one side-branch home per repository from its project anchor, attach
it to the config at load time as a runtime-only `branchHome` (never saved),
and let `getWorktreeDir` and the lock beside each checkout follow it. The
first upgraded pull takes over a checkout left in `~/.teamai/` or a legacy
`<checkout>/.teamai/` under the lock beside that checkout, so a command
still using it is never deleted from under. Config, state, usage and queue
files stay where each scope keeps them; hook ownership and every reader go
through the same seam.
@Walternater
Walternater force-pushed the fix/1443-one-side-branch-checkout branch from a78a027 to 944f550 Compare October 28, 2026 03:20
@github-actions

Copy link
Copy Markdown

No confident findings in the specified PR diff. Earlier passes raised no findings, so there are none to mark resolved.

The PR description satisfies the testing requirement: it records representative real-CLI verification after npm run build, covering migration from both old layouts and alternating user/project pulls.

Review was read-only; I did not run, build, or install anything from the PR.

@Walternater

Copy link
Copy Markdown
Collaborator Author

CI is green on 944f550d (all 6 Lint & Test, 3 E2E shards, Windows, Build) and the PR is CLEAN + approved. Could you merge it when you have a moment? It closes #1443.

@SaulMoro
SaulMoro merged commit ce5dbee into Tencent:main Oct 28, 2026
18 checks passed
Walternater added a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…1465)

Self-mode repos keep their side-branch checkout under ~/.teamai/projects/<slug>/side-branches/, one per repo, instead of a checkout per project. An existing checkout is moved on first use and nothing is deleted.

Fixes Tencent#1443
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.

teamai-reports checkout conflict between user scope and project scope of the same single-repo (kind: self) team repo (variant not covered by #808)

3 participants