Skip to content

fix(push): keep a teammate's update when pushing from a stale worktree (#812) - #819

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
SaulMoro:fix-812-push-stale-worktree
Sep 25, 2026
Merged

jeff-r2026 merged 1 commit into
Tencent:mainfrom
SaulMoro:fix-812-push-stale-worktree

Conversation

@SaulMoro

@SaulMoro SaulMoro commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

teamai push in a stale worktree offered a teammate's newer rule back as its old copy: its pre-scan sync compared with the shared lastPullRev, which another checkout had moved.

~/.teamai/projects/<slug>/state.json
  lastPullRev                      shared by every worktree
  lastPullByWorkspace[checkoutKey] per checkout: { rev, targets, pushBaseRevs? }
 push
-  sync(base = state.lastPullRev)
+  sync(bases = [...entry.pushBaseRevs, entry.rev])   # a skill: all files at one base
+  entry.pushBaseRevs = [team HEAD, ...older].slice(0, 20)   # even if the sync threw; rev untouched
+  base cannot be saved -> error, nothing pushed
+  no entry + a team rule/skill (not a rule it placed) scanned as modified -> error, nothing pushed

 pullForScope, record
-  rev changed (new team rev, or cleared): drop other checkouts' entries
+  keep entries of checkouts `git worktree list` still reports
+  lastPullRev cleared (forced full sync): other entries -> { rev: '', targets, pushBaseRevs }
Step Before After
B, main pull R1; teammate pushes R2 to X; main pulls; push in B R1 offered over R2 B updated to R2
teammate pushes R3; main pulls; push in B again R2 offered over R3 B updated to R3
after an undone edit, a forced sync elsewhere, or a failed sync old copy offered synced
never-pulled worktree with an older copy; main pulled newer; push there (also after exclude) old copy pushed refused until teamai pull

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Test Plan

  • npx tsc --noEmit passes
  • npx vitest run passes: 307 files, 4781 passed, 1 skipped
  • Added/updated tests for the change: src/__tests__/e2e/push-stale-worktree-812.test.ts, src/__tests__/pre-push-sync.test.ts (+3)
  • Every e2e that pushes, plus 807, data-layout, roles-tags and docs-prune (16 files): 102 passed, 22 skipped

Reproduced with the real CLI

Sandbox HOME, bare team repo, worktrees, teammate clone; pushes are teamai --dry-run push unless noted.

1  stale worktree   B, main pull R1; teammate R2; main pulls; push B -> not listed, B at R2
2  local edit       edit X in B; push -> "[rules] team-rule (modified)"
3  second push      teammate R3 (+ new rule); push B -> not listed; pull B -> full sync
4  undone edit      edit, push, restore the pulled copy; teammate; push -> not listed
5  undone to push   same, restoring an earlier push's copy -> not listed
6  cap              21 teammate versions, a push after each -> 20 bases, newest = HEAD
7  removed          remove B; pull --force in main -> only main's key left
8  forced reach     C pulls; exclude + pull main; pull C -> full sync
9  forced base      teammate; exclude + pull main; push C -> not listed
10 no pull record   new rule, never-pulled worktree -> listed (new); older team rule there,
                    `push --all` -> exit 1, no branch on the remote; pull; push -> not listed
11 cleared rev      same, then exclude clears lastPullRev; push --all -> exit 1, no branch
12 partial sync     read-only skill makes the sync throw -> warns; teammate; push -> not listed
13 save fails       state.json read-only; push -> exit 1, "Nothing was pushed", no scan
14 single-repo      B, D at an older commit; exclude + pull main; pull D; pull B -> full sync
Build Tests that fail
origin/main (5e5b86d) 1, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13
previous head (a9587f8) 11 (stale copy pushed)
push reads one base 4, 5
keeps 1 push base / no cap 5, 6 / 6
push records no base 3, 4, 5, 6
no refusal / refuse every unrecorded item 10 / 10
refuse only while lastPullRev is set 11
placed rules count too #649 e2e "sends an edit of the root copy back"
no base after a failed sync / save failure only warns 12 / 13
forced sync deletes entries 9
forced sync keeps entries 8, 14, #807 exclusion
forced sync drops only entries at the synced rev 14
Real CLI, git mode (excerpt)
== 4. teamai --dry-run push in B
ℹ No new or modified resources to push
B rule after push scan: Version two, from a teammate.
== 5c. second teamai --dry-run push in B
ℹ No new or modified resources to push
B rule after second push scan: Version three, from a teammate.
== 5d. pull in B (push left rev alone)
✔ [project] Synced 2 rule(s)
B has new-rule: yes
== 6. remove B, full sync in main, records left
records before: 2
records after: 1

From reading the code

  • Only pull and push write lastPullByWorkspace; checkoutBaseRevs keeps '' away from git.

Related Issues

Closes #812

Notes for Reviewers

@jeff-r2026 jeff-r2026 self-assigned this Sep 24, 2026
@github-actions

Copy link
Copy Markdown
  • [P1 blocking] src/push.ts:981 — The pre-push sync updates the checkout’s files but never advances its lastPullByWorkspace revision. Concrete failure: B is recorded at R1; its first push syncs an unedited file to teammate R2; teammate then publishes R3; B’s next push still compares its R2 copy against R1, classifies it as a local edit, and offers R2 over R3. Persist the current team revision after a successful pre-push sync, or otherwise retain an accurate per-file/workspace baseline.

@SaulMoro
SaulMoro force-pushed the fix-812-push-stale-worktree branch from 90b4330 to ec864d9 Compare September 24, 2026 16:12
@SaulMoro

Copy link
Copy Markdown
Collaborator Author

Re: the [P1 blocking] review of src/push.ts:981 (#819 (comment))

Fixed in ec864d9. After the pre-push sync, and only when the team repo was refreshed, push stores the revision it synced the unedited copies to as pushBaseRev on this checkout's lastPullByWorkspace entry, and reads the base as pushBaseRev ?? rev ?? lastPullRev. It writes the field under --dry-run too, since the sync already writes files there.

rev is left alone on purpose. The pull fast path reads it, and advancing it from push would make B's next pull print "Already synced" and skip the docs and agents of that revision (#807). A pull rewrites the entry as { rev, targets }, so pushBaseRev goes with the next full sync in that checkout. An older CLI drops the optional field and falls back to rev.

Covered by the e2e test "compares the next push with the revision the last push synced, and leaves pull's record alone" in src/__tests__/e2e/push-stale-worktree-812.test.ts: B at R1, push syncs to R2, teammate publishes R3 and main pulls, B's second push lists nothing and B ends at R3, then B's pull is a full sync that delivers a rule only the pull brings. It fails on the previous head at :192. It also fails if push skips writing or reading pushBaseRev, or if push advances rev instead.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] src/push.ts:993 — A single workspace-wide pushBaseRev is advanced even when the sync leaves locally edited resources untouched. Concrete failure: X was pulled at R1, edited locally, and a dry-run against R2 leaves X unchanged but records R2; the user then discards the edit back to R1, a teammate publishes R3, and the next push compares R1 against R2 and offers the stale copy over R3. The baseline must remain accurate per resource or not advance past unsynchronized files.
  • [P1 blocking] src/pull.ts:1466 — A forced full sync still deletes every other checkout’s baseline. Concrete failure: B pulled R1; an exclude/role/project change clears lastPullRev; main pulls and drops B’s entry; after main reaches R2, B’s push falls back to shared R2 at src/push.ts:984, classifies its untouched R1 copy as a local edit, and offers it over R2. Preserve the old revision while separately invalidating B’s pull fast path.

The earlier finding is resolved for repeated pushes where the checkout record remains and every relevant file synchronizes successfully. The PR description includes sufficient real-CLI testing.

@SaulMoro
SaulMoro force-pushed the fix-812-push-stale-worktree branch from ec864d9 to c7b845b Compare September 24, 2026 16:45
@SaulMoro

Copy link
Copy Markdown
Collaborator Author

Re: the two [P1 blocking] findings on ec864d9 (#819 (comment))

Both fixed in c7b845b.

  • src/push.ts:993, a copy left as edited while the base moved: the pre-push sync now accepts a copy at either pushBaseRev or the pull's rev, so an edit undone back to the pulled copy is synced again. A skill counts only when every differing file is at one of those revisions, so a skill mixing files from two revisions still reads as edited. Tests: the e2e "still syncs a copy whose edit was undone after a push left it alone" (fails on ec864d9 at :225), and three unit tests in pre-push-sync.test.ts.
  • src/pull.ts:1466, a forced full sync dropping the other checkouts' baselines: the pull no longer deletes them. It rewrites each as { rev: '', targets, pushBaseRev } (FORCED_FULL_SYNC_REV), keeping the base push compares with. An empty rev matches no revision, so every checkout still does its own full sync. That includes single-repo mode, where each worktree's revision is its own HEAD, and an older CLI, which compares rev too. checkoutBaseRevs never hands '' to git. Tests: the e2e "keeps a stale worktree's push base through a forced full sync in another checkout" (fails on ec864d9 at :264), plus a single-repo e2e where another worktree's pull makes the shared revision equal to a stale worktree's commit, which still gets a full sync. That test fails if the forced sync only drops entries at the synced revision.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] src/push.ts:994 — pushBaseRev still overwrites a workspace-wide baseline when some resources remain locally edited. Concrete failure: B pulls R1; a push syncs X to R2; B edits X; another push against R3 leaves X edited but replaces pushBaseRev with R3; B then discards the edit back to R2; after a teammate publishes R4, the next push compares X only against R3 and R1, misclassifies the stale R2 copy as an edit, and offers it over R4. Preserve synchronized baselines per resource, or retain every still-relevant base rather than only the latest push base and last pull revision.

The earlier forced-full-sync record-loss finding is resolved by retaining pushBaseRev while invalidating rev. The PR description includes sufficient real-CLI testing.

@SaulMoro
SaulMoro force-pushed the fix-812-push-stale-worktree branch from c7b845b to 789e597 Compare September 24, 2026 17:00
@SaulMoro

Copy link
Copy Markdown
Collaborator Author

Re: the [P1 blocking] finding on c7b845b (#819 (comment))

Fixed in 789e597. The scenario takes a chain of preconditions (sync, edit, a push at a new revision, undo to exactly the earlier synced copy, then a new teammate version before any pull). The fix closes the whole class anyway.

The single pushBaseRev is now pushBaseRevs: every team revision a push synced this checkout to since its last pull, newest first. The sync accepts a copy at any of them or at the pull's rev, so a copy undone to whichever version a sync gave it is recognized. A skill still counts only when all its differing files are at one revision. A pull rewrites the entry without the list, and a forced-sync reset keeps it, the old rev included. The list is capped at the 20 newest revisions, because each base costs one file read per differing file. Past the cap, a copy at an older revision reads as an edit until the checkout pulls. The cap is documented in docs/designs/data-directory-layout.md and the PR notes.

Tests: the e2e "still syncs a copy undone to the version an earlier push synced it to" follows your steps and fails on c7b845b at :246. "keeps at most 20 push bases between pulls, newest first" runs 21 teammate versions with a push after each and fails on c7b845b at :257. A cap of 1 fails both, and removing the cap fails the second (26 bases).

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] src/push.ts:993 — Push records the refreshed revision only when this checkout already has a lastPullByWorkspace entry. Concrete failure: a newly created or pre-upgrade worktree has an unedited R1 copy but no entry; its first push syncs it to R2 without recording R2; after another checkout advances the shared revision to R3, its next push classifies R2 as a local edit and offers it over R3. Create a checkout record when push synchronizes a previously unrecorded checkout, or refuse the unsafe fallback.
  • [P1 blocking] src/push.ts:997 — The catch allows scanning to continue after a partially successful sync without saving the new base. Concrete failure: rule A is copied from R1 to R2, then syncing rule B throws; R2 is not recorded, and after a teammate publishes R3 the next push treats A’s untouched R2 copy as an edit and offers it over R3. The sync and baseline update must fail safely or persist the revision covering already-written files.

The previously reported workspace-wide baseline and forced-full-sync findings are resolved. The PR description includes sufficient real-CLI testing.

@SaulMoro
SaulMoro force-pushed the fix-812-push-stale-worktree branch from 789e597 to 9eb8af6 Compare September 24, 2026 17:22
@SaulMoro

Copy link
Copy Markdown
Collaborator Author

Re: the two [P1 blocking] findings on 789e597 (#819 (comment))

Both fixed in 9eb8af6.

  • Checkout with no entry (src/push.ts:993): when a project-scope checkout has no lastPullByWorkspace entry (a new worktree, or one pulled by an older CLI), push now creates one after the sync: { rev: '', targets: [], pushBaseRevs: [<synced HEAD>, <shared lastPullRev>] }. The shared revision stays a base because the sync compared against it. The empty rev and empty targets keep the checkout's next pull a full sync. Test: the e2e "records a push base for a checkout no pull has recorded" follows your steps and fails on 789e597 at :318.
  • Partial sync (src/push.ts:997): this needs an I/O error partway through the sync. When the sync throws, push still records the refreshed revision. The copies the sync wrote are at that revision, and the copies it did not reach still match an older base in pushBaseRevs. The failure is no longer a debug line: push warns once, in English, and says what to check before pushing. Test: "records the push base when the sync stops partway" syncs a rule, then makes the skill sync fail on a read-only local skill. It checks the warning, then checks that the next push after another teammate update does not list the rule. It fails on 789e597, and it also fails if push skips the base after a failed sync.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] src/push.ts:989 — A checkout without a record still trusts the shared lastPullRev. Concrete failure: main pulled R2, an unrecorded stale worktree still contains R1, and its first push compares R1 only against R2, classifies it as a local edit, and offers R1 over R2. The new test only covers an unrecorded checkout whose copy already equals the shared revision; an unknown checkout baseline must not fall back to shared state.
  • [P1 blocking] src/push.ts:1008 — Failure to persist the new push base is downgraded to a warning after synchronization has modified files. Concrete failure: the sync updates R1 to R2, writing state.json fails, and scanning continues; after a teammate publishes R3, the next push has no R2 baseline and offers the untouched R2 copy over R3. Abort the push when the baseline cannot be saved, or otherwise preserve an accurate baseline.

The previously reported baseline accumulation, forced-sync retention, unrecorded-checkout recording, and partial-sync recording findings are resolved. The PR description includes sufficient real-CLI testing.

@SaulMoro
SaulMoro force-pushed the fix-812-push-stale-worktree branch from 9eb8af6 to dd2abe2 Compare September 24, 2026 17:39
@SaulMoro

Copy link
Copy Markdown
Collaborator Author

Re: the two [P1 blocking] findings on 9eb8af6 (#819 (comment))

  • Base save failure (src/push.ts:1008), fixed in dd2abe2 (rebased on 49cf3fd). If push cannot save the revision the sync brought this checkout to, it stops before scanning. It logs an error that says nothing was pushed and to check that the teamai state file is writable, and exits 1, like the placement-records save failure above it. A sync that throws partway still only warns, because its revision is recorded. Test: "stops the push when the synced revision cannot be recorded" makes state.json read-only and expects exit 1, "Nothing was pushed" and no scan. It fails on 9eb8af6 at :369.
  • Checkout with no entry (src/push.ts:989), kept as is on purpose. A checkout with no lastPullByWorkspace entry is either new or was last pulled by a CLI without these entries. Nothing records which revision it holds, so no fallback is right. Skipping the sync would not help either, because the scan would still list the stale copy as modified. Refusing to push until a pull would block every checkout after the upgrade. So it keeps origin/main's behavior, comparing with the shared lastPullRev, and that lasts only until the checkout's first pull, which SessionStart usually runs. From then on, and from its first push on, the checkout has its own bases. This is noted in the PR under Notes, "No entry".

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] src/push.ts:1001 — User-scope pushes never record the revision written by pre-push sync because baseline persistence requires a project key. Concrete failure: user scope pulls R1; pushes after teammate R2, updating HOME’s rule to R2; teammate publishes R3; the next push still compares R2 only with lastPullRev R1 and offers R2 over R3. User scope needs an independent push baseline too.
  • [P1 blocking] src/push.ts:989 — An unrecorded project checkout still falls back to the shared lastPullRev. Concrete failure: main pulled R2, while a newly created or pre-upgrade worktree contains R1 and has no entry; its first push compares R1 against R2, classifies R1 as a local edit, and offers it over R2 before any safe baseline can be created.
  • [P1 blocking] src/utils/pre-push-sync.ts:234 — Recording both revisions does not make a partially copied multi-file skill recoverable because every skill must match one base. Concrete failure: copying R2 writes one file, then fails on another, leaving an R2/R1 mixture; teamai push --all immediately treats the skill as modified and can overwrite the teammate’s R2 files. Partial skill writes must be atomic or recognized per file.

The previously reported save-failure and project baseline-retention issues are resolved. The PR description includes sufficient real-CLI testing.

@SaulMoro

Copy link
Copy Markdown
Collaborator Author

Re: the three [P1 blocking] findings on dd2abe2 (#819 (comment))

No code change for these; all three are out of #812's scope and are now listed in the PR notes with file:line.

@SaulMoro

SaulMoro commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

Follow-ups: the unrecorded-checkout fallback, which only exists in this branch, is being fixed in this PR (push will refuse until the checkout pulls). #823 tracks what already happens on main: item 2 (single-repo pre-push sync path), item 3 (agents still use the shared lastPullRev), item 4 (user-scope push base) and item 5 (staged skill copy).

@SaulMoro
SaulMoro force-pushed the fix-812-push-stale-worktree branch from dd2abe2 to a796390 Compare September 24, 2026 19:08
@SaulMoro

Copy link
Copy Markdown
Collaborator Author

Update on the checkout-without-entry finding (#819 (comment), #819 (comment)). My earlier replies called it transitional and a follow-up. As of a796390 it is fixed in this PR.

A project-scope checkout with no lastPullByWorkspace entry can only sync against the shared lastPullRev. When that revision is set and the scan lists a team rule or skill as modified, push now stops before creating a branch or commit. It exits 1 with: "This checkout has no pull record yet, so a teammate's update cannot be told from your edit ([rules] ). Nothing was pushed. Run teamai pull here, then push again." Config-only pushes and new resources go through, and with lastPullRev cleared push behaves as before. Round 4's entry creation for unrecorded checkouts is gone.

Test: the e2e "refuses to push a team rule from a checkout no pull has recorded, until it pulls" in src/__tests__/e2e/push-stale-worktree-812.test.ts. A new rule in a never-pulled worktree is listed as new. An older team rule there makes push --all exit 1 with no branch on the team remote. After teamai pull, the push has nothing to offer. It fails on dd2abe2 at :326, where the stale copy was pushed on a teamai/push/... branch.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] src/push.ts:985 — Clearing lastPullRev disables the unrecorded-checkout guard. Concrete failure: an unrecorded worktree contains R1, another checkout has fetched R2, then an exclude/tag/role change sets lastPullRev to null; pushing from the stale worktree skips synchronization and can publish R1 over R2. An unknown checkout must remain unsafe regardless of the shared revision value.
  • [P1 blocking] src/push.ts:1006 — User-scope pushes still never record the revision written by pre-push sync. Concrete failure: HOME pulled R1, a push synchronizes it to teammate R2, then after R3 is published the next push compares R2 only with R1 and offers R2 over R3. User scope needs its own push baseline.
  • [P1 blocking] src/utils/pre-push-sync.ts:237 — copyDir can partially overwrite a multi-file skill before throwing, but push records the new revision and continues scanning. A resulting R2/R1 mixture matches neither retained whole-skill base, so push --all can publish the mixed directory over the teammate’s R2 skill. Skill synchronization must be atomic or tracked per file.
  • [P1 blocking] src/push.ts:1417 — The refusal message tells users to run teamai pull even though the command explicitly cannot distinguish a stale copy from a genuine edit. For an unrecorded pre-upgrade worktree containing a real edit, following that instruction overwrites the edit because rule and skill pull writes replace local files. Tell users to back up the listed resources before pulling.

The other previously reported project-worktree baseline retention and state-save failures are resolved. The PR description includes sufficient real-CLI testing.

@SaulMoro
SaulMoro force-pushed the fix-812-push-stale-worktree branch from a796390 to a9587f8 Compare September 24, 2026 19:19
@SaulMoro

Copy link
Copy Markdown
Collaborator Author

Re: the four [P1 blocking] findings on a796390 (#819 (comment))

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/push.ts:985 — An unrecorded checkout is considered unsafe only while lastPullRev is non-null. Concrete failure: B contains R1 without a record; an exclude/tag/role change clears lastPullRev; the refreshed team repo contains R2; B’s push skips synchronization and the refusal guard, then --all can publish R1 over R2. An unknown checkout must remain unsafe when the shared revision is cleared.
  • [P1 blocking] src/push.ts:1006 — User-scope pushes still cannot record the revision written by pre-push synchronization because no checkout record exists outside project scope. Concrete failure: HOME pulled R1, push synchronizes its rule to R2, a teammate publishes R3, and the next push compares the untouched R2 copy only against R1 and offers R2 over R3. User scope needs an equivalent push baseline.
  • [P1 blocking] src/utils/pre-push-sync.ts:237 — copyDir may overwrite part of a multi-file skill before throwing, after which push records HEAD and continues scanning. If one file reaches R2 while another remains R1, then a teammate publishes R3, the mixed skill matches no retained whole-skill base and push --all can publish that mixture over R3. Skill synchronization must be atomic or tracked per file.

The PR description includes sufficient real-CLI testing. The previously reported unsafe pull instruction is resolved: it now explicitly tells users to back up edited files first.

@SaulMoro

Copy link
Copy Markdown
Collaborator Author

Re: #819 (comment)

These three repeat the previous pass and are answered in #819 (comment):

No code change for these.

Tencent#812)

Before scanning, push syncs each rule and skill the member never edited to
the team repo's version, and "never edited" meant equal to the version at the
project's shared lastPullRev. state.json is shared by every worktree, so a
pull in another checkout moved that revision past the copy a stale worktree
still held: the unedited copy read as an edit, and push offered it as
modified, ready to send the teammate's change back as the old version.

Push now compares with the revision this checkout last synced, from its
lastPullByWorkspace entry (checkoutKey is exported from pull.ts), and falls
back to the shared lastPullRev for a checkout with no entry. For that entry to
survive, a pull at a new team revision no longer drops the other checkouts'
records: a checkout recorded at an older revision already misses the fast
path. When the pull finds lastPullRev cleared, it resets the other records
to an empty rev (FORCED_FULL_SYNC_REV), which matches no revision, so a forced
full sync reaches every checkout, single-repo mode included, while each record
keeps its push bases. Each full sync keeps only the records
of checkouts `git worktree list` still reports, and keeps them all when the
list comes back empty, so a removed or re-created worktree's entry does not
pile up.

The sync itself moves the unedited copies to the team repo's revision, so
push then adds that revision to the entry's pushBaseRevs (newest first, the
20 newest kept) and the next push compares with them; otherwise a copy synced
to R2 read as an edit against R1 once a teammate published R3. Push leaves the
entry's rev alone, since the pull fast path reads it and the checkout still
lacks that revision's docs and agents; the next pull rewrites the entry
without pushBaseRevs. The sync accepts a copy at any of pushBaseRevs or rev (a
skill only when all its files are at one of them), so a copy it left alone as
edited is synced again once the member undoes the edit, back to whichever
version a sync gave it. The base is recorded even when the sync stops
partway, which now warns, since the copies it did not reach still match an
older base; a revision push cannot save stops the push before the scan. A
checkout with no entry (a new worktree, or one last pulled by an older CLI)
can only sync against the shared lastPullRev, which may be another
checkout's or cleared: when the scan lists a team rule or skill as modified,
push stops before creating a branch and asks for a pull there, warning that
the pull replaces those files. A rule this machine placed does not count, and
config-only pushes and new resources go through.
@SaulMoro
SaulMoro force-pushed the fix-812-push-stale-worktree branch from a9587f8 to a52ed70 Compare September 24, 2026 22:18
@SaulMoro

Copy link
Copy Markdown
Collaborator Author

Re: #819 (comment)

  1. Unrecorded checkout while lastPullRev is null (src/push.ts:985): fixed in a52ed70. A project checkout with no pull record is now refused whenever the scan lists a team rule or skill as modified, whatever the shared lastPullRev is. The one exception is a rule this machine placed (placedRules), because that is the author's own copy (the [bug] Namespace resolution is inconsistent across resource types: push ignores --role/--project for rules and agents, and root-level claudemd never ships #649 flow). Config-only pushes and new resources still go through. The new e2e "still refuses it after exclude clears the shared lastPullRev" follows your steps: exclude clears the revision, then push --all exits 1 and no teamai/* branch reaches the remote. It fails on a9587f8 at :357, where the stale copy was pushed. The [bug] Namespace resolution is inconsistent across resource types: push ignores --role/--project for rules and agents, and root-level claudemd never ships #649 e2e passes unchanged.
  2. User scope (src/push.ts:1006) and 3. partial skill copy (src/utils/pre-push-sync.ts:237): both happen on main already and are tracked in [bug] Follow-ups to the worktree fixes: import --from-mr never shares its learning, and push can still revert a teammate's update #823.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/push.ts:1008 — User-scope pushes still cannot record the revision written by pre-push synchronization because checkoutRecord exists only for project scope. Concrete failure: HOME pulled R1, push synchronizes an untouched rule to R2, a teammate publishes R3, and the next push compares R2 only against R1 and offers R2 over R3. User scope needs an equivalent push baseline.
  • [P1 blocking] src/utils/pre-push-sync.ts:237 — copyDir can partially overwrite a multi-file skill before throwing, after which push records HEAD and continues scanning. An R2/R1 mixture matches neither retained whole-skill base, so push --all can publish the mixed directory over the teammate’s current skill. Skill synchronization must be atomic or tracked per file.

The previously reported cleared-revision unrecorded-checkout issue is resolved: the refusal guard now applies independently of lastPullRev. The PR description includes sufficient real-CLI testing.

@SaulMoro

Copy link
Copy Markdown
Collaborator Author

Re: #819 (comment)

Both findings are the two already answered in #819 (comment): user scope (src/push.ts:1008) and the partial skill copy (src/utils/pre-push-sync.ts:237). Both happen on main already and are tracked in #823. No code change for them here.

@jeff-r2026
jeff-r2026 merged commit f558b94 into Tencent:main Sep 25, 2026
11 checks passed
SaulMoro added a commit to SaulMoro/teamai-cli that referenced this pull request Sep 25, 2026
…eamai copy (Tencent#823)

Item 4, user scope: push compared HOME's rules and skills with the shared
lastPullRev only, because the per-checkout push bases of Tencent#819 were keyed for
project scope alone. After a push synced HOME's unedited copy to a teammate's
R2, the next push compared it with R1 and offered it back over the teammate's
R3. A user-scope pull now records HOME under checkoutKey(HOME) in the user
state.json, and push reads and extends it like a project checkout's. The
user-scope fast path still reads the shared fields, and an install with no
record yet keeps comparing with lastPullRev without the unrecorded-checkout
refusal: HOME is the scope's only checkout, so that revision is its own.

Item 19, inherited user scope: a project pull with inheritUserScope rewrites
HOME's skills, rules and agents under lastInheritedPullRev without moving the
user scope's push bases, so the next user-scope push offered a teammate's
newer update back the same way. That pull now adds its revision to HOME's
pushBaseRevs, creating the record from lastPullRev if there is none, and
leaves the record's rev, lastPullRev and the fast paths alone.

Item 10, single-repo: the active tree's .teamai/rules and .teamai/skills are
push sources, and on a branch behind the default branch they hold older team
versions nobody edited, which push listed as modified. The isPastVersionOf
guard that held only placed rules now covers every .teamai/rules copy, and
.teamai/skills gets the same guard: a skill is skipped with a warning when
every team file whose copy differs is an older version of it. A team file
missing locally is a teammate's addition when the member's branch never added
it, and the member's deletion otherwise; member-only files are ignored, as the
equality check already ignores them.

The checkout-base resolution that push and the agents scan each repeated
(key, record, checkoutBaseRevs, lastPullRev fallback) is now one exported
helper, resolveCheckoutBases, next to checkoutBaseRevs in pull.ts; pull uses
the same key for its record.
jeff-r2026 pushed a commit that referenced this pull request Sep 26, 2026
…eamai copy (#823) (#835)

* fix(push): stop reverting a teammate's update from HOME or a stale .teamai copy (#823)

Item 4, user scope: push compared HOME's rules and skills with the shared
lastPullRev only, because the per-checkout push bases of #819 were keyed for
project scope alone. After a push synced HOME's unedited copy to a teammate's
R2, the next push compared it with R1 and offered it back over the teammate's
R3. A user-scope pull now records HOME under checkoutKey(HOME) in the user
state.json, and push reads and extends it like a project checkout's. The
user-scope fast path still reads the shared fields, and an install with no
record yet keeps comparing with lastPullRev without the unrecorded-checkout
refusal: HOME is the scope's only checkout, so that revision is its own.

Item 19, inherited user scope: a project pull with inheritUserScope rewrites
HOME's skills, rules and agents under lastInheritedPullRev without moving the
user scope's push bases, so the next user-scope push offered a teammate's
newer update back the same way. That pull now adds its revision to HOME's
pushBaseRevs, creating the record from lastPullRev if there is none, and
leaves the record's rev, lastPullRev and the fast paths alone.

Item 10, single-repo: the active tree's .teamai/rules and .teamai/skills are
push sources, and on a branch behind the default branch they hold older team
versions nobody edited, which push listed as modified. The isPastVersionOf
guard that held only placed rules now covers every .teamai/rules copy, and
.teamai/skills gets the same guard: a skill is skipped with a warning when
every team file whose copy differs is an older version of it. A team file
missing locally is a teammate's addition when the member's branch never added
it, and the member's deletion otherwise; member-only files are ignored, as the
equality check already ignores them.

The checkout-base resolution that push and the agents scan each repeated
(key, record, checkoutBaseRevs, lastPullRev fallback) is now one exported
helper, resolveCheckoutBases, next to checkoutBaseRevs in pull.ts; pull uses
the same key for its record.

* fix(push): address review — record HOME's push base in an upgraded install (#823)

An upgraded user-scope install with no HOME record synced HOME from R1 to R2
on its first push but saved no base, because push recorded one only when the
bases came from a record. A teammate's R3 then made the next push compare the
R2 copy with lastPullRev R1 and offer it back. Push now creates HOME's record
from lastPullRev (userScopeRecord, shared with the inherited pull) and adds
the revision its sync reached. An unrecorded project checkout still records
nothing, since its fallback base may be another checkout's.

skill-data: contribute-member explains the stale .teamai copy warning and
how to publish an edit of such a copy.

* fix(push): address review — keep HOME's inherited base and a partial pull's delivered base (#823)

* fix(push): keep the push bases of skills a pull held, and match a replaced root rule at every base (#823)
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
Tencent#812) (Tencent#819)

Before scanning, push syncs each rule and skill the member never edited to
the team repo's version, and "never edited" meant equal to the version at the
project's shared lastPullRev. state.json is shared by every worktree, so a
pull in another checkout moved that revision past the copy a stale worktree
still held: the unedited copy read as an edit, and push offered it as
modified, ready to send the teammate's change back as the old version.

Push now compares with the revision this checkout last synced, from its
lastPullByWorkspace entry (checkoutKey is exported from pull.ts), and falls
back to the shared lastPullRev for a checkout with no entry. For that entry to
survive, a pull at a new team revision no longer drops the other checkouts'
records: a checkout recorded at an older revision already misses the fast
path. When the pull finds lastPullRev cleared, it resets the other records
to an empty rev (FORCED_FULL_SYNC_REV), which matches no revision, so a forced
full sync reaches every checkout, single-repo mode included, while each record
keeps its push bases. Each full sync keeps only the records
of checkouts `git worktree list` still reports, and keeps them all when the
list comes back empty, so a removed or re-created worktree's entry does not
pile up.

The sync itself moves the unedited copies to the team repo's revision, so
push then adds that revision to the entry's pushBaseRevs (newest first, the
20 newest kept) and the next push compares with them; otherwise a copy synced
to R2 read as an edit against R1 once a teammate published R3. Push leaves the
entry's rev alone, since the pull fast path reads it and the checkout still
lacks that revision's docs and agents; the next pull rewrites the entry
without pushBaseRevs. The sync accepts a copy at any of pushBaseRevs or rev (a
skill only when all its files are at one of them), so a copy it left alone as
edited is synced again once the member undoes the edit, back to whichever
version a sync gave it. The base is recorded even when the sync stops
partway, which now warns, since the copies it did not reach still match an
older base; a revision push cannot save stops the push before the scan. A
checkout with no entry (a new worktree, or one last pulled by an older CLI)
can only sync against the shared lastPullRev, which may be another
checkout's or cleared: when the scan lists a team rule or skill as modified,
push stops before creating a branch and asks for a pull there, warning that
the pull replaces those files. A rule this machine placed does not count, and
config-only pushes and new resources go through.
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…eamai copy (Tencent#823) (Tencent#835)

* fix(push): stop reverting a teammate's update from HOME or a stale .teamai copy (Tencent#823)

Item 4, user scope: push compared HOME's rules and skills with the shared
lastPullRev only, because the per-checkout push bases of Tencent#819 were keyed for
project scope alone. After a push synced HOME's unedited copy to a teammate's
R2, the next push compared it with R1 and offered it back over the teammate's
R3. A user-scope pull now records HOME under checkoutKey(HOME) in the user
state.json, and push reads and extends it like a project checkout's. The
user-scope fast path still reads the shared fields, and an install with no
record yet keeps comparing with lastPullRev without the unrecorded-checkout
refusal: HOME is the scope's only checkout, so that revision is its own.

Item 19, inherited user scope: a project pull with inheritUserScope rewrites
HOME's skills, rules and agents under lastInheritedPullRev without moving the
user scope's push bases, so the next user-scope push offered a teammate's
newer update back the same way. That pull now adds its revision to HOME's
pushBaseRevs, creating the record from lastPullRev if there is none, and
leaves the record's rev, lastPullRev and the fast paths alone.

Item 10, single-repo: the active tree's .teamai/rules and .teamai/skills are
push sources, and on a branch behind the default branch they hold older team
versions nobody edited, which push listed as modified. The isPastVersionOf
guard that held only placed rules now covers every .teamai/rules copy, and
.teamai/skills gets the same guard: a skill is skipped with a warning when
every team file whose copy differs is an older version of it. A team file
missing locally is a teammate's addition when the member's branch never added
it, and the member's deletion otherwise; member-only files are ignored, as the
equality check already ignores them.

The checkout-base resolution that push and the agents scan each repeated
(key, record, checkoutBaseRevs, lastPullRev fallback) is now one exported
helper, resolveCheckoutBases, next to checkoutBaseRevs in pull.ts; pull uses
the same key for its record.

* fix(push): address review — record HOME's push base in an upgraded install (Tencent#823)

An upgraded user-scope install with no HOME record synced HOME from R1 to R2
on its first push but saved no base, because push recorded one only when the
bases came from a record. A teammate's R3 then made the next push compare the
R2 copy with lastPullRev R1 and offer it back. Push now creates HOME's record
from lastPullRev (userScopeRecord, shared with the inherited pull) and adds
the revision its sync reached. An unrecorded project checkout still records
nothing, since its fallback base may be another checkout's.

skill-data: contribute-member explains the stale .teamai copy warning and
how to publish an edit of such a copy.

* fix(push): address review — keep HOME's inherited base and a partial pull's delivered base (Tencent#823)

* fix(push): keep the push bases of skills a pull held, and match a replaced root rule at every base (Tencent#823)
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.

[bug] push from a stale worktree diffs against another checkout's revision and can revert a teammate's update

2 participants