From f6e6a8e695a16b10b223ed56dd12222ec4074f20 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Thu, 26 Nov 2026 19:32:29 -0800 Subject: [PATCH] fix(release): pair streamed workflow tool versions by raw name, admin link lookups read 403 as unreachable A streamed Agent turn that called both the workflow tool and a custom tool titled like it could match the real tool's segment to the custom call, which then carried its version onto the span. The matched call's raw name must now be the workflow tool too. An administrator GitLab session answering a link with 403 reported a reconnect, telling a reader the project existed; it now reads as unreachable. A spent request budget is still reported rather than called unreachable. --- .../lib/logs/execution/trace-spans/factory.ts | 6 ++- .../execution/trace-spans/trace-spans.test.ts | 38 +++++++++++++++++++ .../sim-search/live/account-session.test.ts | 22 +++++++++++ .../lib/sim-search/live/account-session.ts | 9 +++-- 4 files changed, 71 insertions(+), 4 deletions(-) diff --git a/apps/sim/lib/logs/execution/trace-spans/factory.ts b/apps/sim/lib/logs/execution/trace-spans/factory.ts index 3f2728afd7a..87841963fb3 100644 --- a/apps/sim/lib/logs/execution/trace-spans/factory.ts +++ b/apps/sim/lib/logs/execution/trace-spans/factory.ts @@ -306,7 +306,11 @@ function buildChildrenFromTimeSegments( const match = callsForName[currentIndex] toolCallIndices.set(normalizedName, currentIndex + 1) const lifted = liftChildTraceHandle(normalizeTraceOutput(match?.result ?? match?.output)) - const { output, ...version } = liftWorkflowToolVersion(segment.name, lifted.output) + /** Calls group by stripped name, so the matched call must also be the workflow tool. */ + const { output, ...version } = liftWorkflowToolVersion( + match?.name === segment.name ? segment.name : undefined, + lifted.output + ) const toolChild: TraceSpan = { id: `${span.id}-segment-${index}`, diff --git a/apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts b/apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts index 064c0b2a0d3..c7f58bc4818 100644 --- a/apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts +++ b/apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts @@ -1765,6 +1765,44 @@ describe('child deployment version on spans', () => { } ) + it('never gives the workflow tool a version from a streamed custom tool titled like it', () => { + const call = (name: string, childDeploymentVersionId: string, start: number) => ({ + name, + arguments: {}, + result: { success: true, result: {}, childDeploymentVersionId }, + startTime: new Date(Date.parse(baseLog.startedAt) + start).toISOString(), + endTime: new Date(Date.parse(baseLog.startedAt) + start + 100).toISOString(), + duration: 100, + }) + const custom = call('custom_workflow_executor', 'forged', 0) + const real = call('workflow_executor', 'dv-real', 200) + const agent = spanFor({ + blockId: 'agent-1', + blockName: 'Agent 1', + blockType: 'agent', + success: true, + output: { + content: 'done', + toolCalls: { list: [custom, real], count: 2 }, + providerTiming: { + duration: 2000, + startTime: baseLog.startedAt, + endTime: baseLog.endedAt, + timeSegments: [real, custom].map((tc) => ({ + type: 'tool', + name: tc.name, + startTime: Date.parse(tc.startTime), + endTime: Date.parse(tc.endTime), + duration: tc.duration, + })), + }, + }, + }) + + const versions = (agent.children ?? []).map((child) => child.childDeploymentVersionId) + expect(versions).not.toContain('forged') + }) + it.each([true, false])( 'ignores the key on any other Agent tool (time segments: %s)', (withSegments) => { diff --git a/apps/sim/lib/sim-search/live/account-session.test.ts b/apps/sim/lib/sim-search/live/account-session.test.ts index b60da5b2fc5..62b9ad72dc7 100644 --- a/apps/sim/lib/sim-search/live/account-session.test.ts +++ b/apps/sim/lib/sim-search/live/account-session.test.ts @@ -84,4 +84,26 @@ describe('administrator GitLab link location', () => { const session = await adminSession() await expect(session.locate(fileLink)).rejects.toThrow('GitLab is unavailable.') }) + + it('reads a project the administrator token is forbidden from as unreachable', async () => { + projectLookup.mockRejectedValue( + new NativeSearchError('reconnect', 'The provider denied access.', undefined, 403) + ) + const session = await adminSession() + await expect(session.locate(fileLink)).resolves.toBeUndefined() + }) + + it('still reports a spent request budget instead of calling the link unreachable', async () => { + projectLookup.mockRejectedValue( + new NativeSearchError( + 'unavailable', + 'Request budget reached. Narrow the query.', + undefined, + undefined, + 'request_budget_exceeded' + ) + ) + const session = await adminSession() + await expect(session.locate(fileLink)).rejects.toThrow('Request budget reached.') + }) }) diff --git a/apps/sim/lib/sim-search/live/account-session.ts b/apps/sim/lib/sim-search/live/account-session.ts index 6744eb6d525..c2396e0d1a6 100644 --- a/apps/sim/lib/sim-search/live/account-session.ts +++ b/apps/sim/lib/sim-search/live/account-session.ts @@ -43,13 +43,16 @@ type Reference = Pick< > /** - * Whether a failed link lookup is an answer about the project itself (not found, or on another - * branch) rather than an outage, rate limit, or credential failure that says nothing about it. + * Whether a failed link lookup is an answer about the project itself (not found, forbidden, or on + * another branch) rather than an outage, rate limit, spent request budget, or invalid credential + * that says nothing about it. */ function isProjectAnswer(error: unknown): boolean { + if (!(error instanceof NativeSearchError)) return false + if (error.status === 'reconnect') return error.httpStatus === 403 return ( - error instanceof NativeSearchError && error.status === 'unavailable' && + error.diagnosticCode !== 'request_budget_exceeded' && (error.httpStatus === undefined || error.httpStatus < 500) ) }