Skip to content

Set $callers in tool and prompt handler processes - #39

Merged
dbernheisel merged 1 commit into
dbernheisel:mainfrom
merhard:fix/handler-callers
Oct 9, 2026
Merged

dbernheisel merged 1 commit into
dbernheisel:mainfrom
merhard:fix/handler-callers

Conversation

@merhard

@merhard merhard commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

run_handler/5 starts each tool and prompt handler with a bare spawn, so the handler process has no $callers. Mox, Mimic, and the Ecto SQL sandbox find a process's owner through $callers. When a test calls a tool with Phantom.Test.call_tool/4, private stubs and sandbox connections never reach the handler. We hit this in a downstream app: Mimic and Mox stubs set in a tool test weren't seen by the handler until we switched to global mode, which forced async: false. Calling Mimic.allow/3 from the test doesn't work reliably either, because the worker pid reaches the parent only after the handler has already started.

This sets $callers in the worker to the dispatching process plus its own callers, as Task does.

The new tests show a private Req.Test stub, which also finds its owner through $callers, reaching tool and prompt handlers called from an async: true test. Without the change, both tests fail with cannot find mock/stub ... in process #PID<...>.

The follow-up spawn in resume_elicitation/2 runs no handler code, so it is unchanged: the handler resumes in its original worker.

Alternative: start handlers with Task or Task.Supervisor, which set $callers themselves. That also changes linking and supervision, so this PR keeps the minimal change.

Handlers ran in a bare spawn with no $callers, so mocking and stubbing
libraries and the Ecto SQL sandbox could only reach them in global or
shared mode, ruling out async tests through Phantom.Test.
@dbernheisel
dbernheisel merged commit 40ead0b into dbernheisel:main Oct 9, 2026
1 of 2 checks passed
@merhard
merhard deleted the fix/handler-callers branch October 9, 2026 02:15
@merhard

merhard commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants