fix(pi): settle delayed compact ownership

This commit is contained in:
2026-08-26 09:41:25 +08:00
parent f5e6a04c7d
commit 9f05e2d7e1
12 changed files with 334 additions and 25 deletions

View File

@@ -7,6 +7,7 @@ import {
PiWorkerPool,
type PiConversationWorker,
type PiWorkerOpenResult,
type PiWorkerPoolEvent,
} from '../../electron/coding-runtime/pi/worker-pool';
import type { PiProcessError } from '../../electron/coding-runtime/pi/process-errors';
import { PiProcessError as PiProcessFailure } from '../../electron/coding-runtime/pi/process-errors';
@@ -224,6 +225,34 @@ describe('Pi worker pool', () => {
expect(pool.getResilienceProofDiagnostics().runs).toEqual({ active: 0, waiting: 0 });
});
it('settles compact from its authoritative RPC success without agent_settled', async () => {
const worker = new FakeWorker('worker-target');
const events: PiWorkerPoolEvent[] = [];
const pool = new PiWorkerPool({
maxIdle: 2,
openWorker: async () => ({
worker,
session: { piSessionId: 'session-target', sessionKey: 'key-target' },
}),
});
pool.subscribe((event) => events.push(event));
await pool.prepare(conversation('conversation-target'));
const ticket = pool.startTopLevel({
conversationId: 'conversation-target',
runId: 'run-compact-success',
command: { type: 'compact' },
});
await expect(ticket.accepted).resolves.toMatchObject({ success: true });
expect(pool.getActiveRun('conversation-target')).toBeNull();
expect(pool.getState('conversation-target')?.state).toBe('idle');
expect(events).toContainEqual(expect.objectContaining({
type: 'top-level.settled',
runId: 'run-compact-success',
}));
});
it('treats agent settlement as authoritative when the RPC confirmation is still pending', async () => {
const worker = new FakeWorker('worker-target');
const pool = new PiWorkerPool({