← Back to PRs

#20471: fix: share relay auth state across bundler chunks via globalThis

by MisterGuy420 open 2026-02-19 00:20 View on GitHub →
size: XS trusted-contributor
Fixes #20457 ## What changed - Modified `src/browser/extension-relay.ts` to store the relay auth and server Maps on `globalThis` using `Symbol.for()` keys - This ensures that when Rolldown bundles the module into multiple chunks (one for gateway/control-service and one for pi-embedded-helpers), both chunks share the same Map instances - Previously, each chunk had its own `relayAuthByPort` and `serversByPort` Maps, causing the agent tool to read from an empty Map while the gateway stored auth tokens in its own copy ## AI-assisted contribution - This fix was generated by an AI agent (OpenClaw cron: gh-issues-fix) - Testing depth: validated with pnpm build && pnpm tsgo && pnpm format:check && pnpm test -- --run src/browser/extension-relay.test.ts - The fix addresses the root cause described in the issue by using globalThis with Symbol.for() to share state across bundler chunks <!-- greptile_comment --> <h3>Greptile Summary</h3> Replaced module-scoped Maps with globalThis-backed Maps using `Symbol.for()` to share relay authentication state and server instances across Rolldown bundler chunks. This prevents each chunk from maintaining separate Map instances, ensuring the agent tool can access auth tokens stored by the gateway service. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The fix is a well-understood pattern for sharing state across bundler chunks using globalThis and Symbol.for(). The implementation includes proper type guards (instanceof Map checks), maintains backward compatibility by reusing existing Maps if present, and is tested by the existing test suite. The change is minimal, focused, and addresses a specific bundler issue without affecting runtime behavior when the module is loaded normally. - No files require special attention <sub>Last reviewed commit: 6815608</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs