fix(ai): render debug meta portably in ConsoleLogger so payloads survive Cloudflare Workers#734
Conversation
…orkers (TanStack#730) workerd never forwards console.dir output to the terminal, so the default debug logger printed category headlines but dropped every meta payload on Cloudflare Workers. ConsoleLogger now picks a per-runtime strategy: Node keeps the depth-unlimited console.dir dump, Workers gets circular-safe pretty-printed JSON appended to the message, and other runtimes receive meta as a second console argument. Detection checks workerd's navigator.userAgent marker before process.versions.node, since nodejs_compat emulates a Node version string and would otherwise route Workers down the broken Node path. Adds a Miniflare-based e2e spec that runs the built logger inside real workerd and asserts payloads reach the log stream at full depth.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR fixes debug logging on Cloudflare Workers/workerd by replacing Node-only ChangesConsoleLogger workerd meta payload fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
testing/e2e/tests/workerd-console-logger.spec.tsParsing error: "parserOptions.project" has been provided for 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. Comment |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ee9af98c-fa86-427a-8143-f969e7ddc4a8
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (6)
.changeset/console-logger-workerd-meta.mdpackages/ai/src/logger/console-logger.tspackages/ai/src/logger/types.tspackages/ai/tests/logger/console-logger.test.tstesting/e2e/package.jsontesting/e2e/tests/workerd-console-logger.spec.ts
… aimock aimock mocks provider LLM responses; this spec exercises console rendering inside the workerd runtime, a path provider HTTP never reaches. Wiring aimock in would mean bundling the whole chat() + adapter stack into the Miniflare worker without covering any additional fixed behavior.
|
View your CI Pipeline Execution ↗ for commit a020e86
☁️ Nx Cloud last updated this comment at |
@tanstack/ai
@tanstack/ai-anthropic
@tanstack/ai-client
@tanstack/ai-code-mode
@tanstack/ai-code-mode-skills
@tanstack/ai-devtools-core
@tanstack/ai-elevenlabs
@tanstack/ai-event-client
@tanstack/ai-fal
@tanstack/ai-gemini
@tanstack/ai-grok
@tanstack/ai-groq
@tanstack/ai-isolate-cloudflare
@tanstack/ai-isolate-node
@tanstack/ai-isolate-quickjs
@tanstack/ai-mcp
@tanstack/ai-ollama
@tanstack/ai-openai
@tanstack/ai-openrouter
@tanstack/ai-preact
@tanstack/ai-react
@tanstack/ai-react-ui
@tanstack/ai-solid
@tanstack/ai-solid-ui
@tanstack/ai-svelte
@tanstack/ai-utils
@tanstack/ai-vue
@tanstack/ai-vue-ui
@tanstack/openai-base
@tanstack/preact-ai-devtools
@tanstack/react-ai-devtools
@tanstack/solid-ai-devtools
commit: |
tombeckenham
left a comment
There was a problem hiding this comment.
Nice work on this. Thanks heaps!
Fixes #730
Problem
With the default logger (
debug: true), the per-category headlines print but themetapayloads never reach the terminal whenchat()runs on Cloudflare Workers / workerd (wrangler dev, Miniflare, TanStack Start on Workers). Debug mode is effectively headers-only: no request bodies, no chunk contents, noRUN_ERRORpayloads.The issue suggested the Node-only
console.diroptions were to blame, but the mechanism turned out to be broader: workerd never forwardsconsole.diroutput to the terminal at all — with options, without options, even for plain strings. Verified empirically against real workerd.A second trap surfaced while fixing it: under the
nodejs_compatflag (which TanStack Start on Cloudflare uses), workerd emulatesprocess.versions.node(reports"22.14.0"), so the naiveprocess.versions?.noderuntime check routes Workers down the Node path — the exact runtime that's broken. Detection has to rule out workerd first via itsnavigator.userAgent === 'Cloudflare-Workers'marker.Fix
ConsoleLoggernow rendersmetawith a per-runtime strategy:console.dir(meta, { depth: null, colors: true })(unchanged)console.debug(msg, meta)truncates at depth 2console.diris dropped entirely, and workerd's own inspect of extra console args truncates nested objectsmetaas a second console argumentThe JSON serializer handles circular references (
"[Circular]"),Errorinstances (whichJSON.stringifywould render as{}— andRUN_ERRORpayloads are the headline case), andbigint. Logging can never throw into the host app: if serialization and evenString()coercion fail, it falls back to a placeholder.Tests
packages/ai/tests/logger/console-logger.test.ts): all three strategies, including thenodejs_compatfake-Node trap, circular refs,Error/bigintserialization, the never-throws guarantee, and message-before-meta ordering on Node.testing/e2e/tests/workerd-console-logger.spec.ts): runs the built logger inside real workerd via Miniflare withnodejs_compatenabled, captures runtime stdio, and asserts payloads arrive at full depth (a depth-5 marker proves the JSON path — workerd's inspect would truncate it), errors keep their message, and circular meta survives.miniflareis a devDependency of the e2e package only; workerd was already in the lockfile via wrangler.Notes
Loggerinterface JSDoc intypes.tsupdated to describe the new default rendering.ws8.19.0 → 8.20.1 (within all consumers' ranges) and dropped an orphanedundici@7.16.0entry.nodejs_compatthat also lack the userAgent marker would fall through to the second-argument path — still visible output, just shallower than JSON.Summary by CodeRabbit
Bug Fixes
Tests
Documentation
Chores