Skip to content

feat(examples): chat-handler + production-trace-sink#32

Merged
drewstone merged 1 commit into
mainfrom
feat/production-pattern-examples
May 22, 2026
Merged

feat(examples): chat-handler + production-trace-sink#32
drewstone merged 1 commit into
mainfrom
feat/production-pattern-examples

Conversation

@drewstone

Copy link
Copy Markdown
Contributor

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.runTurn end-to-end. Builds the durable manifest from a chat identity (tenantId / sessionId / turnIndex), drives runDurableTurn, emits session.run.* lifecycle around the producer stream, returns the NDJSON ReadableStream the 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/createProductionTraceSink wiring: a per-session TraceEmitter writes spans through the sink's TraceStore; on endRun the sink composes a canonical ProductionRunRecord and persists via your ProductionRunRecordStore (in-memory for the demo, Drizzle / D1 / Postgres in production). OTLP forwarding and recordFeedback are documented in the README.

Both runnable offline via pnpm tsx. The remaining gaps (PlatformAuthClient API tour, defineAgent end-to-end, D1DurableRunStore on real D1) are smaller and can land as follow-ons.

Test plan

  • pnpm typecheck — 0 errors
  • pnpm test251 passed (17 files)
  • pnpm test:workers2 passed under real workerd
  • pnpm exec biome check src tests examples — clean (2 pre-existing warnings)
  • pnpm build — green
  • Both new examples runnable: pnpm tsx examples/<dir>/<name>.ts

…-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 tangletools left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@drewstone drewstone merged commit b339354 into main May 22, 2026
1 check passed
@drewstone drewstone deleted the feat/production-pattern-examples branch May 22, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants