fix(agent): make the models-barrel import in turn-context type-only - #111
Open
w0nche0l wants to merge 1 commit into
Open
fix(agent): make the models-barrel import in turn-context type-only#111w0nche0l wants to merge 1 commit into
w0nche0l wants to merge 1 commit into
Conversation
The runtime namespace import of '@openrouter/sdk/models' existed only to read EasyInputMessageRoleUser.User (the string 'user'), but it put the entire Speakeasy models barrel — hundreds of modules of top-level Zod schema construction — on the static import path of '@openrouter/agent/tool' (tool -> agent-tool -> conversation-state -> turn-context). Consumers that bundle the tool subpath into Cloudflare Workers paid ~200ms of startup CPU per worker, which pushed large workers past the 1s script-validation ceiling (error 10021) and forced OpenRouterTeam/openrouter-web#33740 to revert the 0.9.0 adoption. Make the import type-only, inline the role literal (behavior identical, still typechecked against models.EasyInputMessage), and add a unit test that walks the static runtime import graph of the hot subpaths (/tool, /tool-types, /stop-conditions) and fails if any of them reaches '@openrouter/sdk' at runtime again. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
turn-context.tsruntime-imported the entire@openrouter/sdk/modelsnamespace to read a single value:EasyInputMessageRoleUser.User, i.e. the string'user'. Becauseturn-contextsits on the static import path of@openrouter/agent/tool(tool → agent-tool → conversation-state → turn-context, new in 0.9.0), every consumer that statically imports the tool subpath now evaluates the Speakeasy models barrel — hundreds of modules of top-level Zod schema construction — at module load.bun patchin openrouter-web#33860 until it ships here.'user'literal — behavior identical, still typechecked againstmodels.EasyInputMessage.Regression guard
New unit test
tests/unit/startup-import-closure.test.tswalks the static runtime import graph of the startup-hot subpaths (/tool,/tool-types,/stop-conditions) from source and fails if any of them reaches@openrouter/sdkat runtime. Type-only imports and dynamicimport()are exempt by construction. Verified the test fails when the import is made runtime again.Test plan
pnpm test— 97 files, 1156 tests, no type errors, coverage thresholds metpnpm typecheck,pnpm lint,pnpm buildgreenMade with Cursor