Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(session): reject new work while runtime retirement is pending
zqchrisa183498a0cfd
diff --git a/docs/dev-rules/pi-harness.md b/docs/dev-rules/pi-harness.mdindex c676424647..1e5da1d4aa 100644--- a/docs/dev-rules/pi-harness.md+++ b/docs/dev-rules/pi-harness.md@@ -233,6 +233,8 @@ Pi CLI 管理入口、内核自更新与旧工具兼容的执行边界见关闭正在消费结果的调用者。包变更仍推进原有 generation 并捕获准确 runtime 实例;空闲实例退役,忙碌调用者和同一快照里的兄弟实例保留当前执行,产品终态送达后再退役。`runtimeConvergence=deferred` 表示旧快照暂时服务在途工作,不表示新包已经加载。+ provider 已空闲但 Session 尚未消费终态时,待退役实例仍拒绝新 turn;+ 仅当前 generation 已由 Host 明确 claim 的 silent-stop continuation 可继续发送。调用者的现有 Host lease 必须覆盖兄弟关闭结果汇总及准确收敛回执的 Session 分发;不能把回执入队当作已分发。交付等待有界,显式关闭仍可结束旧实例。内部退役尚未真正开始关闭时,显式 Agent 切换/关闭可接管关闭原因;一旦开始关闭diff --git a/packages/maker-core/src/session.close.test.ts b/packages/maker-core/src/session.close.test.tsindex 6df6903129..76dc9b5523 100644--- a/packages/maker-core/src/session.close.test.ts+++ b/packages/maker-core/src/session.close.test.ts@@ -26,13 +26,18 @@ function createDeferred(): { promise: Promise<void>; resolve: () => void } {}describe('Session close lifecycle', () => {- function liveTurn(hostContinuation = true) {+ function liveTurn(hostContinuation = true, terminalGate?: Promise<void>) {const queue = createAsyncQueue<AgentEvent>();let running = false;const handle = {id: 'pi-runtime', agentKind: 'pi', model: 'm',send: vi.fn(async () => { running = true; }),- events: () => queue,+ events: () => terminalGate ? (async function* () {+ for await (const event of queue) {+ if (event.type === 'done') await terminalGate;+ yield event;+ }+ })() : queue,isTurnRunning: () => running,close: vi.fn(async () => { running = false; queue.end(); }),abort: vi.fn(async () => { running = false; }),@@ -124,6 +129,29 @@ describe('Session close lifecycle', () => {expect(handle.send).toHaveBeenCalledOnce();});+ it('rejects a new turn while a retiring provider is idle but its terminal is queued', async () => {+ const terminalGate = createDeferred();+ const { session, handle, queue, seen, idle } = liveTurn(true, terminalGate.promise);+ await session.send('in-flight work');+ const generation = session.getTurnGeneration();+ expect(await session.closeAfterCurrentTurn()).toBe('deferred');+ idle();+ queue.push({ type: 'done', source: 'pi', data: { status: 'completed', result: 'finished' } });+ try {+ await expect(session.send('new work')).rejects.toThrow(/closing/);+ expect(session.getTurnGeneration()).toBe(generation);+ expect(handle.send).toHaveBeenCalledOnce();+ expect(handle.close).not.toHaveBeenCalled();+ terminalGate.resolve();+ await vi.waitFor(() => expect(session.getStatus()).toBe('closed'));+ expect(seen.at(-1)?.data).toMatchObject({ status: 'completed', result: 'finished' });+ expect(handle.close).toHaveBeenCalledOnce();+ } finally {+ terminalGate.resolve();+ await session.close();+ }+ });+it('keeps the executor available to the existing Host silent-stop continuation', async () => {const { session, handle, queue, seen, idle } = liveTurn();await session.send('work');diff --git a/packages/maker-core/src/session.ts b/packages/maker-core/src/session.tsindex e7caec0a67..751fa662b3 100644--- a/packages/maker-core/src/session.ts+++ b/packages/maker-core/src/session.ts@@ -738,7 +738,7 @@ export class Session {: message;this.logger.debug('send', summarizeUserMessage(msg));this.ensureActive();- if (this.retirementRequested && !this.hasUnsettledTurn()+ if (this.retirementRequested&& this.retirementContinuationGeneration !== this.turnGeneration) {throw new Error(`Session ${this.id} is closing`);}