Skip to content

Commit 6c757e1

Browse files
mchwangclaude
andcommitted
Treat an absent container as settled once the create window passes
After a killed docker create, the create path waited out the settle window but still reported "did not settle" when no container appeared, leaving the profile's staging and network owned. Callers such as runContainer have no later cleanup, so those resources leaked. Absence now counts as settled on every path once the window has passed, matching storage and network cleanup; only inside the window is it reported as unsettled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8bc00da commit 6c757e1

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

‎agents/container/run.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,15 @@ const removeContainerOrThrow = (profile: ContainerProfile, waitForSettle = false
6565
if (before.status === 0) break;
6666
const missing = !before.error && /No such (?:object|container)/i.test(`${before.stdout ?? ''}\n${before.stderr ?? ''}`);
6767
if (!missing) throw new Error('Failed to establish ownership of the agent container; staged credentials were retained.');
68-
// A killed create may still land in the daemon; absence only counts once its settle window has passed. Only the
69-
// create path waits here; later cleanup (such as a supervisor recovery) reports "not settled" and retries later.
70-
const settled = performance.now() >= settleUntil;
71-
if (settled && !(waitForSettle && settleUntil)) {
68+
// A killed create may still land in the daemon; absence only counts once its settle window has passed, on every
69+
// path. Only the create path waits here; later cleanup (such as a supervisor recovery) reports "not settled"
70+
// inside the window and retries later.
71+
if (performance.now() >= settleUntil) {
7272
unsettledCreates.delete(profile);
7373
disposeContainerProfile(profile);
7474
return;
7575
}
76-
if (settled || !waitForSettle)
77-
throw new Error('Agent container creation did not settle; staged credentials were retained.');
76+
if (!waitForSettle) throw new Error('Agent container creation did not settle; staged credentials were retained.');
7877
sleep(250);
7978
}
8079
const inspected = JSON.parse(String(before.stdout || '[]'))[0] as { Config?: { Labels?: Record<string, string> } } | undefined;

‎test/agent-container.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ describe('real Docker agent isolation', () => {
279279
docker('rm', '--force', first.name); containers.delete(first.name);
280280
}, 60_000);
281281

282-
it('retains credentials when a killed create cannot be proven absent', () => {
282+
it('releases a killed create once its settle window passes with no container', () => {
283283
const data = fixture(), unsettled = profile(data, 'planning', 'noop');
284284
const shim = join(data.root, 'docker-shim'); mkdirSync(shim);
285285
const realDocker = execFileSync('sh', ['-c', 'command -v docker'], { encoding: 'utf8' }).trim();
@@ -288,9 +288,13 @@ describe('real Docker agent isolation', () => {
288288
`exec '${realDocker}' "$@"`].join('\n'), { mode: 0o755 });
289289
const path = process.env.PATH;
290290
process.env.PATH = `${shim}:${path}`;
291-
try { expect(() => createValidatedContainer(unsettled, 1_000)).toThrow('cleanup did not settle'); }
291+
const started = performance.now();
292+
// The create path waits out the settle window, then treats absence as settled and releases the profile.
293+
try { expect(() => createValidatedContainer(unsettled, 3_000)).toThrow('ETIMEDOUT'); }
292294
finally { process.env.PATH = path; }
293-
expect(existsSync(unsettled.codexAuthFile!)).toBe(true);
295+
expect(performance.now() - started).toBeGreaterThanOrEqual(10_000);
296+
expect(isContainerProfileAuthentic(unsettled)).toBe(false);
297+
expect(existsSync(unsettled.codexAuthFile!)).toBe(false);
294298
}, 60_000);
295299

296300
it('keeps a killed create unsettled for later cleanup until its settle window passes', () => {

0 commit comments

Comments
 (0)