Skip to content

feat(fs): --overwrite replaces a server-side copy; reject scheme-spelled local paths - #100

Merged
srstack merged 9 commits into
mainfrom
fix/fs-copy-overwrite-followups
Nov 25, 2026
Merged

srstack merged 9 commits into
mainfrom
fix/fs-copy-overwrite-followups

Conversation

@srstack

@srstack srstack commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What

The three follow-ups left out of #99, in one PR.

1. --overwrite replaces a server-side copy

A remote to remote copy cannot replace anything at the service: POST <path>?copy inserts a new node, the unique path index rejects the duplicate, and that surfaces as 500 {"error":"backend unavailable"}. #99 therefore refused the shape. ti fs copy-file --overwrite should mean what it says, so ti now performs the replacement itself:

  1. resolve the destination exactly as the probe does (an existing directory, a trailing separator or the root receives dir/<base(source)>; a symlink only on a local destination, because the service treats a remote link as a file whose payload is the target path),
  2. copy the source to a sibling <destination>.ti-tmp-<8 hex> path,
  3. move the staging path onto the destination with fs mv.

The service's rename replaces the target in one datastore transaction (RenameFileReplacingTarget), so a reader sees either the old file or the complete new one, and a failed copy never touches the destination. The probe and the replace share one destination resolver, so they cannot disagree about the path a copy writes.

Failure handling, all of it user-visible:

  • the cleanup asks the service whether the staging file exists (fs stat, retried) instead of inferring it from one fs rm answer, because the service authorizes DELETE before it looks the path up: a token without delete answers "access denied" for a file that was never created,
  • a failed staged copy removes the staging file when it exists; the copy error remains the one reported unless that cleanup was refused, in which case fs.copy_staging_left_behind carries the copy error as its cause,
  • a failed move whose cleanup worked reports the move error alone,
  • a failed move whose cleanup was refused reports fs.copy_staging_left_behind, naming the staging path and the ti fs delete-file --path that removes it (that command needs delete on the path, which is exactly what was refused),
  • a failed move whose staging file is already gone means the rename was probably applied before its answer was lost, so fs.copy_outcome_unknown names both paths, points at ti fs describe-file for each and says re-running with --overwrite is safe,
  • the cleanup registers its own SIGINT/SIGTERM channel, so the signal that failed the copy does not abandon the cleanup; only a signal delivered after the cleanup started stops it,
  • when ti can neither read nor delete the staging sibling (or the look fails on a backend error, the 30s bound expires, or a second signal arrives) it reports fs.copy_staging_unchecked and says which .ti-tmp- entry to look for, instead of claiming the file exists,
  • the cleanup runs on a context that survives cancellation and with a 30s bound, so an interrupted replace still cleans up,
  • the staging cleanup runs captured, so a copy that failed before creating anything does not print an extra fs rm: not found line,
  • --overwrite on a shape that resolves to the source is refused before any write,
  • a destination that is itself a directory is refused with fs.remote_copy_target_is_directory.

Uploads and downloads keep their single native write: with --overwrite ti skips its own probe and the companion's plain write replaces the destination (no flag is forwarded; the companion's drive9 fs cp has only -f|--force, honored for object-store URIs).

2. Scheme-spelled and drive9-spelled local paths are refused

The companion resolves a location scheme itself and reads a : prefix as a drive9 path, while ti probes a local destination as a literal filesystem path. --to-local file:///path (or --to-local :/path) therefore passed the probe and still wrote somewhere else. --from-local/--to-local now reject both spellings with fs.local_path_scheme_unsupported: every scheme the companion knows (s3:// included), and a leading :. A single-letter scheme is a Windows drive letter and an opaque URL (a:b) is a legal file name, so neither is caught by mistake.

3. Docs match the code

The --overwrite help and the README paragraph describe what each direction does, the staging move, the real permission requirement (read on source and destination, and read, write and delete in the destination's directory), the listing visibility and .ti-tmp- suffix, the unknown-outcome case, the two new refusals and the symlink scoping.

In-repo follow-ups are done in this PR (10847d6): the copy family has its own file, and the post-cancel signal registration is one interrupt.NotifyStop helper used by the cleanup and both mount paths. TestNotifyStopStartsEmpty pins that a fresh registration does not replay an earlier signal; the property the cleanup needs — the signal that cancelled the copy does not abandon it — is pinned by TestDrive9CopyFailureCleansUpAfterTheSignalThatFailedTheCopy in internal/fs.

isDrive9NotFound no longer reads a transport-level HTTP <code>: <body> page as the API's not-found answer. That is wider than the cleanup: the destination probe of a copy without --overwrite now fails closed instead of letting a transport page stand in for "absent" (so it can no longer overwrite a destination that is there), the cleanup's removal is attempted instead of skipped, and two vault flows change in the same conservative direction — ti fs-vault delete-secret/delete-grant report an error instead of "status": "deleted" when the retry after a transient failure lands on a transport page, and ti fs-vault replace-secret stops at a failed vault rm.

Follow-up (different repo): docs/pingcap-docs/docs is a submodule pinned at a8e00c35 of pingcap/docs; ai/ti/reference/commands/fs/ti-fs-copy-file.md still says --overwrite: "Replace an existing destination file." It needs the direction-specific text, the staged rename, fs.remote_copy_target_is_directory, fs.copy_staging_left_behind with its delete-file remedy, fs.copy_outcome_unknown with its describe-file advice, fs.copy_staging_unchecked with its "look for a .ti-tmp- entry" wording, and fs.local_path_scheme_unsupported. A pointer bump needs a commit in pingcap/docs first, so it is its own change.

Tests

go build ./..., go vet ./..., go test ./... -count=1 pass.

  • TestDrive9CopyServerSideOverwriteStagesAndMoves: existing file destination and existing inner path under a directory destination → cp <source> <target>.ti-tmp-* then mv <staged> <target>, result reports the destination the caller named.
  • TestDrive9CopyServerSideOverwriteWithoutExistingTargetCopiesOnce: no staging when nothing is there.
  • TestDrive9CopyServerSideOverwriteRejectsDirectoryTarget: fs.remote_copy_target_is_directory, no write.
  • TestDrive9CopyServerSideOverwriteRefusesSelfCopy: both spellings of a collision, no write.
  • TestDrive9CopyServerSideOverwriteCleansUpAfterFailedMove: staging removed, the move error surfaces.
  • TestDrive9CopyServerSideOverwriteNamesTheStagingPathWhenCleanupFails: fs.copy_staging_left_behind names the path, the delete-file command and its delete requirement.
  • TestDrive9CopyServerSideOverwriteAppliedMoveLostAnswer: the fake applies the rename and then fails, so the staging file is gone → fs.copy_outcome_unknown naming both paths and never a delete.
  • TestDrive9CopyServerSideOverwriteCleansUpAfterFailedStagedCopy: after a failed staged copy there is no mv, the staging file is gone from the fake's path set, and only the destination remains; ...NamesStagingAfterFailedStagedCopy pins the refused-cleanup message.
  • TestDrive9CopyServerSideOverwriteReportsUncheckedStaging: a token that can read the destination and not the staging sibling, with a refused removal → fs.copy_staging_unchecked, saying ti could not determine whether the file exists.
  • TestDrive9CopyFailureCleansUpOnCancelledContext: a cancelled copy still stats and removes the staging file, and the original error comes back.
  • TestDrive9CopyFailureCleansUpAfterTheSignalThatFailedTheCopy (!windows, because it sends itself SIGINT with syscall.Kill): the signal that cancelled the copy does not stop the cleanup; replacing the fresh registration with interrupt.Signals(checkCtx) fails it. Only the test is unix-only — the production code compiles and behaves the same on Windows, where signal.Notify also delivers Ctrl+C.
  • TestDrive9CopyFailureReportsExpiredCleanupBound: a hanging staging stat past the (shortened) bound reports fs.copy_staging_unchecked with the timeout, not a refused removal.
  • TestDrive9CopyFailureRefusedStatWithGoneStaging: a refused stat whose removal answers "not found" reads as absent — the copy error before the move, fs.copy_outcome_unknown after it.
  • TestDrive9CopyFailureRemovalAnswersNotFoundAfterTheLook: the staging file is there for the look and gone for the removal — the copy error before the move, fs.copy_outcome_unknown after it.
  • TestDrive9CopyFailureSecondSignalStopsTheCleanup: a signal that arrives while the cleanup is running stops it and reports that the staging path was not checked.
  • TestNotifyStopStartsEmpty: a fresh interrupt.NotifyStop registration does not replay a signal delivered before it.
  • TestIsDrive9NotFoundIgnoresTransportStatusBodies: HTTP <code>: <body> from whatever answered the request is not the API's not-found answer.
  • TestDrive9CopyServerSideOverwriteNoLeftoverWhenNothingWasCreated: a token without delete and a staged copy that created nothing must report the copy error alone.
  • TestDrive9CopyUploadAndDownloadOverwriteStaySingleCall: one cp, no mv.
  • TestDrive9CopyRejectsSchemeSpelledLocalPaths: file://, file:, and : spellings.
  • TestDrive9CopyArgsForTargetRejectsNonRemoteRoutes: the retarget guard.
  • TestDrive9CopyUploadRejectionStillOffersOverwrite now also covers an upload whose local absolute path spells the remote destination (it must keep the flag advice, not claim "is the source path").

Live e2e: the remote-pair refusal is asserted, then an existing remote path is copied onto both without and with --overwrite (exit 2 with the advice, then exit 0 with the source bytes), and rootPath is listed afterwards to prove no .ti-tmp- entry survives.

I also replayed the live copy steps against the built binary with a stand-in companion (all three directions, fs mkdir/fs cat/fs mv, the service's duplicate-path rejection): 24/24 checks pass, including the staged .ti-tmp-* copy, the move onto the destination, the replaced bytes, no staging leftover, the scheme refusal, and the upload/drive9 spelling separation.

…eme-spelled local paths

Follow-ups from #99, all in one change.

--overwrite for a remote to remote copy. The service inserts a new node at
the destination and the unique path index rejects a duplicate, so asking it
to copy onto an existing path returns 500 backend unavailable. ti now copies
the source to a sibling <target>.ti-tmp-<rand> path and moves it onto the
destination: the rename replaces the target in one datastore transaction, a
failed copy leaves the destination untouched, and a failed move removes the
staging path on a best-effort basis. The probe still refuses without the
flag, and a resolved destination that is itself a directory is refused with
fs.remote_copy_target_is_directory. Uploads and downloads keep their single
native overwrite call.

The directory rule now lives in one resolver shared by the probe and the
replace, so the two cannot disagree about the path a copy writes.

Scheme-spelled local paths. The companion resolves file:///path itself, while
ti probes local destinations as literal paths, so --to-local file:///path
passed the probe and still overwrote the parsed file. --from-local and
--to-local now reject a location scheme with fs.local_path_scheme_unsupported
(a single-letter scheme is a Windows drive letter and is left alone).

Also: --overwrite help and README say what each direction does, and the live
step copies onto an existing remote path both with and without the flag.
@srstack
srstack requested a review from mornyx November 24, 2026 16:17
@ti-chi-bot ti-chi-bot Bot added the size/XL label Nov 24, 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

This change makes --overwrite replace an existing remote destination for a server-side copy (copy to a sibling <destination>.ti-tmp-<8 hex>, then fs mv onto the destination) and refuses scheme-spelled local paths on --from-local/--to-local. The mechanism is sound against the pinned service: its copy cannot replace (the duplicate is 500 backend unavailable), and the rename is one transaction (RenameFileReplacingTarget), so a reader sees either the old file or the complete new one; uploads and downloads keep their single native call. The probe and the replace now share one destination resolver, and a base-vs-head transcript of 56 copy shapes shows no change for any non---overwrite case. Under a strict maintainability bar nothing here is merge-blocking, but five things should be fixed before merge: the refusal users meet without the flag now contradicts the feature, a failed replace can leave the staging file behind silently while the README states the wrong permission, a README clause this PR rewrites promises remote symlink resolution the service does not have, the published reference page still has the old text, and the new tests pin the call sequence rather than the outcome.

What looks good

  • One destination resolver (resolveDrive9RemoteCopyDestination) feeds both the probe and the replace, so they cannot disagree about the path a copy writes.
  • Copy to a private sibling plus the service's one atomic rename, instead of delete-then-copy: a failed copy never touches the destination, and a failed move removes the staging path when the token allows it.
  • The scheme check is conservative in the right direction: drive letters, opaque a:b, UNC paths, whitespace and colons in later segments are left alone, and the file:///path probe bypass from #99 is closed with an actionable message.
  • The new tests live in a dedicated file with descriptive names.

Should fix (non-blocking, strong)

1. The refusal still says a server-side copy cannot replace
internal/fs/drive9_companion.go:784 (comment at :766-771)
Without the flag the message is … already exists; a server-side copy does not replace an existing path, so copy to a new path or delete it first, and the comment still says --overwrite "would only turn a clear refusal into a server error". Both are false after this change, and "delete it first" is the non-atomic path the staged rename was added to avoid. The sentence is pinned in four places: internal/fs/drive9_copy_target_probe_test.go:51-55 (the test fails if the message offers --overwrite), :131, e2e/live_test.go:1340, and the assertion this PR adds at :1358.
Fix: give this direction the same advice as uploads and downloads (… already exists; pass --overwrite to replace it), keep the "is the source path" sentence, and update the comment and the four assertions.

2. A failed replace can leave the staging file behind without saying so, and the README names the wrong permission
internal/fs/drive9_companion.go:511 (and :507-513), README.md:192
On the pinned service the rename needs delete on its source, the staging sibling, and write on the destination (pkg/server/server.go:4171); rm needs delete as well (:3996); a scope matches a path exactly or by prefix/ (fs_authorization.go:156-164). Two consequences the text does not describe:

  • "the file-system token needs delete on the destination as well as write" names the wrong path. A grant scoped to the destination file itself (…:read,write,delete) is refused at the staged copy, because the sibling lies outside it. The requirement is read on the source and on the destination, and write and delete in the destination's directory.
  • With read and write but no delete on the directory (the scoped-token example in AGENTS.md is exactly that shape), the staged copy succeeds, the move is refused, the cleanup rm is refused too and its error is discarded. One <destination>.ti-tmp-<8 hex> stays per attempt, the user sees only the move's error, and nothing names the file. "a failed move removes the temporary path" is false for that key.

The same silent leftover arises when the staged copy itself fails after the service created the node: an ambiguous failure, then the transient retry meets the duplicate (500 backend unavailable), and no cleanup runs because it only follows a failed move. The PR description says two limits are "documented rather than papered over"; that holds for the description only, since the README has neither the listing note nor the staging name.
Fix: reword the two README sentences to state the real requirement and that the staging file stays without delete; when the cleanup fails, return an error that names the staging path and the ti fs delete-file --path … that removes it; document the .ti-tmp- suffix so a leftover can be found.

3. The README promises remote symlink resolution the service does not have
README.md:192
"a directory destination (an existing directory, a trailing separator, the root, or a symlink resolving to a directory) receives dir/<base(source)>" is true for local destinations only. The pinned service has no symlink resolution: a remote symlink is a node whose payload is the target path, and HEAD reports the link itself as a non-directory (pkg/server/server.go:3908). So ti's probe and the companion both treat --to-remote /lt as a file path, and with --overwrite an upload overwrites the link's own payload (checked for a small file): the link is lost and nothing lands in the directory. The clause predates this PR, but this PR rewrites the sentence and presents the paragraph as the copy contract.
Fix: restrict "or a symlink resolving to a directory" to --to-local, and say that a remote symlink destination is the link itself. If the documented behavior is wanted, that is a separate change (resolve the link before the copy).

4. The published reference page still documents the old --overwrite
docs/pingcap-docs/docs/ai/ti/reference/commands/fs/ti-fs-copy-file.md:52 (submodule a8e00c35)
It says "--overwrite: Replace an existing destination file." — the sentence this PR replaces in the flag help — and has neither the staged rename nor the two new refusals. AGENTS.md requires the matching ti page to follow published behavior, and "docs match the code" is one of the three goals in the description.
Fix: update the page and bump the submodule in this change, or name it as a follow-up in the PR description.

5. The new tests pin the call sequence, not the outcome
internal/fs/drive9_copy_overwrite_test.go:143
TI_FAKE_DRIVE9_MV_FAIL covers only "move fails, rm succeeds". Not covered: a cleanup that fails (the error the user actually sees, and whether the staging path is named), a staged copy that fails (no mv, no rm), and the message text of the two new codes. The live step is the only place the real service is exercised and does not check that no staging entry remains; the description reports that from a replay outside the suite.
Fix: add fake-companion switches for a failing rm and a failing staged cp and assert on them; in the live step, list rootPath after the overwrite and assert that no entry contains .ti-tmp-.

Nits

  • Self-copy with --overwrite reports success (internal/fs/drive9_companion.go:489). --from-remote /a --to-remote /a --overwrite, directly or through a directory destination, now stages a copy of the file and renames it onto itself, then reports copied. Nothing is lost, but it reads as a refresh while the same shape without the flag is refused as "is the source path". Reuse sameDrive9RemotePath(source, destination.Path) and refuse.
  • The :-prefixed spelling still bypasses the local probe (internal/fs/drive9_companion.go:603). --to-local :/x passes (url.Parse fails on the leading colon), skips the local probe, and reaches the companion as a drive9 path, so the "download" becomes a server-side copy into /x (it cannot overwrite anything, and main behaves the same). The comment at :573-578 says such spellings are rejected instead; reject a leading : too. Also worth one clause in the README or the commit: the check now refuses every registered scheme, object-store URIs (s3://, gs://, …) included, which were passed through before.
  • Unreachable guard (internal/fs/drive9_companion.go:1935-1939). drive9CopyArgsForTarget's "a retargeted copy must be a remote to remote copy" cannot fire, since its only caller runs after isDrive9ServerSideReplace, and it has no test; drop it or test it. If the staged argv is ever built at the call site instead, keep the --tag/--description pass-through: the staged copy carries them today and the companion refuses them for a server-side copy, so dropping them silently would make the same command succeed with an existing destination and fail without one. (Follow-up, not for this PR: the copy family is about 500 lines inside a 2,194-line file and would be easier to maintain in its own file.)
  • Live assertion attribution (e2e/live_test.go:1365). The mismatch is found on overwriteRead.stdout but reported through overwriteCopy.fail(...), so the diagnostic prints the copy's successful output; use overwriteRead.fail(...) with got and want.

Recommendation

Comment. No merge-blocking defect was found; the five items above should be fixed before merge.

- Without the flag, a server-side copy now gets the same advice as every
  other direction (pass --overwrite to replace it), because this change
  makes that advice true; the 'delete it first' advice and the comment that
  said --overwrite could only turn the refusal into a server error are gone.
  The four assertions that pinned the old sentence are updated.
- A replace that cannot clean up its staging file no longer fails silently:
  the error names the staging path and the ti fs delete-file command that
  removes it, and a failed staged copy runs the same cleanup instead of
  leaving the node behind. README states the real permission requirement
  (read on source and destination, write and delete in the destination's
  directory), that the staging sibling is visible in a listing, and how to
  find a leftover by its .ti-tmp- suffix.
- README no longer promises remote symlink resolution: only a local
  destination resolves a directory symlink, and a remote link destination is
  the link itself. The scheme paragraph now names the drive9 ':' spelling
  and says every scheme the companion knows is refused.
- --overwrite on a shape that resolves to the source is refused instead of
  staging a copy of a file onto itself.
- New tests cover a failing cleanup (message names the staging path and the
  command), a failing staged copy (cleanup runs, no move, the copy error is
  what surfaces), the self-copy refusal on both spellings, the retarget
  guard, and the ':' spelling.
- The live step lists rootPath after the replace to prove no .ti-tmp- entry
  survives, and reports a byte mismatch through the read command.
@srstack

srstack commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

All five items and the nits are addressed in 3c59d58 (signed, Verified). No production behaviour changed beyond the wording and the two guards the review asked for.

1. The refusal now offers the flag. remoteTargetExistsError gives every remote direction the same advice — already exists; pass --overwrite to replace it — and keeps the "is the source path" sentence for the collision. The comment that claimed --overwrite could only produce a server error is rewritten. All four assertions you listed are updated (internal/fs/drive9_copy_target_probe_test.go:51, :131, e2e/live_test.go:1340, :1358), and the live replay script now expects that sentence too.

2. The staging leftover is no longer silent, and the README states the real requirement. A failed cleanup returns fs.copy_staging_left_behind naming the path and the remedy, e.g.:

replace "/dst.txt" failed (fs mv: backend unavailable: exit status 1) and the staging copy
"/dst.txt.ti-tmp-316e330b" could not be removed (fs rm: permission denied: exit status 1);
delete it with `ti fs delete-file --path /dst.txt.ti-tmp-316e330b`

A failed staged copy now runs the same cleanup instead of skipping it, and keeps the copy error as the one the caller sees. The README says: read on source and destination, write and delete in the destination's directory (a rename deletes its staging source), that a grant scoped to the destination file alone is refused at the staged copy, that the sibling is briefly visible in a listing, and that a leftover is found by its .ti-tmp- suffix.

3. Remote symlinks. The clause is now scoped: only a local destination resolves a directory symlink; a remote destination has none, because the service treats a link as a file whose payload is the target path, so a remote link destination is the link itself.

4. The published page is named as a follow-up below rather than bumped here: docs/pingcap-docs/docs is a submodule pinned to a8e00c35 of pingcap/docs, and a pointer bump would need a commit in that repository first. The exact edit is small and I have it ready if you want it in a separate PR.

5. Tests pin outcomes, not just the call sequence. New cases: TestDrive9CopyServerSideOverwriteNamesTheStagingPathWhenCleanupFails (failing mv + failing rm → code, staging path, delete-file command), TestDrive9CopyServerSideOverwriteCleansUpAfterFailedStagedCopy (no move, cleanup attempted, the copy error surfaces), TestDrive9CopyServerSideOverwriteRefusesSelfCopy (both spellings, no write), TestDrive9CopyArgsForTargetRejectsNonRemoteRoutes (the guard), plus : spelling in the scheme table. The live step now lists rootPath after the replace and fails if any entry contains .ti-tmp-.

Nits. Self-copy with --overwrite is refused through the same sameDrive9RemotePath check. --to-local :/x is rejected with fs.local_path_scheme_unsupported ("is a drive9 path; pass a local filesystem path"), and the comment says so; the README also notes that every scheme the companion knows (s3:// included) is refused now. The retarget guard has the test you asked for, and the staged argv still carries --tag/--description. The live byte mismatch is reported through overwriteRead.fail with got and want.

Follow-up (docs). docs/ai/ti/reference/commands/fs/ti-fs-copy-file.md (--overwrite: "Replace an existing destination file.") needs: the new direction-specific text, the staged rename, fs.remote_copy_target_is_directory, fs.copy_staging_left_behind with its delete-file remedy, and fs.local_path_scheme_unsupported. I can send that as a pingcap/docs PR and then bump the pin.

Local: go build ./..., go vet ./..., go test ./... -count=1 clean. The live replay (built binary + stand-in companion) is 24/24, including the replaced bytes and "no staging path left".

@ti-chi-bot ti-chi-bot Bot added size/XXL and removed size/XL labels Nov 24, 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 second commit points the --overwrite=false refusal at the flag for every direction, reports a staging file it could not remove, cleans up after a failed staged copy, refuses a self-replace, rejects :-prefixed local values, and rewrites the README paragraph. On this head the earlier items are resolved, with one partial point left (a leftover after a failed staged copy is still unnamed) and the published page kept as the agreed follow-up. No merge-blocking defect was found, and the replace itself is unchanged and still correct against the pinned service. The rewrite of two helpers introduced two should-fix inaccuracies, each reproduced with a built binary: one refusal now gives false advice for an upload shape, and the staging cleanup misreports on three paths.

Resolved since the last review

  • The refusal offers --overwrite in every direction and keeps the "is the source path" sentence; the four assertions follow.
  • A failed move whose cleanup fails now returns fs.copy_staging_left_behind with the staging path and the removal command, and the README states the real permission requirement, the listing visibility and the .ti-tmp- suffix.
  • The symlink clause is scoped to local destinations.
  • --overwrite on a shape that resolves to the source is refused before any write: the same path, a directory destination with or without a trailing separator, the root and .. spellings all hold.
  • :-prefixed local values are rejected exactly where the companion reads them as drive9 paths, with the same code and exit code as the scheme case.
  • The retarget guard has a test and the --tag/--description pass-through is kept; the live step lists the directory after the replace and reports through the read command.

What looks good

  • fs.copy_staging_left_behind is the right shape for this failure: it keeps the move error as the cause and tells the user which file to remove.
  • The new tests assert on the message, not only on the argv, for the cleanup failure and the self-copy refusal.
  • The fix commit is small and stays inside the copy family.

Should fix (non-blocking, strong)

1. An upload whose local absolute path equals the remote path is refused as "is the source path"
internal/fs/drive9_companion.go:802
remoteTargetExistsError no longer branches on the source kind, so the same-path check compares the raw --from-local string with the remote path. ti fs copy-file --from-local /data/x.csv --to-remote /data/x.csv without --overwrite (remote file present) now answers remote target "/data/x.csv" is the source path; copy to a different path instead. On main and on the previous head it answered … already exists; pass --overwrite to replace it. The local file is not a remote source path, the sentence is false, and the advice that would have worked is gone. Only an absolute local path can trigger it, and --overwrite still works. The same edit leaves sourceKind unused (:801-806) and repeats the sentence at :502-504.
Fix: gate the comparison on sourceKind == drive9CopySourceRemote inside remoteTargetExistsError, call that helper from drive9CopyReplacingRemoteTarget instead of repeating the sentence, and add an upload case whose local absolute path equals the remote path to TestDrive9CopyUploadRejectionStillOffersOverwrite.

2. The staging cleanup misreports on three paths
internal/fs/drive9_companion.go:531
discardDrive9CopyStaging returns the raw fs rm error, and its two callers read it differently.

  • Move applied, answer lost. If the service committed the rename and the answer was lost, fs rm <staging> answers not found and ti exits with fs.copy_staging_left_behind: it says the replace failed and points at a delete command for a path that no longer exists, while the destination already holds the new bytes. The previous head returned the move error alone. The helper's comment says "removed" and "never existed" are treated alike; this caller says the opposite.
  • Failed staged copy without delete. At :513 the cleanup result is discarded. When the staged copy created its node and then failed, and the token cannot delete, one staging file stays per attempt and the ti error is only the copy's. The README now says the error names the staging path whenever the replace fails and the token cannot delete.
  • Stray output. The cleanup runs uncaptured and the runner streams companion stderr (internal/fswrap/runner.go:95-98), so a staged copy that failed before creating anything now prints an extra fs rm error line (… not found) between the copy's error and ti's. The previous head printed one error.

The fake companion cannot show any of this: its rm succeeds on any path and its only failure text is permission denied (internal/fs/drive9_fake_companion_test.go:248), so TestDrive9CopyServerSideOverwriteCleansUpAfterFailedStagedCopy pins the rm argv against a behavior the service does not have.
Fix: have the helper report three outcomes (removed, already absent through isDrive9NotFound, failed) and run the rm captured, so its raw line reaches the user only when ti decides it matters; attach the same leftover note to the primary error at both call sites; when the move failed and the staging path is already absent, say the move's outcome is unknown and point at ti fs describe-file --path <destination>. Two fake switches (rm answers not found; mv applied then failed) with assertions on the messages would pin all three.

Nits

  • README.md:192, three sentences. "both pass --overwrite to the companion" is not what happens: ti forwards no such flag; with --overwrite ti skips its own probe and the companion's plain write replaces. The directory rule is now stated for local destinations only, but a remote destination follows it for an existing directory, a trailing separator and the root as well; only the symlink clause needed scoping. And ti fs delete-file --path <staging> needs a token with delete, which is exactly what the "token without delete" case lacks; say so there and in the fs.copy_staging_left_behind message.
  • Stale text after the fix. The doc comment at internal/fs/drive9_companion.go:486-487 still says the staging path is "removed on a best-effort basis". The PR description still carries the first commit's wording ("a failed move removes the staging path on a best-effort basis", "the move needs delete on the destination in addition to write") and lists neither the : rule, fs.copy_staging_left_behind, the new tests, the live listing assertion nor the docs follow-up (which is in a comment).

Recommendation

Comment. No merge-blocking defect was found; the two items above were introduced by the fix commit and should be corrected before merge.

…leanup honestly

Two regressions from the previous fix commit, both reproduced with the
built binary.

The refusal lost its source-kind branch, so a local absolute path that
merely spelled the remote destination (--from-local /data/x.csv
--to-remote /data/x.csv) was told it was the source path, losing the
--overwrite advice that works. The collision sentence now applies only to
a remote source, and drive9CopyReplacingRemoteTarget reuses the helper
instead of repeating it.

The staging cleanup returned the raw fs rm error, which made its two
callers misreport: an applied rename whose answer was lost came back as
'staging left behind' pointing at a delete for a path that is already
gone, a refused cleanup after a failed staged copy was discarded while the
README promised the staging path would be named, and a failed copy that
never created the node printed the companion's not-found line. The helper
now reports removed/absent/failed, runs captured so its error only reaches
the user when ti decides it matters, and both call sites attach the same
leftover note; when the move failed but the staging path is gone, the
error says the outcome is unknown and points at ti fs describe-file.

README: with --overwrite ti forwards no flag, it skips its own probe and
lets the companion's plain write replace; the directory rule applies to a
remote destination too (only the symlink clause is local-only); the
delete-file remedy itself needs delete on the staging path.

New tests: upload whose local path spells the destination, unknown outcome
after an applied-but-unreported rename, a refused cleanup after a failed
staged copy, and the delete permission note in the message.
@srstack

srstack commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Both regressions are real and both were mine; 6a7cbd9 (signed, Verified) fixes them.

1. The refusal lost its source-kind branch. remoteTargetExistsError now gates the collision sentence on sourceKind == drive9CopySourceRemote, and drive9CopyReplacingRemoteTarget calls the helper instead of repeating it. On the built binary:

$ ti fs copy-file --from-local /data/x.csv --to-remote /data/x.csv      # remote file exists
ti [ERROR]: remote target "/data/x.csv" already exists; pass --overwrite to replace it
$ ti fs copy-file --from-remote /data/x.csv --to-remote /data/x.csv
ti [ERROR]: remote target "/data/x.csv" is the source path; copy to a different path instead

TestDrive9CopyUploadRejectionStillOffersOverwrite now covers the same-spelling upload: it fails if the message claims "is the source path" and fails if the --overwrite advice is missing.

2. The staging cleanup now reports what happened. discardDrive9CopyStaging returns removed / absent / failed, and runs with CaptureStdout: true, so the companion's raw fs rm line only reaches the user when ti decides it matters. Both call sites attach a note:

  • move failed, cleanup worked → the move error alone (as before),
  • move failed, cleanup refused → fs.copy_staging_left_behind naming the staging path, the delete-file command and the fact that command needs delete,
  • move failed, staging already gone → fs.copy_outcome_unknown: "replacing %q reported %v and its staging copy is gone, so the copy may have been applied; check the destination with ti fs describe-file --path %s" — no delete advice for a path that no longer exists,
  • staged copy failed, cleanup refused → the same leftover note, naming the path (the partial point you left open),
  • staged copy failed before creating anything → the copy error alone, with no stray fs rm: not found line.

Three new tests pin those paths (...ReportsUnknownOutcome, ...NamesStagingAfterFailedStagedCopy, and the extended failed-move case asserting no leftover note when cleanup worked), plus a TI_FAKE_DRIVE9_RM_NOT_FOUND switch so the fake can express "already absent" instead of only "permission denied".

Nits, all taken. README: with --overwrite ti forwards no flag — it skips its own probe and the companion's plain write replaces; the directory rule is stated for remote destinations too and only the symlink clause is local-only; and the delete-file remedy is called out as itself needing delete, in both the README and the fs.copy_staging_left_behind message. The stale "removed on a best-effort basis" comment is rewritten. The PR description is rewritten to the final behaviour and now lists the : rule, fs.copy_staging_left_behind, fs.copy_outcome_unknown, the new tests, the live listing assertion and the docs follow-up.

go build ./..., go vet ./..., go test ./... -count=1 clean; the built-binary replay is 24/24. CI is running on 6a7cbd9.

@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 third commit gates the same-path refusal on a remote source and reuses that helper in the replace path, makes the staging cleanup report removed / absent / failed and run captured, adds fs.copy_outcome_unknown, attaches the leftover note after a failed staged copy, and takes the README and description nits. Both items from the second review are fixed as asked, and the replace itself is correct and unchanged. One thing is still wrong: the cleanup decides whether a staging file exists from the failure text of a single fs rm instead of asking the service, and that inference is wrong in three reproduced cases, two of them regressions against the previous head. No data is lost or corrupted in any reproduced case.

Resolved since the last review

  • The same-path refusal applies to a remote source only: an upload whose local absolute path equals the remote path is back to the main wording, with a test, and the replace path calls the same helper.
  • The cleanup runs captured: a copy that created nothing under a token that can delete prints one error and no stray fs rm line.
  • A rename that was applied before its answer was lost is reported as fs.copy_outcome_unknown pointing at ti fs describe-file, when the rm reaches the service.
  • A leftover after a failed staged copy is named when the cleanup is refused.
  • README: no flag is forwarded, the directory rule covers both destination kinds, the remedy needs delete; the doc comment and the PR description are rewritten.

What looks good

  • remoteTargetExistsError is the single owner of the collision sentence, and nothing else changed for non---overwrite users.
  • Capturing the cleanup is the right call, and the leftover message keeps the cause, names the path and states the permission the remedy needs.
  • fs.copy_outcome_unknown is the right instinct for a rename whose answer was lost.

Should fix (non-blocking, strong)

1. The staging cleanup still infers instead of observing
internal/fs/drive9_companion.go:515 (and :521-531, :552-562)
discardDrive9CopyStaging maps one fs rm attempt to "removed", "absent" or "failed" from its error text, and each caller reports from that. Three reports are wrong on this head, all reproduced with a built binary:

  • False leftover under a token without delete (regression against 3c59d583). The service authorizes DELETE before it looks the path up, so fs rm <staging> answers fs access denied whether or not the file was created. Every staged copy that created nothing - a missing source, a directory source, no write, a grant that does not cover the staging sibling - is now reported as fs.copy_staging_left_behind, with a delete command for a file that is not there. README.md:287 gives exactly this token as the scoped-token example (--allow /workspace:read,list,write), so for it the report no longer depends on what happened.
  • A non-JSON 404 reads as "absent" (regression against 3c59d583). isDrive9NotFound is a substring test, and the companion renders a non-JSON error body as HTTP 404: <body>. A gateway page on the rm makes ti report fs.copy_outcome_unknown ("its staging copy is gone") while the staging file is still there and the destination untouched: a real leftover, unnamed.
  • fs.copy_outcome_unknown depends on one unretried rm. If that rm fails on a transport error right after the move failed, the outcome is "failed" and the user gets the leftover note this commit set out to remove, for a path that is gone while the destination already holds the new bytes.

The same root cause shows on Ctrl+C: the cleanup runs on the cancelled context, cannot start, and an interrupted replace reports a leftover it never looked for.

The second review asked for the leftover note at both call sites. That suggestion did not account for authorize-before-lookup; this item is its correction.

Fix: ask the service whether the staging file is there before trying to delete it. drive9StatTarget already makes that call, retried, on these paths, and needs read, which the destination probe has already used in that directory. Then delete what exists through drive9RunTransientRetry (a 404 is the goal state), keep today's reading of a refused rm only as the fallback for a token whose stat is refused, and run the check on a context that survives cancellation. Once the stat has seen the file, a failed removal is a leftover whatever its text says.
While there, one function that returns the final error would replace the outcome type, the two different dispatches over it and the free-text clause of drive9StagingLeftoverError (:540-567). Both call sites want the same decision: the error the user should see after a failed replace.

Tests (internal/fs/drive9_copy_overwrite_test.go:178): the fake cannot express "refused before the lookup" - its rm outcomes are process-wide switches and its stat answers from a static map - which is how the first case passed the new tests. Give it a small state file (paths created by cp, moved by mv, removed by rm) and a permission set, and pin three things: a staged copy that creates nothing under a token without delete gives the copy error alone; a failed staged copy with rm answering not found prints no stray line; and the failed-move test asserts the move error itself rather than only the absence of the leftover code. A stat-first change needs that stateful fake: against the static one, four of the current tests fail because every staging path answers not found.

Nits

  • README.md:192. The paragraph names every other copy error code but neither fs.copy_staging_left_behind nor fs.copy_outcome_unknown. "(no overwrite flag is forwarded - the companion has none)" is inexact: the pinned fs cp has -f|--force, honored for object-store URIs only. And the unknown-outcome pointer names only the destination; a server-side copy shares the source's file id, so naming both paths makes the describe-file comparison decisive, and saying that re-running with --overwrite is safe gives the user something to do.
  • PR description. "a failed staged copy tries to remove the staging file; the copy error remains the one reported" is not what happens when the cleanup is refused (the reported error becomes fs.copy_staging_left_behind, with the copy error as its cause), and the docs follow-up list omits fs.copy_outcome_unknown.

Recommendation

Comment. No merge-blocking defect was found; the cleanup item above should be corrected before merge.

The cleanup decided whether a staging file existed from the error text of a
single fs rm, and that reading is wrong in three ways the review
reproduced: the service authorizes DELETE before it looks a path up, so a
token without delete reports every staged copy that created nothing as a
leftover; a non-JSON 404 body is matched by the 'not found' substring and
turns a real leftover into 'outcome unknown'; and an unretried transport
error turns a gone staging file into a leftover note. On Ctrl+C the cleanup
inherited the cancelled context and could not start at all.

The cleanup now asks the service whether the staging path exists (fs stat,
retried) before deleting, treats an absent path as 'nothing to clean',
deletes what exists through the transient retry, and keeps the old reading
of a refused rm only as the fallback for a token whose stat is refused. It
runs on a context that survives cancellation with a 30s bound, and one
function now returns the error the user should see, so both call sites
share the decision.

The messages the review asked for: fs.copy_outcome_unknown names both paths
and says re-running with --overwrite is safe; fs.copy_staging_left_behind
carries the cause, the staging path, the delete command, the permission it
needs and the source.

The fake companion gained a stateful mode (paths created by cp, moved by
mv, removed by rm, plus delete/stat refused switches), because the static
stat map could not express any of the three cases; four of the replace
tests now run against it, including a staged copy that creates nothing
under a token without delete.
@srstack

srstack commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Correct on all three counts, and the root cause was mine: I inferred existence from an error string instead of asking the service. aa52214 (signed, Verified) replaces that inference with an observation.

The cleanup now:

  • asks drive9StatTarget (retried) whether the staging path exists before deleting anything,
  • absent → nothing to clean; the copy error (or, after a failed move, fs.copy_outcome_unknown) is reported,
  • present → removes it through drive9RunTransientRetry (a 404 on the removal is the goal state),
  • stat refused → falls back to today's reading of a refused rm, which is the case that inference actually fits,
  • runs on context.WithoutCancel with a 30s bound, so Ctrl+C no longer reports a leftover it never looked for,
  • and returns the final error from one function, so both call sites share the decision; the outcome type and the free-text clause of the leftover error are gone.

Your three cases, on the built binary with a stateful stand-in:

# staged copy created nothing, token without delete
ti [ERROR]: fs cp: backend unavailable                      # no leftover claim, no stray fs rm line

# rename applied, answer lost
ti [ERROR]: replacing "/dst.txt" reported fs mv: backend unavailable: exit status 1 and its staging copy
is gone, so the copy may have been applied; check both paths with `ti fs describe-file --path /dst.txt`
and `--path /src.txt`, then re-run with --overwrite if it was not

# rename failed, staging present, delete refused
ti [ERROR]: replacing "/dst.txt" failed (...) and the staging copy "/dst.txt.ti-tmp-bac68b8b" could not be
removed (fs rm: fs access denied: exit status 1); delete it with `ti fs delete-file --path
/dst.txt.ti-tmp-bac68b8b`, which needs delete on that path; the source is /src.txt

# rename failed, staging present, delete allowed
ti [ERROR]: fs mv: backend unavailable                      # move error alone, no staging file left

The fake can express it now. It gained a stateful mode (TI_FAKE_DRIVE9_STATE_DIR: paths created by cp, moved by mv, removed by rm, failures before and after the state change, and DELETE_DENIED/STAT_DENIED switches that answer before the lookup). Four of the replace tests run against it, and the three you asked for are pinned:

  • TestDrive9CopyServerSideOverwriteNoLeftoverWhenNothingWasCreated — staged copy creates nothing under a token without delete → the copy error alone,
  • TestDrive9CopyServerSideOverwriteAppliedMoveLostAnswer — rename applied, answer lost → fs.copy_outcome_unknown naming both paths, never a delete,
  • TestDrive9CopyServerSideOverwriteCleansUpAfterFailedMove — asserts the move error text itself, not just the absence of the leftover code.

You were also right that the static fake would have failed four tests under a stat-first change; that is why the mode exists rather than a patched map.

Nits. README now names both fs.copy_staging_left_behind and fs.copy_outcome_unknown, says the unknown-outcome pointer names both paths and that re-running with --overwrite is safe, and corrects the forwarded-flag note: ti forwards none, and the pinned fs cp has -f|--force, honoured for object-store URIs only. The PR description now says the copy error becomes fs.copy_staging_left_behind (with the copy error as cause) when the cleanup is refused, and lists fs.copy_outcome_unknown in the docs follow-up.

go build ./..., go vet ./..., go test ./... -count=1 clean; the built-binary replay (staging, replace, cleanup refused, applied-but-unreported, scheme) is green. CI is running on aa52214.

@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 fourth commit replaces the outcome type and the two dispatches with one function, drive9CopyFailure: it stats the staging path first (retried), removes what exists through the transient retry, keeps the old reading of a refused rm when the stat itself is not answered, and runs on a context that ignores cancellation with a 30 second bound; the two messages are rewritten, the replace tests are rebuilt on a stateful fake, and the README and description nits are taken. The misreports from the third review are fixed for the tokens and sequences that hit them, and an interrupted replace now cleans up. Two things should be fixed before merge, both in what this commit added: when the stat is refused or times out, the fallback still reports a leftover it never saw, and the test rewrite dropped assertions and leaves the fallback and the cancellation fix without a test. No merge-blocking defect was found.

Resolved since the last review

  • The scoped token the README documents (--allow /workspace:read,list,write) now gets the copy error alone when nothing was created, and a named leftover when the staged copy did create the file.
  • A rename that was applied before its answer was lost is reported as fs.copy_outcome_unknown without depending on an rm; the message names both paths and says re-running with --overwrite is safe.
  • The removal goes through the transient retry: a first transport error no longer produces a leftover note.
  • An interrupted replace cleans up or reports truthfully: Ctrl+C during the staged copy gives the plain copy error with no leftover claim, and Ctrl+C during the move removes the staging file.
  • The outcome type and the free-text clause are gone; one function returns the final error for both call sites.
  • README names both codes and corrects the flag note; the description's failure bullet and the docs follow-up list are fixed.

What looks good

  • Stat-first is the right order for a service that authorizes DELETE before it looks the path up.
  • The cleanup survives cancellation and is bounded: in the two interrupted replaces I replayed (during the staged copy and during the move) nothing was left behind, no false leftover was claimed, and the command returned in about a tenth of a second.
  • TestDrive9CopyServerSideOverwriteAppliedMoveLostAnswer and the reworked failed-move test assert on the message the user sees, and the applied-but-unreported rename is expressed as state rather than as a static switch.

Should fix (non-blocking, strong)

1. The fallback for a refused or unanswered stat still states a leftover it never saw
internal/fs/drive9_companion.go:544
When the stat of the staging path is refused or fails, the !state.known branch reads one fs rm answer, and its default arm returns fs.copy_staging_left_behind with "the staging copy … could not be removed". That is a claim that the file exists - the one thing this branch could not establish:

  • The stat is refused for a token whose read covers the destination file but not its directory (the grant the README itself names as insufficient), and it fails for any token while the backend answers 500. In both cases the staged copy has already failed without creating a node, so the leftover is false on every attempt and the copy error the user needs is demoted to a parenthetical cause.
  • After a failed move the same arm can name a leftover that is gone: rename applied, answer lost, then stat 500 and rm 500, while the destination already holds the new bytes.
  • When the 30 second bound expires during the stat, the rm never starts, and the message blames fs rm … context deadline exceeded.

The README's new parenthetical ("fs.copy_staging_left_behind (the staging file is still there and the error names it)") repeats the claim, and the paragraph does not describe the fallback. Keeping a fallback for a refused stat was the third review's own suggestion; the problem is only that it states an outcome where it has a possibility.
Fix: treat "could not look" as its own outcome instead of folding it into "present". When the stat was refused or timed out and the removal then fails, say that ti could not check the staging path (with the stat error) and that a .ti-tmp- entry in that directory, if one is listed, should be deleted; and stop promising in the README that the file is there. Check checkCtx.Err() before the rm, so an expired bound is reported as a timeout rather than as a refused removal. Do not trade the old inference for a new one drawn from the refusal text. The "not found" text match itself (a gateway page on the stat or on the rm) needs a failure and then a page on the very next call; that is follow-up material, not for this PR.

2. The test rewrite dropped assertions and leaves the new behavior untested
internal/fs/drive9_copy_overwrite_test.go:286

  • TestDrive9CopyServerSideOverwriteCleansUpAfterFailedStagedCopy used to assert "no mv after a failed staged copy" and "the staging path was removed". It now asserts only that the error is fs.companion_failed, which is also what no cleanup at all returns. The PR description still lists "no move, cleanup attempted" for it.
  • The fallback and the cancellation fix are uncovered: on this head, making the fallback unreachable, or replacing context.WithoutCancel(ctx) with ctx, leaves the whole Drive9Copy family green.
  • The fake cannot express the refusal that reaches the fallback: TI_FAKE_DRIVE9_STAT_DENIED is one global switch, so through CopyFile it refuses the destination probe first, and no test sets it. TI_FAKE_DRIVE9_RM_NOT_FOUND and TI_FAKE_DRIVE9_RM_FAIL have no user left, and the static mv, rm and staged-cp branches of the fake are unreachable.
  • newStatefulCopyService returns the state directory and no test reads it, so the tests still pin the rm argv rather than the final set of paths - the thing the stateful mode was added for. The new "the source is …" clause of the leftover message is not asserted either.

Fix: read the state file after each scenario (the staging path is gone after the two cleans-up tests; only the destination remains after the applied-move test). Add a test that cancels the context before the cleanup and asserts that stat and rm still run and the original error comes back. Give the fake a read scope so the destination probe succeeds and the staging stat is refused, and pin the fallback with it. Delete the unused switches and the dead branches.

Nits

  • Signals during the cleanup (internal/fs/drive9_companion.go:534). The cleanup ignores not only the first Ctrl+C, which is the point, but every later signal: SIGINT and SIGTERM stay captured until ti exits and nothing in the cleanup reads them. With a stat that does not answer, ti sits out the full 30 seconds whatever the user sends, and kill <pid> does not end it (reproduced: three SIGINTs and a SIGTERM ignored until the bound). Wait on interrupt.Signals(checkCtx) alongside the companion calls and stop the cleanup on the next signal, reporting that the staging path was not checked.
  • Shape of drive9CopyFailure (:540-590). The fs.copy_outcome_unknown message is built twice, verbatim (:540, :553); fs rm is invoked twice with the same argv (:547, :561); drive9StagingLeftoverError takes a positional moveFailed bool whose only use is to choose between two openings; and a type and a method are both named drive9StagingState (:574, :579), so state := s.drive9StagingState(…) reads as a conversion. One look, one removal and one helper for the unknown case would remove all of it.
  • Text (README.md:192). The permission sentence leaves out read in the destination's directory, which the staged copy's own HEAD on the staging sibling needs - that is the actual reason "a grant scoped to the destination file alone is refused at the staged copy". "the pinned fs cp" is review vocabulary in a user-facing sentence, and "honoured" is the README's only British spelling. In the PR description, the line for …CleansUpAfterFailedStagedCopy describes the previous head's test, and the failure-handling list has no bullet for the fallback.

Recommendation

Comment. No merge-blocking defect was found; the two items above should be corrected before merge.

The fallback for an unreadable staging path read one fs rm answer and
reported 'could not be removed', which states that the file exists - the
one thing that branch could not establish. It fires for a token whose read
covers the destination but not its directory, for a backend error during the
stat, for an expired 30s bound and for a second interrupt, and each of those
turns a clean failure into a false leftover with the copy error demoted to a
parenthetical cause.

The cleanup now has three outcomes: absent (nothing to clean), present
(remove it, and a refused removal is a real leftover), and unobserved. The
unobserved case reports fs.copy_staging_unchecked, carries the stat failure,
and says which .ti-tmp- entry to look for instead of claiming one; an
expired bound is reported as a timeout rather than as a refused removal. It
also waits on interrupt.Signals, so a second Ctrl+C stops the cleanup
instead of being captured until the bound.

Tests: the path set is read after each scenario (the staging file is gone
after the two cleans-up cases, only the destination remains after the
applied-move case), a cancelled copy still stats and removes the staging
file, and the unreadable-staging fallback is pinned with a fake that denies
stat for the staging sibling only. Mutating context.WithoutCancel(ctx) back
to ctx, or making the fallback unreachable, now fails those two tests.

The fake drops the switches and branches that no longer have a caller.
README: read in the destination's directory is part of the requirement, the
companion command is named as such, and the three failure codes are
described by what they observed.
@srstack

srstack commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Both items are fixed in dab7caf (signed, Verified).

1. The fallback no longer states an outcome it could not observe. The cleanup now has three outcomes:

  • absent → nothing to clean; the copy error, or fs.copy_outcome_unknown after a failed move,
  • present → remove it; a refused removal is a real fs.copy_staging_left_behind,
  • unobserved → fs.copy_staging_unchecked, carrying the stat failure and telling the caller which .ti-tmp- entry to look for, without claiming one exists.

An expired bound is checked before the removal and reported as the cleanup bound expired: …, not as a refused fs rm. On the built binary:

# stat refused for the staging sibling, removal refused
ti [ERROR]: the replace at "/dst.txt" failed (fs mv: backend unavailable: exit status 1) and ti could not
determine whether the staging file "/dst.txt.ti-tmp-6bdfcd61" exists (reading it said fs stat: fs access
denied ... and removing it said fs rm: fs access denied ...); look next to the destination for an entry
ending in .ti-tmp- and, if it is there, delete it with `ti fs delete-file --path ...`

# stat allowed, file present, removal refused
ti [ERROR]: replacing "/dst.txt" failed (...) and the staging copy "/dst.txt.ti-tmp-5096344b" could not be
removed (fs rm: fs access denied ...); delete it with `ti fs delete-file --path ...`, which needs delete
on that path; the source is /src.txt

The cleanup also waits on interrupt.Signals, so a second Ctrl+C stops it and reports that the staging path was not checked, instead of staying captured until the 30s bound.

2. Tests restored and extended, and the new behaviour is covered. The fake state file is now read after each scenario: after the two cleans-up cases only the destination remains, after the applied-move case the path set is exactly the destination, and TestDrive9CopyServerSideOverwriteCleansUpAfterFailedStagedCopy again asserts "no mv" and "the staging file is gone". New tests:

  • TestDrive9CopyServerSideOverwriteReportsUncheckedStaging: a fake that denies stat only for the staging sibling (so the destination probe still succeeds) plus a refused removal → fs.copy_staging_unchecked, asserting the message does not say "could not be removed" and does say what to look for.
  • TestDrive9CopyFailureCleansUpOnCancelledContext: an already-cancelled context still stats and removes the staging file, and the original error comes back.

I checked that coverage by mutation: replacing context.WithoutCancel(ctx) with ctx fails the cancelled-context test, and making the fallback unreachable fails the unchecked test; both pass on dab7caf. The fake also lost the switches and static branches that no longer have a caller.

Nits. README: read in the destination's directory is now part of the requirement (that is why a destination-only grant is refused at the staged copy), the flag note names the companion command instead of review vocabulary, and "honored" instead of "honoured"; the three failure codes are described by what ti observed. The description's …CleansUpAfterFailedStagedCopy line is corrected and the unchecked case is listed.

go build ./..., go vet ./..., go test ./... -count=1 clean. CI is running on dab7caf. I am monitoring this PR every 20 minutes and will handle the next review or a red check.

@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 fifth commit replaces the "stat refused, so read one fs rm answer as a leftover" fallback with three outcomes that say what ti observed (absent, present, unobserved as fs.copy_staging_unchecked), moves the cleanup body into a goroutine so a signal can stop it, and restores the tests. Both items from the fourth review are resolved, and every branch that runs without a signal reports the truth. But the new signal wait is wired to the command's own signal channel, which still holds the signal that stopped the copy: on the first Ctrl+C or SIGTERM the cleanup is abandoned without one companion call, the staging file stays, and a move that had committed is no longer reported as fs.copy_outcome_unknown. That undoes the round-3 fix on the path it was about, contradicts the README, the description and the commit message, and no test can see it.

Resolved since the last review

  • A refused, failed or expired stat is no longer reported as a leftover: fs.copy_staging_unchecked says ti could not determine whether the staging file exists, carries the stat and removal answers, and an expired bound is reported as a timeout.
  • The two dropped assertions are back and assert the final path set; the fallback and the cancellation fix are pinned (both fourth-review mutations now fail a test, and so does skipping the removal).
  • A cleanup whose stat does not answer is stopped by a signal that arrives while it runs, instead of holding the command for 30 seconds.
  • README: read in the destination's directory, the companion command named instead of review vocabulary, "honored", and the three codes described.

What looks good

  • The three outcomes are named for what ti observed, and every branch that runs without a signal is truthful.
  • The fake's TI_FAKE_DRIVE9_STAT_DENIED is path-aware now, which is what made the unchecked case testable at all.
  • The unknown-outcome message is built once, and the drive9StagingState name clash is gone.

Blocking (please address before merge)

1. On the first Ctrl+C or SIGTERM the cleanup no longer runs
internal/fs/drive9_companion.go:546
drive9CopyFailure selects on interrupt.Signals(checkCtx), and the comment says the first signal "was already used to cancel the copy" and this one is a further signal. It is the same signal. checkCtx derives from the command's context through context.WithoutCancel, so it carries the same channel: the one interrupt.NotifyContext created for the whole process (cmd/ti/main.go:22). Its goroutine cancels the context and then puts that first signal into the channel (internal/interrupt/context.go:38-41, buffer of two at :30), and nothing on the companion Run path reads it (internal/fswrap/runner.go:82-103; the only other reader is waitStreaming). So when the staged copy or the move fails because of Ctrl+C, a signal is queued, and the select takes the "further signal" branch at once.

Reproduced on this head with one signal (SIGINT and SIGTERM behave the same):

  • during the staged copy: fs stat <destination>, fs cp - nothing else;
  • during the move: fs stat, fs cp, fs mv - nothing else, and the staging file stays;
  • during a move that had already committed: the destination holds the new bytes, and the error only says to look for a .ti-tmp- entry. fs.copy_outcome_unknown and its describe-file advice are gone for this case.

On aa52214a the same inputs ran fs stat and fs rm on the staging path, removed it, and reported fs.copy_outcome_unknown for the committed move. The select does what it says only when the failure had another cause and a signal arrives while the cleanup runs. README.md:192 ("or a second interrupt"), the PR description ("so an interrupted replace still cleans up") and this commit's message ("so a second Ctrl+C stops the cleanup") all describe a behavior the code does not have, and all five messages land. TestDrive9CopyFailureCleansUpOnCancelledContext cancels a plain context, where interrupt.Signals is nil, so the signal case can never fire; replacing the select with return <-done leaves the Drive9Copy family green.

Fix: wait on a channel that cannot contain the signal that failed the copy. The mount code in this package already registers one of its own (internal/fs/fuse_mount.go:96-98, internal/fs/vault_mount.go:60-62): register a fresh channel for the cleanup, so that only a signal delivered after the cleanup started stops it. I checked that on a private copy: one Ctrl+C before the cleanup now runs fs stat and fs rm on the staging path and removes it, a committed move is reported as fs.copy_outcome_unknown again, and a Ctrl+C during a hanging stat still stops the cleanup. Draining the queued signal before the select also restores the behavior, but the forward into the channel is not ordered before the cancellation the copy observed, so the drain can run too early. Either way, add a test that builds its context with interrupt.NotifyContext, sends itself one SIGINT and asserts a stat and an rm on the staging path; the hand-cancelled test cannot cover this.

Nits

  • Three decisions still have no test (internal/fs/drive9_companion.go:577). Removing the bound check leaves the family green, so "an expired bound is reported as a timeout" is unpinned; the same holds for both "the stat was refused and the removal answered not found" decisions (:581-586). The fake can already produce the two latter (TI_FAKE_DRIVE9_STAT_DENIED=ti-tmp together with TI_FAKE_DRIVE9_CP_STAGED_FAIL=1, or with TI_FAKE_DRIVE9_MV_APPLIED_FAIL=1); a switch that makes the staging stat hang would pin the bound. The fake also keeps branches no test reaches: denied == "1", && !applied, and the mv and rm not-found branches.
  • Shape (:566). The same fs rm is still built and run at two sites with a copied "not found" decision (:566-570, :580-588), and the positional afterMove bool is still there. drive9StagingLeftoverError now takes an opening string that has one call site and one value, and that call dropped the old "copying to the staging path for …" wording, so a failed staged copy now opens with replacing "…" failed (fs cp: …). And cleanDrive9CopyStaging removes nothing in the absent case and always returns the error the user sees, so its name describes one of its three outcomes.
  • Text. failuere in the comment at :609. README.md:192 lists "a token without read on the staging sibling" as a cause of fs.copy_staging_unchecked; a token without read but with delete gets the file removed and the copy error alone. The PR description is behind in three places: its permission requirement lacks the read in the destination's directory, it still says "the companion has none" about the overwrite flag, and its list of what the published page needs omits fs.copy_staging_unchecked.

Recommendation

Request changes. On the first Ctrl+C or SIGTERM the staging cleanup no longer runs, which is the case the round-3 fix was about, and the README, the description and the commit message state the opposite.

interrupt.Signals(checkCtx) returns the command's channel, which already
holds the signal that cancelled the copy: the select took the 'further
signal' branch immediately, so on the first Ctrl+C the cleanup made no
companion call, the staging file stayed, and a rename that had committed
was no longer reported as fs.copy_outcome_unknown. The registration is now
fresh for the cleanup (SIGINT/SIGTERM), the same way the mount code does
it, so only a signal delivered after the cleanup started stops it.

Pinned with a test that builds its context with interrupt.NotifyContext,
sends itself one SIGINT and requires a stat and a removal on the staging
path; the hand-cancelled test could not see this. Verified against the
built binary with a partially written staged copy: one SIGINT now runs
stat, cp, stat and rm and leaves nothing behind.

Also from the review: the removal answers whether the staging file was
there, so 'not found' reads as absent rather than as a failed cleanup; the
stage is an enum instead of a positional bool and chooses the leftover
wording (a failed staged copy opens with 'copying to the staging path for
…' again); the cleanup function is named for what it does; the one-fs-rm
helper is shared. Tests for the expired bound (now a variable so it can be
shortened), and for a refused stat whose removal answers not found before
and after the move. The fake gained a hanging stat and lost two branches no
test reached.

README: fs.copy_staging_unchecked now says it needs a token that can
neither read nor delete the staging sibling, and the description carries
read in the destination's directory plus the unchecked code in the docs
follow-up.
@srstack

srstack commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

This was a real bug and it was mine: interrupt.Signals(checkCtx) returns the command's own channel, and that channel already holds the signal that cancelled the copy, so the select took the "further signal" branch at once. 170318a (signed, Verified) registers a fresh channel for the cleanup, the way the mount code does:

signalCh := make(chan os.Signal, 2)
signal.Notify(signalCh, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(signalCh)

Only a signal delivered after the cleanup started can stop it now. On the built binary, with a staged copy that leaves a partially written sibling and one SIGINT during it:

fs stat --output json :/dst.txt
fs cp :/src.txt :/dst.txt.ti-tmp-76b5619d
fs stat --output json :/dst.txt.ti-tmp-76b5619d
fs rm :/dst.txt.ti-tmp-76b5619d
→ nothing left behind

On the previous head the last two lines did not happen. A committed rename interrupted by the same signal reports fs.copy_outcome_unknown again, since the staging path is observed absent rather than the cleanup being skipped.

The test you asked for. TestDrive9CopyFailureCleansUpAfterTheSignalThatFailedTheCopy builds its context with interrupt.NotifyContext, sends itself one SIGINT, waits for cancellation, then runs drive9CopyFailure and requires a stat and an rm on the staging path plus the file removed. Replacing the fresh registration with interrupt.Signals(checkCtx) fails that test; it passes on the fix.

The three untested decisions are pinned too:

  • expired bound → drive9CopyCleanupTimeout is a variable, the fake can hang a stat for a path fragment (TI_FAKE_DRIVE9_STAT_HANG), and TestDrive9CopyFailureReportsExpiredCleanupBound requires fs.copy_staging_unchecked with "cleanup bound expired". Deleting the bound check fails it.
  • refused stat whose removal answers "not found", before the move → the copy error (…RefusedStatWithGoneStaging/before the move), and after the move → fs.copy_outcome_unknown (same test's second case).

Shape. The removal now returns whether the staging file was there, so "not found" reads as absent instead of as a failed cleanup, and both branches share one fs rm call. afterMove became drive9CopyStage (before/after the move) and chooses the leftover opening again, so a failed staged copy says copying to the staging path for "…" rather than replacing "…". cleanDrive9CopyStaging is now drive9CopyCleanup, which is what it does.

Text. failuere is gone. README: fs.copy_staging_unchecked is described as a token that can neither read nor delete the staging sibling (a token with delete but no read removes the file and gets the copy error). The description now lists read in the destination's directory and fs.copy_staging_unchecked in the docs follow-up, and the forwarded-flag sentence names the companion's -f|--force instead of "the companion has none".

go build ./..., go vet ./..., go test ./... -count=1 clean; the live-copy replay against the built binary is green. CI is running on 170318a; I am polling the PR every 20 minutes and will handle the next review or a red check.

The test sends itself SIGINT with syscall.Kill, which does not exist on
windows, and the test file is type-checked for every platform by the vet
step. Move it to a !windows file; the behaviour it pins is unix-only by
construction.
@srstack

srstack commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

CI caught one thing in 170318a: the new signal test sends itself SIGINT with syscall.Kill, which does not exist on windows, and the test step type-checks every platform (GOOS=windows go vet ./...). The test moved to internal/fs/drive9_copy_signal_test.go behind //go:build !windows — the behaviour is unix-only by construction — and the rest is unchanged in 58f3fba.

Verified locally: GOOS=windows go vet ./... and GOOS=darwin GOARCH=arm64 go vet ./... are clean, go test ./... -count=1 passes, and the SIGINT replay against the built binary still runs stat, cp, stat, rm and leaves no staging file.

@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 last two commits give the staging cleanup its own SIGINT/SIGTERM registration and pin the fix with a test that fails the copy's context with a real signal. The blocking item is resolved: with exactly one Ctrl+C or SIGTERM the cleanup now runs - during the staged copy it stats the staging path and, when the node was created, removes it; during the move it removes the staging file; a move that had already committed is reported as fs.copy_outcome_unknown again - while a signal that arrives while the cleanup runs still stops it, and with no signal the 30 second bound expires as documented. The same inputs against dab7caf3 still show the cleanup abandoned, and replacing the fresh registration with interrupt.Signals(checkCtx) fails the new test with exactly that symptom. The fifth review's nits are taken: the bound check and both "stat refused, removal answered not found" decisions have tests, the two fs rm sites are one helper, the stage chooses the leftover opening again, and the README is accurate. No correctness or security defect remains on this head, and nothing changed for users without --overwrite. Nothing further is requested; this approval supersedes the changes requested on dab7caf3.

What looks good

  • The fix is the smallest correct one: a fresh registration, no change to the cleanup's decisions, and a reproduction that is sensitive to exactly this change.
  • TestDrive9CopyFailureCleansUpAfterTheSignalThatFailedTheCopy exercises the real mechanism (interrupt.NotifyContext plus a real SIGINT) instead of a hand-cancelled context, fails deterministically on the old select, and is safe next to the rest of the package (no test of the package runs in parallel; the whole package is clean under the race detector).
  • removeDrive9Staging answering "was it there" removes the duplicated fs rm and its copied "not found" reading, and drive9CopyStage reads better than the positional bool at both call sites.

Verified on this head

  • Build, vet for the host, for Windows and for Linux, the package tests, and the race detector on the whole fs package: all pass; CI is green.
  • Every cleanup branch reports what can have happened on the pinned service: absent, present, refused look, expired bound and signal during the cleanup, before and after the move.

Nits

None that need another commit.

Needs no commit (the description only)

  • Three sentences still disagree with the code: the permission requirement lacks read in the destination's directory; "(no flag is forwarded - the companion has none)" - the companion's drive9 fs cp has -f|--force, for object-store URIs only; and fs.copy_staging_unchecked is listed for "a token without read on the sibling", where a token with delete gets the file removed and the copy error alone. README.md:192 already has the right wording for all three.
  • The test list does not name the three tests this change adds.
  • The sixth commit message says the pinned behaviour "is unix-only by construction"; only the test's syscall.Kill is. The production code compiles for Windows and signal.Notify delivers Ctrl+C there as well, so the fix applies there without a test. Worth a sentence in the description; the message itself is not worth a rewrite.

Follow-up material, not for this PR

  • Three cleanup decisions have no test: a further signal stopping the cleanup; a look that saw the file followed by a removal that answers "not found" (now read as absent); and the stage-chosen opening of fs.copy_staging_left_behind. TestDrive9CopyFailureRefusedStatWithGoneStaging sets two fake switches its subtests never read, and the fake's mv not-found branch is unreachable.
  • The fresh-registration idiom now sits at three sites (drive9_companion.go, fuse_mount.go, vault_mount.go), each repeating the signal list that cmd/ti/main.go registers; and interrupt.Signals does not say that code which runs because the first signal cancelled the context must not select on that channel for a further one. One sentence there, or a small helper in internal/interrupt, would keep the fifth-round defect from coming back.
  • Carried over: the published ti-fs-copy-file page, the copy family's own file, and the "not found" text match on a gateway 404 page.

Recommendation

Approve. The blocking item is fixed and reproduces as fixed; only optional follow-ups remain.

@srstack

srstack commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Both done, and thank you for the rounds — the signal-channel bug was the kind of thing only a replay catches.

  • Description: the three stale sentences are fixed (read, write and delete in the destination's directory; the companion's -f|--force honored for object-store URIs only; fs.copy_staging_unchecked needs a token that can neither read nor delete the staging sibling), and the test list now names the signal, expired-bound and refused-stat tests, including the note that only the test is unix-only.
  • Leaving the follow-ups alone: the extra cleanup-decision tests, a shared registration helper in internal/interrupt, and the published ti-fs-copy-file page are better as their own changes; the page needs a pingcap/docs commit before the submodule pin can move, and I will send that separately if you want it.

Nothing merged from my side — merging is yours. The branch is at 58f3fba, CI green, MERGEABLE/CLEAN.

…al hazard

The approval listed three cleanup decisions without a test and two dead
paths in the fake; they are cheap to close now.

- TestDrive9CopyFailureSecondSignalStopsTheCleanup: a signal that arrives
  while the cleanup is running stops it and reports that the staging path
  was not checked.
- TestDrive9CopyFailureRemovalAnswersNotFoundAfterTheLook: the file is
  there for the look and gone for the removal, before the move (copy error)
  and after it (fs.copy_outcome_unknown).
- The two leftover tests now assert the opening, so the stage chooses
  between 'copying to the staging path for …' and 'replacing …'.

The fake gained TI_FAKE_DRIVE9_REMOVE_VANISHED for the vanished removal,
lost its unreachable mv not-found branch, and the refused-stat test no
longer sets two switches its subtests never read.

interrupt.Signals now says that the channel already holds the signal that
cancelled the context, so code running because of that cancellation must
register its own channel instead of selecting on this one - the defect the
last review found.
@srstack

srstack commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

The description-only items were already updated before this message, and I have now closed the optional follow-up nits too, in 26902c4 (tests and a doc comment, no production behaviour):

  • The three untested cleanup decisions are covered: TestDrive9CopyFailureSecondSignalStopsTheCleanup (a signal during the cleanup stops it and reports that the staging path was not checked, with a hanging stat), TestDrive9CopyFailureRemovalAnswersNotFoundAfterTheLook (the file is there for the look and gone for the removal - the copy error before the move, fs.copy_outcome_unknown after it), and the two leftover tests now assert the opening, so the stage really chooses between copying to the staging path for … and replacing ….
  • The fake's dead paths: added TI_FAKE_DRIVE9_REMOVE_VANISHED for the vanished removal, removed the unreachable mv not-found branch, and the refused-stat test no longer sets two switches its subtests never read.
  • The signal hazard is documented where it bit: interrupt.Signals now says the channel already holds the signal that cancelled the context, so code running because of that cancellation must register its own channel instead of selecting on this one.

Still deliberately out of this PR, as you listed them:

  • a shared registration helper for the three sites (drive9_companion.go, fuse_mount.go, vault_mount.go) - the doc sentence covers the hazard for now;
  • the published ti-fs-copy-file page, which needs a pingcap/docs commit before the submodule pin can move;
  • splitting the copy family into its own file;
  • the not found text match on a gateway 404 body.

The branch is at 26902c4, CI is running; the PR stays unmerged on my side.

… them

- The copy family moves out of drive9_companion.go (2,338 lines) into
  drive9_copy.go: the route resolver, the --overwrite probe, the server-side
  replace with its staging cleanup, and the companion argv they share. No
  behaviour change; drive9_companion.go is 1,710 lines and the copy file 655.
- The post-cancel signal registration is interrupt.NotifyStop, used by the
  cleanup and by the two mount paths instead of three copies of the same
  channel registration. NotifyStop starts empty - a signal delivered before it
  registered is not replayed - which is the property the fifth review's defect
  turned on; a test pins it.
- isDrive9NotFound no longer reads a transport-level 'HTTP <code>: <body>'
  rendering as the API's not-found answer. That body comes from whatever
  answered the request (a gateway page titled Not Found included), so it says
  nothing about the path; a failed look now surfaces as unknown rather than
  'the file is gone'.
@srstack

srstack commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Your 'follow-up material' was all in this repo, so instead of carrying it I closed it in 10847d6 (signed, Verified). No behaviour change except the third item.

  1. The copy family has its own file. internal/fs/drive9_copy.go (655 lines) holds the route resolver, the --overwrite probe, the server-side replace with its staging cleanup and the companion argv they share; drive9_companion.go went from 2,338 to 1,710 lines. Pure move - go build, go vet, the package tests and the race detector pass unchanged.
  2. One registration helper. interrupt.NotifyStop() registers a fresh SIGINT/SIGTERM channel and returns its stop function; the cleanup and the two mount paths (fuse_mount.go, vault_mount.go) use it instead of three copies. It starts empty, which is the property the fifth-round defect turned on, and TestNotifyStopStartsEmpty pins it next to Signals' new doc warning.
  3. Transport-level 404s are not "not found" any more. isDrive9NotFound now rejects the companion's HTTP <code>: <body> rendering: that body comes from whatever answered the request - a gateway page titled Not Found included - so a failed look surfaces as fs.copy_staging_unchecked instead of "the file is gone". TestIsDrive9NotFoundIgnoresTransportStatusBodies covers the API message, the gateway HTML page, a proxy JSON page and a 502.

Remaining, and genuinely not this repo: the published ti-fs-copy-file page. The submodule is pinned at a8e00c35; changing the page needs a commit in pingcap/docs first, so it cannot ride here. Say the word and I will send that PR plus the pin bump next.

Local: go build ./..., go vet ./..., go test ./... -count=1, internal/fs -race, GOOS=windows/GOOS=darwin go vet ./..., and the built-binary live-copy replay all pass. CI is running on 10847d6; the approval is retained and I have not merged.

@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

This covers the two commits since the approval on 58f3fba2: 26902c4d (tests and one comment) and 10847d62. The copy family's move into drive9_copy.go is a pure move, interrupt.NotifyStop is equivalent to the three registrations it replaced, and the stricter isDrive9NotFound only fails more conservatively. Everything the earlier approval relied on still holds on this head, checked with real signals on the built binary, and the predicate change closes a real hole in the --overwrite guard. Nothing further is needed for this PR; this approval stands on 10847d62.

Verified on this head

  • The move is pure: of the 116 top-level declarations in the old drive9_companion.go, 114 are identical across the two files, the two that differ are the intended edits (drive9CopyFailure, isDrive9NotFound), one var was added, none is missing, and no declaration moved that has a caller outside the copy family.
  • NotifyStop registers the same two signals on a channel of the same size and releases it at the same points. A NotifyStop that hands every caller one shared channel now fails TestDrive9CopyFailureCleansUpAfterTheSignalThatFailedTheCopy.
  • One Ctrl+C or SIGTERM during the staged copy, during the move, or during a committed move; a second signal during the cleanup; the expired bound: the same results as at the approved head.
  • The stricter isDrive9NotFound, compared on built binaries of 26902c4d and this head: the service's own not-found answers are still recognised in every flow, and a transport-level HTTP <code>: <body> page is no longer read as "absent". Every caller changes in the conservative direction.
  • Build, vet for the host, Windows and Linux, the tests of all 46 packages, the race detector with shuffle, and the signal tests over repeated runs: all pass. CI is green, including its make e2e. On this machine three mount e2e tests cannot complete (no FUSE device) and fail identically on main.

What looks good

  • The split reverses the growth this PR had caused in drive9_companion.go (2,338 to 1,710 lines) and gives the copy family one 655-line file with an accurate header.
  • The predicate change closes a real hole. A plain upload whose destination probe is answered by a transport page used to run and replace an existing destination without --overwrite (reproduced on 26902c4d); it now fails closed with the destination intact. After a refused move it turns two false reports into truthful ones: a leftover that is really there is named as fs.copy_staging_left_behind instead of fs.copy_outcome_unknown, and a removal is attempted instead of skipped.
  • The follow-ups from the earlier approval were closed in the PR instead of deferred, and the new tests fail under the mutations they guard.

Nits

None that need another commit.

Needs no commit (the description only)

  • The predicate change is wider than the commit message and the description say. Besides the cleanup's look it changes the cleanup's removal, the destination probe of a copy without --overwrite, ti fs-vault delete-secret and delete-grant (a transport page on the retry after a transient failure is now an error instead of "status": "deleted"), and ti fs-vault replace-secret (it now stops at a failed vault rm). All of that is the right direction, and the README promises nothing about it, but the description should name it in one sentence.
  • The test list lacks the four tests added by the last two commits, and the failure-handling list states one bullet twice.
  • The ninth commit message says "a test pins it" for NotifyStop. TestNotifyStopStartsEmpty cannot fail for that property; the pin is TestDrive9CopyFailureCleansUpAfterTheSignalThatFailedTheCopy in internal/fs. Worth a sentence in the description; the message itself is not worth a rewrite.

Before release, not for this PR

  • The stricter match assumes that the service's own 404 reaches the companion as JSON. That holds for the pinned server. If the deployed endpoint sat behind something that rewrote 404 bodies, every copy onto a new path would fail at its probe. The live copy steps, which have not been run against the deployed service, settle it in one run: a copy onto a new path without --overwrite, then one onto an existing path with it.
  • Carried over: the published ti-fs-copy-file page.

Recommendation

Approve. The refactor preserved everything the earlier approval relied on, the stricter predicate is correct and only fails more conservatively, and what remains is description text and a release-time check.

@srstack

srstack commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Description-only items, all taken (no commit, per your note):

  • The predicate change is described for what it is. The paragraph now names the wider effect of the stricter isDrive9NotFound: the destination probe of a copy without --overwrite fails closed instead of letting a transport page stand in for "absent" (so it can no longer overwrite a destination that is there), the cleanup's removal is attempted instead of skipped, and the two vault flows move the same conservative way (delete-secret/delete-grant report an error instead of "status": "deleted" when the retry lands on a transport page, and replace-secret stops at a failed vault rm).
  • The test list now names TestDrive9CopyFailureRemovalAnswersNotFoundAfterTheLook, TestDrive9CopyFailureSecondSignalStopsTheCleanup, TestNotifyStopStartsEmpty and TestIsDrive9NotFoundIgnoresTransportStatusBodies, and the duplicated cleanup-signal bullet is gone.
  • The NotifyStop pin is attributed correctly: TestNotifyStopStartsEmpty covers "a fresh registration does not replay an earlier signal"; the cleanup property itself is pinned by TestDrive9CopyFailureCleansUpAfterTheSignalThatFailedTheCopy in internal/fs. The ninth commit message keeps its wording rather than rewriting approved history.

What stays outside the PR, as you listed it:

  • the live check before release — a copy onto a new path without --overwrite and one onto an existing path with it — still needs deployed credentials;
  • the pingcap/docs page and the submodule pin bump.

Nothing else from the nits is open, and I have not merged anything.

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