Repository navigation
Conversation
authHeaders() built a new object on each call, and App passes it to CopilotKitProvider on every render. The provider pushes each new headers object to the runtime client, which refetches /inspector-metadata. App re-renders on its 3 s polls, so a production page sent that request (answered 403) every few seconds. Return the same headers object until the token changes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
NathanTarbert
left a comment
There was a problem hiding this comment.
Thanks @HEOJUNFO, this is a great find. The trace is exactly right: a new headers object on every render goes through the provider's memo into setHeaders, and each of those refreshes inspector metadata. Keeping one object until the token changes fixes it at the source. In a quick check over 20 seconds, inspector-metadata requests dropped from 13 to 1. Login still swaps in the new headers, since setToken builds a fresh object and App re-renders.
Whether the one remaining 403 should become a 204 seems like a call for the maintainers, so keeping it out of this PR makes sense.
Looks good to me.
|
Friendly bump. Nathan's check above confirmed the fix, and it still merges cleanly into main. Happy to change anything you'd like. |
Part of #70 (third point: the inspector-metadata 403 polling).
authHeaders()returned a new object on every call, andApppasses it toCopilotKitProvideron every render (headers={authHeaders()}). The provider memoizes its headers on that object's identity, so each render ran its setup effect again. That calledcopilotkit.setHeaders(), and the runtime client then refetched/api/copilotkit/inspector-metadata.Appre-renders on its two 3 s polls (/stateand the capture poll). With an Intelligence runtime,/infoadvertisesinspectorMetadata: true, so the page sent that request every few seconds, andvalidateRuntimeScopeanswered each one with 403.authHeaders()now returns the same object untilsetToken()changes the token. TheuseVoiceand setup-telemetry callers spread it into their own headers, so they are unaffected.The single request on page load still gets a 403, because the server keeps that route closed on purpose (
runtime-scope.test.ts). I left the server alone. If you'd rather it answered 204, the SDK treats that as "no metadata" and logs nothing; I can add that here.Checked locally:
A new test,
tests/auth-headers.test.ts: the same object is returned until the token changes. It fails onmain.npm run check-format,npm run lint,npm run typecheck,npm test(49 files, 303 tests) andnpm run buildall pass.A throwaway test (not committed) rendered the real
CopilotKitProvider6 times with a mocked runtime that advertises inspector metadata:authHeaders()sent 1.It needs
@copilotkit/*inlined in Vitest because of the package's CSS import, which is why it isn't in this PR.I did not run the Docker setup with an Intelligence key, so I haven't watched the network tab in a real browser.
Prepared with AI assistance (Claude Code).
🤖 Generated with Claude Code