Skip to content

Commit 67805cb

Browse files
fix(agent): forward the execution id through the provider payload
1 parent 7b5590a commit 67805cb

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

apps/sim/executor/handlers/agent/agent-handler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,10 @@ export class AgentBlockHandler implements BlockHandler {
10291029
isDeployedContext: ctx.isDeployedContext,
10301030
callChain: ctx.callChain,
10311031
billingAttribution: ctx.metadata.billingAttribution,
1032+
// Reaches tool `_context` via `prepareToolExecution`, so a tool that starts
1033+
// its own child execution (a custom block) correlates and cancels against
1034+
// this real run instead of minting a phantom id.
1035+
executionId: ctx.executionId,
10321036
reasoningEffort: providerRequest.reasoningEffort,
10331037
verbosity: providerRequest.verbosity,
10341038
thinkingLevel: providerRequest.thinkingLevel,

apps/sim/providers/utils.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,3 +1730,40 @@ describe('transformBlockTool knowledge-base multi-instance unique IDs', () => {
17301730
expect(result?.id).toBe('knowledge_search')
17311731
})
17321732
})
1733+
1734+
describe('prepareToolExecution invoker identity hand-off', () => {
1735+
const tool = { params: {}, parameters: {} }
1736+
1737+
/**
1738+
* A custom block invoked as an agent tool starts its own child execution, and
1739+
* correlates + cancels against the INVOKING run. That id only reaches it via
1740+
* `_context`, so this asserts the hand-off rather than any single hop — three
1741+
* separate fixes each repaired one hop and left the chain broken elsewhere.
1742+
*/
1743+
it("puts the invoking run's execution id on tool _context", () => {
1744+
const { executionParams } = prepareToolExecution(
1745+
tool,
1746+
{},
1747+
{
1748+
workflowId: 'wf-1',
1749+
workspaceId: 'ws-1',
1750+
executionId: 'real-execution-id',
1751+
}
1752+
)
1753+
1754+
expect(executionParams._context.executionId).toBe('real-execution-id')
1755+
})
1756+
1757+
it('omits the execution id when the request carries none', () => {
1758+
const { executionParams } = prepareToolExecution(
1759+
tool,
1760+
{},
1761+
{
1762+
workflowId: 'wf-1',
1763+
workspaceId: 'ws-1',
1764+
}
1765+
)
1766+
1767+
expect(executionParams._context.executionId).toBeUndefined()
1768+
})
1769+
})

0 commit comments

Comments
 (0)