Skip to content

baml-language-source-0545acebf981d304b567b88d3b53cd724f0dda10

@sxlijin sxlijin tagged this 13 Aug 00:54
artisanal human note:

this is the "wrong" fix, because it doesn't establish a canonical key
for call graph nodes. (i _think_ the right fix is for all nodes to be
keyed off the fully qualified name, and then render the names based on
the namespace corresponding to the file containing the rendered
function.)

but this fix works in the basic case, so yolo i guess (less flippant:
this is, i think, a strict improvement on what's in canary, even though
it's not "correct". so it gets merged.)

ai pr summary:

## Summary

- resolve expression-function call paths with the compiler's package and
namespace resolver before expanding their graph nodes
- use canonical playground function names for recursion guards and graph
expansion caches
- cover an LLM call from a workflow namespace into a relative child
namespace
- keep dependency functions outside user-function graph expansion, even
when a user namespace has the same name

## Root cause

The graph builder joined call path segments into a dotted string and
looked that string up as though it were already a canonical playground
function name. Relative cross-namespace paths such as
`prompts.Summarize` from the `workflows` namespace resolve semantically
to `workflows.prompts.Summarize`, so the raw string lookup missed the
LLM function. The call node remained a generic scope node and was pruned
during visualization preparation.

## Impact

Cross-namespace LLM calls now remain visible in playground workflow
graphs and retain their LLM client metadata.

## Validation

- `cargo test -p baml_project` (79 passed, 2 ignored)
- `cargo clippy -p baml_project --all-targets -- -D warnings`
- `cargo fmt --all -- --check`

Fixes B-880.

## Before / after

### Before — base `02b7355`

The cross-namespace `root.workflows.prompts.Summarize(...)` call is
absent from the playground graph.

![Before: cross-namespace LLM call missing from the playground
graph](https://github.com/user-attachments/assets/a2bef3fe-db40-49e0-a3d3-e8e63bfe1480)

### After — head `e8cddc5`

The same call resolves to the canonical namespaced LLM function and
appears with its `GPT4` client metadata.

![After: cross-namespace LLM call rendered in the playground
graph](https://github.com/user-attachments/assets/9b63edcf-b64c-48aa-9df9-4738ac39b317)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
  * Improved playground call resolution across namespaces and packages.
* Fixed recursive and nested function expansion to use accurate caller
context.
* Prevented dependency calls from incorrectly expanding same-named local
functions.
  * Preserved fallback behavior for unresolved dotted paths.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Assets 2
Loading