Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(pi): notify when idle runtime retirement fails
Chris278037275095
diff --git a/packages/maker-core/src/session.close.test.ts b/packages/maker-core/src/session.close.test.tsindex 933634f489..24edb12780 100644--- a/packages/maker-core/src/session.close.test.ts+++ b/packages/maker-core/src/session.close.test.ts@@ -95,6 +95,27 @@ describe('Session close lifecycle', () => {expect(close).toHaveBeenCalledTimes(2);});+ it('publishes idle retirement failure without turning recovery into product output', async () => {+ const { session, handle, seen } = liveTurn();+ const recovered: AgentEvent[] = [];+ session.onRuntimeRecovery((event) => recovered.push(event));+ vi.mocked(handle.close).mockRejectedValueOnce(new Error('process exit unconfirmed'));+ const recovery: AgentEvent = { type: 'text', source: 'pi', data: {+ text: 'partial: restart-cindy-to-refresh-packages', isFinal: true,+ } };++ await expect(session.closeAfterCurrentTurn({ failureEvent: () => recovery }))+ .rejects.toThrow('process exit unconfirmed');+ expect(session.getStatus()).toBe('error');+ expect(recovered).toEqual([{ ...recovery, runtimeRecovery: true,+ sessionInstanceId: session.instanceId, sessionTurnGeneration: session.getTurnGeneration() }]);+ expect(seen).toEqual([]);+ expect(handle.send).not.toHaveBeenCalled();+ await session.close();+ expect(session.getStatus()).toBe('closed');+ expect(recovered).toHaveLength(1);+ });+it('keeps a failed tool caller alive until its reply and product terminal are consumed', async () => {const { session, handle, queue, seen, idle } = liveTurn();await session.send('update and report', { turnAttemptToken: 7 });diff --git a/packages/maker-core/src/session.ts b/packages/maker-core/src/session.tsindex 24ca09ed65..d32ebb7b96 100644--- a/packages/maker-core/src/session.ts+++ b/packages/maker-core/src/session.ts@@ -1357,19 +1357,19 @@ export class Session {/** Retire this runtime at its product terminal boundary, without replaying work. */async closeAfterCurrentTurn(opts?: { failureEvent?: () => AgentEvent }): Promise<'closed' | 'deferred'> {this.retirementRequested = true;+ if (!this.retirementFailureEvent && opts?.failureEvent) {+ const createEvent = opts.failureEvent;+ const generation = this.turnGeneration;+ this.retirementFailureEvent = () => ({+ ...createEvent(),+ runtimeRecovery: true,+ sessionInstanceId: this.instanceId,+ sessionTurnGeneration: generation,+ });+ }if (this.hasUnsettledTurn() || this.sendReservation !== null|| this.hostTurnLeases.size > 0|| this.retirementContinuationGeneration === this.turnGeneration) {- if (!this.retirementFailureEvent && opts?.failureEvent) {- const createEvent = opts.failureEvent;- const generation = this.turnGeneration;- this.retirementFailureEvent = () => ({- ...createEvent(),- runtimeRecovery: true,- sessionInstanceId: this.instanceId,- sessionTurnGeneration: generation,- });- }return 'deferred';}await this.close();