Plan: Remote execution phase 3 — the commit path on the seam
Closes: #491 (phase 3). Relates to: #488 (meta plan: plans/remote-execution.adoc), #498 (2c), #492 (phase 4). Branch: feat/workflow-on-the-seam. Status: Done (2026-10-26) — implemented as planned, with the errata below
Design
What this phase is for
Phase 2c made a remote project a pi session and refused git commit there, because the guard reads a local checkout that an anchor is not. This phase makes the guard read the checkout where it is. "Functions identically" (the meta plan) means: the same refusals, the same review, the same snapshot and declared context, the same trailers, whether the checkout is on this machine or on dev@box.
The shape: a pure core and one async shell
pi-workflow’s guard mixes two things in the same functions: deciding (what a command line commits, whether a message is well-formed, whether a relocation leaves the checkout, which trailer to splice) and reading (the index, .git/HEAD, a -F file, AGENTS.md at HEAD). Fifty-three functions touch node:fs or execFileSync directly or through a callee (call-graph count, 2026-10-26), most of them only because a pure decision takes a cwd and reads inline.
Two shapes were weighed. A synchronous facade over a worker thread (Atomics.wait on a SharedArrayBuffer) keeps every signature and every test, and is rejected: it blocks pi’s main thread for each remote round trip, so the TUI freezes and the lone-Esc patch (#483), which needs a free event loop, regresses; and the worker cannot reach the session’s connection, which lives in the main thread’s slot, so it would open a second one. It preserves the look of the code by hiding that the guard now does network I/O. An await on all fifty-three propagates the tangle. So:
-
The core stays synchronous and pure.
validateMessage,attributed,stagesAndCommits,nestedCommit,noVerifyBackstop,textFindCommits, the structural parsers, `commitTargetOf’s policy, `splitApprovedPlan’s arithmetic: untouched, or given the fact they used to read. A pure function receives facts (text already read, a layout already found) and returns a decision. -
One async shell per module gathers the facts through
Workspace(packages/pi-workspace/types.ts:readFile,readCappedwith workspace-read’s never-truncated rule,stat,lstat,realpath,readdir,git(args, cwd, options)), fromworkspaceFor(ctx.cwd): the local implementation in a local session, the SSH one in a remote session. The shell is whereawaitlives, and it is thin. -
The public functions keep their names and gain
wsandasync, soindex.tsand the tests change by anawaitand an argument, while the decision they wrap is also exported pure for new tests to drive with hand-built facts. Nothing defaultswssilently: the caller names the workspace.
The facts, module by module
| Module | Reads today | On the seam |
|---|---|---|
|
|
|
|
|
|
|
|
Pure |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
orchestrates the above; 2c’s |
Passes |
|
|
Computes |
Not moved, because they read local state by design (meta plan): glab-ambient.ts, plan-pause.ts’s draft read, `workflow-config.ts, `batch-order.ts’s settings.
One addition to the seam. Workspace.home(): Promise<string>: the host’s home directory, for followCd’s bare `cd and ~ (git-guard.ts:331-341), which today read this machine’s. Local: os.homedir(). SSH: the hello already carries home (protocol.ts:20), so sshWorkspace answers from it with no protocol change. The contract suite gains the case (equal to os.homedir() for the local implementation; equal to the hello’s for the helper over pipes).
What a commit over SSH then does
The agent runs git commit -F .gadhs-commit-msg through bash, which 2b runs on the remote. At tool_call, the shell reads the remote checkout’s facts, the message file on the remote, the staged diff and stat from the remote index, the declared context from the remote index, and AGENTS.md at the remote HEAD. The reviewer’s snapshot tools read the remote index. The guard’s mutation splices the trailers into the command text, which then runs on the remote, where the repository’s own hooks run. The verdict and the ledger key are what they would be for the same index on this machine.
Behaviour held equal, and how
-
The existing suites are the contract for local behaviour. They change by
awaitand awsargument only, and that is checked: a script over the test diff counts the changed lines and fails the MR when a change is anything but an addedawait/async, awsargument, or a hand-built fact where a test used to lean on implicit I/O; the exceptions are listed in the commit message. -
The same suites run against the SSH workspace.
test/workspace-under-test.tsreturnslocalWorkspace(cwd)or, underGADHS_PI_WORKFLOW_TEST_WS=ssh,sshWorkspaceover the pipe transport (@gadhs/pi-ssh/test/transports.ts’s helper over pipes, root and anchor the same local path) for the same real repositories the suites build. `node tools/task.mjs validateruns pi-workflow’s suite in both modes. A behaviour that differs between the two fails here, by name. -
Security (contract): with a remote workspace published for the session’s cwd,
git commit -m 'feat: x'throughbashis reviewed (the reviewer sees the remote’s staged diff and the message), refused for a--no-verify, refused onmain, and attributed with the trailers;git commitfrom a local session is unchanged. Containment of a-Fpath and of declared context holds through the remote’s real paths (a link out of the checkout is refused as it is locally). -
Regression: the 2c test "a commit in a remote session is refused" is replaced by "a commit in a remote session is guarded as a local one".
-
No test is weakened: a case that today asserts a synchronous throw asserts the rejection.
Fail modes
-
The link is down at the guard:
ws.gitand the reads fail; the staged state is unknown, which the guard already treats as a pause-and-retry refusal (UNKNOWN_STAGED), never a pass (fail-closed, loud: the refusal names the loss). -
A read is truncated on the remote (
ExecResult.truncated): read as unknown, asmaxBufferis today (fail-closed). -
A
-Ffile or declared path resolves outside the remote checkout: refused, as locally (fail-closed). -
The reviewer’s snapshot exhausts its budget over a slow link: the review answers from what it has, as today (fail-open on detail, disclosed in the review’s reads).
Scope
In
-
packages/pi-workspace/:types.ts(home()),local.ts,contract.ts, README. -
packages/pi-ssh/:ssh-workspace.ts(home()from the hello). -
packages/pi-workflow/: the modules in the table;test/workspace-under-test.ts; every test file that calls a shell function (awaitandws); new tests for the pure core (scanCommits,relocationTargets/elsewhereVerdict,decideCommitwith hand-builtRepoFacts); the security contract above intest/extension-wiring.test.ts;package.jsondevDependency@gadhs/pi-sshfor the pipe transport. -
tools/task.mjs:validateruns pi-workflow’s suite twice, local andssh. -
tools/or the commit: the test-diff check for this MR (a script run once, its output quoted in the commit message; not a permanent gate). -
Mutation check: each refusal’s read moved to the seam (branch on
main,--no-verify, a-Foutside the checkout, a stale-Fwritten earlier on the line, an elsewhere relocation throughcd ~, an untracked declared file), the truncation-as-unknown rule, a scratch root absent on the host; each killed before the MR, under both workspaces. -
Docs:
modes.adoc"Workflow guards" gains one paragraph (the guard reads the session’s workspace, local or SSH);ssh.adocdrops the commit limitation and gains the round-trip note;packages.adoc’s pi-workflow and pi-workspace rows; `architecture.adoc’s pi-workflow line; `CHANGELOG.adocChanged(where the guards read) andFixed(the refusal lifted); the meta plan’s phase-3 row stands, with an erratum naming the core/shell shape; ADR-006 one line (phase 3 lands the pure core/async shell split the Negative consequence foresaw). -
Delivery: one MR,
Closes #491,Relates to #488; the merge SHA on #488; phase 4 (#492) next.
Out
pi-modes' reads (phase 4, #492): count, generate_image, monitors, session facts, helper worktrees, detectLanguages. A sync facade or worker. Caching facts across calls. Changing any refusal’s wording or order. The reviewer’s model calls, which are not workspace reads.
Named but not supplied to the cold reviewer (the review budget is twelve files): CHANGELOG.adoc, docs/modules/ROOT/pages/{modes,ssh,packages,architecture}.adoc, docs/modules/ROOT/pages/adrs/adr-006-remote-execution.adoc, packages/pi-workflow/{review-rules,approved-plan,workspace-audit,git-dir,glab-ambient,workflow-config,batch-order}.ts, packages/pi-workflow/test/*, packages/pi-workspace/{local,contract}.ts, packages/pi-ssh/{protocol.ts,ssh-workspace.ts}, packages/pi-ssh/test/transports.ts, tools/task.mjs.
Erratum (2026-10-26): findCommits keeps the scan whole and synchronous (scanCommits), handed a NamedFiles lookup; the async findCommits runs it once with a recording lookup to learn which files its own logic names, resolves them on the host, and runs it again. This keeps the order of -m, -F, stdin and substitution settlement exactly as it was.
Erratum (2026-10-26): AuthoringDeps stays, as the required fact carrier with no filesystem default, instead of becoming a previous argument; pauseWrite reads the target through the workspace and hands it in, relative paths resolved against the session’s directory. The existing authoring tests already drove it with facts and are unchanged.
Erratum (2026-10-26): the workspace’s home is optional to the relocation walk: when the host cannot say, a cd or ~ that needs it is unknown (refused) and a plain commit carries on to the staged-state read, which holds it; a thrown handler, which pi also blocks on, would have shown an extension error instead of the guard’s reason.
Erratum (2026-10-26): readIndexed’s explicit truncation check is gone: output cut at cap + 1 bytes is over the cap by the length test after it (found equivalent by the mutation check).
Erratum (2026-10-26): the CHANGELOG replaces 2c’s unreleased "commit refused over SSH" entry with this phase’s `Changed entry instead of adding a Fixed one: both ship in one release, and the refusal never did.