Skip to content

Commit 67a8c76

Browse files
committed
🧪 Tear down a cancelled transport, and stop printing tokens
Review of 6ce7173. The findings that do not depend on the blocked credential channel. **A cancelled transport now actually tears down.** Blocking the loopback remote after it accepted the credential — rather than suspending before `git()` — put a real Git child with a live authenticated connection under the halt, and it hung. Native Git runs its transport in `git-remote-http`, a grandchild that inherits this host's pipes, so signalling only the process XMD spawned left the helper holding them open and the `close` that teardown waits on never arrived. Each command now runs in a process group of its own and cancellation signals the group. The test that found it asserts the remote accepted a request, one session opened and one disposed, nothing retained, and a fresh acquisition afterwards. **Teardown is observed, not scanned for.** A prefix scan of the temporary directory is a claim about the whole machine, and two concurrent invocations would each see the other's. Sessions report their own working directories, and the suite watches the invocation it started. **No assertion prints a credential-shaped value.** Both precedence tests now map each token to an opaque source label and compare the label, so a failure says which source answered rather than what it answered with. **Replay reaches no session.** A completed `<PullRequest>` replays over a source whose `open()` throws, and never opens one. Blocked, and reported separately rather than worked around again: the HTTP credential channel (finding 1) and the classification and exact-locator evidence that depend on it (2 and 3). Git offers no opaque-capability channel to a native subprocess, so a broker lease cannot reach it without a mechanism no settled document specifies. Findings 5's crash fixture and host-assembly regression remain open. Refs #522
1 parent 6ce7173 commit 67a8c76

5 files changed

Lines changed: 273 additions & 93 deletions

File tree

‎packages/workflow/src/deno/composition/authentication.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,14 @@ function pinned(ssh: string, settings: readonly string[]): readonly string[] {
242242
*/
243243
export function configuredCredentialSettings(
244244
ambient: Readonly<Record<string, string | undefined>>,
245+
observe: GitAuthenticationObserver = {},
245246
): Operation<string[]> {
246247
return resource<string[]>(function* (provide) {
247248
const directory = yield* until(mkdtemp(join(tmpdir(), "xmd-workflow-credential-")));
249+
observe.opened?.(directory);
248250
yield* ensure(function* () {
249251
yield* until(rm(directory, { recursive: true, force: true }));
252+
observe.released?.(directory);
250253
});
251254

252255
const env: Record<string, string> = {};
@@ -335,9 +338,24 @@ function helperEnvironment(
335338
return environment;
336339
}
337340

341+
/**
342+
* What a session did with host resources, for a suite that has to prove it.
343+
*
344+
* A claim that nothing survives teardown needs something that counted, and
345+
* counting by scanning the temporary directory for a name prefix is a claim
346+
* about the whole machine rather than about this invocation — two concurrent
347+
* ones would each see the other's. So a session reports its own working
348+
* directories, and a suite watches the invocation it started.
349+
*/
350+
export interface GitAuthenticationObserver {
351+
opened?: (directory: string) => void;
352+
released?: (directory: string) => void;
353+
}
354+
338355
export interface GitAuthenticationOptions {
339356
/** The environment the ambient mechanisms are found in. */
340357
readonly ambient?: Readonly<Record<string, string | undefined>>;
358+
readonly observe?: GitAuthenticationObserver;
341359
}
342360

343361
/**
@@ -351,6 +369,7 @@ export interface GitAuthenticationOptions {
351369
*/
352370
export function denoGitAuthentication(options: GitAuthenticationOptions = {}): GitAuthentication {
353371
const ambient = options.ambient ?? process.env;
372+
const observe = options.observe ?? {};
354373
const ssh = sshCommand(ambient["HOME"], ambient["SSH_AUTH_SOCK"]);
355374

356375
return {
@@ -374,7 +393,7 @@ export function denoGitAuthentication(options: GitAuthenticationOptions = {}): G
374393
return;
375394
}
376395

377-
const settings = yield* configuredCredentialSettings(ambient);
396+
const settings = yield* configuredCredentialSettings(ambient, observe);
378397
yield* provide({
379398
attachment: {
380399
environment: helperEnvironment(ambient),

‎packages/workflow/src/deno/composition/subprocess.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import { ensure, type Operation, withResolvers } from "effection";
1313
import { spawn as spawnChild } from "node:child_process";
14+
import process from "node:process";
1415

1516
/** What one invocation reported. A nonzero exit is an answer, not a throw. */
1617
export interface ProcessOutcome {
@@ -46,7 +47,14 @@ export function* runProcess({
4647
// selected by the host, not written against one, and `spawn` replaces the
4748
// child's environment outright when `env` is given — which is the whole point
4849
// of building one rather than inheriting it.
49-
const options = { cwd, env: { ...env } };
50+
// `detached` puts the child in a process group of its own, which is what makes
51+
// cancellation reach the whole of what it started. Native Git runs its
52+
// transport in a helper of its own — `git-remote-http` holds the connection —
53+
// and that grandchild inherits these pipes. Signalling only the process this
54+
// spawned would leave the helper alive holding them open, so the `close`
55+
// waited for below would never arrive and a cancelled operation would hang
56+
// instead of tearing down.
57+
const options = { cwd, env: { ...env }, detached: true };
5058
const child =
5159
input === undefined
5260
? spawnChild(command, [...args], { ...options, stdio: ["ignore", "pipe", "pipe"] })
@@ -70,7 +78,16 @@ export function* runProcess({
7078
if (settled) {
7179
return;
7280
}
73-
child.kill("SIGKILL");
81+
// The group, so the transport helper goes with the command that started it.
82+
// A group that is already gone raises, and that is the same answer as a
83+
// group that was killed — the wait below is what decides either way.
84+
try {
85+
if (child.pid !== undefined) {
86+
process.kill(-child.pid, "SIGKILL");
87+
}
88+
} catch {
89+
child.kill("SIGKILL");
90+
}
7491
yield* closed.operation;
7592
});
7693

0 commit comments

Comments
 (0)