Plan: a project’s jobs and plan draft follow it under either path
Closes: #843 (its memory part moves to #873). Relates to: #839 (the rule this reuses), #842 and #816 (left open, with the counts below). Branch: fix/project-by-either-path. Status: Done (2026-11-21) — as planned, with the errata below; not run: a real remote session on the patched build
Erratum (2026-11-21): the Context table’s 113 local job records was a tally by eye; counted with a tool there are 99. Every one is under the /home/… spelling, as the table says. Measured before merge: from /data/code/pi all 99 count as the project’s where the old rule counted none; the names are had in 1 to 3 ms locally and in 57 to 81 ms over SSH from the Windows box, against the 2 s bound. The anchor count asked for #842: the Windows box has five remote directories with two anchors each, every pair differing in the destination’s spelling as well as the path; no plan was made for it.
Erratum (2026-11-21): the job cases are in packages/pi-modes/test/job-sessions.test.ts, which drives sessions on real jobs, not job-tools.test.ts; one more regression is in packages/pi-modes/test/wiring.test.ts (plan mode entered from the other path names the found draft). The quit notice uses the names kept at the start only when they hold the quitting session’s directory, else that directory alone: an existing test quits from another directory.
Erratum (2026-11-21): two of the job cases need a mount table that names the test’s directories, which Windows paths cannot be; they are skipped there by the runner. Found by the Windows seat, where they failed.
Context
On luchs /data/code is bind-mounted at ~/code, so every project has two paths and nothing resolves one to the other (#839). Since 0.164.0 the messaging agent is named by the directory’s canonical path. Three other things still key on the path as spelled (#843): a job’s project, the plan draft, and the memory pool of a repository with no origin.
Counted on luchs, 2026-11-21, read-only:
| What | Count |
|---|---|
Local job records ( |
113, all |
Remote job records ( |
403, all under |
Plan drafts ( |
7 under the |
Checkouts under |
17; 15 distinct projects; 0 projects cloned once by https and once by ssh; 0 with no origin |
Memory records |
2 project records under one key, 4 box records |
SSH anchors on luchs |
1, a test’s |
So no state is split today. A session started from /data/code/pi would find no jobs to adopt and a blank plan draft, and that is the whole exposure. The operator’s choice (2026-11-21): narrow. Jobs and the draft answer to either spelling with nothing re-keyed; the path-keyed memory pool and #816 stay open with these counts; #842 is planned only if panther’s anchors turn out split.
Design
D1. The names a project directory has. New packages/pi-modes/project-names.ts:
projectNames(ws, root, waitMs = PROJECT_NAMES_WAIT_MS): Promise<string[]>. It asks canonicalOf(ws, root) (@gadhs/pi-workspace, the #839 rule: every spelling is checked by device and inode on the host the directory is on) and returns root first, then the canonical path and its aliases, without repeats. If the answer does not come within PROJECT_NAMES_WAIT_MS (2,000 ms, the bound the agent name uses) or the call throws, it returns [root]: today’s behaviour. Nothing is folded for case; Windows has no mount table and gets [root] plus the link-resolved path.
D2. Jobs: read by any name, written as today. In packages/pi-modes/job-tools.ts:
-
session_startcomputesnames = await projectNames(ws, ws.root)and keeps it onJobHosts(cleared byreset()). -
adoptJobstakes the names and keeps a job whennames.includes(job.project). -
The quit notice filters the same way, from the kept names; with none kept (a session whose start never ran the handler) it uses
[root]. -
executeJobstill recordsproject: ws.root, as spelled. Why: a record is read by sessions of earlier releases too, which compare by equality; an unchanged record keeps them working, and no stored record is rewritten.
D3. The plan draft: one per directory, found under any name. New packages/pi-modes/plan-draft-home.ts, holding a map from a session’s cwd to the spelling its draft is filed under:
-
resolveDraftHome(cwd, agentDir): Promise<void>, called atsession_start(session-wiring.ts,onSessionStart), not awaited there. It asksprojectNames(localWorkspace(cwd), cwd); the draft is local state, so the local workspace is asked even in a remote session, whosecwdis its anchor. Of the names whose draft file exists it takes the one written last; with none,cwd. -
draftHomeOf(cwd): string, synchronous; the map is keyed bypath.resolve(cwd), the form the carve already uses. It returns the pinned spelling. If none is pinned yet it pinscwdand returns it;resolveDraftHomenever replaces a pinned answer. So within one process acwdhas one draft path from the first time anything asks, and the write carve and the tools cannot disagree. -
draftHomeReady(cwd): Promise<void>settles when the resolution running forcwdhas (at once when none is).enterPlanMode(plan-tools.ts) awaits it before it asks, so the ordinary case uses the found draft. -
Every caller of
planDraftPath(cwd, agentDir)passesdraftHomeOf(cwd)instead ofcwd:plan-tools.ts(two),session-wiring.ts(three),authorize.ts(the carve’s allow). The carve’s refusal outside plan mode covers two paths, the pinned spelling’s draft and thecwdspelling’s, so the path refused today stays refused when another spelling is pinned; in plan mode only the pinned one is allowed and the other goes on to plan mode’s own rule, which denies it.planDraftPathandcwdSlugare unchanged, and so is the approval record beside the draft.
D4. Unchanged. The memory pool, gadhs-memory.json, the SSH anchor, pi’s own session directory (#844), the job record’s shape, the remote helper and its protocol.
Scope
In: packages/pi-modes/project-names.ts (new), packages/pi-modes/plan-draft-home.ts (new), packages/pi-modes/job-tools.ts, packages/pi-modes/plan-tools.ts, packages/pi-modes/session-wiring.ts, packages/pi-modes/authorize.ts; tests packages/pi-modes/test/project-names.test.ts (new), packages/pi-modes/test/plan-draft-home.test.ts (new), packages/pi-modes/test/job-tools.test.ts, packages/pi-modes/test/authorize.test.ts; docs/modules/ROOT/pages/modes.adoc; CHANGELOG.adoc.
Out:
-
The memory pool of a repository with no origin, keyed by its git directory’s path: 0 such checkouts here. Split from #843 into #873, with the count.
-
#816 (one pool for a project cloned two ways): 0 such pairs among 15 projects here. The count goes on the issue; it stays open.
-
#842 (two anchors for one remote directory): luchs holds no real anchor. The Windows seat is asked for panther’s count of anchors per remote directory; the count goes on #842, and a plan follows only if any directory has two.
-
A draft under each spelling merged into one: the newer is used, the older is left where it is.
Risks
| Risk | Mode | Mitigation |
|---|---|---|
A session adopts another project’s jobs, or is told of them |
fail-closed |
A name counts only if it has the directory’s device and inode ( |
The plan-draft carve allows a write to a file other than the session’s draft |
fail-closed |
The carve still allows exactly one path, |
The draft path changes mid-session, so the tool announces one file and the carve allows another |
fail-closed |
The first answer for a |
The names are not had in time (a slow remote), and a session misses jobs under the other spelling |
silent |
Bounded at 2 s, then |
A session of an earlier release does not see a job |
fail-open |
Records keep |
Drafts exist under both spellings and the older one is the one wanted |
silent |
The newer is used and the tool’s entry text names the path, as today; the other file is untouched and readable. Stated in |
A job’s end is told twice, by sessions at the two spellings |
fail-open |
Unchanged mechanism: a job’s end is marked told in its record by whichever session sees it first. Test: two sessions, one at each spelling, tell an ended job once between them. |
Tests
Unit (project-names.test.ts): luchs’s two mount lines verbatim give both spellings from either one, the asked root first; a path outside the bind gives itself; no mount table gives the root (and its link-resolved path when that differs); a workspace that throws gives [root].
Concurrency (project-names.test.ts, plan-draft-home.test.ts, fake timers): a workspace that never answers gives [root] at 2,000 ms and not before; a draftHomeOf made while the resolution is pending is kept after it settles.
Unit (plan-draft-home.test.ts): a draft under the other spelling is found; with drafts under both, the one written last; with none, cwd; a second resolveDraftHome for a pinned cwd changes nothing.
Regression, the cases that would have shown #843 (job-tools.test.ts): job records under /home/u/code/x, a session started in /data/code/x with that mount table: the running ones are watched and the ended ones told; the quit notice names them; a sibling’s are not; a job the session starts records its own root as spelled; two sessions at the two spellings tell an ended job once.
Regression (authorize.test.ts): with the draft home pinned to the other spelling, plan mode’s write to that draft is allowed and a write to the cwd spelling’s path is not carved (it returns no verdict); outside plan mode a write to either path is denied by the plan-draft rule, never passed to the judge.
A real bind mount: one test in project-names.test.ts makes one in a user namespace (unshare --user --map-root-user --mount, as packages/pi-workspace/test/canonical-path.test.ts does), skipped by the runner where that is refused; it asserts both spellings give the same set through the local workspace.
Measured before merge, prediction on file first, read-only on luchs: projectNames for /data/code/pi and for ~/code/pi each hold both; from /data/code/pi the 113 local records count as the project’s; the draft home from /data/code/pi is the --home-bitskrieg-code-pi-- file; the time projectNames takes locally, and over SSH from panther (the Windows seat), against the 2 s bound. The Windows seat also runs the pi-modes suite and confirms its own local names are unchanged.
Not tested: macOS; two btrfs subvolume mounts of one filesystem (not unified, as in #839).
Delivery
-
One branch, one MR: D1, then D2 and D3 with their tests.
-
Canonical doc:
modes.adoc, in the jobs section ("A session starts") and where the plan draft is described: a project is the directory, by whichever of its paths; the newer draft is used when both exist. -
CHANGELOG, under Unreleased, Fixed: a project reached through a bind mount has one set of jobs and one plan draft from either path.
-
node tools/task.mjs validate, fullconsumer-sim, the measurements above; MRCloses #843, merged with squash off; the merge SHA on the issue. -
At approval: the memory-pool issue filed; the counts noted on #816 and #842; the Windows seat asked for panther’s anchor count.
-
Released with the next release;
@gadhs/pi-modesand@gadhs/pimove (a patch).