Skip to content

fix(fs): replay mount --pack-path values to umount so auto-pack includes them - #101

Merged
srstack merged 17 commits into
mainfrom
fix/fs-mount-pack-path-replay
Nov 26, 2026
Merged

srstack merged 17 commits into
mainfrom
fix/fs-mount-pack-path-replay

Conversation

@srstack

@srstack srstack commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

ti fs mount-file-system --pack-path /src mounts successfully, but the automatic pack written at unmount silently omits /src.

The companion's mount has no pack-path flag — it derives effectivePackPaths from the mount profile only (drive9/cmd/drive9/cli/mount.go:576) — so a mount-time forward can never work. The only channel that feeds the automatic pack is drive9 umount --pack-path (repeatable), which merges the values with the mount's pack state (mount.go:2089-2091, :2254, :2572-2580). ti recorded the flag in MountResult/mountstate and never replayed it; after af669e9 dropped the (ineffective) mount-time forward, the flag was simply inert.

Effect: --mount-profile portable --pack-path /src produces an archive without the local overlay paths the user asked for.

Change

Record the values at mount and replay them at unmount, and make every state that reaches the replay one the companion accepts. Both review rounds are addressed; the second round's items are the last four bullets.

  • Mount-time validation (normalizeMountPackPaths in internal/fs/mount_pack_paths.go, shared with --dry-run):
    • --pack-path with an effective WebDAV driver is refused with fs.pack_path_requires_fuse: a WebDAV mount has no local overlay to pack. The check follows the companion's own --mode auto rule (companionMountMode, darwin/windows included).
    • the shapes the companion's joinArchivePath rejects are refused with fs.invalid_pack_path: backslashes, a ./.. segment (absolute values included), and a relative value with an empty segment; a blank value is dropped rather than refused.
    • values are trimmed and de-duplicated once, through the existing mergeMountPackPaths; the locator only records them.
  • Locator keeps the extra paths and the local overlay root (local_root, pack_paths, both omitempty, only written for a FUSE mount). The root is resolved independently of the unpack decision, so --no-auto-unpack without --local-root still records the root the companion packs from. Older locators omit both fields, which means "none", so existing mounts replay nothing.
  • Unmount replays a value only when it is still present in <local-root>/overlay (the same mapping the automatic pack uses: resolvePackPath with the empty local prefix, then overlayPathForArchivePath). Values the overlay no longer holds are dropped and reported as pack_path checks on UnmountResult — in JSON and, now, in the text output. A locator with paths but no recorded root replays nothing and says so. --no-auto-pack still suppresses the pack and the replay, except beside an explicit --pack-archive-path, which is the companion's own rule.
  • A failed unmount after a completed drain (fs.unmount_failed_after_drain, exit code 1) says the kernel mount may already be detached and names --no-auto-pack. It offers --ignore-absent only when the kernel no longer lists the mount, because dropping the record for a live mount hides it from the drain gate and the token guards. A failed unmount whose drain gate was skipped (--force, WebDAV, a locator with no driver) keeps fs.companion_failed and the companion's exit status.
  • Dry-run unmount mirrors the replay decision in an auto_pack_paths check, including the explicit-archive interaction; one predicate (replayPackPaths) decides for both, so the prediction cannot drift from the execution.
  • Dead code: the legacy pack write path in internal/fs/pack.go is deleted (24 functions, three types, 1736 -> 1073 lines): ti fs pack-file-system has delegated to the companion since the drive9 cutover, so its entry point, source resolution, archive writers and the second copy of resolvePackPath/joinArchivePath (which accepted /a/../b, the drift that revealed the divergence) had no caller. Nothing compiled reaches any of it, and no behaviour changes. The legacy read half that remains, including canonicalArchivePath, is reachable only from Service.mountForeground, Service.autoUnpackMount and Service.autoPackAfterUnmount, which have no caller, and from the ti-native FUSE runtime and RestoreGitWorkspace; removing it belongs with those in a follow-up.
  • Docs: --pack-path and --no-auto-pack help text, the README paragraph (overlay semantics, the skipped-path behaviour, the refusals, --pack-archive-path adding an archive, and the archive restore still being the mount profile's decision), AGENTS.md (what the locator records, and normalizeMountPackPaths as the owner of trimming, de-duplication and the refusals), and the v0.2.11 release notes.

Tests

make test (47 packages), gofmt, go mod tidy, go vet ./internal/..., go build ./... and the binary e2e suite (against a make build binary) are clean.

  • TestMountRejectsPackPathOnWebDAV, TestMountRejectsPackPathFormsThePackRefuses, TestMountRejectsDotSegmentsInAbsolutePackPaths, TestMountAcceptsAbsolutePackPathShapes — the failing shapes never reach a mount, the accepted ones still do.
  • TestMountPackArchivePathMapping, TestMountPackOverlayPathMapping — literal vectors for the replica of the companion's path mapping, because seedOverlay builds its fixture with the same helpers.
  • TestMountRecordsPackPathsOnLocator, TestMountRecordsRootWithoutAutoUnpack — the locator keeps normalized values, and the root survives --no-auto-unpack.
  • TestUnmountForwardsOnlyPathsStillInTheOverlay, TestUnmountSkipsReplayWithoutRecordedLocalRoot, TestUnmountSkipsReplayForANonFUSELocator — what is replayed and what is skipped, both reported.
  • TestUnmountFailureAfterDrainNamesTheRecovery, TestUnmountFailureAfterDetachedMountOffersIgnoreAbsent, TestUnmountForceFailureKeepsTheCompanionError, TestUnmountKeepsLocatorWhenThePackFails — the post-failure advice, the skipped gate, and the record that must survive for a --no-auto-pack retry.
  • TestUnmountReplaysPackPathsForAnExplicitArchive, TestDryRunUnmountReportsPackReplay, TestDryRunKeepsReplayForAnExplicitArchive — the explicit-archive interaction in execution and in the dry run.
  • TestUnmountForceWithMissingOverlayPathSucceeds, TestUnmountLegacyLocatorSendsNoPackFlag, TestUnmountSkipsPackPathsWhenAutoPackDisabled, TestPackPathsAndLocalRootRoundTrip, TestMergeMountPackPathsDropsBlanksAndDuplicates — the surrounding invariants.
  • TestFSMountPackPathReachesUmount (e2e/) — flag → locator → umount argv through the installed layout, plus the WebDAV exit code.
  • TestLiveFSMountPackPathPacksOverlay (e2e/live_test.go) — the live check that the archive really contains the directory, mounted with coding-agent so it fails without the replay; registered in make live-e2e-fs. Dispatch-only: it needs FUSE and a provisioned File System (TI_LIVE=1).

Notes

  • The archive restore is still decided by the mount profile: this PR makes the pack contain the requested paths, and --unpack-archive-path (or a profile that unpacks the default archive, such as portable) is what brings them back. The README says so instead of implying the next mount unpacks them automatically.
  • The live FUSE assertion is written but not dispatched here (no drive9 deployment in this environment). Until it runs, "the archive contains the directory" is covered only against the fake companion, whose umount accepts any argv.
  • The pre-detach check compares raw bytes while the companion normalizes to NFC; golang.org/x/text is not a dependency, so a non-ASCII name in another normalization form can be skipped rather than packed. Left as a known limit.

The companion's `mount` has no pack-path flag: it builds the effective pack
paths from the mount profile only. The only place that accepts extra paths is
`umount --pack-path`, which merges them with the pack state before running the
automatic pack. ti therefore has to keep the values from mount time until
unmount.

- Locator gains PackPaths (`pack_paths,omitempty`); an omitted field means
  "none", so locators written by earlier versions keep working.
- WithPackPaths/NormalizePackPaths trim, drop blank entries and remove
  duplicates while preserving order, because the companion appends one
  --pack-path flag per entry.
- Tests pin the round trip and the normalization.
`ti fs mount-file-system --pack-path /src` mounted fine while the automatic
pack silently omitted /src: the flag only reached MountResult/mountstate, and
the companion mount ignores it (it derives pack paths from the profile). The
previous change dropped the mount-time forward without providing another
channel, which left the flag inert.

Record the values on the locator at mount time and replay them as repeated
`drive9 umount --pack-path` on unmount, which is what feeds the automatic
pack. --no-auto-pack keeps suppressing both the pack and the replay; a mount
without extra paths sends no flag, so existing behaviour is unchanged.

Tests drive the fake companion end to end: the umount argv carries the paths
in order, --no-auto-pack sends none, and a mount without extra paths sends
none.
@ti-chi-bot ti-chi-bot Bot added the size/L label Nov 25, 2026

@mornyx mornyx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review summary

The diagnosis is right and well argued against the companion source: drive9 mount has no pack-path flag, so umount --pack-path is the only channel into the automatic pack, and recording the values on the locator is the additive, backward-compatible way to carry them there. The --no-auto-pack boundary is correct, and every fix line is pinned by a test.

What blocks the merge is that the replay makes unvalidated mount-time input load-bearing at unmount, where the companion treats --pack-path strictly and only after the mount has been detached. Several reachable states — including the example in the PR description, and any WebDAV mount started with --pack-path — unmounted cleanly before this change and now fail. The structural points further down (a second pack-path normalizer, docs that no longer match the code) are not blockers.

I checked the companion behaviour by reading drive9 81bb0d92 (the revision the PR description cites) and by running its own runUmount and defaultPackAfterUnmount in an isolated test with fake unmount and terminate dependencies. I did not run a real mount.

What looks good

  • The root cause is identified correctly: effectivePackPaths comes from the profile alone (drive9 cmd/drive9/cli/mount.go:576), so a mount-time forward could never have worked.
  • Locator.PackPaths is additive (omitempty, "omitted means none", no schema bump). Read and List use plain json.Unmarshal (internal/fs/mountlocator/locator.go:153, :229), so older builds ignore the field and this build reads older locators as none. The locator has a single production writer, so nothing rewrites the field away.
  • A mount without extra paths keeps the exact same umount argv. Reverting the fix lines one at a time fails at least one new test every time: the replay loop fails TestUnmountForwardsPackPathsToCompanion, dropping the else fails TestUnmountSkipsPackPathsWhenAutoPackDisabled, removing the locator write fails TestMountRecordsPackPathsInLocator, and removing trimming or de-duplication fails the two locator tests.
  • Both commit messages explain the why, and the record/replay split reads cleanly.

Blocking (please address before merge)

1. Replayed --pack-path values can fail an unmount that used to succeed, after the mount is already gone

drive9UnmountFileSystem now replays every recorded value unless --no-auto-pack is set (internal/fs/drive9_companion.go:1357-1358). At mount time the only check is the none-profile rejection (internal/fs/mount.go:689-692), and NormalizePackPaths only trims and de-duplicates. On the companion side umount --pack-path is the strict form of a pack path, not the lenient profile form:

  • Each value must exist under <local-root>/overlay/, otherwise the pack fails with stat pack path … (resolveExplicitPackSources is called with skipMissing=false, drive9 cmd/drive9/cli/pack.go:591 and :600-620; defaultPackAfterUnmount sets no SkipMissing, cmd/drive9/cli/mount.go:2601-2607).
  • ./x, x/, x//y and backslashes are refused (joinArchivePath, cmd/drive9/cli/pack.go:1077-1101).
  • The builtin profiles route only node_modules, .venv, target and Git workspaces into the overlay (cmd/drive9/cli/profile.go:268-290), so a path such as /src is not there.

Four reachable states, each of which unmounted cleanly before this PR:

  1. Path absent from the overlay (FUSE). For a portable mount and the default archive, defaultPackAfterUnmount succeeds without an explicit path and fails with /src replayed: drive9 umount: pack :/.drive9/packs/workspace-….tar.gz: stat pack path /workspace/src (<local-root>/overlay/src): lstat …: no such file or directory. That is the PR description's own example (--mount-profile portable --pack-path /src): nothing routes src into the overlay, so there is nothing to pack. The pack is the last step of runUmount, after the stop and the kernel unmount (cmd/drive9/cli/mount.go:2397-2401, :2452-2466). ti then reports a failed unmount for a mount that is already detached and keeps the locator (internal/fs/drive9_companion.go:1377). For as long as that locator exists, the token guards refuse refresh, disable and delete with fs.token_mount_active (internal/fs/tokenmgmt/service.go:840-876) and point back at the same failing unmount. With --ignore-absent, ti removes the locator and returns status: absent (internal/fs/drive9_companion.go:1363-1375): exit 0 and no archive.
  2. Path in a form the pack refuses (FUSE). ./src, src/ and src//sub all fail with invalid relative pack path. Same outcome as 1.
  3. WebDAV. ti accepts --pack-path with the WebDAV driver when --mount-profile is omitted: the empty profile is treated as coding-agent for eligibility (internal/fs/pack.go:31, :1658-1669), ti forwards no --profile, and the locator is written with driver=webdav and the paths on it. Unmount skips the drain for WebDAV (internal/fs/drive9_mount_drain.go:108-109, :210-214) and replays. A WebDAV mount state has no local_root (cmd/drive9/cli/mount_webdav.go:194-199), so validateUmountPackState rejects it (cmd/drive9/cli/mount.go:2249-2252, :2559-2562). Run against such a state, umount --pack-path /src returns drive9 umount: --pack requires mount metadata with local_root, with no kernel unmount and no bridge termination; the same state unmounts cleanly without the flag. On macOS and Windows the default --driver auto is a WebDAV mount (cmd/drive9/cli/mount_webdav.go:46-56), so this needs no unusual flag combination. On non-Windows the companion also terminates the live bridge by PID identity before that check runs (cmd/drive9/cli/mount.go:2208-2213, :2239-2244); I read that from the source and did not execute it.
  4. --force with an unreadable mount state. --force skips the drain (internal/fs/drive9_mount_drain.go:120-121), so umount is reached with the replayed path and fails with read mount state for pack before the stop (cmd/drive9/cli/mount.go:2148-2151). Without the flag the same state unmounts cleanly.

The note in the PR description does not hold for --force and WebDAV: ti does not fail earlier at the drain step when the drain gate is skipped. The message it quotes is produced only when --pack-path is sent together with --no-auto-pack (cmd/drive9/cli/mount.go:2265-2267), which ti never does.

Suggested direction:

  • Validate at mount, in a place shared with --dry-run (mountOverlayPolicy or normalizeMountOptions): reject --pack-path when the effective driver is WebDAV, and reject the forms the pack refuses (./../empty segments, backslash). At minimum, record PackPaths only when the companion reported a FUSE mount (mountedDriver, internal/fs/drive9_mount_audit.go:131-132).
  • Record the overlay root next to the paths (the mount already resolves it as auditRoot) and check each recorded path in drive9UnmountFileSystem before umount: either fail before anything is detached, or skip the missing ones with a visible check in UnmountResult. Mirror the decision in DryRunUnmountFileSystem.
  • When umount fails after a successful drain, say that the mount may already be detached and name --no-auto-pack and --ignore-absent, instead of only asking for a retry.
  • Add the cases listed under item 4.

Should fix (non-blocking, strong)

2. A second pack-path normalizer, in the wrong package

mountlocator.NormalizePackPaths (internal/fs/mountlocator/locator.go:65-88) is mergeMountPackPaths (internal/fs/mount.go:740-757) again: trim, drop blanks, exact de-duplication, order preserved. AGENTS.md:1283-1284 names mountOverlayPolicy the single owner of the effective pack paths, and internal/fs/mountlocator is the non-secret routing record (AGENTS.md:1161). The split already shows: MountResult.PackPaths reports the raw flag values (internal/fs/drive9_mount_audit.go:179) while the locator stores normalized ones.

Normalize once, where flag values are already trimmed for the companion argv: opts.PackPaths = mergeMountPackPaths(opts.PackPaths) in normalizeMountOptions (internal/fs/mount.go:173), then assign locator.PackPaths = opts.PackPaths in writeDrive9MountLocator. WithPackPaths, NormalizePackPaths and their two tests can go; keep one JSON write-then-read assertion for the pack_paths key and move the table to a mergeMountPackPaths test, which has none. Separately, the zero-or-one mountOpts ...MountFileSystemOptions parameter now has a second dependency behind len(mountOpts) > 0 (internal/fs/drive9_companion.go:1412-1419); explicit arguments would be clearer.

3. Docs and help text no longer match the code

  • ti fs unmount-file-system --no-auto-pack still says "Skip the portable mount profile's default auto-pack action" (internal/cli/commands.go:2687). After this PR it also drops the recorded paths (internal/fs/drive9_companion.go:1350-1360), which for coding-agent is the only thing that triggers an auto-pack.
  • The README paragraph this PR extends still says auto-unpack applies when "portable supplies / by default and --pack-path adds more". In the companion path the profile alone decides: effectivePackPaths comes from the profile (cmd/drive9/cli/mount.go:576, :741), coding-agent has none (cmd/drive9/cli/profile.go:224), and ti forwards --unpack only for an explicit --unpack-archive-path (internal/fs/drive9_mount_audit.go:103-110). A coding-agent --pack-path X mount therefore never restores the archive this PR writes, while ti's unpackPossible predicate (internal/fs/mount.go:726) audits an unpack that does not happen. For portable, / already packs the whole overlay (cmd/drive9/cli/profile.go:236, cmd/drive9/cli/pack.go:628-634), so the replay adds no content there.

With either builtin profile, the stated outcome (the next sandbox unpacks the requested paths) is not reached by this change alone. It is worth deciding what --pack-path is for and saying it once: either close the loop (have the mount unpack the default archive when extra pack paths are recorded, after confirming that ti's defaultPackArchivePath names the same file as the companion's), or state that the extras are packed at unmount and must already be overlay paths, and add the --pack-archive-path interaction to the README sentence.

4. Tests stop at argv shape

The fake companion's umount accepts anything (internal/fs/drive9_fake_companion_test.go:133-137), so no test can see any state in item 1. The pieces are already there: TI_FAKE_UMOUNT_FAIL (for example internal/fs/drive9_mount_drain_test.go:362) and legacyTestLocator (:578). Missing: a failing umount with recorded paths and the locator state that follows; a WebDAV locator with pack paths; --force with a gone mount; a legacy locator without pack_paths. Under e2e/ there is no flag → locator → umount test (only the help assertion at e2e/cli_test.go:65), and the live suite never mounts with --pack-path. One live FUSE mount and unmount with an existing overlay directory, asserting that the archive contains it, is the only way the PR's claim gets checked against the real companion.

Two small ones in the new test file: the variadic opts parameter of mountWithPackPaths (internal/fs/drive9_unmount_pack_paths_test.go:14) is unused by all four callers, and TestUnmountWithoutPackPathsSendsNoFlag (:111) cannot fail while the loop iterates locator.PackPaths. It would sit better as a table case next to TestUnmountSkipsPackPathsWhenAutoPackDisabled (:95).

Nits

  • AGENTS.md:1161 still describes the mount locator as routing state only.

Recommendation

Request changes. The replay turns unmounts that worked before into reported failures (the PR's own example, and any WebDAV mount started with --pack-path) and leaves a locator that blocks token operations; it needs mount-time validation and a check before the mount is detached.

Review of #101 found that replaying mount-time --pack-path values turned
unmounts that used to succeed into reported failures. The companion treats
`umount --pack-path` as the strict form: each value must exist under
<local-root>/overlay, the forms `./x`, `x/`, `x//y` and backslashes are
refused, and a WebDAV mount has no local_root at all, so validateUmountPackState
rejects it. Because the pack runs after the stop and the kernel unmount, a
rejected value left the mount detached with the locator still present, which
also blocks token refresh, disable and delete.

- Validate at mount, where --dry-run sees it too: --pack-path is refused for a
  WebDAV mount (fs.pack_path_requires_fuse) and for the shapes the companion's
  joinArchivePath rejects (fs.invalid_pack_path). Normalization now happens
  once in normalizeMountPackPaths via mergeMountPackPaths; the second
  normalizer in mountlocator is gone.
- Record the mount's local root next to the paths, and only for a FUSE mount.
  Unmount replays a value only when it is still in `<local-root>/overlay`;
  the rest are reported as skipped checks so the pack cannot fail after the
  detach. A locator without a recorded local root replays nothing and says so.
- A failed unmount after a successful drain now says the kernel mount may
  already be detached and names --no-auto-pack and --ignore-absent instead of
  only asking for a retry.
- Dry-run unmount reports the same decision (auto_pack_paths).
- Docs: --pack-path and --no-auto-pack help text, the README paragraph that
  claimed a mount-time forward, and the locator description in AGENTS.md.

Tests cover the four reachable states from the review: an absent overlay path
(FUSE), --force with a gone mount, a WebDAV locator with recorded paths, and a
legacy locator without pack paths, plus locator retention after a failed pack.
@ti-chi-bot ti-chi-bot Bot added size/XXL and removed size/L labels Nov 26, 2026
@srstack

srstack commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — the review was right on the blocking point, and I've reworked the change in 091b72c. Summary of what changed and why.

Blocking: the replay could break an unmount that used to work

Confirmed your reading of the companion: umount --pack-path is the strict form, the check happens after the stop and the kernel unmount, so a rejected value left a detached mount plus a locator that blocks token refresh/disable/delete.

The fix moves every unsafe case before the detach and keeps the replay only where it is known to be packable:

  • Mount-time validation, in normalizeMountPackPaths (runs for the real path and for --dry-run):
    • --pack-path with an effective WebDAV driver is refused with fs.pack_path_requires_fuse (the companion's --mode auto on darwin/windows included, via companionMountMode). This removes your case 3 before a mount exists.
    • the shapes joinArchivePath rejects are refused with fs.invalid_pack_path: backslashes, and relative paths with an empty, . or .. segment. This removes case 2 before a mount exists.
  • The mount's local root is recorded on the locator, next to the paths, and only for a mount the companion reported as FUSE (mountedDriver). Without it a path cannot be checked, so nothing is replayed.
  • Unmount replays a value only when it is still in <local-root>/overlay, computed with the same mapping the automatic pack uses (resolvePackPath with the empty local prefix, then overlayPathForPackPath). Missing values are dropped and reported as pack_path checks on UnmountResult, so the pack can no longer fail after the detach — your case 1 returns to the pre-PR behaviour, with a visible warning instead of a silent omission.
  • A failed unmount after a successful drain now reports fs.unmount_failed_after_drain: it says the drain succeeded, that the kernel mount may already be detached, and names --no-auto-pack and --ignore-absent — instead of only asking for a retry.
  • --force with a gone mount (your case 4): the missing paths are skipped before umount, so the strict flag never reaches a state that cannot satisfy it.
  • Dry-run unmount mirrors the decision in an auto_pack_paths check, so a dry run cannot promise a pack the overlay no longer satisfies.

Should fix 2 — one normalizer

WithPackPaths / NormalizePackPaths and their tests are gone. Normalization happens once, in normalizeMountPackPaths, through the existing mergeMountPackPaths; the locator is a plain record again (PackPaths, LocalRoot). The round trip is pinned by one JSON write/read assertion (TestPackPathsAndLocalRootRoundTrip), and the table moved to TestMergeMountPackPathsDropsBlanksAndDuplicates, which previously had no coverage. writeDrive9MountLocator now takes explicit arguments instead of the zero-or-one variadic option.

Should fix 3 — docs

  • --pack-path help: it is a local overlay path packed by the automatic pack at unmount, must exist in the overlay, and WebDAV cannot use it.
  • --no-auto-pack help: it also drops the recorded paths.
  • README: removed the claim that the mount forwards pack paths; states that the values are overlay paths replayed at unmount, that an absent one is skipped with a check, that WebDAV refuses the flag at mount, and how --pack-archive-path and --no-auto-pack interact. It now also says the archive restore is still decided by the mount profile, so the outcome for coding-agent is "the archive contains the paths", not "the next mount unpacks them" — that gap belongs to the unpack side, not this PR.
  • AGENTS.md: the locator description mentions the local root and the replayed pack paths.

Should fix 4 — tests

All four states now have a case through the fake companion, including the locator state that follows a failure:

  • TestUnmountForwardsOnlyPathsStillInTheOverlay — one path present, one absent: only the present one is replayed, the absent one is a skipped check.
  • TestUnmountKeepsLocatorWhenThePackFails — failing umount keeps the locator for a --no-auto-pack retry.
  • TestUnmountSkipsReplayWithoutRecordedLocalRoot and TestUnmountSkipsReplayForANonFUSELocator — nothing replayed, both reported.
  • TestUnmountForceWithMissingOverlayPathSucceeds, TestUnmountLegacyLocatorSendsNoPackFlag, TestUnmountSkipsPackPathsWhenAutoPackDisabled.
  • TestMountRejectsPackPathOnWebDAV, TestMountRejectsPackPathFormsThePackRefuses (table), TestMountRecordsPackPathsOnLocator.

The two small ones are addressed: the unused variadic in the test helper is now a single optional tweak used by no caller, and the "no flag" case is a table sibling rather than a loop that cannot fail.

go test ./internal/..., go vet ./internal/... and go build ./... are clean; CI test is green. I did not run a live FUSE mount — this environment has no drive9 deployment — so the end-to-end "archive contains the directory" assertion still needs the live suite; happy to add it if the repository has a job that can mount.

One thing I did not change: MountResult.PackPaths still reports the flag values and the locator stores the normalized ones, because normalization now happens before both are written, so they agree.

The dry run is the only way to see the replay decision before the mount is
detached, so cover it: a path present in the overlay is reported as replayed,
and one that is not is named as skipped.
@srstack

srstack commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Pushed one test-only commit (ab4e92a): TestDryRunUnmountReportsPackReplay pins the dry-run side of the replay decision — a path present in the overlay is reported as replayed, and one that is not is named as skipped. No behaviour change; go test ./internal/... and go vet ./internal/... are clean and CI test is green on the new head.

@srstack
srstack requested a review from mornyx November 26, 2026 09:59
--no-auto-pack suppresses the automatic archive, but an explicit
--pack-archive-path still runs the pack, so dropping the recorded --pack-path
values there produces an explicit archive that omits them.

Replay whenever a pack will run: the automatic one, or an explicit archive that
outlives --no-auto-pack. --no-auto-pack alone still suppresses both, and the
dry run reports the same rule. Help text and README say which flag wins.
@srstack

srstack commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

One more fix in 961bf49, from the --pack-archive-path interaction you asked to make explicit:

--no-auto-pack suppresses the automatic archive, but an explicit --pack-archive-path still packs, so dropping the recorded paths there produced an explicit archive that omitted them. The replay now runs whenever a pack will run — the automatic one, or an explicit archive that outlives --no-auto-pack; --no-auto-pack alone still suppresses both. The dry run reports the same rule, and the --no-auto-pack help plus the README say which flag wins.

New test: TestUnmountReplaysPackPathsForAnExplicitArchive (explicit --pack stays in argv and /src rides along). go test ./..., go vet ./internal/... clean, CI green on 961bf49.

The locator is no longer routing state only: it also carries the local overlay
root and the --pack-path values unmount replays, and the replay is filtered by
what the overlay still holds.
@srstack

srstack commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Also closed the AGENTS.md nit in f6d8371: the prose section that documented the locator as routing state now says it also carries the mount's local overlay root and the --pack-path values unmount replays, and that a value is replayed only while it is still present in <local_root>/overlay (the companion treats umount --pack-path as a strict path that fails after the detach). Docs-only; CI green on f6d8371.

User-visible Filesystem behaviour changed: the flag now reaches the automatic
pack, WebDAV refuses it, and an absent overlay path is reported instead of
failing the pack after the detach.
The review noted that e2e/ asserted only the help text: nothing drove the real
binary from the flag through the locator to the companion argv. Mount through
the installed layout with --mount-profile portable --pack-path /src and an
existing overlay directory, unmount, and assert the recorded umount argv
replays --pack-path /src; also assert a WebDAV mount refuses the flag before
the companion runs.
@srstack

srstack commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Covered the last gap from item 4 in e067aa0: e2e/ only asserted the help text, so nothing drove the real binary from the flag through the locator to the companion argv.

TestFSMountPackPathReachesUmount mounts through the installed layout with --mount-profile portable --pack-path /src and an existing overlay directory, unmounts, and asserts the recorded umount argv replays --pack-path /src; it also asserts a WebDAV mount refuses the flag with fs.pack_path_requires_fuse before the companion runs.

Verified locally with make build (-tags ti_test_controls) + TI_E2E_BIN=bin/ti go test ./e2e -count=1 (whole suite green) and go test ./...; CI green on e067aa0.

The one thing still uncovered is the live assertion you named — a real FUSE mount whose archive is then inspected. This environment has no Drive9 deployment, so I can only add it if the live suite (TI_LIVE=1, dispatch-only) is an acceptable home for it; say the word and I will.

@mornyx mornyx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review summary

The rework does what the previous review asked for where the problem was reachable most. --pack-path is validated at mount inside normalizeMountOptions, so --dry-run sees the same refusal; the locator records the overlay root; unmount checks every recorded value before the detach and reports the ones it skips; the dry run predicts the same decision; and the explicit-archive rule added later is the companion's own rule.

Two things still block, and both are small and local. The new WebDAV refusal makes --pack-path driver-sensitive, and that breaks three existing tests in internal/fs on macOS. The new fs.unmount_failed_after_drain error is returned whenever no drain error is set, which includes the case where no drain ran; it then says the drain succeeded, exits with the authentication code, and recommends --ignore-absent even for a mount that is still attached.

I reviewed e067aa06. Its code is identical to 961bf499; the three later commits are documentation and one e2e test. Besides reading, I ran the tests on darwin/arm64, reverted the fix lines one at a time, compared ti's path mapping with the companion's own functions at drive9 81bb0d92, and applied each fix suggested below in a scratch copy to see that it holds. I did not run a real mount.

Resolved since the previous review

  • A recorded value missing from the overlay is skipped before the detach, instead of failing the pack after it (internal/fs/drive9_companion.go:1438-1447).
  • ./src, src/ and src//sub are refused at mount (internal/fs/mount.go:205-219).
  • WebDAV refuses --pack-path at mount (internal/fs/mount.go:201-204), and a non-FUSE locator never replays.
  • There is one pack-path normalizer again, writeDrive9MountLocator has an explicit signature, and the locator is a plain additive record.
  • The help texts, the README paragraph and the AGENTS.md locator description are updated, and the release-notes entry is accurate.
  • Tests now cover a failing umount with the locator state that follows, a WebDAV locator, a legacy locator, the dry-run report, and (in e067aa06) the e2e path from the flag through the locator to the recorded umount argv. TestFSMountPackPathReachesUmount passes against a make build binary on this machine and fails when I remove the replay or the WebDAV refusal.

What looks good

  • Record and replay is the right shape for this, and the filter before the detach removes the failure the previous review blocked on for every value the overlay does not hold.
  • With --no-auto-pack plus --pack-archive-path, the recorded paths ride along with the explicit archive, which is what the companion accepts (cmd/drive9/cli/mount.go:2247-2267).
  • Reverting the fix lines one at a time fails at least one test for 9 of the 12 lines I tried.

Blocking (please address before merge)

1. make test fails on macOS

normalizeMountPackPaths refuses --pack-path when companionMountMode(opts.Driver) == "webdav" (internal/fs/mount.go:201), and companionMountMode maps an empty or auto driver to WebDAV on darwin and Windows (internal/fs/mount_durability.go:138-150). Three tests this PR does not change call MountFileSystem with PackPaths: []string{"/"} and no Driver, so they fail on darwin/arm64 at e067aa06:

  • TestDrive9MountDerivesOverlayRootForAudit (internal/fs/drive9_mount_audit_test.go:175)
  • TestDrive9MountRejectsPackFlagsWithoutProfile (:318)
  • TestDrive9MountNoAutoUnpackKeepsOldFlagShape (:582)

Each gets --pack-path needs a FUSE mount …. go test ./internal/fs/... ./internal/cli/... fails with exactly these three, and the same three pass at the merge base f13d62df. CI stays green because it runs on ubuntu only (.github/workflows/ci.yml:18, :47-48). The new tests are host-independent only because they set Driver explicitly.

Fix: pass Driver: "fuse" at the three call sites, which is the convention e2e/cli_test.go:1224-1227 already states. With only that applied, the three and the rest of internal/fs and internal/cli pass on darwin/arm64. Please run make test on a macOS host before merging.

2. fs.unmount_failed_after_drain is wrong when the drain gate was skipped, and it changes the exit code of every failed unmount

The block at internal/fs/drive9_companion.go:1385 is returned whenever drainErr == nil. That also holds when drainBeforeUnmount skipped the gate and returned MountDrain{Status: "skipped"} (internal/fs/drive9_mount_drain.go:211-213): under --force, for a WebDAV locator, and for a locator that records no driver. The message then says "the pre-unmount drain succeeded, so writes are safe". Under --force with a failing umount I get that sentence while the drain status is skipped, and AGENTS.md:1181-1182 defines --force as the path that accepts the loss.

This is also how the fourth state of the previous review reports itself now, for a recorded value that is still in the overlay: --force on a mount whose companion state is gone while ti's locator and the overlay persist. The value is replayed, the companion fails with read mount state for pack before the stop (cmd/drive9/cli/mount.go:2148-2151), and ti reports a drain that never ran. Only a value missing from the overlay is filtered out under --force; the reply's "the strict flag never reaches a state that cannot satisfy it" holds for those alone.

Three more problems in the same block:

  • Exit code. apperr.New("fs.unmount_failed_after_drain", "runtime", 3, …). Every other error in internal/fs that exits 3 is an "authentication" error, and AGENTS.md:1367-1368 reserves 3 for authentication. The block also replaces fs.companion_failed, which carries the companion's own exit status (internal/fswrap/runner.go:113), for every failed unmount that follows a nil drain error, pack paths or not. A busy FUSE mount now exits 3.
  • The --ignore-absent advice. It is offered for any failure after the drain. When the mount is still attached, following it removes the locator and returns absent (internal/fs/drive9_companion.go:1370-1383), which leaves a live mount that the drain gate and the token guards can no longer see.
  • No test covers a failing umount under a skipped gate. TestUnmountFailureAfterDrainNamesTheRecovery drains for real.

Fix: key the block on the drain outcome (drain.Status == "drained"), use exit code 1, and offer --ignore-absent only when the mount is no longer listed. Add a --force variant of the test. With the first two applied in a scratch copy, --force returns the plain fs.companion_failed, a drained failure exits 1, and the PR's tests still pass.

Should fix (non-blocking, strong)

3. A --pack-path mount with --no-auto-unpack and no --local-root records no root and never replays

The locator's root is auditRoot (internal/fs/drive9_mount_audit.go:135), and mountOverlayAudit returns an empty root when nothing unpacks and no --local-root was given (internal/fs/mount.go:819-822). I ran --driver fuse --mount-profile portable --pack-path /src --no-auto-unpack: the locator holds pack_paths and an empty local_root. With src present in the companion's overlay, the unmount sends no --pack-path and reports "the mount did not record its local overlay root … pass --pack-archive-path to pack explicitly" (internal/fs/drive9_companion.go:1429-1435). That advice goes nowhere: unmount has no flag for paths, and an explicit archive runs the same filter. In --output text nothing is printed at all, because UnmountResult.Human() (internal/fs/mount.go:903-922) does not render checks. So in the one configuration that says "pack, but do not unpack", --pack-path is inert again.

The root is knowable there. companionMountLocalRoot (internal/fs/mountroot.go:27) is a pure computation, and the companion uses that default root for any FUSE overlay-profile mount regardless of auto-unpack (cmd/drive9/cli/mount.go:713-718). Fix: resolve the locator's root independently of the audit decision, drop the advice from the check, and add a test that mounts with --no-auto-unpack and no --local-root. With only that applied, the same mount records the default root and the unmount replays /src.

4. The copy of the companion's path mapping is loose for absolute values, and nothing pins it

mountPackArchivePath and mountPackOverlayPath (internal/fs/mount.go:228-254) mirror resolvePackPath and overlayPathForArchivePath (cmd/drive9/cli/pack.go:993-1049). Mount-time validation skips absolute values (internal/fs/mount.go:210-212). I ran both sides over 140 (remote root, value) pairs. The pairs where ti replays a value and the companion then refuses it are the absolute ones with a . or .. segment: ti checks the cleaned path, <root>/overlay/b for /a/../b, and if that exists it replays /a/../b, which the companion rejects inside the pack that runs after the detach. That is the failure class the previous review blocked on, now with an actionable error. One rarer difference points the same way: the companion normalizes to NFC and ti checks the raw bytes, so a non-ASCII name in another normalization form is skipped, or not found by the companion.

Nothing would catch a drift: seedOverlay (internal/fs/drive9_unmount_pack_paths_test.go:46-52) builds the overlay path with the same two functions the check uses. The repository already pins a companion replica with vectors observed from the real one (TestCompanionMountLocalRootMatchesDrive9, internal/fs/drive9_mount_audit_test.go:193; AGENTS.md:1302-1305).

Fix: run the segment check on absolute values too and reject only . and .. there. / and /a//b are valid pack paths, and the existing tests pack with --pack-path /, so do not reject empty segments. With only that applied, the . and .. pairs disappear from the comparison and the PR's tests still pass. Give the two functions a table test with literal expected strings.

5. The live test is addable

The reply declined the live FUSE test because this environment has no drive9 deployment. The repository has a job that mounts: .github/workflows/live-e2e.yml:61-71 installs fuse3 and runs make live-e2e, which includes TestLiveFSMountRuntime (e2e/live_test.go:1482; it mounts at :1524). "The archive contains the directory" is still checked only against the fake companion, whose umount accepts any argv. A case next to that test (mount with --pack-path <existing overlay directory>, unmount, unpack the archive, assert the path) is the only way the PR's central claim gets checked against the real companion. Writing it for the maintainer to dispatch is enough.

Nits

  • TestUnmountSkipsReplayWithoutRecordedLocalRoot passes with the blank-root branch removed: with an empty root the overlay path is relative, so each value is skipped by the per-value check instead. Assert the message.
  • The dry-run rule for --no-auto-pack with --pack-archive-path (internal/fs/mount.go:460-462) is not pinned. Reverting the condition leaves every test green.
  • README: "Pass --pack-archive-path to choose the archive name". It adds one. Without --no-auto-pack the companion writes both the default archive and the named one (cmd/drive9/cli/mount.go:2254-2263).
  • The reply credits the README with a sentence about the archive restore being decided by the mount profile. It is not there.
  • The PR description is stale in its Notes, Change and Tests sections. Merge commits here carry the title only, so it costs the PR page.
  • AGENTS.md:1288 still names mountOverlayPolicy the single owner of the effective pack paths. Trimming, de-duplication and the two refusals now live in normalizeMountPackPaths.
  • The tweak parameter of mountWithPackPaths has no caller, and the pack-path helpers could sit in their own file next to their tests (internal/fs/mount.go is at 938 lines).

Recommendation

Request changes. Two small local fixes: make test must pass on macOS again, and the new failure path must not report a drain that never ran or exit with the authentication code.

Two review blocking points, both local.

The locator's overlay root came from the unpack audit decision, so
`--pack-path` with `--no-auto-unpack` and no `--local-root` recorded an
empty root and the replay was skipped: the one configuration that says
"pack, but do not unpack" made the flag inert. Resolve the root from
`companionMountLocalRoot` whenever the mount records pack paths, which is
the root the companion itself uses for any FUSE overlay-profile mount, and
drop the check's advice that pointed at an explicit archive that runs the
same filter.

`fs.unmount_failed_after_drain` keyed on a nil drain error, which is also
true when the gate was skipped (--force, a WebDAV locator, a locator with
no driver): it then claimed a drain that never ran. Key it on the drain
result instead, exit with `1` rather than the authentication code `3`, and
offer `--ignore-absent` only when the kernel no longer lists the mount,
because dropping the record for a live mount hides it from the drain gate
and the token guards. Render the unmount checks in the text output so a
skipped `--pack-path` is not silent.
The mount-time check skipped absolute values, so `/a/../b` was validated
as its cleaned overlay path and then replayed verbatim; the companion
refuses it inside the pack that runs after the detach. Refuse `.` and `..`
segments in absolute values too, and keep the shapes the pack accepts
(`/`, repeated slashes below the root).

Move the pack-path normalizer, the refusals, and the replica of the
companion's archive/overlay path mapping into their own file next to their
tests, and pin that replica with literal path vectors: `seedOverlay` builds
its fixture with the same helpers the check uses, so a drift would satisfy
both sides.
`companionMountMode` maps an empty or `auto` driver to WebDAV on darwin
and Windows, so three tests that mount with `PackPaths` and no `Driver`
fail on macOS with the new WebDAV refusal. Pass `Driver: "fuse"`, the
convention the e2e suite already states, so the suite is host-independent
again and CI's ubuntu-only runner stops hiding it.
The fake companion's `umount` accepts any argv, so "the archive contains
the directory named by --pack-path" was only ever checked against the
fake. Mount with `--pack-path` on an existing overlay directory, unmount
with `--no-auto-pack` and an explicit archive, unpack it, and assert the
path is there. Dispatch-only: it needs FUSE and a provisioned File
System, so it runs under `make live-e2e` (TI_LIVE=1).
README: `--pack-archive-path` adds an archive rather than choosing the
only one; `--pack-path` is refused for WebDAV and for values the pack
cannot accept; restoring the archive is still the mount profile's
decision. AGENTS: `normalizeMountPackPaths` owns trimming, de-duplication
and the refusals, and the companion path replicas are pinned by vectors.
Release notes: the replay no longer depends on the unpack decision, the
skip is visible in text output, and a failed unmount after a completed
drain exits 1 with evidence-gated `--ignore-absent` advice.
@srstack

srstack commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Reworked at f38ed17. Both blocking items are fixed, and so are the strong non-blocking points and the nits.

1. make test on macOS. You are right that CI's ubuntu-only runner hid it: the three tests mount with PackPaths and no Driver, and companionMountMode maps empty/auto to WebDAV on darwin and Windows. They now pass Driver: "fuse", the convention e2e/cli_test.go already states (518d7c6). I do not have a macOS host here, so I verified host-independence by forcing the darwin mapping (""/auto → webdav) in a scratch copy and running the whole internal/fs and internal/cli suites: the only failure left was TestCompanionMountModeMatchesCompanionAutoResolution, which is the test that pins the GOOS rule itself and therefore cannot hold under a forced mapping. Nothing else depends on the host, but please re-run make test on darwin before merging — that is the one claim I cannot check myself.

2. fs.unmount_failed_after_drain. It now keys on drain.Status == "drained" instead of drainErr == nil, so --force, a WebDAV locator, and a locator with no driver return the plain fs.companion_failed and no longer claim a drain that never ran. The exit code is 1; 3 stays reserved for authentication. --ignore-absent is offered only when mountEvidence no longer lists the mount — otherwise the message says that retrying with --no-auto-pack keeps the record and that --ignore-absent would orphan a mount that is still listed. Tests: TestUnmountForceFailureKeepsTheCompanionError (skipped gate, companion code and exit status kept, locator survives), TestUnmountFailureAfterDrainNamesTheRecovery (drained, still listed: no --ignore-absent), TestUnmountFailureAfterDetachedMountOffersIgnoreAbsent (drained, detached: it is offered).

3. Root without --no-auto-unpack. The locator's root no longer comes from the audit decision: when the mount records pack paths and the audit has no root, drive9MountFileSystem resolves companionMountLocalRoot directly, which is the root the companion uses for any FUSE overlay-profile mount. TestMountRecordsRootWithoutAutoUnpack mounts --no-auto-unpack without --local-root, asserts the locator has a root, and asserts the unmount replays /src. I also dropped the "pass --pack-archive-path to pack explicitly" advice, which ran the same filter, and the unmount text output now renders the checks, so a skip is no longer invisible in --output text.

4. Absolute values with . or ... The mount check now runs the segment test on absolute values too and refuses only . and .. there; /, /a//b and /src/ still pass. mount_pack_paths_test.go pins mountPackArchivePath and mountPackOverlayPath with literal vectors (remote root /, a nested root, a trailing slash, a sibling that shares the prefix, an absolute value outside the root, a relative value) and pins the refused and accepted forms. The two helpers, the normalizer and mergeMountPackPaths moved to internal/fs/mount_pack_paths.go. The NFC difference remains: golang.org/x/text is not a dependency, so a non-ASCII name in another normalization form can still be skipped by the pre-detach check. I left that as a known limit instead of adding a dependency.

5. Live test. Added TestLiveFSMountPackPathPacksOverlay in e2e/live_test.go (b697a80): mount with --pack-path /cached on a seeded overlay directory and an explicit --local-root, unmount with --no-auto-pack plus --pack-archive-path, unpack the archive, assert the file is there. It is written but not run here — it needs FUSE and a provisioned File System, so it is for make live-e2e (TI_LIVE=1). Until it is dispatched, the central claim still only has fake-companion coverage on CI.

Nits: the blank-root test asserts the message; the dry-run --no-auto-pack + --pack-archive-path rule is pinned by TestDryRunKeepsReplayForAnExplicitArchive (both halves, so reverting the condition fails); README says --pack-archive-path adds an archive, states the restore is still the profile's decision, and no longer credits a sentence that is not there; AGENTS.md names normalizeMountPackPaths as the owner of trimming, de-duplication and the refusals; mountWithPackPaths lost its unused tweak parameter.

make test passes (47 packages), gofmt is clean, go mod tidy is a no-op, and the binary e2e suite passes against a make build binary. The branch is at f38ed17 with the code identical to the working tree I tested.

@mornyx mornyx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review summary

The five commits answer every item of the second review, and I could confirm the one claim the author could not: on this darwin/arm64 host make test passes at f38ed170 (47 packages), and the full e2e suite passes against a make build binary (47 tests; the live ones skip as designed).

Nothing blocking remains. One thing should be fixed before the new live test's first green run is read as confirmation: it mounts with the portable profile, whose own pack path / puts the whole overlay into every archive, so it passes with or without the replay.

Besides reading, I ran the tests on darwin/arm64, reverted the fix lines one at a time, re-ran the mapping comparison against the companion's functions at drive9 81bb0d92, and built archives with the companion's own pack function. I did not run a real mount.

Closed since the second review

  • macOS make test. The three call sites pass Driver: "fuse" (internal/fs/drive9_mount_audit_test.go:175, :318-319, :582). The three tests pass on darwin, and so does the rest of the suite.
  • fs.unmount_failed_after_drain. It is keyed on drain.Status == "drained", exits 1, and offers --ignore-absent only when mountListed says the mount is gone (internal/fs/drive9_companion.go:1385-1398, :1422-1428). Under --force with a failing umount I now get the companion's own fs.companion_failed.
  • The locator's root. It is resolved before the mount runs when the audit has none (internal/fs/drive9_mount_audit.go:66-73). A --no-auto-unpack mount without --local-root records the default root and its unmount replays /src. The dead-end advice is gone, and --output text prints the checks.
  • Absolute values with a . or .. segment. They are refused (internal/fs/mount_pack_paths.go:33-44). The 140-pair comparison no longer has a pair where ti replays a value the companion refuses, apart from the normalization difference the author named.
  • The rest. The two mapping functions have literal vectors (internal/fs/mount_pack_paths_test.go:14, :45), the blank-root test asserts its message, the dry-run rule is pinned (internal/fs/drive9_unmount_pack_paths_test.go:476), and the README, AGENTS.md, the release notes and the PR description match the code.

What looks good

  • Every fix line of these five commits that I reverted (12 of 14) fails a test, including the two branches the second review found unpinned.
  • Resolving the locator's root before the mount runs, with its own error, is the right shape: nothing is started when the root cannot be known.
  • The advice now depends on a fact (mountListed) instead of on which branch failed, and it errs toward withholding --ignore-absent.
  • Pack-path logic sits in one file with one normalizer, and mount.go got smaller.

Should fix (non-blocking, strong)

1. The new live test cannot fail for the reason it exists

TestLiveFSMountPackPathPacksOverlay (e2e/live_test.go:1561) mounts with --mount-profile portable (:1608) and checks the claim by reading the directory back after unpacking the explicit archive. The portable profile carries / as its own pack path (cmd/drive9/cli/profile.go:236), and the companion packs every archive with the mount's profile pack paths as well as the --pack-path values (cmd/drive9/cli/mount.go:2601-2616). So the whole overlay is in that archive whether or not ti replays anything.

I built the archive with the companion's own writePackArchive at 81bb0d92, over an overlay that holds cached/item.txt:

profile replayed --pack-path result
portable /cached archive holds cached/
portable none archive holds cached/
coding-agent /cached archive holds cached/
coding-agent none drive9 pack: path arguments are required unless the profile config has [pack] paths

The other two assertions hold without the fix as well: the mount result has carried pack_paths since before this PR, and no skipped status appears when no check is reported. A green run will show that the real companion accepts the flag combination and that the flow completes, not that the directory is in the archive because of the replay.

Fix: mount with coding-agent on e2e/live_test.go:1608 and pass the same profile to the unpack on e2e/live_test.go:1624. coding-agent has no profile pack paths (cmd/drive9/cli/profile.go:224), so the unmount fails without the replay and succeeds with it. Reword the comment at e2e/live_test.go:1613-1614 ("the archive holds exactly the paths replayed from the mount"), and add the test to the focused target: make live-e2e-fs enumerates test names (Makefile:73) and does not include it, while make live-e2e does (Makefile:64). The comment at e2e/live_test.go:1559 should name both.

Nits

  • The text output of checks. Nothing pins it: removing the loop in UnmountResult.Human() (internal/fs/mount.go:837-846) leaves every test green. One assertion on Human() in TestUnmountForwardsOnlyPathsStillInTheOverlay would do. The loop also prints the drain check that --ignore-absent can add, so that output now carries the same drain message twice: drain: <message> and drain: failed (<message>). Decide whether that check should print.
  • The advice in the detached branch (internal/fs/drive9_companion.go:1396) offers --no-auto-pack first. Once the companion's state is gone, that retry stops at the drain gate, because ti still drains a FUSE locator unless --force is passed and returns the drain error without --ignore-absent. One wasted attempt. Lead with the flag that completes.
  • README (README.md:218): "a relative value may not be empty". An empty or blank value is dropped, not refused (internal/fs/mount_pack_paths.go:89); only a value with an empty segment is refused. The PR description says the same.
  • The normalization limit is stated only in the PR description, and only in one direction. Say it at the Lstat (internal/fs/drive9_companion.go:1458): the companion normalizes to NFC and this check compares bytes, so a name in another form is skipped, or replayed and then not found after the detach. The mount-time refusal is also a subset of the companion's rule, which also refuses control characters and invalid UTF-8.
  • Same names, different rules. The comments say "the companion's joinArchivePath" and "drive9's resolvePackPath" (internal/fs/mount_pack_paths.go:17, :35), and this package has an older copy of both in internal/fs/pack.go (internal/fs/pack.go:1148, :1206) whose pack entry point has no caller (internal/fs/pack.go:350) and which has drifted: /a/../b is accepted there (internal/fs/pack.go:1194-1202) and refused here. Name the companion file in the comments and delete the old copy in a follow-up.
  • The replay rule is written twice, in inverse form: internal/fs/drive9_companion.go:1361 and internal/fs/mount.go:395. One predicate would keep them together. Optional.
  • TestMountRecordsRootWithoutAutoUnpack does not clear XDG_CACHE_HOME, which the neighbouring tests do (internal/fs/drive9_mount_audit_test.go:194, :225). On Linux with it set, the seeded overlay lands outside the temp home.
  • Fine to leave. Under --force on a mount whose companion state is gone, a recorded value that is still in the overlay is replayed, and the companion's read mount state for pack error comes back as fs.companion_failed. The error is honest and --no-auto-pack and --ignore-absent both complete.

Recommendation

Comment. The code closes the second review. What remains is the live test's choice of profile, which decides whether its first green run means anything.

The live test mounted with `portable`, whose own pack path `/` puts the
whole overlay into every archive, so it passed with or without the replay:
its first green run would have confirmed the flag combination, not the fix.
Mount with `coding-agent`, which carries no pack paths of its own, so the
unmount fails with "path arguments are required" unless ti replays the
recorded value. Pass the same profile to the unpack, correct the comment
that claimed the archive holds exactly the replayed paths, and register the
test in `make live-e2e-fs`, which enumerates test names.
Say the replay rule once (`replayPackPaths`), so the dry run predicts
exactly what execution does instead of keeping an inverse copy of it.

Lead the post-drain advice with the flag that completes: once the
companion state is gone, `--no-auto-pack` stops at the drain gate, so a
detached mount is offered `--ignore-absent` first, and a listed mount
keeps the record. Print the unmount checks in the text output without the
drain check, which already has its own line, and pin that output.

Comments: name the companion file the mappings mirror and the older
drifted copy in `pack.go`, state that the mount-time refusal is a subset of
the companion's rule, and record the NFC limit at the byte comparison.
README: a blank value is dropped, not refused. Clear `XDG_CACHE_HOME` in
the locator-root test, as the neighbouring tests do.
@srstack

srstack commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 1b0f0d7 and e4d00db. Thank you for confirming the darwin run — that was the one claim I could not check.

1. The live test now depends on the replay. It mounts and unpacks with coding-agent (e2e/live_test.go:1608, :1626), which carries no pack paths of its own, so the unmount fails with "path arguments are required" unless ti replays the recorded value — your table's third and fourth rows are now the two outcomes the test separates. I reworded the comment at :1613-1617 ("the archive holds exactly what was replayed, which is what makes the case fail without the fix") and registered TestLiveFSMountPackPathPacksOverlay in make live-e2e-fs (Makefile:73), with the test's doc comment naming both targets. Still not dispatched here; the first run has to be somebody's with FUSE and a provisioned File System.

Nits:

  • Text output pinned. TestUnmountForwardsOnlyPathsStillInTheOverlay now asserts pack_path: skipped appears in UnmountResult.Human() and that drain: drained does not, so removing the loop fails a test. I took the second option you offered for the duplicate: the drain check is skipped in that loop, because the drain: line above already carries the same message.
  • Detached advice leads with the flag that completes. The message is now built in two shapes (internal/fs/drive9_companion.go:1388-1400): a detached mount is offered --ignore-absent first with --no-auto-pack second, a listed mount is offered --no-auto-pack and told that --ignore-absent would orphan it. Both branches are asserted.
  • README. "a relative value may not contain an empty segment; a blank value is dropped" (README.md:218), and the PR description says the same.
  • Normalization limit is recorded at the Lstat (internal/fs/drive9_companion.go:1462-1465), one direction each way, and the mount-time refusal now says it is a subset of the companion's rule (control characters and invalid UTF-8 pass through ti).
  • Names and rules. internal/fs/mount_pack_paths.go names cmd/drive9/cli/pack.go (joinArchivePath, resolvePackPath, overlayPathForArchivePath) and cmd/drive9/cli/profile.go, and records that the older copy in pack.go has drifted and should be deleted. I did not delete it here: it is the follow-up you named, and removing an entry point with no caller is a separate change from this fix.
  • One predicate. replayPackPaths (internal/fs/mount.go:390-396) is now the single owner of "does this unmount pack", used by execution and --dry-run.
  • TestMountRecordsRootWithoutAutoUnpack clears XDG_CACHE_HOME like its neighbours.
  • The --force case with a gone companion state is unchanged, per "fine to leave".

make test passes (47 packages), gofmt is clean, go mod tidy is a no-op, and the binary e2e suite passes against a make build binary (47 tests, the live ones skipping). Your review decided the live profile question; nothing else in it changes the behaviour of the code path.

One request: a COMMENTED review leaves reviewDecision at CHANGES_REQUESTED, so GitHub still reports the PR as blocked for review. If nothing blocking remains, an approving review is what clears it — I am not merging anything.

@mornyx mornyx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review summary

Both commits do what the third review asked, and the only change to behaviour in them, the shared predicate and the two shapes of the advice, holds on every path I tried. make test passes on this darwin/arm64 host at 1b0f0d78 (47 packages), and the full e2e suite passes against a make build binary (47 tests; the live ones skip as designed).

Nothing remains that needs another commit on this PR.

Closed since the third review

  • The live test depends on the replay. It mounts and unpacks with coding-agent (e2e/live_test.go:1612, :1630). The unmount it runs sends --pack :<archive> --no-auto-pack --pack-path /cached, and with that profile the companion packs cached/ only because of the replayed path; without it the pack has no paths and fails. The test is listed in make live-e2e-fs (Makefile:73). It has still never been run. Its first run belongs to the live workflow, and that run is what confirms the archive claim against the real companion.
  • One predicate. replayPackPaths (internal/fs/mount.go:396-398) is used by execution (internal/fs/drive9_companion.go:1361) and by the dry run (internal/fs/mount.go:404), and it is the same rule as before for all four flag combinations. Reverting either call site, or the predicate, fails a test.
  • The advice has two shapes, and each is pinned: a mount that is still listed is offered --no-auto-pack and told why not to drop the record; a mount that is no longer listed is offered --ignore-absent first (internal/fs/drive9_companion.go:1398-1403).
  • The text output is pinned. Removing the loop in UnmountResult.Human() fails TestUnmountForwardsOnlyPathsStillInTheOverlay, and a tolerated drain failure now prints once.
  • The README wording, the normalization note at the Lstat, the companion file names in internal/fs/mount_pack_paths.go and XDG_CACHE_HOME in the root test are as asked.

What looks good

  • The predicate is a three-line function whose comment says why both callers must share it. That is the right size for it.
  • The live test's comment explains the choice of profile, so the next reader will not simplify it back to portable.

Optional, for a follow-up. Neither needs a new commit here.

  • The second assertion added in TestUnmountForwardsOnlyPathsStillInTheOverlay (internal/fs/drive9_unmount_pack_paths_test.go:216) cannot fail. A drain check is only ever appended with status failed (internal/fs/drive9_companion.go:1380, :1419), and in that test the drain succeeded. So the skip at internal/fs/mount.go:851-853 is still unpinned: removing it fails no test. A result with a tolerated drain failure would pin it.
  • README.md:218 says a mount that does not unpack is not audited. A coding-agent mount with --pack-path unpacks nothing, and ti still audits it, because unpackPossible counts the flag values (internal/fs/mount.go:763). The predicate predates this PR.

Recommendation

Approve. Nothing remains that needs another commit on this PR.

@srstack

srstack commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Took the two "Optional, for a follow-up" items here rather than deferring them (20cb2e2), and cleared the follow-up the third review named (eafdce5).

The drain-check skip is pinned. You were right that the assertion I added could not fail: a drain check is only ever appended with status failed, and that test drains successfully. It now sits in TestUnmountIgnoreAbsentAbsentPathStillReportsDrainFailure, which keeps a tolerated drain failure, so removing the skip in UnmountResult.Human() prints the same message twice and fails the test — I verified that by deleting the branch and watching it fail.

README. It no longer implies the audit follows the companion's decision: a mount that unpacks nothing at the companion is not audited, but the predicate counts the effective pack paths, so a coding-agent mount with --pack-path is audited even though that profile carries no unpack paths.

The old copy is gone. ti fs pack-file-system has delegated to the companion since the drive9 cutover, but internal/fs/pack.go still carried the legacy write path: the entry point with no caller, its source resolution, the archive writers, and the second copy of resolvePackPath/joinArchivePath that accepted /a/../b. 24 functions and the three types only they used are deleted; pack.go goes from 1736 to 1073 lines. I kept everything the live paths use — extractPackArchive and the overlay audit helpers the mount runs, loadPackProfileConfig, validatePackLocalRoot, defaultPackArchivePath, and the archive/overlay helpers the FUSE and Git paths call — and checked the removal changed no behaviour: make test (47 packages), gofmt and the binary e2e suite pass unchanged. With it deleted, the replica in mount_pack_paths.go is the only copy of the mapping to keep in step, and its comment says so.

Head is eafdce5, CI is green, and the decision is still APPROVED — this is cleanup on top of what you approved, not a change to the --pack-path behaviour. I am leaving the merge to you.

@mornyx mornyx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review summary

The deletion is safe. The 27 removed declarations were a closed component with no caller, nothing refers to them on any platform the release builds for, and make test and the full e2e suite pass on this darwin/arm64 host at eafdce57 (47 packages; 47 tests, the live ones skipped). The new assertion pins the skip of the drain check, and the README sentence is now true.

What should be fixed before merge is the record, not the code. The deletion commit's message describes extractPackArchive and the archive/overlay path helpers as "what the live paths use", and says the change "removes the last second copy of the companion's path mapping". Neither is true: 16 functions of internal/fs/pack.go (414 lines) are as unreachable as the 663 lines that went, and they include canonicalArchivePath, the function that accepts /a/../b. The comment the same commit added to internal/fs/mount_pack_paths.go says the same. This repository keeps branch commits and their messages, so this can only be corrected before merge.

This review covers the two commits pushed after the approval on 1b0f0d78. That approval did not cover them.

What was verified

  • Platforms. Build and go vet for darwin, linux and windows on amd64 and arm64, with CGO off: all clean. go vet compiles the test files too.
  • The removed names. No reference anywhere at the head, except comments that name the companion's own resolvePackPath and joinArchivePath.
  • What is still unreachable. A type-checked call graph over internal/fs at the head (roots: init, package initializers, and the exported functions and methods that other packages reference) reports 16 functions of internal/fs/pack.go unreachable, 414 lines. It reports the same for Service.mountForeground, Service.autoUnpackMount and Service.autoPackAfterUnmount (internal/fs/mount.go:604, :613, :310), for Service.RestoreGitWorkspace (internal/fs/git.go:503) and for the ti-native FUSE runtime behind them.
  • The drift. canonicalArchivePath("/a/../b") still returns /b with no error.
  • The assertion. Removing the skip at internal/fs/mount.go:851-853 now fails TestUnmountIgnoreAbsentAbsentPathStillReportsDrainFailure.

What looks good

  • The deleted set was exactly a closed component: four entry points with no caller, everything below them, and no test touching any of it. That made the check mechanical.
  • The new assertion sits where the behaviour shows, a tolerated drain failure, and it can fail in both directions.
  • The README now states the predicate the code applies instead of the intent behind it.

Should fix (non-blocking, strong)

1. The deletion commit's message, and the comment it added, describe dead code as live

Commit eafdce57 says it kept "extractPackArchive and the overlay audit helpers the mount runs … and the archive/overlay path helpers the FUSE and Git paths call", and that it "removes the last second copy of the companion's path mapping, so the replica in mount_pack_paths.go is the only one to update".

  • extractPackArchive (internal/fs/pack.go:312) has one caller, Service.autoUnpackMount, which has none.
  • The path helpers canonicalArchivePath (internal/fs/pack.go:569), overlayPathForArchivePath (:592), toRemotePath (:1037) and remoteToLocalPath (:1052) are reached only from the ti-native FUSE runtime and from the RestoreGitWorkspace subtree. Their entries, Service.mountForeground and Service.RestoreGitWorkspace, have no caller.
  • The audit helpers, loadPackProfileConfig, validatePackLocalRoot and defaultPackArchivePath are live, as the message says.
  • The comment at internal/fs/mount_pack_paths.go:15-17 now reads "This package keeps no second copy of those mappings: the legacy one that did drifted (it accepted /a/../b) and is gone". The function that accepted /a/../b is canonicalArchivePath, and it is still in the package.
  • The reply on the PR thread repeats both claims: "I kept everything the live paths use", and "the replica in mount_pack_paths.go is the only copy of the mapping to keep in step".

None of this is a regression. Everything listed was equally unreachable at the base, and the 663 lines removed are a strict improvement. What the increment adds is the claim that the rest is live.

Either way of fixing it is fine:

  • Finish the deletion. Remove the unreachable read half of internal/fs/pack.go: extractPackArchive, extractPackEntry, installStagedPack, moveStagedPath, mergeStagedPath, removeManifestPaths, packEntryRel, safeOverlayTarget, ensureNoSymlinkPath, manifestReplacePaths, manifestPathRel, supportedPackFormat, canonicalArchivePath, overlayPathForArchivePath, toRemotePath and remoteToLocalPath, with the types and constants only they use. Their three callers in internal/fs/mount.go go with them, and so do the pack_test.go cases that only exercise them (internal/fs/pack_test.go:24, :40, :44). Keep validatePackSymlinkTarget, which the live audit calls. The comment is then true as written, and the commit message can be amended to say so. The FUSE runtime and the Git subtree can stay for a follow-up.
  • Or leave the code and correct the words. Take extractPackArchive and the path helpers out of the "live paths" sentence, say that the read half and its caller-less entry points are left for a follow-up, and reword the comment to name overlayPathForArchivePath in internal/fs/pack.go as the one other copy.

In both cases, add a line to the PR description saying that it also deletes the legacy pack write path in internal/fs/pack.go. The description is what the merge commit links to.

Nits

  • AGENTS.md:1299-1300 still says "a mount that does not unpack is not audited". The README sentence (README.md:218) was corrected and this twin was not, which invites "fixing" the predicate to match it.
  • internal/fs/drive9_unmount_pack_paths_test.go:216-218: the drain: drained assertion, which the latest commit's message calls unable to fail, is still there under a comment that calls it a pin. Delete it. The new assertion covers the skip.

Recommendation

Comment. The deletion is safe and cannot change behaviour. The message that will stay in history, and the comment in the source, call 414 lines of the same dead implementation live; correct them before merge, with the rest of the removal as a follow-up.

The `drain: drained` assertion added earlier could not fail: a `drain`
check is only ever appended with status `failed`, and that test drains
successfully. It is deleted. The skip is pinned instead where it is
observable: `TestUnmountIgnoreAbsentAbsentPathStillReportsDrainFailure`
keeps a tolerated drain failure, so removing the skip in
`UnmountResult.Human()` prints the same message twice and fails the test.

README and AGENTS.md said a mount that does not unpack is not audited,
which is not the predicate the code applies: `unpackPossible` counts the
effective pack paths, so a `coding-agent` mount with `--pack-path` is
audited although that profile carries no unpack paths. Both now say that,
so neither invites "fixing" the predicate to match the old sentence.
`ti fs pack-file-system` has delegated to the companion since the drive9
cutover, but `internal/fs/pack.go` still carried the old write path: an
entry point with no caller, its source resolution, the archive writers, and
a second copy of `resolvePackPath`/`joinArchivePath` that had drifted to
accept `/a/../b`. 24 functions and the three types only they used are gone;
`pack.go` drops from 1736 to 1073 lines. No behaviour changes: `make test`
(47 packages), `gofmt` and the binary e2e suite pass unchanged.

What is deliberately left, and why: `internal/fs/pack.go` still holds the
legacy *read* half. `overlayPathForArchivePath`, `toRemotePath` and
`remoteToLocalPath` are compiled into the ti-native FUSE runtime
(`internal/fs/fuse_mount.go: //go:build !windows`), and the rest --
`extractPackArchive` and its helpers, `canonicalArchivePath` included, the
function that still accepts `/a/../b` -- is reachable only from
`Service.mountForeground`, `Service.autoUnpackMount` and
`Service.autoPackAfterUnmount`, which have no caller. That half goes with
the FUSE runtime and the `RestoreGitWorkspace` subtree in a follow-up; this
commit does not make those paths live, it only removes the ones nothing
compiled reaches. The comment in `mount_pack_paths.go` says so, instead of
calling the remaining copy gone.
@srstack
srstack force-pushed the fix/fs-mount-pack-path-replay branch from eafdce5 to d9b6392 Compare November 26, 2026 17:44
@srstack

srstack commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

You are right about the record, and I rewrote it rather than leaving it. Both commits that landed after your approval are now b032601 and d9b6392 (force-pushed with --force-with-lease over eafdce5; the tree is identical to what you reviewed, only the messages and two comments changed).

The message describes what the deletion actually did. It no longer claims extractPackArchive or the path helpers are live. It now says: the legacy write path is gone; the legacy read half stays, overlayPathForArchivePath, toRemotePath and remoteToLocalPath because the ti-native FUSE runtime compiles them in, and the rest — extractPackArchive and its helpers, canonicalArchivePath included — because the only callers are Service.mountForeground, Service.autoUnpackMount and Service.autoPackAfterUnmount, which nothing calls. It says the removal belongs with the FUSE runtime and the RestoreGitWorkspace subtree in a follow-up. I did not take the "finish the deletion" option: overlayPathForArchivePath and the two path helpers are genuinely compiled in at this head, so removing them means removing the FUSE runtime and the Git subtree in the same commit, which is the follow-up you named.

The source comment says the same. internal/fs/mount_pack_paths.go no longer claims the second copy is gone. It names overlayPathForArchivePath in pack.go as the other copy, records that canonicalArchivePath still accepts /a/../b, and says that half goes with the FUSE runtime, so nothing in the file may be "fixed" to match it.

PR description. It now has a line for the deletion, including what was left and why, since that is what the merge commit links to.

Nits:

  • AGENTS.md carried the twin of the README sentence. It now states the predicate the code applies — the effective pack paths, not the companion's unpack decision — so a coding-agent mount with --pack-path is audited. Both files say the same thing, which is what stops someone "fixing" the predicate.
  • The drain: drained assertion and the comment calling it a pin are deleted from TestUnmountForwardsOnlyPathsStillInTheOverlay; b032601 says so, and the skip stays pinned by TestUnmountIgnoreAbsentAbsentPathStillReportsDrainFailure.

make test (47 packages), gofmt, go mod tidy and the binary e2e suite pass at d9b6392, which is the tree you reviewed. No behaviour changed after your approval; the remaining dead read half and the FUSE/Git subtree are the follow-up.

@mornyx mornyx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review summary

The rewrite does what the fifth review asked. The two commit messages, the comment at the top of internal/fs/mount_pack_paths.go and the PR description now describe the deletion as it is: the legacy write path is gone, the read half stays, canonicalArchivePath still accepts /a/../b, and that half belongs with the FUSE runtime in a follow-up. The AGENTS.md sentence now matches the README and the code, and the assertion that could not fail is gone.

The tree differs from eafdce57 in three files (AGENTS.md, the test file, internal/fs/mount_pack_paths.go), and the only change inside a function is the three deleted lines of that assertion. Build and go vet are clean for darwin, linux and windows on amd64 and arm64; make test (47 packages) and the full e2e suite (47 tests, the live ones skipped) pass on this darwin/arm64 host at d9b63926.

Nothing remains that needs another commit on this PR.

Closed since the fifth review

  • The record. Commit d9b6392 no longer calls extractPackArchive or the path helpers live. Its "What is deliberately left, and why" paragraph, and the "Dead code" bullet of the PR description, match what a type-checked call graph shows at the head: 16 functions of internal/fs/pack.go (414 lines) are unreachable, overlayPathForArchivePath, toRemotePath and remoteToLocalPath are compiled into the ti-native FUSE runtime, and no ti command reaches any of that half. The comment at internal/fs/mount_pack_paths.go:15-23 no longer calls the second copy gone, and names canonicalArchivePath as the function that still accepts /a/../b.
  • AGENTS.md:1299-1303 now states the predicate the code applies, as README.md:218 does.
  • The assertion. The drain: drained assertion is deleted. The skip in UnmountResult.Human() is still pinned: removing it fails TestUnmountIgnoreAbsentAbsentPathStillReportsDrainFailure, and removing the whole loop still fails TestUnmountForwardsOnlyPathsStillInTheOverlay.

What looks good

  • The commit was rewritten while it still could be, instead of leaving a correction in a later message.
  • The new comment says what is left and why, and tells the next reader not to "fix" the replica to match the drifted copy.

Recommendation

Approve. This covers d9b63926, including the deletion of the legacy pack write path. Nothing remains that needs another commit on this PR.

@srstack
srstack merged commit 6b555db into main Nov 26, 2026
2 checks passed
@srstack
srstack deleted the fix/fs-mount-pack-path-replay branch November 26, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants