Skip to content

Commit 2d8ca8a

Browse files
committed
fix: clear terminal app log recovery markers
1 parent a108975 commit 2d8ca8a

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

packages/contracts/src/app-log-process-recovery.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ test.each([
4242
},
4343
);
4444

45+
test('dead owned marker recovery clears terminal evidence before the next start', async () => {
46+
let marker: AppLogProcessMarkerReadOutcome = decoded;
47+
const clearMarker = vi.fn(async () => {
48+
marker = { status: 'missing' };
49+
});
50+
const host = {
51+
processes: {
52+
readMarker: vi.fn(async () => marker),
53+
clearMarker,
54+
inspect: vi.fn(async () => 'missing' as const),
55+
terminate: vi.fn(async () => 'already-missing' as const),
56+
},
57+
};
58+
const startReplacement = vi.fn(async () => {
59+
if (marker.status !== 'missing') throw new Error('stale marker still blocks replacement');
60+
return 'launched';
61+
});
62+
63+
assert.deepEqual(await reattachCleanupOnlyAppLogProcess(host, '/pid'), { status: 'missing' });
64+
assert.equal(await startReplacement(), 'launched');
65+
assert.equal(clearMarker.mock.calls.length, 1);
66+
});
67+
4568
test.each([
4669
[
4770
undefined,

packages/contracts/src/app-log-process-recovery.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export async function reattachCleanupOnlyAppLogProcess(
3333
};
3434
}
3535
const ownership = await host.processes.inspect(marker.marker);
36-
if (ownership === 'missing') return { status: 'missing' };
36+
if (ownership === 'missing') {
37+
if (pidPath) await host.processes.clearMarker(pidPath);
38+
return { status: 'missing' };
39+
}
3740
if (ownership === 'ownership-lost') {
3841
return { status: 'unreattachable', reason: 'ownership-fence-lost' };
3942
}

0 commit comments

Comments
 (0)