Skip to content

fix(client): give each graph() run its own run id - #132

Draft
apucacao wants to merge 1 commit into
mainfrom
fix/graph-run-id-per-run-clean
Draft

apucacao wants to merge 1 commit into
mainfrom
fix/graph-run-id-per-run-clean

Conversation

@apucacao

@apucacao apucacao commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Running the same graph() twice for the same context reported both runs under one run id, so separate runs looked like one in the $ld:ai:graph:* events.

graph() caches the built graph per context so it doesn't re-evaluate every node's flag on each call. The run id was created in that build, so it was cached too. Each run now gets a fresh id. Every graph event within a run still shares it, and the flag evaluations stay cached.

JS twin: launchdarkly/js-ai-sdk#109. Source branch: fix/graph-run-id-per-run.

Testing

  • New test in test_graph_stream.py, for both invoke and stream: two runs on one graph() instance and context get different ids, and all graph events in a run (node, handoff, success) share one. It fails on main.
  • Client, openai-agents, claude-agents and langchain-agents suites pass. mypy and ruff are clean.

Note

Overview
Fixes duplicate runId across separate graph() runs when the same instance and LD context reuse the cached graph build.

Each invoke/stream now merges the cached build track payload with a new UUID runId, passes that copy on route options via _run_track_data, and uses it for handoff success/failure events inside the cached closures so analytics still group node, handoff, and invocation events per run without rebuilding the graph.

Adds TestGraphRunId (invoke + stream): two runs on one graph() share one id within a run and get different ids across runs.

Reviewed by Cursor Bugbot for commit 12ad1ff. Bugbot is set up for automated code reviews on this repo. Configure here.

graph() caches the built graph per context so repeated runs skip
re-evaluating every node's flag. The build also created the graph's
track data, run id included, so every run for the same context
reported the same runId on its $ld:ai:graph:* events.

Each run now copies the cached track data with a fresh runId and passes
it to route and stream_route through their opts, so the node, handoff
and graph-level events of one run share one id and the next run gets
another. The flag evaluations stay cached.
@apucacao

apucacao commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 12ad1ff. Configure here.

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.

1 participant