feat(examples): chat-handler + production-trace-sink#32
Merged
Conversation
…-pattern bundle Two production patterns the prior nine examples did not cover. - examples/chat-handler — DurableChatTurnEngine.runTurn end-to-end: the durable manifest from a chat identity, runDurableTurn under the hood, session.run.* lifecycle, NDJSON ReadableStream the HTTP route forwards verbatim. Shows fresh / replay paths — same identity hits the cached run. - examples/production-trace-sink — createProductionTraceSink wiring: a per-session TraceEmitter writes spans, the sink composes a canonical ProductionRunRecord on endRun, persists via a ProductionRunRecordStore (in-memory for the demo; drizzle/D1/Postgres in production). OTLP forwarding + recordFeedback are documented in the README. Both runnable offline via pnpm tsx. README + examples/README updated. typecheck 0, Node suite 251, workerd suite 2, biome clean, build green.
tangletools
approved these changes
May 22, 2026
tangletools
left a comment
Contributor
There was a problem hiding this comment.
Verified. Two missing production-pattern examples: chat-handler (DurableChatTurnEngine.runTurn end-to-end with fresh + replay paths) and production-trace-sink (per-session TraceEmitter + canonical RunRecord persistence). Both offline. typecheck 0, Node suite 251, workerd suite 2, biome clean, build green.
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
Two production patterns the prior nine examples did not cover — the most-asked-for missing pieces from the DX audit.
examples/chat-handler/—DurableChatTurnEngine.runTurnend-to-end. Builds the durable manifest from a chat identity (tenantId/sessionId/turnIndex), drivesrunDurableTurn, emitssession.run.*lifecycle around the producer stream, returns the NDJSONReadableStreamthe HTTP route forwards verbatim. Shows fresh and replay paths — turn 0 retried with the same identity hits the cached run without re-running the producer.examples/production-trace-sink/—createProductionTraceSinkwiring: a per-sessionTraceEmitterwrites spans through the sink'sTraceStore; onendRunthe sink composes a canonicalProductionRunRecordand persists via yourProductionRunRecordStore(in-memory for the demo, Drizzle / D1 / Postgres in production). OTLP forwarding andrecordFeedbackare documented in the README.Both runnable offline via
pnpm tsx. The remaining gaps (PlatformAuthClientAPI tour,defineAgentend-to-end,D1DurableRunStoreon real D1) are smaller and can land as follow-ons.Test plan
pnpm typecheck— 0 errorspnpm test— 251 passed (17 files)pnpm test:workers— 2 passed under realworkerdpnpm exec biome check src tests examples— clean (2 pre-existing warnings)pnpm build— greenpnpm tsx examples/<dir>/<name>.ts