Skip to content

fix(sdk-python): prevent copilotkit_customize_config from mutating caller metadata - #7076

Closed
AyushCipher wants to merge 1 commit into
CopilotKit:mainfrom
AyushCipher:fix/customize-config-metadata-mutation
Closed

AyushCipher wants to merge 1 commit into
CopilotKit:mainfrom
AyushCipher:fix/customize-config-metadata-mutation

Conversation

@AyushCipher

@AyushCipher AyushCipher commented Sep 11, 2026 •

Copy link
Copy Markdown

Summary

Fixes #6941.

copilotkit_customize_config previously reused the caller's
config["metadata"] dictionary by reference. Adding CopilotKit
metadata could therefore mutate the caller's config and affect
subsequent invocations.

This change creates a copy of the metadata dictionary before
adding CopilotKit-specific metadata.

Changes

  • Copy base_config["metadata"] before modifying it.
  • Add regression tests covering:
    • metadata isolation
    • missing metadata
    • None base config
    • preservation of other config fields

Tests

  • pytest tests/test_customize_config.py
  • pytest tests/
  • ruff check tests/test_customize_config.py
  • ruff format --check tests/test_customize_config.py

All passed.

Full test suite: 243 passed, 12 skipped.

Summary by CodeRabbit

  • Bug Fixes

    • Prevented configuration customization from modifying the original metadata dictionary.
    • Preserved existing configuration fields while ensuring customized configurations maintain independent metadata.
  • Tests

    • Added coverage for metadata isolation, missing metadata, null base configurations, and preservation of other configuration values.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 12d3d995-ca3b-4d7f-81a6-6dbeae6e292d

📥 Commits

Reviewing files that changed from the base of the PR and between 7a36707 and 0a25492.

📒 Files selected for processing (2)
  • sdk-python/copilotkit/langgraph.py
  • sdk-python/tests/test_customize_config.py

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

copilotkit_customize_config now copies existing metadata before applying settings. New tests verify caller isolation, default behavior, and preservation of other configuration fields.

Changes

Configuration metadata isolation

Layer / File(s) Summary
Copy metadata before customization
sdk-python/copilotkit/langgraph.py
The function copies existing metadata before adding CopilotKit settings.
Validate configuration isolation
sdk-python/tests/test_customize_config.py
Tests cover existing and missing metadata, None base configs, metadata isolation, and preservation of other fields.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 0a254

The configuration customizer now avoids leaking CopilotKit metadata into caller-owned LangChain configurations, with regression coverage for the relevant input cases. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preventing copilotkit_customize_config from mutating caller metadata.
Linked Issues check ✅ Passed The change satisfies #6941. copilotkit_customize_config now creates an independent metadata dictionary with dict(...) before writing CopilotKit emission settings. The returned configuration preser…
Out of Scope Changes check ✅ Passed The changes stay within #6941 and the Python SDK scope. The production change is limited to sdk-python/copilotkit/langgraph.py. The added tests directly verify the reported metadata aliasing defect …
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AyushCipher

Copy link
Copy Markdown
Author

Hi @BenTaylorDev, I split the metadata mutation fix into #7076 as suggested. The pkg-pr-new workflow on my fork is failing because the pkg-pr-new GitHub App isn't installed on AyushCipher/CopilotKit (404: app not installed). The actual build step passes. I haven't made any code changes for this failure.

@BenTaylorDev

Copy link
Copy Markdown
Contributor

Thanks for this, and sorry you landed on a duplicate — #6943 filed the same fix on 09-08 and we are going with it on first-filed.

Your version was not wasted: the or {} guard is the better line, and it is being folded into #6943 with credit to you. {"metadata": None} raises TypeError without it.

Closing in favour of #6943. Your test file covered more ground than ours and I would take more PRs from you.

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: copilotkit_customize_config mutates the caller's config["metadata"] in place

2 participants