Issue for this PR
Every tool call made inside an execute program used the execute call's own ID. So ctx.id in the tool, event.id in the tool.execute.before and tool.execute.after hooks, and gen_ai.tool.call.id on the span were the same for every call in a program. A plugin couldn't match a call's before hook to its after hook when a program ran several calls at once.
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
Each call in a program now gets its own unique ID.
was now
execute call_abc call_abc
tools.echo(...) call_abc call_01KA...
tools.echo(...) call_abc call_01KB...
Permission prompts still need the old ID: the UI finds a prompt's row by its ID, and only the execute call has a row. So the permission service gets one internal method, nested(call, parent), and the Code Mode tool calls it for each call it runs.
script call_abc starts tools.echo remember call_01KA -> call_abc
echo asks permission as call_01KA request shown on call_abc
script finishes forget call_01KA
This is a known hack. The lookup exists only so prompts from a program's calls land on the program's row, and Code Mode is its only caller. I went with it because it fixes the immediate problem without changing any public API. A tool keeps passing its own ctx.id, as it does today, and that works for Core's tools, MCP tools, and Effect and promise plugin tools alike, since the lookup goes by ID and not by where the code runs.
The IDs are unique rather than call_abc_0 because the permission service is shared by every session in a directory, and some providers reuse IDs like call_0 across sessions. The entries are removed when the execute call's scope closes, including on failure or interrupt.
Other takes I tried and closed:
Limits: a request made after the whole program has ended (from a fiber a tool left running) keeps the call's own ID. A plugin that hooks both tool.execute.before and permission.evaluate sees the call's ID in the first and the execute call's ID in the second. Scheduled checks are unchanged.
How did you verify your code works?
New tests: calls in a program get distinct IDs and are registered through nested, the permission service shows a nested call's request on its parent until the scope closes and not after, and hooks see one ID per call with matching before and after. Two MCP tests that read the raw request now expect the call's own ID. I ran core's full suite locally: 7487 pass, 3 fail. The 3 are shell tests that fail the same way on my machine without the change. bun run check passes.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Added by the opencode bot (AI-generated).
Public API: tool calls inside a Code Mode program now get their own ctx.id/hook event.id instead of the execute call's (no shape change, backwards compatible)