Skip to content

fix(core): replace all case variants when overlaying headers - #8111

Open
Elon-Jiang wants to merge 1 commit into
CopilotKit:mainfrom
Elon-Jiang:fix/header-case-overlay
Open

Elon-Jiang wants to merge 1 commit into
CopilotKit:mainfrom
Elon-Jiang:fix/header-case-overlay

Conversation

@Elon-Jiang

@Elon-Jiang Elon-Jiang commented Oct 30, 2026 •

Copy link
Copy Markdown

What does this PR do?

Fix case-insensitive replacement in ɵoverlayCoreHeaders for record and tuple-list inputs. If an agent supplies both x-request-id and X-Request-Id, overlaying the core value currently leaves one stale spelling behind. Native Headers then combines the stale and current values (agent-one, core-current) instead of sending only core-current.

The initial key lookup also becomes stale when the core map contains multiple spellings of a header. Resolve all matching spellings from the current output before each replacement, so record/tuple inputs agree with the existing Headers branch. Preserve request-owned Content-Type/Accept, output behavior, unrelated headers and input immutability.

Add parameterized regressions across all three input forms and a CopilotKitCore.ɵruntimeFetch integration regression. Against unchanged production code, the targeted file has 11 failures / 17 passes; with the fix it has 28 passes.

Related PRs and Issues

Source-discovered bug; no existing issue found. Checked current main, file history, header-related issues/PRs, and file lists for open PRs targeting main before preparing this change.

Validation

  • pnpm nx run @copilotkit/core:test --excludeTaskDependencies --skipNxCache: 1,552 tests passed.
  • pnpm nx run @copilotkit/core:check-types --excludeTaskDependencies --skipNxCache: passed.
  • Local HTTP wire check using unmodified baseline/fixed production helpers: server receives agent-one, core-current before the fix and only core-current after it.
  • Changed-file oxlint: passed, 0 warnings/errors.
  • Changed-file oxfmt --check: passed.
  • Normal pre-commit and commit-message hooks: passed, including dependency builds, all core tests, publint, attw, lint and commitlint.

Validation uses an isolated local dependency environment satisfying the affected package manifests (Node 24, Nx 22.7.5, Vitest 3.2.6, TypeScript 5.8.2), with local learning/shared dependencies built. This is package-scoped validation, not a whole-monorepo test run. AI-assisted preparation; the reported checks were executed locally.

Checklist

  • Read the contribution guide.
  • No public API or documented behavior changes; no documentation update needed for this internal bug fix.
  • No breaking change.
  • Allow edits by maintainers.

Summary by CodeRabbit

  • Bug Fixes
    • Core request headers now replace all case-insensitive duplicates, preventing conflicting variants from being sent.
    • Existing Content-Type, Accept, and unrelated request headers remain preserved.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between be9a2ca and a03a87e.

Files selected for processing: 2
  • packages/core/src/__tests__/core-runtime-fetch-headers.test.ts
  • packages/core/src/core/header-source.ts

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

Walkthrough

ɵoverlayCoreHeaders now handles all case-insensitive matches for core headers. Added tests cover record, tuple-list, and Headers inputs, plus runtime request-ID headers with different casing.

Changes: Core header overlay

Layer / File(s) Summary
Overlay behavior and tests
packages/core/src/core/header-source.ts, packages/core/src/__tests__/core-runtime-fetch-headers.test.ts
The overlay removes all matching header-name variants before assigning core values, except when a matching content-type or accept header already exists. Tests cover casing, preservation, input representation, and runtime request IDs.

Priority: Normal

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

Change: Bug fix

Suggested reviewers: jpr5

Merge Risk: Minimal · up to a03a8

The change removes stale header-name variants while preserving request-owned protocol headers. No merge-blocking issue is identified; merge after normal checks pass.

Pre-merge checks: Passed 5
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: replacing all case variants during core header overlay.
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 with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

This branch has not been deployed

No deployments
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