Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
show on this site's /mcp
CLI
abso show 280 --json
JSON
/christopher/abso-core/versions/280?format=json

A pull whose answer never arrives no longer leaves the folder behind

of shared·pinch··Not checked

The server moves the agent's base when it answers a pull, and later pulls send only what changed since that base. When the answer was lost (a timeout on a slow server), the files it carried were never written, and every later pull, status, restore and export agreed the folder was current.

Now the client notes a pull in .abso/pulling.json before asking, and takes the note away once the answer is written. While the note is there, abso status says a pull didn't finish, and the next pull asks for every file in the view (as pull --full does) and writes the ones that differ, keeping work done in the folder meanwhile, as every pull does. follow, draft switching and draft-pull pull the same way. A server without full pulls gets a plain pull.

Tests: client/test/lost-pull.test.ts (a fake server that carries out a pull and drops its answer), plus held-push, join-signed-out and record-batches: 19 pass. tsc and Biome clean.

Version 279 · Files at version 280

7 files, 171 lines added, 5 removed.

--- a/client/src/commands.ts
+++ b/client/src/commands.ts
@@ -7,6 +7,7 @@
77// The engine's own key, so both sides match spellings the same way (#49). Not in core.ts: the edit mod installs core.ts alone.
88import {
99 type Api,
10+ ApiError,
1011 type Collision,
1112 type FileChange,
1213 type MergedLine,
@@ -431,9 +432,54 @@
431432 * overwritten.
432433 */
433434export async function syncFolder(root: string, api: Api, full = false): Promise<Applied> {
434− return applyAnswer(root, api, await api.sync({ full }));
435+ const applied = await applyAnswer(root, api, await pullAnswer(root, api, full));
436+ pullWritten(root);
437+ return applied;
435438}
436439
440+const PULLING_FILE = "pulling.json";
442+/**
443+ * Whether a pull here asked the server and never wrote its answer (abso-core 26): it timed out, or stopped
444+ * partway. The server moved the agent's base when it answered, and later pulls send only what changed since
445+ * that base, so the files it would have written stay behind until a pull asks for every file.
446+ */
447+export function pullUnfinished(root: string): boolean {
448+ return existsSync(join(stateDir(root), PULLING_FILE));
449+}
451+/**
452+ * Ask the server for a pull, noting first that one is under way, so a pull whose answer never gets written
453+ * leaves the note behind. With that note, or `full`, it asks for every file in the agent's view, which the
454+ * folder's own checks then write only where the folder differs. pullWritten takes the note away.
455+ */
456+export async function pullAnswer(root: string, api: Api, full = false): Promise<SyncAnswer> {
457+ const unfinished = pullUnfinished(root);
458+ writeFileAtomic(join(stateDir(root), PULLING_FILE), `${JSON.stringify({ at: new Date().toISOString() })}\n`);
459+ if (!full && !unfinished) return api.sync();
460+ try {
461+ return await api.sync({ full: true });
462+ } catch (err) {
463+ // A server from before full pulls (501): the plain pull is still better than none.
464+ if (unfinished && !full && err instanceof ApiError && err.status === 501) return api.sync();
465+ throw err;
466+ }
467+}
469+/** The pull's answer is written into the folder: take away pullAnswer's note. */
470+export function pullWritten(root: string): void {
471+ rmSync(join(stateDir(root), PULLING_FILE), { force: true });
472+}
474+/** Status's line, and pull's when it caught up. */
475+export function pullUnfinishedText(root: string): string[] {
476+ return pullUnfinished(root)
477+ ? [
478+ "A pull here didn't finish (its answer never arrived or wasn't written), so files may be behind this folder's base. abso pull fetches every file and writes the ones that differ.",
479+ ]
480+ : [];
481+}
437483/** What writing a sync or switch answer into the folder did. */
438484export interface Applied {
439485 readonly version: number;
--- a/client/src/drafts.ts
+++ b/client/src/drafts.ts
@@ -19,6 +19,8 @@
1919 type Output,
2020 open,
2121 plural,
22+ pullAnswer,
23+ pullWritten,
2224 recordedFirst,
2325 recordFolder,
2426} from "./commands.ts";
@@ -57,9 +59,10 @@
5759 note(answer.files);
5860 const switched = await applyAnswer(root, api, answer);
5961 // The switch brings back the space as it was when parked; sync straight away so the folder shows it as it is now (#22).
60− const syncAnswer = await api.sync();
62+ const syncAnswer = await pullAnswer(root, api);
6163 note(syncAnswer.files);
6264 const synced = await applyAnswer(root, api, syncAnswer);
65+ pullWritten(root);
6366 const touched = new Set([...switched.written, ...switched.deleted, ...synced.written, ...synced.deleted]);
6467 const written: string[] = [];
6568 const deleted: string[] = [];
@@ -148,7 +151,8 @@
148151 const moved = await api.draftSync();
149152 // Bring the moved draft's new view into this folder straight away.
150153 const recorded = await recordFolder(root, api);
151− const applied = await applyAnswer(root, api, await api.sync());
154+ const applied = await applyAnswer(root, api, await pullAnswer(root, api));
155+ pullWritten(root);
152156 const lines = [
153157 `Moved draft ${moved.draft} onto shared version ${moved.sharedBase} (the draft is at version ${moved.version}).`,
154158 ...recordedFirst(recorded),
--- a/client/src/publish-commands.ts
+++ b/client/src/publish-commands.ts
@@ -13,6 +13,7 @@
1313 FOLDER_LOG_LIMIT,
1414 LISTED,
1515 meantBinary,
16+ pullUnfinished,
1617 READER_REFUSES,
1718 recordedFirst,
1819 recordFolder,
@@ -621,6 +622,8 @@
621622 const { root, api } = open(env);
622623 const recorded = await recordFolder(root, api);
623624 const ignoredDropped = await dropIgnoredFromDraft(root, api);
625+ // A pull here that never wrote its answer (abso-core 26): this one asks for every file to catch up.
626+ const catchingUp = pullUnfinished(root) && !bool(args, "full");
624627 const s = await syncFolder(root, api, bool(args, "full"));
625628 const changes = s.written.length + s.deleted.length;
626629 // A renamed file is one line, not an update and a delete.
@@ -632,6 +635,9 @@
632635 ...droppedIgnoredText(ignoredDropped),
633636 `Pulled to version ${s.version}: ${changes === 0 ? "no files changed" : `${plural(updated.length, "file")} updated, ${removed.length} deleted${s.renamed.length > 0 ? `, ${s.renamed.length} renamed` : ""}`}.`,
634637 ...changedFilesText("pull", updated, removed, s.renamed, bool(args, "verbose")),
638+ ...(catchingUp
639+ ? ["The last pull here didn't finish, so this one asked for every file and wrote the ones that differed."]
640+ : []),
635641 ...refusedText(s.refused),
636642 // Ones an earlier sync couldn't write; this sync's are named just above.
637643 ...unwrittenText(s.unwritten, new Set(s.refused.map((r) => r.path))),
--- a/client/src/status-commands.ts
+++ b/client/src/status-commands.ts
@@ -14,6 +14,7 @@
1414import {
1515 LISTED,
1616 leftOutText,
17+ pullUnfinishedText,
1718 READER_REFUSES,
1819 readUnwritten,
1920 recordedFirst,
@@ -349,6 +350,7 @@
349350 ...modsBehindText(env.env),
350351 ...missingText(missing),
351352 ...unwrittenText(unwritten),
353+ ...pullUnfinishedText(root),
352354 ...(crlf.length > 0
353355 ? [
354356 `${plural(crlf.length, "file")} differ${crlf.length === 1 ? "s" : ""} from what abso recorded only in line endings (CRLF here; abso records and abso run sends LF). Harmless; abso fix-eol rewrites ${crlf.length === 1 ? "it" : "them"} with LF.`,
--- a/client/src/versions.ts
+++ b/client/src/versions.ts
@@ -3,7 +3,18 @@
33
44import type { VersionRef } from "./api.ts";
55import { bool, type Parsed, str, UsageError } from "./args.ts";
6−import { applyAnswer, collisionText, type Env, EXIT, type Output, open, plural, recordFolder } from "./commands.ts";
6+import {
7+ applyAnswer,
8+ collisionText,
9+ type Env,
10+ EXIT,
11+ type Output,
12+ open,
13+ plural,
14+ pullAnswer,
15+ pullWritten,
16+ recordFolder,
17+} from "./commands.ts";
718import { writeConfig } from "./config.ts";
819import { refusedText } from "./safety.ts";
@@ -144,7 +155,8 @@
144155 // Sync now (recording first, as sync does), so the folder is where it now says it is.
145156 const { api } = open(env);
146157 await recordFolder(root, api);
147− const s = await applyAnswer(root, api, await api.sync());
158+ const s = await applyAnswer(root, api, await pullAnswer(root, api));
159+ pullWritten(root);
148160 const changes = s.written.length + s.deleted.length;
149161 const head = follow
150162 ? `This folder now follows label ${follow}: every pull takes it to the newest version with that label. It is on version ${s.version}.`
--- a/client/test/fake-server.ts
+++ b/client/test/fake-server.ts
@@ -89,6 +89,8 @@
8989 queueHold: boolean;
9090 /** The next publish: commit it and answer 500 ('after'), or answer 500 without it ('before'), as a storage reset does. */
9191 failPublish: "after" | "before" | undefined;
92+ /** How many of the next pulls to carry out and then cut before answering, as an answer that never arrives (abso-core 26). */
93+ loseSyncAnswers: number;
9294 /** Run the merge queue's rounds now (after queueHold is let go). */
9395 kickQueue(name: string): Promise<void>;
9496 /** Each run POST's X-Abso-Run-Key, and whether a run started for it. */
@@ -155,6 +157,7 @@
155157 boxExtra: undefined,
156158 queueHold: false,
157159 failPublish: undefined,
160+ loseSyncAnswers: 0,
158161 kickQueue: async () => {},
159162 close: async () => {},
160163 };
@@ -632,6 +635,11 @@
632635 ...(typeof body.label === "string" ? { label: body.label } : {}),
633636 ...(body.full === true ? { full: true } : {}),
634637 });
638+ if (fake.loseSyncAnswers > 0) {
639+ fake.loseSyncAnswers--;
640+ res.destroy();
641+ return;
642+ }
635643 const extra = fake.injectSync;
636644 fake.injectSync = undefined;
637645 if (extra === undefined) return send(res, 200, synced);
--- /dev/null
+++ b/client/test/lost-pull.test.ts
@@ -0,0 +1,88 @@
1+// A pull whose answer never arrives (abso-core 26): the server has moved the agent's base, so later pulls
2+// send only what changed since then. The folder notes the pull it started and, until one is written, the
3+// next pull asks for every file and writes the ones that differ. Status says so in the meantime.
4+
5+import assert from "node:assert/strict";
6+import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
7+import { tmpdir } from "node:os";
8+import { join } from "node:path";
9+import { after, before, describe, it } from "node:test";
10+import { main } from "../src/main.ts";
11+import { type Fake, startFake } from "./fake-server.ts";
13+const TOKEN = "test-token-not-secret";
14+const ENV = { AVCS_TOKEN: TOKEN, AVCS_HOOK_FORCE: "1", AVCS_SERVERS_FILE: "no-servers.json" };
16+let fake: Fake;
17+const dirs: string[] = [];
18+before(async () => {
19+ fake = await startFake(0, TOKEN);
20+});
21+after(async () => {
22+ await fake.close();
23+ for (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });
24+});
26+function temp(): string {
27+ const d = mkdtempSync(join(tmpdir(), "abso-lost-pull-"));
28+ dirs.push(d);
29+ return d;
30+}
32+async function run(cwd: string, ...argv: string[]): Promise<{ exit: number; out: string }> {
33+ const r = await main(argv, { cwd, env: ENV, write: () => {} });
34+ return { exit: r.exit, out: r.stdout + r.stderr };
35+}
37+let projects = 0;
38+/** alice and bob on one project; alice pushes a change and a new file, and bob's pull of them is lost. */
39+async function lost(): Promise<{ alice: string; bob: string }> {
40+ const name = `lost${++projects}`;
41+ const alice = temp();
42+ writeFileSync(join(alice, "a.txt"), "one\n");
43+ assert.equal(
44+ (await run(alice, "init", "--server", fake.url, "--project", name, "--agent", "alice", "--as-is")).exit,
45+ 0,
46+ );
47+ const bob = temp();
48+ assert.equal((await run(bob, "join", name, "--agent", "bob", "--server", fake.url)).exit, 0);
49+ writeFileSync(join(alice, "a.txt"), "two\n");
50+ writeFileSync(join(alice, "b.txt"), "new\n");
51+ const pushed = await run(alice, "push", "-m", "Change a.txt and add b.txt");
52+ assert.equal(pushed.exit, 0, pushed.out);
53+ fake.loseSyncAnswers = 1;
54+ assert.notEqual((await run(bob, "pull")).exit, 0, "the pull whose answer was lost fails");
55+ return { alice, bob };
56+}
58+const text = (dir: string, rel: string) => readFileSync(join(dir, rel), "utf8");
60+describe("a pull whose answer never arrives", () => {
61+ it("leaves the folder as it was, and status says a pull didn't finish", async () => {
62+ const { bob } = await lost();
63+ assert.equal(text(bob, "a.txt"), "one\n");
64+ assert.equal(existsSync(join(bob, "b.txt")), false);
65+ const status = await run(bob, "status");
66+ assert.match(status.out, /A pull here didn't finish/);
67+ });
69+ it("the next pull asks for every file and writes what the lost one would have", async () => {
70+ const { bob } = await lost();
71+ const pulled = await run(bob, "pull");
72+ assert.equal(pulled.exit, 0, pulled.out);
73+ assert.match(pulled.out, /The last pull here didn't finish, so this one asked for every file/);
74+ assert.equal(text(bob, "a.txt"), "two\n");
75+ assert.equal(text(bob, "b.txt"), "new\n");
76+ assert.doesNotMatch((await run(bob, "status")).out, /A pull here didn't finish/);
77+ const again = await run(bob, "pull");
78+ assert.doesNotMatch(again.out, /didn't finish/, "once caught up, pulls are plain again");
79+ });
81+ it("keeps work done in the folder meanwhile", async () => {
82+ const { bob } = await lost();
83+ writeFileSync(join(bob, "a.txt"), "bob's own\n");
84+ const pulled = await run(bob, "pull");
85+ assert.equal(text(bob, "a.txt"), "bob's own\n", pulled.out);
86+ assert.equal(text(bob, "b.txt"), "new\n");
87+ });
88+});