🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(agent-intervention): resend an approval without streamFeatures to an older server (stack L2 follow-up: G-02) (#20165)
Arvin Xu0b22b7f53273
diff --git a/src/services/aiAgent.intervention.test.ts b/src/services/aiAgent.intervention.test.tsindex 9dbaeda67d4..f262a8d8d4a 100644--- a/src/services/aiAgent.intervention.test.ts+++ b/src/services/aiAgent.intervention.test.ts@@ -26,7 +26,7 @@ describe('aiAgentService.resolveAgentInterventionBySource', () => {};beforeEach(() => {- vi.clearAllMocks();+ vi.resetAllMocks();});// G-02: the resolving client subscribes to the continuation, so it declares@@ -42,6 +42,43 @@ describe('aiAgentService.resolveAgentInterventionBySource', () => {});});+ // G-02 mixed-version: a server from before `streamFeatures` validates this+ // input with a strict schema, so the declaration must not block the approval.+ it('resends without stream features when an older server rejects the key', async () => {+ const validationError = Object.assign(+ new Error(+ JSON.stringify([+ { code: 'unrecognized_keys', keys: ['streamFeatures'], message: 'Unrecognized key' },+ ]),+ ),+ { data: { code: 'BAD_REQUEST', httpStatus: 400 } },+ );+ mocks.resolveAgentInterventionBySource+ .mockRejectedValueOnce(validationError)+ .mockResolvedValueOnce({+ contractVersion: 2,+ state: 'already_resolved',+ status: 'approved',+ success: true,+ });++ await expect(aiAgentService.resolveAgentInterventionBySource(params)).resolves.toEqual({+ execution: undefined,+ handled: true,+ state: 'already_resolved',+ });+ expect(mocks.resolveAgentInterventionBySource).toHaveBeenCalledTimes(2);+ expect(mocks.resolveAgentInterventionBySource).toHaveBeenLastCalledWith(params);+ });++ it('does not resend on any other failure', async () => {+ const error = Object.assign(new Error('conflict'), { data: { code: 'CONFLICT' } });+ mocks.resolveAgentInterventionBySource.mockRejectedValueOnce(error);++ await expect(aiAgentService.resolveAgentInterventionBySource(params)).rejects.toBe(error);+ expect(mocks.resolveAgentInterventionBySource).toHaveBeenCalledTimes(1);+ });+it('preserves a claimed result and its precreated execution', async () => {const execution = {autoStarted: true,diff --git a/src/services/aiAgent.ts b/src/services/aiAgent.tsindex c019f5a6937..43d01a27eb1 100644--- a/src/services/aiAgent.ts+++ b/src/services/aiAgent.ts@@ -15,6 +15,18 @@ export type { ExecAgentResult, ScheduleAgentRunParams, ScheduleAgentRunResult };/** Gateway stream features every run started from this client handles. */const STREAM_FEATURES: AgentStreamClientFeature[] = ['member_runtime_end'];+/** An older server's strict input schema rejected the `streamFeatures` key. */+const isUnknownStreamFeaturesError = (error: unknown): boolean => {+ const { data, message } = (error ?? {}) as { data?: { code?: string }; message?: unknown };++ return (+ data?.code === 'BAD_REQUEST' &&+ typeof message === 'string' &&+ message.includes('unrecognized_keys') &&+ message.includes('streamFeatures')+ );+};+/*** Resume instruction for an operation that hit `human_approve_required`. When* present, the new op acts as the "continue" step: server reads the target tool@@ -348,11 +360,19 @@ class AiAgentService {async resolveAgentInterventionBySource(params: ResolveAgentInterventionBySourceParams,): Promise<ResolveAgentInterventionBySourceResult> {- const result = await lambdaClient.aiAgent.resolveAgentInterventionBySource.mutate({- ...params,+ const mutate = lambdaClient.aiAgent.resolveAgentInterventionBySource.mutate;+ let result: Awaited<ReturnType<typeof mutate>>;+ try {// This client subscribes to the continuation it starts.- streamFeatures: STREAM_FEATURES,- });+ result = await mutate({ ...params, streamFeatures: STREAM_FEATURES });+ } catch (error) {+ // A server from before `streamFeatures` validates this input strictly and+ // rejects the unknown key before claiming anything, so resending the same+ // resolution without it is safe. That server never renames a mirrored+ // member terminal, so dropping the declaration loses nothing.+ if (!isUnknownStreamFeaturesError(error)) throw error;+ result = await mutate(params);+ }if (!result.success) return { handled: false };