{"draft":null,"from":175,"to":318,"files":[{"path":"client/src/commands.ts","added":47,"removed":1,"diff":"--- a/client/src/commands.ts\n+++ b/client/src/commands.ts\n@@ -7,6 +7,7 @@\n // 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.\n import {\n \ttype Api,\n+\tApiError,\n \ttype Collision,\n \ttype FileChange,\n \ttype MergedLine,\n@@ -431,9 +432,54 @@\n  * overwritten.\n  */\n export async function syncFolder(root: string, api: Api, full = false): Promise<Applied> {\n-\treturn applyAnswer(root, api, await api.sync({ full }));\n+\tconst applied = await applyAnswer(root, api, await pullAnswer(root, api, full));\n+\tpullWritten(root);\n+\treturn applied;\n }\n \n+const PULLING_FILE = \"pulling.json\";\n+\n+/**\n+ * Whether a pull here asked the server and never wrote its answer (abso-core 26): it timed out, or stopped\n+ * partway. The server moved the agent's base when it answered, and later pulls send only what changed since\n+ * that base, so the files it would have written stay behind until a pull asks for every file.\n+ */\n+export function pullUnfinished(root: string): boolean {\n+\treturn existsSync(join(stateDir(root), PULLING_FILE));\n+}\n+\n+/**\n+ * Ask the server for a pull, noting first that one is under way, so a pull whose answer never gets written\n+ * leaves the note behind. With that note, or `full`, it asks for every file in the agent's view, which the\n+ * folder's own checks then write only where the folder differs. pullWritten takes the note away.\n+ */\n+export async function pullAnswer(root: string, api: Api, full = false): Promise<SyncAnswer> {\n+\tconst unfinished = pullUnfinished(root);\n+\twriteFileAtomic(join(stateDir(root), PULLING_FILE), `${JSON.stringify({ at: new Date().toISOString() })}\\n`);\n+\tif (!full && !unfinished) return api.sync();\n+\ttry {\n+\t\treturn await api.sync({ full: true });\n+\t} catch (err) {\n+\t\t// A server from before full pulls (501): the plain pull is still better than none.\n+\t\tif (unfinished && !full && err instanceof ApiError && err.status === 501) return api.sync();\n+\t\tthrow err;\n+\t}\n+}\n+\n+/** The pull's answer is written into the folder: take away pullAnswer's note. */\n+export function pullWritten(root: string): void {\n+\trmSync(join(stateDir(root), PULLING_FILE), { force: true });\n+}\n+\n+/** Status's line, and pull's when it caught up. */\n+export function pullUnfinishedText(root: string): string[] {\n+\treturn pullUnfinished(root)\n+\t\t? [\n+\t\t\t\t\"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.\",\n+\t\t\t]\n+\t\t: [];\n+}\n+\n /** What writing a sync or switch answer into the folder did. */\n export interface Applied {\n \treadonly version: number;"}],"unmatched":[]}