Skip to content

Commit 409b8d5

Browse files
thymikeeclaude
andcommitted
fix(daemon): re-enter a retained lock the enclosing request holds
A batch step whose lock plan resolved no device and that reopens the batch session's app retained a lock its batch already held. The same-Mac rule saw it as busy. A lock an enclosing request holds is now re-entered, as initial locks already were. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 783cfe2 commit 409b8d5

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎packages/daemon/src/server/__tests__/request-execution-locks.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,22 @@ test('a nested request is refused a busy lock on its parent Mac but still waits
260260
// The refused step left nothing queued on the host.
261261
expect(locks.has('device:mac')).toBe(false);
262262
});
263+
264+
test('a nested request retaining a lock its enclosing request holds re-enters it', async () => {
265+
const locks = new Map<string, Promise<unknown>>();
266+
const parent = createRequestExecutionLocks({
267+
locks,
268+
initialKeys: ['session:batch', 'device:mac:app:com.example.one'],
269+
});
270+
271+
await expect(
272+
parent.run(async () => {
273+
// A batch step whose lock plan resolved no device reopens the same app.
274+
const step = createRequestExecutionLocks({ locks, initialKeys: ['session:batch'] });
275+
return await step.run(async () => {
276+
await step.retainDevice('mac:app:com.example.one');
277+
return 'reentered';
278+
});
279+
}),
280+
).resolves.toBe('reentered');
281+
});

‎packages/daemon/src/server/request-execution-locks.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ export function createRequestExecutionLocks(params: {
8585
}
8686
const key = `device:${deviceId}` as const;
8787
if (initialKeySet.has(key)) return;
88+
// An enclosing request already holds it, and this request runs inside that hold.
89+
if (enclosing().some((held) => held.has(key))) return;
8890

8991
let retained = retainedLocks.get(key);
9092
if (!retained) {

0 commit comments

Comments
 (0)