Skip to content

fix: scope final-content fallback to model invocation - #672

Closed
pedrojreis wants to merge 1 commit into
LibreChat-AI:mainfrom
pedrojreis:fix/stable-stream-invocation-key
Closed

pedrojreis wants to merge 1 commit into
LibreChat-AI:mainfrom
pedrojreis:fix/stable-stream-invocation-key

Conversation

@pedrojreis

@pedrojreis pedrojreis commented Nov 10, 2026 •

Copy link
Copy Markdown

Problem

A caller-tool host can mark a tool ID in graph.invokedToolIds from its on_run_step handler before the current model invocation finishes. The final-content fallback then recomputes an invocation base key containing the new tool count, fails to find the text deltas already emitted under the original key, and emits the complete assistant plan again after the tool announcement.

This produces duplicate streamed/completed assistant content and can break a downstream caller-executed Tool replay.

Change

  • Capture the delta-lookup base key immediately before the model invocation.
  • Reuse that captured key for final text/reasoning checks and failed-attempt marker cleanup.
  • Leave getStepBaseKey / getStepKey and their Tool-count discriminator unchanged, so a later post-tool invocation can still emit its own nonstreaming answer.
  • Document the invocation-scoped fallback behavior.

Regression proof

The new test uses the real graph streaming/event path with a deterministic model fixture. It streams a plan, announces a caller Tool, marks its ID from the host callback, and lets the model complete. Before the fix, the aggregated output contains the plan twice; after the fix, both aggregated content and message deltas contain it once.

The full graph reasoning/fallback suite plus Langfuse/deterministic-trace-id coverage passed: 12 suites, 232 tests, including the existing post-tool final-text and invoke-only fallback cases.

node --experimental-vm-modules node_modules/jest/bin/jest.js \
  src/graphs/__tests__/Graph.reasoning.test.ts langfuse deterministic-trace-id --runInBand

No dependency/version bump, release, merge, or deployment is included. This draft is held for owner approval before any upstream merge/publication or downstream rollout.

Additional local checks passed: scoped ESLint on Graph.ts and its regression suite; npm run build (CJS/ESM bundles and TypeScript declarations). Existing source formatting is preserved; no repository-wide formatter changes are included.

Hosted CI status

The upstream CI run currently concludes action_required for this first-time contributor: https://github.com/LibreChat-AI/agents/actions/runs/42845956936. Maintainer action is required before hosted checks can run; no hosted CI success is claimed. The PR remains a draft, with no merge/publication/rollout performed.

@pedrojreis pedrojreis closed this Nov 10, 2026
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