Skip to content

Commit 6f78f96

Browse files
committed
fix(publication): require private throttle detail sink
1 parent f74ae5e commit 6f78f96

4 files changed

Lines changed: 135 additions & 10 deletions

File tree

‎docs/proof/github-egress-pool-coordinator/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ deployments, or credentials.
8888
- Target-App and disabled rollback calls still reach their independent loopback
8989
path while repository Actions is open; disabled rollback records the durable
9090
attempt before the wire call.
91+
- Failure to create an invocation-private throttle-header sink releases the
92+
started permit as unexecuted and defers without reaching GitHub.
9193
- Terminating the production runner forwards termination to its active `gh`
9294
child; the focused real-process regression observes the child receipt and a
9395
nonzero wrapper exit.

‎docs/proof/github-egress-pool-coordinator/run-proof.mjs‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,43 @@ try {
630630
assert.equal(targetApp.code, 0);
631631
assert.equal(targetApp.deferred, false);
632632

633+
const detailIsolationOutcomePath = path.join(scratch, "detail-isolation-outcome.json");
634+
await writeFile(detailIsolationOutcomePath, `${JSON.stringify({ kind: "eligible" })}\n`);
635+
const detailWorkerPort = await availablePort();
636+
const detailWorker = await startWorker(
637+
detailWorkerPort,
638+
path.join(scratch, "wrangler-detail-isolation-state"),
639+
path.join(scratch, "wrangler-detail-isolation.log"),
640+
);
641+
workers.push(detailWorker);
642+
await waitForWorker(detailWorker.origin);
643+
const beforeDetailIsolationFailure = totalRequests();
644+
const detailIsolationFailure = await runGithubEgressPoolCommand(
645+
proofGh,
646+
["api", "repos/proof-owner/proof-repo/issues/203/comments"],
647+
{
648+
env: {
649+
...runnerEnv,
650+
CLAWSWEEPER_GITHUB_POST_EFFECT_OUTCOME_PATH: detailIsolationOutcomePath,
651+
EXACT_REVIEW_QUEUE_URL: detailWorker.origin,
652+
GITHUB_RUN_ID: "9005",
653+
},
654+
isolateRateLimitDetails: () => null,
655+
},
656+
);
657+
assert.equal(detailIsolationFailure.code, GITHUB_EGRESS_POOL_DEFERRED_EXIT);
658+
assert.equal(detailIsolationFailure.deferred, true);
659+
assert.equal(totalRequests(), beforeDetailIsolationFailure);
660+
assert.equal(
661+
JSON.parse(await readFile(detailIsolationOutcomePath, "utf8")).postEffectsGithubAttempted,
662+
undefined,
663+
);
664+
const detailIsolationState = await coordinatorState(detailWorker.origin);
665+
assert.equal(detailIsolationState.permits_in_flight, 0);
666+
assert.equal(detailIsolationState.state, "closed");
667+
await stopWorker(detailWorker);
668+
workers.splice(workers.indexOf(detailWorker), 1);
669+
633670
const rollback = await runGithubEgressPoolCommand(
634671
proofGh,
635672
["api", "repos/proof-owner/proof-repo/issues/202/comments"],
@@ -703,6 +740,7 @@ try {
703740
target_app_independent: true,
704741
disabled_rollback_reaches_egress: true,
705742
disabled_rollback_preserves_attempt_accounting: true,
743+
detail_isolation_failure_requests_avoided: 1,
706744
public_privacy_scan_passed: true,
707745
},
708746
request_summary: requestSummary,

‎src/repair/github-egress-pool-runner.ts‎

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type RunnerRuntime = {
4040
args: readonly string[],
4141
env: NodeJS.ProcessEnv,
4242
) => Promise<CommandResult>;
43+
isolateRateLimitDetails?: typeof isolatedRateLimitDetails;
4344
};
4445

4546
type RunnerResult = CommandResult & { deferred: boolean };
@@ -131,9 +132,40 @@ export async function runGithubEgressPoolCommand(
131132
}
132133
if ("granted" in started) return deferredResult(env, now(), started);
133134

135+
const rateDetails = (runtime.isolateRateLimitDetails ?? isolatedRateLimitDetails)(env);
136+
if (!rateDetails) {
137+
const observedAt = now();
138+
const receiptId = digest(
139+
[
140+
"finish:v1",
141+
permit.permitId,
142+
permit.epoch,
143+
OPERATION_INDEX,
144+
"rate_detail_isolation_unavailable",
145+
observedAt,
146+
].join(":"),
147+
64,
148+
);
149+
try {
150+
await retryCoordinatorCall(() =>
151+
client.finish({
152+
permit,
153+
operationIndex: OPERATION_INDEX,
154+
receiptId,
155+
outcome: "unexecuted_failure",
156+
}),
157+
);
158+
} catch {
159+
// The started-permit TTL remains the final bound if the conservative
160+
// release acknowledgement is unavailable.
161+
}
162+
return deferredResult(env, observedAt, unavailableDeferral(observedAt, permit.epoch));
163+
}
164+
134165
try {
135166
markPostEffectAttempted(env);
136167
} catch {
168+
rateDetails.cleanup();
137169
const observedAt = now();
138170
const receiptId = digest(
139171
[
@@ -162,7 +194,6 @@ export async function runGithubEgressPoolCommand(
162194
return deferredResult(env, observedAt, unavailableDeferral(observedAt, permit.epoch));
163195
}
164196

165-
const rateDetails = isolatedRateLimitDetails(env);
166197
let result!: CommandResult;
167198
let executionError: unknown;
168199
let throttle: SanitizedThrottle | null = null;
@@ -428,7 +459,7 @@ function isolatedRateLimitDetails(env: NodeJS.ProcessEnv): {
428459
path: string | undefined;
429460
persist: () => void;
430461
cleanup: () => void;
431-
} {
462+
} | null {
432463
const sharedPath = env.CLAWSWEEPER_GITHUB_RATE_LIMIT_DETAILS_PATH?.trim();
433464
try {
434465
const root = mkdtempSync(join(tmpdir(), "clawsweeper-github-egress-pool-"));
@@ -451,14 +482,7 @@ function isolatedRateLimitDetails(env: NodeJS.ProcessEnv): {
451482
cleanup: () => rmSync(root, { recursive: true, force: true }),
452483
};
453484
} catch {
454-
const commandEnv = { ...env };
455-
delete commandEnv.CLAWSWEEPER_GITHUB_RATE_LIMIT_DETAILS_PATH;
456-
return {
457-
env: commandEnv,
458-
path: undefined,
459-
persist: () => {},
460-
cleanup: () => {},
461-
};
485+
return null;
462486
}
463487
}
464488

‎test/repair/github-egress-pool-runner.test.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,67 @@ test("disabled repository execution fails closed before wire when its attempt re
101101
assert.equal(executions, 0);
102102
});
103103

104+
test("enabled repository execution defers before wire when throttle-detail isolation is unavailable", async (t) => {
105+
const root = mkdtempSync(join(tmpdir(), "clawsweeper-pool-detail-unavailable-"));
106+
const attemptedOutcomePath = join(root, "attempted-outcome.json");
107+
const observationPath = join(root, "rate-observations.jsonl");
108+
writeFileSync(attemptedOutcomePath, `${JSON.stringify({ kind: "eligible" })}\n`);
109+
t.after(() => rmSync(root, { recursive: true, force: true }));
110+
const secret = "detail-unavailable-secret";
111+
const now = Date.parse("2026-08-13T03:15:00Z");
112+
const operations: string[] = [];
113+
const coordinator = new GithubEgressPoolCoordinator(
114+
{ storage: new MemoryDurableStorage() },
115+
{},
116+
{ now: () => now, random: () => 0, permitId: () => "detail-unavailable-permit" },
117+
);
118+
let wireCalls = 0;
119+
const result = await runGithubEgressPoolCommand("gh", ["api", "rate_limit"], {
120+
env: {
121+
CLAWSWEEPER_REPOSITORY_POOL_COORDINATOR_ENABLED: "true",
122+
CLAWSWEEPER_GITHUB_POOL_CLASS: "repository_actions",
123+
CLAWSWEEPER_GITHUB_POST_EFFECT_OUTCOME_PATH: attemptedOutcomePath,
124+
CLAWSWEEPER_GITHUB_RATE_LIMIT_OBSERVATION_PATH: observationPath,
125+
EXACT_REVIEW_QUEUE_URL: "https://clawsweeper.test",
126+
CLAWSWEEPER_WEBHOOK_SECRET: secret,
127+
},
128+
fetch: async (input: RequestInfo | URL, init?: RequestInit) => {
129+
const request = input instanceof Request ? input : new Request(input, init);
130+
const body = await request.text();
131+
const operation = new URL(request.url).pathname.split("/").at(-1) ?? "";
132+
operations.push(operation);
133+
return coordinator.fetch(
134+
new Request(`https://pool.test/${operation}`, {
135+
method: "POST",
136+
headers: { "content-type": "application/json" },
137+
body,
138+
}),
139+
);
140+
},
141+
now: () => now,
142+
isolateRateLimitDetails: () => null,
143+
execute: async () => {
144+
wireCalls += 1;
145+
throw new Error("detail-sink failure reached GitHub");
146+
},
147+
});
148+
assert.equal(result.code, GITHUB_EGRESS_POOL_DEFERRED_EXIT);
149+
assert.equal(result.deferred, true);
150+
assert.equal(wireCalls, 0);
151+
assert.deepEqual(operations, ["acquire", "start", "finish"]);
152+
assert.equal(
153+
JSON.parse(readFileSync(attemptedOutcomePath, "utf8")).postEffectsGithubAttempted,
154+
undefined,
155+
);
156+
const observation = JSON.parse(readFileSync(observationPath, "utf8").trim());
157+
assert.equal(observation.coordinator_deferred, true);
158+
assert.equal(observation.retry_at, new Date(now + 5 * 60_000).toISOString());
159+
const state = await (
160+
await coordinator.fetch(new Request("https://pool.test/observability"))
161+
).json();
162+
assert.equal(state.permits_in_flight, 0);
163+
});
164+
104165
test(
105166
"wrapper termination reaches the on-wire GitHub CLI child",
106167
{ skip: process.platform === "win32" ? "POSIX workflow signal boundary" : false },

0 commit comments

Comments
 (0)