Skip to content

Commit b639fab

Browse files
committed
🐛 Name a file by when it came into being, and read a directory as a set
The two failures CI found on this head, and nothing else. **An owner's exit removed a replacement it had never published.** `same()` identified a published attachment file by device and inode. An inode number is reused, and ext4 on the runner did reuse one: the file this owner wrote was unlinked, a replacement was created in its place and was handed the same number, and the exit took it away. `ENOENT` on the read that followed, in both the Deno and the Bun job. The correction is the one the dependent layout branch already carries, taken whole and unchanged: the moment a file came into existence is part of its identity. Measured here — a creation time is reported, an untouched file keeps it, and a file created after another was unlinked does not share it. Strictly stricter, so it can only ever leave a name alone and never remove one this owner did not publish. This host does not reuse inodes eagerly and so cannot reproduce the failure itself; the preserved run logs are that evidence. **A directory was read as a list.** `readdir` of `.acpx` was compared to a literal pair in one order, and a runner handed the two names back the other way round. It is sorted now, exactly as the assertion above it already was: what this row is about is which names are there, and a directory promises nothing about the order it enumerates them in. The membership is unchanged and nothing is skipped, slept on or excluded.
1 parent b60e58d commit b639fab

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎packages/cli/src/sidekick-acp/posix.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,26 @@ function closeSocket(socket: Socket): Operation<void> {
5757
return () => socket.off("close", closed);
5858
});
5959
}
60+
/**
61+
* Whether these two readings are of the same file, and not merely of the same
62+
* name and number.
63+
*
64+
* An inode number is reused. A file this owner published, unlinked by somebody
65+
* else, and a new file created in its place can be handed the number the first
66+
* one had — on Linux commonly, and ext4 in CI did exactly that: the owner's
67+
* exit removed a replacement it had never published, and the name it was asked
68+
* to leave alone was gone. macOS does not reuse as eagerly, which is why one
69+
* host saw it and the other did not.
70+
*
71+
* So the moment the file came into existence is part of its identity. An
72+
* unchanged file keeps it — measured, two readings of one untouched file agree
73+
* — and a file created after another was unlinked cannot share it. Stricter
74+
* rather than looser: it can only ever leave a name alone, never remove one
75+
* this owner did not publish. Where a filesystem reports no creation time both
76+
* readings carry the same substitute and this is the pair it always was.
77+
*/
6078
function same(a: Stats, b: Stats): boolean {
61-
return a.dev === b.dev && a.ino === b.ino;
79+
return a.dev === b.dev && a.ino === b.ino && a.birthtimeMs === b.birthtimeMs;
6280
}
6381
function* removeOwned(path: string, identity: Stats | undefined): Operation<void> {
6482
if (identity === undefined) {

‎packages/cli/tests/session-ownership-cli.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,11 @@ describe("Session ownership command", () => {
325325
).join();
326326
expect(plugin.code).toBe(1);
327327
expect((yield* until(readdir(work))).sort()).toEqual(["poison.cjs", "poison.ts", "session"]);
328-
expect(yield* until(readdir(join(home, ".acpx")))).toEqual([
328+
// Sorted, like the directory above it: what this asserts is exactly which
329+
// names are there, and a directory does not promise the order it hands
330+
// them back in. Measured, one runner enumerated these two the other way
331+
// round and the membership was the membership either way.
332+
expect((yield* until(readdir(join(home, ".acpx")))).sort()).toEqual([
329333
"config.json",
330334
"xmd-native-sessions",
331335
]);

0 commit comments

Comments
 (0)