Skip to content

fix: preserve parallel connector runs and state - #552

Open
Gautam Sharma (GautamSharma99) wants to merge 1 commit into
langchain-ai:mainfrom
GautamSharma99:fix/serialize-connector-state
Open

fix: preserve parallel connector runs and state#552
Gautam Sharma (GautamSharma99) wants to merge 1 commit into
langchain-ai:mainfrom
GautamSharma99:fix/serialize-connector-state

Conversation

@GautamSharma99

Copy link
Copy Markdown

Summary

Fixes #542.

Connector run IDs previously used only an ISO timestamp, so calls in the same millisecond shared raw-data directories and fixed filenames. MCP operations also read connector state before network work and later replaced the whole document from that stale snapshot, dropping parallel run history.

Changes

  • Add a UUID suffix to every connector run ID while retaining the sortable timestamp prefix.
  • Add updateConnectorState, a process-local FIFO transaction per connector that re-reads state immediately before applying an updater and committing it.
  • Move MCP discovery and tool-call run recording to the atomic update API, so parallel operations preserve both run summaries and cursor/state fields.
  • Write connector state and raw JSON through unique same-directory temporary files followed by atomic rename, avoiding partial files and temp-path collisions.
  • Add regression coverage for distinct run IDs and deterministic concurrent state transactions, asserting both runs survive in state.json.
  • Add a patch changeset.

Why this fixes the race

Each invocation now owns a unique raw directory, so mcp-tools.json and mcp-tool-result.json cannot replace evidence from another invocation. MCP state commits are serialized per connector and each queued commit reads the latest file, so a later completion merges with the prior run instead of writing an old snapshot over it. Atomic replacement preserves the existing file until the new JSON is complete.

Validation

  • pnpm run lint:check
  • pnpm run typecheck
  • pnpm exec prettier --check (changed files)
  • pnpm test — 68 files, 793 tests passed

@changeset-bot

changeset-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2d8ca45

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openwiki Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

[Bug]: Millisecond connector run IDs and unlocked state writes lose parallel MCP results

1 participant