Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(pi): allow retry after empty failures with context edits
elfcv9b473c2d1c47
diff --git a/packages/maker-core/src/agents/pi/__tests__/session-tree.test.ts b/packages/maker-core/src/agents/pi/__tests__/session-tree.test.tsindex c60d4c974d..476b4bd457 100644--- a/packages/maker-core/src/agents/pi/__tests__/session-tree.test.ts+++ b/packages/maker-core/src/agents/pi/__tests__/session-tree.test.ts@@ -90,6 +90,26 @@ describe('pi session tree adapter', () => {expect(() => piRetryBranch(retryTree(settings), '0')).toThrow('no failed response');});+ it('allows omission context edits around repeated empty failures', () => {+ const omit = { type: 'context_edit', targetId: 'failed', replacement: null };+ expect(piRetryBranch(retryTree([emptyFailure, omit, emptyFailure, omit]), '0')).toEqual({+ parentId: null,+ requestTooLarge: true,+ });+ });++ it('does not treat an omission edit alone as a failed response', () => {+ expect(() => piRetryBranch(retryTree([{ type: 'context_edit', targetId: '0', replacement: null }]), '0'))+ .toThrow('no failed response');+ });++ it('still protects a context edit that replaces message content', () => {+ expect(() => piRetryBranch(retryTree([+ emptyFailure,+ { type: 'context_edit', targetId: '1', replacement: 'rewritten' },+ ]), '0')).toThrow('discard output or session state');+ });+it.each([{ type: 'message', message: { role: 'assistant', stopReason: 'error', content: [{ type: 'text', text: 'partial' }] } },{ type: 'message', message: { role: 'assistant', stopReason: 'error', content: [{ type: 'toolCall', name: 'bash' }] } },diff --git a/packages/maker-core/src/agents/pi/session-tree.ts b/packages/maker-core/src/agents/pi/session-tree.tsindex 786071ec2a..75892622f7 100644--- a/packages/maker-core/src/agents/pi/session-tree.ts+++ b/packages/maker-core/src/agents/pi/session-tree.ts@@ -140,7 +140,7 @@ export function normalizePiSessionTree(data: unknown): SessionTreeSnapshot {return { roots, leafId, activePathIds: reversed.reverse() };}-/** Retry empty failures, allowing native model/effort changes that do not produce output. */+/** Retry empty failures, allowing model/effort changes and omission-only context edits that do not produce output. */export function piRetryBranch(data: unknown, entryId: string): {parentId: string | null; requestTooLarge: boolean;} | null {@@ -159,6 +159,11 @@ export function piRetryBranch(data: unknown, entryId: string): {// Native navigateTree replaces messages only; it keeps the currently selected// model and thinking level. Their history entries are not generated output.if (item?.type === 'model_change' || item?.type === 'thinking_level_change') continue;+ // Pi appends context_edit(replacement=null) after an empty failed reply so the+ // next automatic attempt omits it. That edit is not output: raw history stays,+ // and navigating before it restores the original target. A content replacement+ // is session state and must still block retry.+ if (item?.type === 'context_edit' && item.replacement === null) continue;const message = recordOf(item?.message);if (item?.type !== 'message' || message?.role !== 'assistant' ||message.stopReason !== 'error' || !Array.isArray(message.content) || message.content.length !== 0) {