Skip to content

Commit bf65dec

Browse files
committed
Validate profile capability before cleanup
1 parent 8b963a4 commit bf65dec

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎agents/adapters/supervisor.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { execFile, spawn, type ChildProcess } from 'node:child_process';
22
import type { InvocationHandle, InvocationInput, InvocationResult, StopReason } from '../contract.ts';
33
import { assertPhasePolicy } from '../policy.ts';
44
import { createValidatedContainer, disposeValidatedContainer, validateContainer } from '../container/run.ts';
5-
import type { ContainerProfile } from '../container/profile.ts';
5+
import { assertContainerProfileAuthenticity, type ContainerProfile } from '../container/profile.ts';
66
import { removeVendorNetwork, type VendorNetwork } from '../network/network.ts';
77

88
export const OUTPUT_LIMITS = Object.freeze({
@@ -202,6 +202,7 @@ export function isInvocationActive(attemptId: string): boolean {
202202
}
203203

204204
export function startProfileInvocation(profile: ContainerProfile, options: SupervisorOptions = {}): InvocationHandle {
205+
assertContainerProfileAuthenticity(profile);
205206
const invocation = assertPhasePolicy(profile.policy);
206207
const rejectWithCleanup = (error: unknown, register = true): InvocationHandle => {
207208
try { disposeValidatedContainer(profile); }

‎agents/container/profile.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ const captureInput = (directory: string): InputCapture => {
127127
return Object.freeze({ inputDirectory: canonical, schema, content: captured.content });
128128
};
129129

130+
/** Prove that a profile object is the exact capability issued by this module. */
131+
export function assertContainerProfileAuthenticity(profile: ContainerProfile): void {
132+
if (!identities.has(profile)) throw new Error('Container profile was not created by the trusted profile builder.');
133+
}
134+
130135
/** Internal authenticity and host-file revalidation used at every launch boundary. */
131136
export function assertContainerProfile(profile: ContainerProfile, timeoutMs = 30_000): void {
132137
const expected = identities.get(profile);

‎test/agent-supervisor.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ describe('container invocation supervisor', () => {
152152
expect((await first.settled).stopReason).toBe('shutdown');
153153
}, 60_000);
154154

155+
it('rejects a cloned profile without disposing the authentic active container', async () => {
156+
const current = profile(fixture(), 'ignore-term', 'cloned-profile');
157+
const first = startProfileInvocation(current, { timeoutMs: 30_000 });
158+
const clone = Object.freeze({ ...current });
159+
expect(() => startProfileInvocation(clone)).toThrow('not created by the trusted profile builder');
160+
expect(isInvocationActive('cloned-profile')).toBe(true);
161+
expect(spawnSync('docker', ['container', 'inspect', current.name]).status).toBe(0);
162+
first.cancel('shutdown');
163+
expect((await first.settled).stopReason).toBe('shutdown');
164+
}, 60_000);
165+
155166
it('records decoder failure without publishing a successful result', async () => {
156167
const handle = startProfileInvocation(profile(fixture(), 'finite-output', 'capture-failure'), {
157168
decode: () => { throw new Error('simulated capture failure'); },

0 commit comments

Comments
 (0)