Skip to content

fix(python): copy metadata in copilotkit_customize_config - #6943

Merged
BenTaylorDev merged 7 commits into
CopilotKit:mainfrom
Zsanz3:cursor/fix-customize-config-metadata-5cf9
Sep 17, 2026
Merged

BenTaylorDev merged 7 commits into
CopilotKit:mainfrom
Zsanz3:cursor/fix-customize-config-metadata-5cf9

Conversation

@Zsanz3

@Zsanz3 Zsanz3 commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6941

Problem

copilotkit_customize_config aliased the caller's config["metadata"] dict, so writing mute / emit flags mutated shared metadata used by later LangChain calls.

Fix

Shallow-copy metadata before writing CopilotKit keys:

metadata = dict(base_config.get("metadata", {})) if base_config else {}

Test

sdk-python/tests/test_customize_config.py asserts a shared metadata dict is not mutated and the returned config still carries the emit keys.

Python only; does not touch the JS SDK or #6930.

Summary by CodeRabbit

  • Bug Fixes

    • Prevented configuration metadata from being unintentionally modified when customizing settings.
    • Preserved original configuration values while applying customized metadata.
    • Handled missing or null metadata safely by treating it as empty metadata.
  • Tests

    • Added regression coverage confirming metadata remains unchanged and isolated between configurations.
    • Verified customized metadata preserves existing values and remains valid when no metadata is provided.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 1a224f57-24e4-4b28-a3fb-77cb3a009d57

📥 Commits

Reviewing files that changed from the base of the PR and between 5938e7b and 8a5b4cd.

📒 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 base metadata before adding CopilotKit emission settings. Tests verify caller metadata isolation and handling of None metadata.

Changes

Python metadata isolation

Layer / File(s) Summary
Copy metadata and verify isolation
sdk-python/copilotkit/langgraph.py, sdk-python/tests/test_customize_config.py
copilotkit_customize_config copies metadata and defaults falsy metadata to an empty dictionary. Tests verify that the original metadata remains unchanged and that None metadata produces a separate dictionary.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 8a5b4

The metadata isolation fix and null handling are covered by regression tests, with no remaining merge-blocking risk identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the Python SDK fix and the metadata-copying change in copilotkit_customize_config, which matches the main purpose of the pull request.
Linked Issues check ✅ Passed The change satisfies the coding requirements in #6941. copilotkit_customize_config now creates an independent metadata dictionary with dict(base_config.get("metadata", {}) or {}). This prevents ca…
Out of Scope Changes check ✅ Passed The changes are limited to the Python SDK implementation and its regression tests. The tests directly support the fix in #6941. No unrelated SDK or JavaScript changes are included.
✨ 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.

@BenTaylorDev

Copy link
Copy Markdown
Contributor

Thanks — this is the right fix and the test genuinely fails without it (verified on 3.14 against unpatched main).

One addition before merge, borrowed from @AyushCipher's parallel PR #7076: guard the None case.

metadata = dict(base_config.get("metadata", {}) or {}) if base_config else {}

Without or {}, a caller passing {"metadata": None} gets TypeError: 'NoneType' object is not iterable. That input is already broken on main today, so this is not a regression in your PR — but the guard is free and it closes the case. Ping me when it is in and I will merge.

@AyushCipher

Copy link
Copy Markdown

@BenTaylorDev @Zsanz3 I can implement the or {} guard from #7076 that Ben mentioned.

Since #6943 is on Zsanz3's fork, would you like me to make the change directly on the PR branch if edits are enabled, or should I prepare the commit on my fork for you/Zsanz3 to apply?

Happy to handle the change.

@Zsanz3

Zsanz3 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

@BenTaylorDev Added the or {} guard you asked for:

metadata = dict(base_config.get("metadata", {}) or {}) if base_config else {}

Also covered {"metadata": None} in the regression test so that case no longer raises. Ready for merge when you have a moment — thanks.

@Zsanz3

Zsanz3 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

@AyushCipher Thanks for offering — the or {} guard (plus a regression for {"metadata": None}) is already on this branch as of the latest push. Appreciate it!

cursoragent and others added 2 commits September 16, 2026 22:38
`.get("metadata")` aliases the caller's dict, so emit flags leaked
onto later LangChain calls that reused the original config.

Fixes CopilotKit#6941

Co-authored-by: Zsanz3 <[email protected]>
Treat explicit metadata=None as {} so dict() does not raise TypeError.

Co-authored-by: Zsanz3 <[email protected]>
@cursor
cursor Bot force-pushed the cursor/fix-customize-config-metadata-5cf9 branch from 8a5b4cd to 389e6dd Compare September 16, 2026 22:38

@BenTaylorDev BenTaylorDev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verified locally before approving.

Ran the full sdk-python suite on the branch: 241 passed, 12 skipped. Then reverted the one-line guard and re-ran just tests/test_customize_config.py — both new tests fail without it:

  • test_none_metadata_is_treated_as_empty_dict → TypeError: 'NoneType' object does not support item assignment
  • test_shared_metadata_dict_is_not_mutated → mutation assertion fails

So the coverage is real, not vacuous. CI is green across the full matrix (3.10–3.14 × ag-ui-langgraph 0.0.42–0.0.44).

@AyushCipher — thanks for offering to carry this; #7076 is already closed and nothing further is needed from you here.

Merging.

@BenTaylorDev
BenTaylorDev merged commit 621e17c into CopilotKit:main Sep 17, 2026
45 checks passed
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

5 participants