Revert "fix(protocol): preserve gateway session attribution across node runs"

This reverts commit 735f176b01.
This commit is contained in:
joshavant
2026-08-07 13:57:45 -05:00
committed by Josh Avant
parent 75eeacd445
commit 026f4045b7
55 changed files with 622 additions and 3860 deletions
+6 -54
View File
@@ -95,11 +95,6 @@ const preparedPlan = vi.hoisted(() => ({
sha256: "abc123",
},
}));
const gatewayBoundPreparedPlan = {
...preparedPlan,
agentId: "requested-agent",
sessionKey: "requested-session",
};
const nodeCommandMarker = vi.hoisted(() => "=node-command:test");
const exactCommandMarker = (commandText: string): string =>
`=command:${crypto.createHash("sha256").update(commandText).digest("hex").slice(0, 16)}`;
@@ -361,7 +356,6 @@ function createNodeHostRequest(
type MockNodeInvokeParams = {
command?: string;
timeoutMs?: number;
sessionKey?: string;
params?: Record<string, unknown>;
};
@@ -1176,7 +1170,7 @@ describe("executeNodeHostCommand", () => {
expect(result.details?.status).toBe("approval-pending");
expect(requireRegisteredApprovalRequest()).toMatchObject({
systemRunPlan: gatewayBoundPreparedPlan,
systemRunPlan: preparedPlan,
toolCallId: "tool-node",
});
@@ -1188,15 +1182,11 @@ describe("executeNodeHostCommand", () => {
expect(call.options.timeoutMs).toBe(40_000);
expect(call.params?.timeoutMs).toBe(35_000);
expect(call.callOptions).toEqual({ scopes: ["operator.write", "operator.approvals"] });
expect(requireGatewayCommand("system.run.prepare").params?.sessionKey).toBe(
"requested-session",
);
expect(call.params?.sessionKey).toBe("requested-session");
const runParams = requireRunParams(call);
expect(runParams.approved).toBe(true);
expect(runParams.approvalDecision).toBe("allow-once");
expect(runParams.approvalSource).toBeUndefined();
expect(runParams.systemRunPlan).toEqual(gatewayBoundPreparedPlan);
expect(runParams.systemRunPlan).toEqual(preparedPlan);
expect(runParams.timeoutMs).toBe(30_000);
expect(runParams.turnSourceChannel).toBe("telegram");
expect(runParams.turnSourceTo).toBe("telegram:12345");
@@ -1205,38 +1195,6 @@ describe("executeNodeHostCommand", () => {
expect(resolveExecHostApprovalContextMock).toHaveBeenCalledTimes(2);
});
it("clears node-prepared attribution when the gateway request has none", async () => {
resolveExecHostApprovalContextMock.mockReturnValue({
approvals: { allowlist: [], file: { version: 1, agents: {} } },
hostSecurity: "full",
hostAsk: "always",
askFallback: "deny",
});
const result = await executeNodeHostCommand(
createNodeHostRequest({
agentId: undefined,
sessionKey: undefined,
}),
);
expect(result.details?.status).toBe("approval-pending");
expect(requireRegisteredApprovalRequest()).toMatchObject({
systemRunPlan: {
agentId: null,
sessionKey: null,
},
});
await vi.waitFor(() => {
expect(callGatewayToolMock).toHaveBeenCalledTimes(3);
});
expect(requireRunParams(requireGatewayCall(2)).systemRunPlan).toMatchObject({
agentId: null,
sessionKey: null,
});
});
it("forwards cancellation without removing detached node approval scopes", async () => {
const abortController = new AbortController();
resolveExecHostApprovalContextMock.mockReturnValue({
@@ -2003,8 +1961,8 @@ describe("executeNodeHostCommand", () => {
command: "rm -rf /tmp/work",
argv: ["rm", "-rf", "/tmp/work"],
agent: {
id: "requested-agent",
sessionKey: "requested-session",
id: "prepared-agent",
sessionKey: "prepared-session",
},
}),
);
@@ -2097,7 +2055,7 @@ describe("executeNodeHostCommand", () => {
expect(autoReviewer).not.toHaveBeenCalled();
expect(createAndRegisterDefaultExecApprovalRequestMock).not.toHaveBeenCalled();
expect(resolveExecApprovalsFromFileMock).toHaveBeenCalledWith(
expect.objectContaining({ agentId: "requested-agent" }),
expect.objectContaining({ agentId: "prepared-agent" }),
);
expectSystemRunInvoke({ invokeDeadlineMs: 35_000, invokeWaitMs: 40_000, runTimeoutMs: 30_000 });
});
@@ -3708,12 +3666,7 @@ describe("executeNodeHostCommand", () => {
FOO: "bar",
});
expect(requireGatewayCommand("system.run.prepare").params?.params?.cwd).toBe("/tmp/work");
expect(requireGatewayCommand("system.run.prepare").params?.sessionKey).toBe(
"requested-session",
);
const runCall = requireGatewayCommand("system.run");
expect(runCall.params?.sessionKey).toBe("requested-session");
const runParams = requireRunParams(runCall);
const runParams = requireRunParams(requireGatewayCommand("system.run"));
expect(runParams.env).toEqual({ FOO: "bar" });
expect(runParams.cwd).toBe("/tmp/work");
const evalEnvs = evaluateShellAllowlistMock.mock.calls.map(
@@ -3734,7 +3687,6 @@ describe("executeNodeHostCommand", () => {
const call = requireGatewayCall(0);
expect(call.options.timeoutMs).toBe(40_000);
expect(call.params?.timeoutMs).toBe(35_000);
expect(call.params?.sessionKey).toBe("requested-session");
const runParams = requireRunParams(call);
expect(runParams.command).toEqual(["/bin/sh", "-lc", "bun ./script.ts"]);
expect(runParams.rawCommand).toBe("bun ./script.ts");