Repository navigation
fix(partition): adopt pre-#546 legacy-named partitions instead of stranding them - #551
Conversation
…anding them #546 widened the partition slug prefix from the anchor's basename to its whole path but kept the sha256 suffix — without migrating existing installs. On an upgraded CLI, a partition still named <basename>-<hash> (every install created before #546) stops matching projectSlug(anchor): detectProjectConfig finds no config (the project looks uninitialized), planMigration would re-copy a retired workspace into a second, empty partition, and status --all flags the perfectly good data as "corrupt — dir name does not match anchor". Both formats share the same hash, so an anchor's legacy name is computable exactly — no directory scanning. resolvePartitionDir becomes the seam for "the partition that actually holds this project's data" (detection, init, migration): when the canonical current-format directory is absent and a legacy-named one exists, it ATOMICALLY RENAMES the legacy partition into place — a same-parent metadata move, no data copied, and an interruption leaves either name intact. An authoritative current-format partition is never clobbered by a leftover legacy one; a rename that is genuinely impossible (read-only home) keeps serving the legacy directory so no data is stranded. status --all stays read-only and reports a legacy-named partition as "active (legacy name; renamed automatically on next command)" instead of corrupt. Verified end-to-end with the real CLI in an isolated HOME: a legacy .teamai migrates into the readable whole-path slug; status --all reverse-resolves it as [active]; a partition renamed to the pre-#546 format is reported active-legacy (no rename, no corrupt), then adopted by the next command (detection) with data intact, and pull runs through the adopted partition.
A pre-#546 partition stores repo.localPath as an ABSOLUTE path to its team-repo clone (<legacyPartition>/team-repo). resolvePartitionDir renamed the directory but left config.yaml pointing at the now-gone old path, so every later `pull` read the team config from a dead directory and silently skipped the sync ("Team config (teamai.yaml) not found. Skipping.", exit 0) — the project could never sync again after an upgrade. Adoption now rebases repo.localPath onto the new partition (mirroring migrate.ts's rebaseConfigPaths). The rewrite is idempotent and self-healing: a modern install whose localPath already sits in the canonical dir is left untouched, an external clone outside the partition is left untouched, and an adoption interrupted between the rename and the config rewrite is finished by the next command. Reproduced with the real CLI (isolated HOME, real local git team repo): a legacy-named partition + two `pull --force` runs printed "Team config not found. Skipping." (exit 0) before this fix; after it both runs print "Synced 1 skills" and localPath points at the live clone. Regression tests: localPath rebased off the legacy dir / external localPath left alone / modern-install no-op. Verified they fail when the rebase is disabled.
|
Confirmed and fixed in Root cause: Fix: adoption now rebases
Reproduced + verified with the real CLI (isolated
Regression tests (in |
…runcation
The localPath rebase overwrote config.yaml with a plain (non-atomic) write.
By that point the legacy partition has already been renamed away, so
config.yaml is the partition's ONLY copy — a write that fails partway
(ENOSPC, EFBIG, crash mid-write) truncates it with no source to recover from,
and the CLI still prints "Your original data is unchanged, re-run to retry"
while the data is in fact corrupt and cannot self-recover.
Add writeFileAtomic (same-dir temp + rename, preserving mode) alongside the
existing writeJsonAtomic, and use it for the adopted config.yaml. rename(2)
is atomic, so a failed write removes the temp file and leaves the original
config.yaml byte-for-byte intact; the next command retries the idempotent
rebase and converges.
Reproduced with the real CLI (isolated HOME, real local git team repo, NO fs
mock) by injecting a write failure with RLIMIT_FSIZE=128:
before: pull --force reports EFBIG, config.yaml truncated 453 -> 128 bytes,
legacy partition already moved, retry after lifting the limit exits
0 but never syncs and cannot recover
after: config.yaml preserved at 453 bytes, retry after lifting the limit
prints "Synced 1 skills" and localPath points at the live clone
Regression test: the localPath rewrite failing mid-write leaves config.yaml
intact with no leftover temp file. Verified it fails when the write is made
non-atomic. Full suite: 3109 passed, 0 regressions; tsc clean.
|
Confirmed and fixed in Root cause: the Fix: added Reproduced + verified with the real CLI (isolated
Regression test ( |
… of stranding them (Tencent#551) * fix(partition): adopt pre-Tencent#546 legacy-named partitions instead of stranding them Tencent#546 widened the partition slug prefix from the anchor's basename to its whole path but kept the sha256 suffix — without migrating existing installs. On an upgraded CLI, a partition still named <basename>-<hash> (every install created before Tencent#546) stops matching projectSlug(anchor): detectProjectConfig finds no config (the project looks uninitialized), planMigration would re-copy a retired workspace into a second, empty partition, and status --all flags the perfectly good data as "corrupt — dir name does not match anchor". Both formats share the same hash, so an anchor's legacy name is computable exactly — no directory scanning. resolvePartitionDir becomes the seam for "the partition that actually holds this project's data" (detection, init, migration): when the canonical current-format directory is absent and a legacy-named one exists, it ATOMICALLY RENAMES the legacy partition into place — a same-parent metadata move, no data copied, and an interruption leaves either name intact. An authoritative current-format partition is never clobbered by a leftover legacy one; a rename that is genuinely impossible (read-only home) keeps serving the legacy directory so no data is stranded. status --all stays read-only and reports a legacy-named partition as "active (legacy name; renamed automatically on next command)" instead of corrupt. Verified end-to-end with the real CLI in an isolated HOME: a legacy .teamai migrates into the readable whole-path slug; status --all reverse-resolves it as [active]; a partition renamed to the pre-Tencent#546 format is reported active-legacy (no rename, no corrupt), then adopted by the next command (detection) with data intact, and pull runs through the adopted partition. * fix(partition): rebase repo.localPath when adopting a legacy partition A pre-Tencent#546 partition stores repo.localPath as an ABSOLUTE path to its team-repo clone (<legacyPartition>/team-repo). resolvePartitionDir renamed the directory but left config.yaml pointing at the now-gone old path, so every later `pull` read the team config from a dead directory and silently skipped the sync ("Team config (teamai.yaml) not found. Skipping.", exit 0) — the project could never sync again after an upgrade. Adoption now rebases repo.localPath onto the new partition (mirroring migrate.ts's rebaseConfigPaths). The rewrite is idempotent and self-healing: a modern install whose localPath already sits in the canonical dir is left untouched, an external clone outside the partition is left untouched, and an adoption interrupted between the rename and the config rewrite is finished by the next command. Reproduced with the real CLI (isolated HOME, real local git team repo): a legacy-named partition + two `pull --force` runs printed "Team config not found. Skipping." (exit 0) before this fix; after it both runs print "Synced 1 skills" and localPath points at the live clone. Regression tests: localPath rebased off the legacy dir / external localPath left alone / modern-install no-op. Verified they fail when the rebase is disabled. * fix(partition): write the adopted config.yaml atomically to prevent truncation The localPath rebase overwrote config.yaml with a plain (non-atomic) write. By that point the legacy partition has already been renamed away, so config.yaml is the partition's ONLY copy — a write that fails partway (ENOSPC, EFBIG, crash mid-write) truncates it with no source to recover from, and the CLI still prints "Your original data is unchanged, re-run to retry" while the data is in fact corrupt and cannot self-recover. Add writeFileAtomic (same-dir temp + rename, preserving mode) alongside the existing writeJsonAtomic, and use it for the adopted config.yaml. rename(2) is atomic, so a failed write removes the temp file and leaves the original config.yaml byte-for-byte intact; the next command retries the idempotent rebase and converges. Reproduced with the real CLI (isolated HOME, real local git team repo, NO fs mock) by injecting a write failure with RLIMIT_FSIZE=128: before: pull --force reports EFBIG, config.yaml truncated 453 -> 128 bytes, legacy partition already moved, retry after lifting the limit exits 0 but never syncs and cannot recover after: config.yaml preserved at 453 bytes, retry after lifting the limit prints "Synced 1 skills" and localPath points at the live clone Regression test: the localPath rewrite failing mid-write leaves config.yaml intact with no leftover temp file. Verified it fails when the write is made non-atomic. Full suite: 3109 passed, 0 regressions; tsc clean.
Why
PR #546 widened the partition slug prefix from the anchor's basename to its whole path (
teamai-cli-<hash>→Users-x-Project-teamai-cli-<hash>) but kept the sha256 suffix — without migrating existing installs. On an upgraded CLI, a partition still named<basename>-<hash>(every install created before #546) stops matchingprojectSlug(anchor), so:detectProjectConfigfinds no config → the project looks uninitializedplanMigrationwould re-copy a retired workspace into a second, empty partitionstatus --allflags the perfectly good data ascorrupt — dir name does not match anchorWhat
Both name formats share the same hash, so an anchor's legacy name is computable exactly — no directory scanning. A new
resolvePartitionDir(anchor)becomes the single seam for "the partition that actually holds this project's data" and every resolver (detection, init, migration) goes through it:mkdir) is replaced by the full legacy partition (POSIX rename does this in one call; Windows takes the explicit rmdir-then-rename path).status --allstays read-only: it recognizes the legacy name vialegacyProjectSlugand reportsactive (legacy name; renamed automatically on next command)instead ofcorrupt.The authoritative reverse lookup remains the per-partition
anchorfile; the readable slug is a convenience only.Test Plan
Type + build
npx tsc --noEmit— cleannpm run build— cleanUnit (new + extended)
legacyProjectSlugkeeps the old<basename>-<hash>format and shares the hash with the current slugresolvePartitionDir: fresh install (pure resolution, no mkdir) / adopts a legacy dir by rename / keeps an authoritative canonical & leaves a stale legacy alone / replaces an empty canonical leftover / idempotent after adoptiondetectProjectConfigadopts a pre-feat(partition): encode the full project path into the data-home slug #546 legacy-named partition on detectionplanMigrationadopts before planning (retire-only, not a re-copy into a second empty partition)status --allreports a legacy-named partition asactive (legacy name), notcorruptReal-CLI end-to-end (isolated
HOME,dist/index.js, real git repo; slugs computed via the CLI's ownprojectSlug/legacyProjectSlugso case-folding matches production)<basename>-<hash>partition (config + state +env.local+anchor)status --all→[active (legacy name; renamed automatically on next command)], not corrupt, and does not rename (stays read-only)config.yaml,state.json,env.local(plaintext content preserved),anchorall carried overstatus --allafter adoption →[active]Docs
docs/designs/data-directory-layout.md— new "Partition naming (feat(partition): encode the full project path into the data-home slug #546 + adoption)" section documenting the slug formula and the rename-based adoption path