Repository navigation
feat(git): route independent-clone reports onto teamai-reports - #489
Conversation
Independent git clones currently push members/sessions/votes/stats onto the default branch, so every member needs write access on main. Reuse the existing orphan-branch worktree writer: git-kind reports live beside the clone on teamai-reports; self stays nested under .teamai/; HTTP is unchanged. Empty-repo init may still seed teamai.yaml on the default branch; leftover report files on main are ignored. Closes Tencent#484
Review: one blocking bug — stale sibling reports worktree causes silent data lossNice work overall — Where: // Already a valid worktree — nothing to do.
if (await isGitRepo(wt)) {
return wt;
}Root cause: for git-kind, Trigger — a routine flow: Impact: every git op in the stale worktree throws Reproduction (real git, run against this PR head — fails):
Suggested fix (verified: turns the repro green, full suite still passes): if (await isGitRepo(wt)) {
try {
await createGit(wt).revparse(['--is-inside-work-tree']);
return wt;
} catch {
// stale/dangling worktree link (clone was re-cloned/pruned) — recreate below.
}
}The existing |
isGitRepo only checks that reports-wt has a .git file. After init replaces the clone, that file still exists but the backing gitdir is gone, so ensureReportsWorktree returned the husk and commitAndPushReports failed silently. Probe revparse --is-inside-work-tree and fall through to the existing remove+recreate path.
|
Thanks for the review and the repro. Fixed in d11e101: Added a real-git regression in CI on that commit is green. |
|
Thanks for addressing this. This matches our GitLab setup and solves the |
* fix(reports): keep teamai-reports reads fresh and read-only #489 moved independent git clones onto the teamai-reports worktree but kept the single-repo reader/writer patterns, which regressed git-kind clones: read-only commands published a missing teamai-reports branch (#558), pull indexed votes and read stats from a stale reports checkout (#557), and writers merged per-member files into that stale copy, so a second machine of the same member stayed diverged and its reports never reached origin. - Read-only callers (members, digest, projects members, stats, viz, the vote read in contribute, pull's votes/stats reads) pass pushIfCreated: false. - A cold start reuses an unpublished local teamai-reports branch instead of failing with "a branch named 'teamai-reports' already exists". - refreshReportsWorktree syncs under the reports lock: offline keeps the local copy, unpushed report commits are rebased onto origin and dropped only when they conflict, and a busy lock reads the local copy. - pull refreshes the reports worktree once per scope before the search index and skill recommendations. - updateReports() replaces ensure + write + commitAndPushReports: it syncs, runs the merge/write, commits and pushes under one lock. Pull auto-report, Stop-hook votes, session save --push, init and bootstrap member registration use it; auto-report and the Stop hook skip the round-trip when nothing is pending. Closes #557 Closes #558 Claude-Session: https://claude.ai/code/session_01TFtw1GRR7pJNTGzNCikoKe * refactor(reports): narrow the fix to #557/#558, move writer changes to #561 Keep this PR to what the two issues ask for: read-only callers never publish teamai-reports, cold start reuses an unpublished local branch, and pull refreshes the reports worktree (under the reports lock) before reading votes and stats. Pull's auto-report runs after that refresh, so its stats merge also starts from fresh data. The writer-side refactor (updateReports replacing commitAndPushReports in init, bootstrap, session save, the Stop hook and auto-report) is reverted here and proposed separately in #561. Because writers still write before taking the lock, the refresh no longer discards uncommitted report files: it fast-forwards, or rebases unpushed commits with --autostash, and only resets a clean worktree whose unpushed commits conflict with origin. Claude-Session: https://claude.ai/code/session_01TFtw1GRR7pJNTGzNCikoKe * fix(reports): restore uncommitted files after rebase autostash conflicts git rebase --autostash can exit 0 when the rebase itself succeeds but reapplying the autostash conflicts. That left UU paths, conflict markers in report YAML, and a leftover autostash stash, so a read-only command could serve invalid stats. After rebase/merge, inspect the worktree. If the rebase has finished and stash-apply conflicts remain, restore the original uncommitted content (the stash --theirs side) and drop the autostash instead of treating exit 0 as proof that the checkout is clean. * fix(reports): drop only the rebase autostash, not shared stashes Git worktrees share refs/stash. dropRebaseAutostash scanned the whole stash list and dropped every entry whose message contained autostash, so a self-mode members refresh could delete a business-tree stash created with `git stash push -m autostash`. Snapshot stash SHAs before rebase --autostash and drop only objects created by that refresh. Do not select stashes by message text. * fix(reports): carry dirty reports without touching refs/stash stashShasCreatedSince treated every stash SHA that appeared after the pre-rebase snapshot as this refresh's autostash. Worktrees share refs/stash, and the reports lock does not serialize ordinary git stash in the business tree, so a stash created during rebase was deleted. Stop using rebase --autostash. Snapshot dirty tracked files with git stash create (a dangling commit, not stored in refs/stash), rebase on a clean tree, then stash apply that object. Never drop from the shared stash list.
…er the reports switch The orphan-branch switch (Tencent#489) made members list and projects members read only the teamai-reports worktree, so a team whose roster still lives on the default branch saw "No team members registered" right after upgrading (Tencent#735). The default-branch clone now stays a read-only inherited member root, the way learnings' already is (Tencent#485): listing unions both roots (the reports-branch copy wins when the same file exists on both), nothing is copied or deleted, and read-only commands still never publish the reports branch. Member registration merges against the inherited copy too, so a re-init keeps the original registeredAt/projects and converges the data onto the branch. Fixes Tencent#735
…er the reports switch (#741) The orphan-branch switch (#489) made members list and projects members read only the teamai-reports worktree, so a team whose roster still lives on the default branch saw "No team members registered" right after upgrading (#735). The default-branch clone now stays a read-only inherited member root, the way learnings' already is (#485): listing unions both roots (the reports-branch copy wins when the same file exists on both), nothing is copied or deleted, and read-only commands still never publish the reports branch. Member registration merges against the inherited copy too, so a re-init keeps the original registeredAt/projects and converges the data onto the branch. Fixes #735
…nt#489) * feat(git): route independent-clone reports onto teamai-reports Independent git clones currently push members/sessions/votes/stats onto the default branch, so every member needs write access on main. Reuse the existing orphan-branch worktree writer: git-kind reports live beside the clone on teamai-reports; self stays nested under .teamai/; HTTP is unchanged. Empty-repo init may still seed teamai.yaml on the default branch; leftover report files on main are ignored. Closes Tencent#484 * fix(git): recreate stale sibling reports worktree after re-clone isGitRepo only checks that reports-wt has a .git file. After init replaces the clone, that file still exists but the backing gitdir is gone, so ensureReportsWorktree returned the husk and commitAndPushReports failed silently. Probe revparse --is-inside-work-tree and fall through to the existing remove+recreate path.
) * fix(reports): keep teamai-reports reads fresh and read-only Tencent#489 moved independent git clones onto the teamai-reports worktree but kept the single-repo reader/writer patterns, which regressed git-kind clones: read-only commands published a missing teamai-reports branch (Tencent#558), pull indexed votes and read stats from a stale reports checkout (Tencent#557), and writers merged per-member files into that stale copy, so a second machine of the same member stayed diverged and its reports never reached origin. - Read-only callers (members, digest, projects members, stats, viz, the vote read in contribute, pull's votes/stats reads) pass pushIfCreated: false. - A cold start reuses an unpublished local teamai-reports branch instead of failing with "a branch named 'teamai-reports' already exists". - refreshReportsWorktree syncs under the reports lock: offline keeps the local copy, unpushed report commits are rebased onto origin and dropped only when they conflict, and a busy lock reads the local copy. - pull refreshes the reports worktree once per scope before the search index and skill recommendations. - updateReports() replaces ensure + write + commitAndPushReports: it syncs, runs the merge/write, commits and pushes under one lock. Pull auto-report, Stop-hook votes, session save --push, init and bootstrap member registration use it; auto-report and the Stop hook skip the round-trip when nothing is pending. Closes Tencent#557 Closes Tencent#558 Claude-Session: https://claude.ai/code/session_01TFtw1GRR7pJNTGzNCikoKe * refactor(reports): narrow the fix to Tencent#557/Tencent#558, move writer changes to Tencent#561 Keep this PR to what the two issues ask for: read-only callers never publish teamai-reports, cold start reuses an unpublished local branch, and pull refreshes the reports worktree (under the reports lock) before reading votes and stats. Pull's auto-report runs after that refresh, so its stats merge also starts from fresh data. The writer-side refactor (updateReports replacing commitAndPushReports in init, bootstrap, session save, the Stop hook and auto-report) is reverted here and proposed separately in Tencent#561. Because writers still write before taking the lock, the refresh no longer discards uncommitted report files: it fast-forwards, or rebases unpushed commits with --autostash, and only resets a clean worktree whose unpushed commits conflict with origin. Claude-Session: https://claude.ai/code/session_01TFtw1GRR7pJNTGzNCikoKe * fix(reports): restore uncommitted files after rebase autostash conflicts git rebase --autostash can exit 0 when the rebase itself succeeds but reapplying the autostash conflicts. That left UU paths, conflict markers in report YAML, and a leftover autostash stash, so a read-only command could serve invalid stats. After rebase/merge, inspect the worktree. If the rebase has finished and stash-apply conflicts remain, restore the original uncommitted content (the stash --theirs side) and drop the autostash instead of treating exit 0 as proof that the checkout is clean. * fix(reports): drop only the rebase autostash, not shared stashes Git worktrees share refs/stash. dropRebaseAutostash scanned the whole stash list and dropped every entry whose message contained autostash, so a self-mode members refresh could delete a business-tree stash created with `git stash push -m autostash`. Snapshot stash SHAs before rebase --autostash and drop only objects created by that refresh. Do not select stashes by message text. * fix(reports): carry dirty reports without touching refs/stash stashShasCreatedSince treated every stash SHA that appeared after the pre-rebase snapshot as this refresh's autostash. Worktrees share refs/stash, and the reports lock does not serialize ordinary git stash in the business tree, so a stash created during rebase was deleted. Stop using rebase --autostash. Snapshot dirty tracked files with git stash create (a dangling commit, not stored in refs/stash), rebase on a clean tree, then stash apply that object. Never drop from the shared stash list.
…er the reports switch (Tencent#741) The orphan-branch switch (Tencent#489) made members list and projects members read only the teamai-reports worktree, so a team whose roster still lives on the default branch saw "No team members registered" right after upgrading (Tencent#735). The default-branch clone now stays a read-only inherited member root, the way learnings' already is (Tencent#485): listing unions both roots (the reports-branch copy wins when the same file exists on both), nothing is copied or deleted, and read-only commands still never publish the reports branch. Member registration merges against the inherited copy too, so a re-init keeps the original registeredAt/projects and converges the data onto the branch. Fixes Tencent#735
Summary
Independent git clones currently write
members/sessions/votes/stats/onto the default branch viapushRepoDirectly, so every member needs write access onmain. This reuses the existingteamai-reportsorphan-branch worktree writer that single-repo mode already uses.<dirname(localPath)>/reports-wt), so clonereset --hardcannot nest-destroy it.kind: selfkeeps today's nested<knowledgeDir>/reports-wt.kind: httpis unchanged (no git reports branch).initmay still pushteamai.yaml+ gitkeeps to the default branch so the knowledge tree exists; member YAML goes toteamai-reports.mainare not copied, not deleted, and not used as the source of truth after the switch.learnings/to ateamai-learningsbranch (direct push, no PR) #485 is separate).Closes #484
Type of Change
Test Plan
npx tsc --noEmit— cleannpx vitest runfocused suites — 117 tests passed, including:src/__tests__/git-kind-reports.test.ts(real git: write toorigin/teamai-reports, leftover clonemembers/ignored, empty-repo skeleton on default branch, dedicated-root guard)src/__tests__/self-mode-no-business-reset.test.ts(git-kind no longerreset --hards the clone)src/__tests__/members.test.ts(listMembersreads reports worktree; leftover clone YAML is not listed)src/__tests__/team-push-interventions.test.ts(git-kind auto-report usescommitAndPushReports, notpushRepoDirectly)npm run buildthen built CLI (dist/index.js) against a local bare remote whoseupdatehook rejects default-branch pushes:teamai init https://git.example.test/acme/team.git --scope user --force— English success;Member registered on the teamai-reports branchteamai session save --push --force --session-id s1 --scope user—Pushed: sessions/alice/2026-09.mdteamai pull— auto-report wrotestats/alice.yamlgit ls-tree origin/teamai-reportscontainedmembers/alice.yaml,sessions/alice/2026-09.md,stats/alice.yamlteamai.yaml+ knowledge gitkeeps (no new report files)~/.teamai/reports-wt); clone had nomembers/stats/sessions/docs/usage-guide.mdupdated so independent git clones also write reports toteamai-reports(learnings still on the default branch)Related Issues
Closes #484
Notes for Reviewers
initmember registration,session save --push, pull auto-report, Stop-hook votes.members,digest,stats,viz,pullvotes/stats index,recall,maintenance/paths,projects members(manifest still from knowledge clone).reportUsageToTeamstill has a no-config fallback thatpushRepoDirectlys the clone; productionpullnow always passesselfConfigfor non-HTTP repos.learnings/to ateamai-learningsbranch (direct push, no PR) #485 (learnings/→teamai-learnings) and Document branch layout and minimum Git permissions after reports/learnings leavemain#486 (permission-matrix docs).