{"version":42,"agent":"speed","message":"client/launch.mjs follow-ups from review: reads the commit in a git worktree too (.git as a file, following gitdir and commondir; info/exclude in the shared folder); a stale lock is renamed aside before it's removed, and put back if it turns out to be live, so two runs can't both take it over; the README says to point it at a checkout nobody edits in; the tests remove their temporary folders.","time":1791550634480,"timeIso":"2026-10-09T12:57:14.480Z","changes":4,"change":543,"files":["client/README.md","client/launch.mjs","client/test/launch.test.ts"],"draft":null,"diff":[{"path":"client/README.md","added":3,"removed":0,"diff":"--- a/client/README.md\n+++ b/client/README.md\n@@ -27,6 +27,9 @@\n It never changes the command's output or exit code, and writes its own notices\n to `~/.abso/launcher.log`.\n \n+Point it at a clone or worktree that nobody edits in. The bundle is keyed on\n+the commit, so changes that aren't committed don't run until the next commit.\n+\n ## Setting up a folder\n \n Folders and machines set up before abso had its name keep working: the older "},{"path":"client/launch.mjs","added":52,"removed":12,"diff":"--- a/client/launch.mjs\n+++ b/client/launch.mjs\n@@ -24,7 +24,7 @@\n import { appendFileSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from \"node:fs\";\n import { createRequire } from \"node:module\";\n import { homedir } from \"node:os\";\n-import { dirname, join } from \"node:path\";\n+import { dirname, join, resolve } from \"node:path\";\n import { fileURLToPath, pathToFileURL } from \"node:url\";\n \n const repo = dirname(dirname(fileURLToPath(import.meta.url)));\n@@ -38,29 +38,69 @@\n /** Set by the bundle's first line: an error after it came from the command, so it's never run again. */\n const STARTED = \"__absoBundleStarted\";\n \n+/**\n+ * The checkout's git folders: its own (HEAD) and the shared one (refs, info/exclude). They are the same\n+ * folder in a plain clone; in a worktree .git is a file naming its own folder, which names the shared one.\n+ */\n+function gitDirs(root = repo) {\n+\tconst dot = join(root, \".git\");\n+\ttry {\n+\t\tif (statSync(dot).isDirectory()) return { own: dot, common: dot };\n+\t\tconst own = resolve(\n+\t\t\troot,\n+\t\t\treadFileSync(dot, \"utf8\")\n+\t\t\t\t.trim()\n+\t\t\t\t.replace(/^gitdir:\\s*/, \"\"),\n+\t\t);\n+\t\tlet common = own;\n+\t\ttry {\n+\t\t\tcommon = resolve(own, readFileSync(join(own, \"commondir\"), \"utf8\").trim());\n+\t\t} catch {}\n+\t\treturn { own, common };\n+\t} catch {\n+\t\treturn undefined;\n+\t}\n+}\n+\n /** The checkout's commit, read from .git without running git; undefined if it can't be read. */\n function headCommit(root = repo) {\n+\tconst dirs = gitDirs(root);\n+\tif (!dirs) return undefined;\n \ttry {\n-\t\tconst head = readFileSync(join(root, \".git\", \"HEAD\"), \"utf8\").trim();\n+\t\tconst head = readFileSync(join(dirs.own, \"HEAD\"), \"utf8\").trim();\n \t\tif (!head.startsWith(\"ref:\")) return head;\n \t\tconst ref = head.slice(4).trim();\n-\t\ttry {\n-\t\t\treturn readFileSync(join(root, \".git\", ...ref.split(\"/\")), \"utf8\").trim();\n-\t\t} catch {\n-\t\t\tconst line = readFileSync(join(root, \".git\", \"packed-refs\"), \"utf8\")\n-\t\t\t\t.split(\"\\n\")\n-\t\t\t\t.find((l) => l.endsWith(` ${ref}`));\n-\t\t\treturn line?.split(\" \")[0];\n+\t\tfor (const dir of [dirs.own, dirs.common]) {\n+\t\t\ttry {\n+\t\t\t\treturn readFileSync(join(dir, ...ref.split(\"/\")), \"utf8\").trim();\n+\t\t\t} catch {}\n \t\t}\n+\t\tconst line = readFileSync(join(dirs.common, \"packed-refs\"), \"utf8\")\n+\t\t\t.split(\"\\n\")\n+\t\t\t.find((l) => l.endsWith(` ${ref}`));\n+\t\treturn line?.split(\" \")[0];\n \t} catch {\n \t\treturn undefined;\n \t}\n }\n \n-/** Runs fn under a lock folder; a lock older than 10 minutes is a dead run's and is cleared. */\n+/**\n+ * Runs fn under a lock folder, or not at all when another run holds it. A lock older than 10 minutes is a\n+ * dead run's: it is renamed aside before it's removed, so of two runs that find it stale only one takes it\n+ * over, and one that renamed away a lock taken over a moment ago puts it back.\n+ */\n function locked(lock, fn) {\n+\tconst stale = (path) => Date.now() - statSync(path).mtimeMs > 10 * 60 * 1000;\n \ttry {\n-\t\tif (Date.now() - statSync(lock).mtimeMs > 10 * 60 * 1000) rmSync(lock, { recursive: true, force: true });\n+\t\tif (stale(lock)) {\n+\t\t\tconst aside = `${lock}.${process.pid}.stale`;\n+\t\t\trenameSync(lock, aside);\n+\t\t\tif (stale(aside)) rmSync(aside, { recursive: true, force: true });\n+\t\t\telse {\n+\t\t\t\trenameSync(aside, lock);\n+\t\t\t\treturn;\n+\t\t\t}\n+\t\t}\n \t} catch {}\n \ttry {\n \t\tmkdirSync(lock);\n@@ -124,7 +164,7 @@\n \t} catch {\n \t\treturn;\n \t}\n-\tconst exclude = join(repo, \".git\", \"info\", \"exclude\");\n+\tconst exclude = join(gitDirs()?.common ?? join(repo, \".git\"), \"info\", \"exclude\");\n \ttry {\n \t\tif (!readFileSync(exclude, \"utf8\").split(/\\r?\\n/).includes(\"client/dist/\"))\n \t\t\tappendFileSync(exclude, \"\\nclient/dist/\\n\");"},{"path":"client/test/launch.test.ts","added":39,"removed":2,"diff":"--- a/client/test/launch.test.ts\n+++ b/client/test/launch.test.ts\n@@ -3,16 +3,31 @@\n \n import assert from \"node:assert/strict\";\n import { execFileSync, spawnSync } from \"node:child_process\";\n-import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from \"node:fs\";\n+import {\n+\tcopyFileSync,\n+\texistsSync,\n+\tmkdirSync,\n+\tmkdtempSync,\n+\treaddirSync,\n+\treadFileSync,\n+\trmSync,\n+\tutimesSync,\n+\twriteFileSync,\n+} from \"node:fs\";\n import { tmpdir } from \"node:os\";\n import { join } from \"node:path\";\n-import { describe, it } from \"node:test\";\n+import { after, describe, it } from \"node:test\";\n \n const LAUNCH = new URL(\"../launch.mjs\", import.meta.url);\n+const roots: string[] = [];\n+after(() => {\n+\tfor (const root of roots) rmSync(root, { recursive: true, force: true });\n+});\n \n /** A checkout on main with one commit, launch.mjs and a stand-in client/abso.ts that names itself. */\n function checkout(): { repo: string; home: string; head: string } {\n \tconst root = mkdtempSync(join(tmpdir(), \"abso-launch-\"));\n+\troots.push(root);\n \tconst repo = join(root, \"repo\");\n \tconst home = join(root, \"home\");\n \tmkdirSync(join(repo, \"client\"), { recursive: true });\n@@ -127,6 +142,28 @@\n \t\tassert.equal(existsSync(lock), true);\n \t});\n \n+\tit(\"takes over a lock a dead run left behind, and removes it after\", () => {\n+\t\tconst c = checkout();\n+\t\tconst lock = join(c.home, \".abso\", \"client-update.lock\");\n+\t\tmkdirSync(lock);\n+\t\tconst old = new Date(Date.now() - 11 * 60 * 1000);\n+\t\tutimesSync(lock, old, old);\n+\t\tassert.equal(launch(c, [], { ABSO_LAUNCH_UPDATE: \"1\" }).status, 0);\n+\t\tassert.deepEqual(\n+\t\t\treaddirSync(join(c.home, \".abso\")).filter((f) => f.includes(\"lock\")),\n+\t\t\t[],\n+\t\t);\n+\t});\n+\n+\tit(\"reads the commit in a git worktree, where .git is a file\", () => {\n+\t\tconst c = checkout();\n+\t\tconst wt = join(c.repo, \"..\", \"wt\");\n+\t\texecFileSync(\"git\", [\"-C\", c.repo, \"worktree\", \"add\", \"-q\", \"--detach\", wt, \"HEAD\"]);\n+\t\tbundle(wt, NAMES_ITSELF, c.head);\n+\t\tconst r = launch({ repo: wt, home: c.home }, [\"status\"]);\n+\t\tassert.match(r.stdout, /^bundle /);\n+\t});\n+\n \tit(\"keeps the background step quiet when it can't fetch or build\", () => {\n \t\tconst c = checkout();\n \t\tconst r = launch(c, [], { ABSO_LAUNCH_UPDATE: \"1\" });"}],"ci":null}