Skip to content

Transfers and fleet: re-check authority mid-call, guard reopen and sweep races, keep links Link all didn't make - #2333

Merged
arpan404 merged 27 commits into
mainfrom
ace/transfer-auth-routes-fixes
Nov 19, 2026
Merged

arpan404 merged 27 commits into
mainfrom
ace/transfer-auth-routes-fixes

Conversation

@arpan404

@arpan404 arpan404 commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Fixes from the post-merge reviews of #2312 (Allow projects, fleet.request scope) and #2317 (transfers over every route). Seven findings are fixed and one is disputed. Finding 9 had no code bug, only a weak test, which is now replaced.

Fixed

Disputed

  • Continue on and Open on: allow projects between your machines without pairing again #2312, 2 (transfer dialog link cache). The chooser for another machine renders inside MachineScope. That swaps in that machine's client and its own QueryClient (machineCache), and usePrimaryMachine() reads the host identity through that client. So fleetKeys.links(own.id) already lives in a separate cache per source machine, and Allow projects sends the device id from that machine's own links. A new test in transfer-allow.test.tsx reads this window's links first, then opens the chooser from the build server's thread. It checks that only the build server's links show and that only the build server's device on the laptop gains Projects. It passes on main and fails when the scope's cache is shared and keyed by one id.

Review rounds on this PR

Four reviews of this branch asked for more fixes. All of them are in, and the last round replaced two earlier fixes, as noted below.

First round

  • Payload file names. Ids may contain dots, so x.ignored's code file was x's ignored payload. This round renamed files to avoid that; the second round replaced the scheme with hashing.
  • Links to the same machine. Every link now holds its machine from right before redeeming until it is saved. A second link there meanwhile is refused (busy, or exists for a gap fill). Links still being made count toward the 64-link limit, so nothing is redeemed that couldn't be saved.
  • Closing during a sweep. Closing stops the retention sweep and waits for all of it.
  • Refused first chunk. The authority check runs before the payload file is opened, as well as right before the write.
  • Link all test. The fake daemon's fleet records what it was asked. The test now proves the fill was sent with keep and its unused pairing was cancelled.

Second round

  • Case-insensitive volumes. Payload files are named by the lowercase hex SHA-256 of the transfer id, so ids that differ only in case (Move-1, move-1) or in dots never share a file.
  • Upgrading with files under old names. This round added a migration that renamed old-named files to their hashed names. The fourth round removed it (below).
  • Older source daemons. An older daemon drops keep unread, so a fill sent there replaced its link. A machine's links answer now says whether it honours keep (keep: true), and before each fill Link all reads the source's links again and skips a gap that is already linked. How Link all treats a daemon without keep changed again in the fourth round (below).
  • A begin waiting on the sweep. It now refuses once closing has begun. The shutdown test also checks that close() is still pending while a removal is held.
  • Refused while the file opens. A chunk refused after its file was opened removes the file it made. The test revokes access between the open and the write.

Third round

  • Transfers begun during recovery. Recovery's stray removal decides from the live rows, page by page. A transfer begun meanwhile could lose its acknowledged upload. A begin now waits, right before its insert, until stray removal ends. Chunks only write for rows that were already live, so they need no wait.
  • Ambiguous old names and older daemons mid-fill: fixed in this round, then replaced in the fourth (below).
  • Tests on real names. One helper (incoming-files.ts) names payload files. The size-cap, cancel, refusal and recovery tests build paths through it; before, they checked names no longer written. The recovery test checks every old-named upload moves to its own name and resumes at its offset.

Fourth round

  • No old-name migration. Renaming old-named files could take another transfer's upload (an id equal to another transfer's hash) and race a chunk, so the migration is gone and nothing is renamed. At recovery, a transfer still receiving or importing that has a part only under its old name, and none under its hashed name, is cancelled with a reason. Its sender sees it cancelled and can start again. A name any live transfer owns now is never taken for an old one. The old files go with the strays, decided per file by exact name against the live rows, so no live file is touched.
  • Link all and older daemons. A source daemon that doesn't advertise keep is never asked to link. Link all skips it before issuing any pairing, and the toast says that machine needs ace updated before Link all can link it. That removes the older-daemon race outright, along with the re-read added in the third round.

Tests

Each new or changed test was run with its fix removed and failed, then passed with the fix:

  • transfers/incoming-guards.test.ts (new, now 12 tests)
  • transfers/transfer-refusals.process.test.ts
  • transfers/transfer-retention.process.test.ts
  • machines/relay-link.test.ts
  • machines/fleet-links.test.ts
  • fleet-access.server.process.test.ts
  • settings/fleet-page.test.tsx
  • transfers/transfer-allow.test.tsx

Also run: typecheck, lint, fmt:check and check:size. The full suite was not run.

ADR 0101 and 0192 are amended to match.

arpan404 and others added 27 commits November 19, 2026 15:36
…gest failures and sweeps

A commit or chunk admitted with operate and projects reads the device
again right before it claims the transfer or appends, after every await.
A stale commit's digest failure claims only its own upload generation,
and a begin waits while the sweep is still removing that id's files.

Co-Authored-By: spade <bot@acehq.dev>
… queued write

The mid-body test now begins a real transfer, shows the same slow chunk is
taken when nothing narrows, and checks the target hadn't answered before
Projects went. A new test narrows while an admitted chunk's write waits.

Co-Authored-By: spade <bot@acehq.dev>
…estart

The simulated crash now also drops the hand-over's receipt, and the test
checks the thread stored the result's input after the restart, so a
delivery that does nothing fails it.

Co-Authored-By: spade <bot@acehq.dev>
…l waits

Co-Authored-By: spade <bot@acehq.dev>
A successful receipt without a title, from another kind of command, no
longer reads as the scope change done. Only another device's receipt is
answered as forbidden; anything else is refused as invalid.

Co-Authored-By: spade <bot@acehq.dev>
Redeeming a pairing replaces this machine's device on the other one, so a
stale gap list could swap a link with Projects for an operate-only one.
The link op takes keep: the linking machine refuses it as exists, right
before redeeming, while a link to that machine is saved or being made.
Link all sends it, cancels the unused pairing, and its toast counts only
the links it made.

Co-Authored-By: spade <bot@acehq.dev>
…own link

Guards that a dialog opened from another machine's thread, after this
window read its own links, lists that machine's links and Allow projects
widens that machine's device there, never this window's.

Co-Authored-By: spade <bot@acehq.dev>
…p, guarded sweeps

Also moves the guard test's file holds into its hoisted block for lint,
and types the transfer fixture's history option.

Co-Authored-By: spade <bot@acehq.dev>
…holds

Ids may contain dots, so x.ignored's code file was x's ignored payload,
and a write, cancel or sweep of one could touch the other's file. Files
now use the id's stem, with each dot as ~ (never in an id), so names are
one-to-one and read back to their own transfer.

Co-Authored-By: spade <bot@acehq.dev>
close() waited only for the removals running when it was called, so a
sweep could start the next one during teardown. A sweep now stops once
closing began, and close waits for every sweep as a whole.

Co-Authored-By: spade <bot@acehq.dev>
A refused first chunk left an empty payload file behind, since the file
was opened for append before the check. It is now checked before opening
and again right before the write.

Co-Authored-By: spade <bot@acehq.dev>
…re redeeming

Every link now holds its machine from right before redeeming until it is
saved or fails: a second link there is refused (busy, or exists for a
gap fill), so a late answer never saves a credential already replaced.
The 64-link limit counts links being made, so two new machines can't
both redeem when only one can be saved.

Co-Authored-By: spade <bot@acehq.dev>
… cancelled

The fake fleet records what it was asked and answered. The test now
checks the build server issued one pairing, this computer was asked to
link with keep and answered exists, and that pairing was cancelled, so
a Link all that skipped the attempt fails it.

Co-Authored-By: spade <bot@acehq.dev>
…t a time

Co-Authored-By: spade <bot@acehq.dev>
…pt old names

Ids that differ only in case shared a payload file on a case-insensitive
volume, so cancelling one removed the other's upload. Files are now named
by the lowercase hex SHA-256 of the transfer id. On recovery, files an
earlier build named after the id move to the hashed names, in pages of
live rows (ADR 0170), and stray removal keeps every name a live row can
own, worked out from the rows, so no live transfer's file is deleted.

Co-Authored-By: spade <bot@acehq.dev>
…sing began

A begin waiting for a swept id's files could resume after close() and
insert a row. It now refuses as unavailable once closing has begun. The
shutdown test also checks close() is still pending while a removal is
held, so it fails without the join.

Co-Authored-By: spade <bot@acehq.dev>
Projects revoked while the first chunk's file was opening left an empty
payload file: the check right before the write refused, but the file was
already there. A file the refused call created is now removed.

Co-Authored-By: spade <bot@acehq.dev>
An ace from before keep drops the field unread, so a fill sent there
replaced its link. A machine's links answer now says it honours keep.
Before each fill, Link all reads the source machine's links again and
skips a gap that is already linked, and it sends keep only to a machine
that advertises it.

Co-Authored-By: spade <bot@acehq.dev>
…e honoured

Co-Authored-By: spade <bot@acehq.dev>
…l names

incoming-files.ts now owns the hashed names and the old ones. The size
cap, cancel, refusal and recovery tests build paths through it: before,
they looked at names no longer written, so they passed with the payload
still there. The recovery test now checks every old-named upload moved
to its own name and resumes at its offset.

Co-Authored-By: spade <bot@acehq.dev>
… names it

With dots in ids, x.ignored.part is x's ignored files or x.ignored's
code, and recovery visiting x first took it. Every live transfer's old
names are now gathered first; a file moves only when exactly one live
transfer's part names it. Any other stays, kept, and is logged.

Co-Authored-By: spade <bot@acehq.dev>
Recovery decides which files to keep from the live rows, page by page,
then removes the rest. A transfer begun meanwhile was not among them, so
its acknowledged chunk was deleted. A begin now waits, right before its
insert, until stray removal ends; chunks write only for rows that were
already live, so they need no wait. The hold covers the live rows' pages
and one directory listing.

Co-Authored-By: spade <bot@acehq.dev>
…inking

A Projects link another window made after the first read could still be
replaced on an older ace. Link all now reads that machine's links again
once the pairing is issued, right before the link request, and skips the
gap (cancelling the pairing) on any link there. What remains is the one
request's round trip, which only a machine that honours keep closes.

Co-Authored-By: spade <bot@acehq.dev>
…r ace re-read

Co-Authored-By: spade <bot@acehq.dev>
…have moved

Renaming files from an earlier build's names could take another
transfer's upload (an id equal to another's hash) and race a chunk.
Nothing is renamed now. At recovery, a live transfer with a part only
under its old name and none under its hashed name is cancelled with a
reason, so its sender starts it again. A name any live transfer owns is
never taken for an old one, and the old files go with the strays,
decided per file against the live names.

Co-Authored-By: spade <bot@acehq.dev>
An ace from before keep drops it unread, so a link it is sent could
replace one it holds, however late it was checked. Link all now skips
such a machine before issuing anything, and its toast says that machine
needs ace updated before Link all can link it. The re-read before the
link request is gone with the race it narrowed.

Co-Authored-By: spade <bot@acehq.dev>
@arpan404
arpan404 merged commit 47c7ecf into main Nov 19, 2026
1 check passed
arpan404 added a commit that referenced this pull request Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant