Skip to content

fix(decopilot): instrument silent failure points in /stream publish path - #3951

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/decopilot-stream-silent-failure-diagnostics
Jun 16, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/decopilot-stream-silent-failure-diagnostics

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jun 16, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Reports of: a decopilot run where the live /stream is stuck — zero chunks arrive — yet the assistant message is saved, and there are no error logs on client or server. On reload, the order breaks (run 1's response renders under run 2's user message, run 1 shows "No response was generated"); a second reload fixes it.

Root cause family: persistence and live streaming are decoupled. consumeHarnessStream persists the message upstream of the NATS pump(). So when the JetStream client is degraded on a pod, the run completes + persists while nothing is published to the subject — and every fork that handles this is silent:

  • NatsStreamBuffer.pump() returns early when this.js is null (no log) → chunks never published.
  • NatsStreamBuffer.createTailStream() returns null when this.js is null (no log).
  • dispatchRunAndWait falls back to draining uiStream directly when createTailStream returns null — never pumps to the subject (silent).
  • /stream returns a bare 204 on null tail (silent).

this.js is cached at init() and only refreshed via the onReady/reconnect path; a NATS blip ([NatsProvider] Disconnected, console.log — not error, easy to miss) can leave an in-flight run publishing into a void.

What

Logging only — no behavior change.

  • nats-stream-buffer: init logs ready/degraded (js=null)/skipped; pump and createTailStream warn when they no-op on a null JetStream client; per-run published-chunk count behind DECOPILOT_STREAM_TRACE=1.
  • dispatch-run: warn (producer-fallback-no-pump) when dispatchRunAndWait takes the direct-drain fallback and never pumps.
  • routes /stream: always log the null-tail 204 (tail-unavailable-204); behind DECOPILOT_STREAM_TRACE=1 log deliverPolicy + run age + delivered chunk count (tail-open/tail-closed) to confirm the deliverPolicy / cross-run replay race.

All structured logs share msg: "decopilot-stream-diag" for grepping.

How to use in the affected env

  1. First check existing logs: grep "NatsProvider" for Disconnected/Reconnected near the incident.
  2. grep "decopilot-stream-diag" — producer-fallback-no-pump or pump: JetStream client unavailable ⇒ producer published nothing; tail-unavailable-204 ⇒ consumer pod's buffer degraded.
  3. Set DECOPILOT_STREAM_TRACE=1 to correlate pump-done publishedChunks=N (producer) against tail-closed deliveredChunks=0 (consumer).

Testing

bun test nats-stream-buffer.test.ts — 23 pass. bun run check clean on changed files (pre-existing ct/ playwright-dep errors unrelated).

🤖 Generated with Claude Code


Summary by cubic

Add diagnostic logging to Decopilot /stream to surface silent JetStream degradation where runs persist but no chunks are delivered. No behavior changes; this makes “stream stuck, message saved, no logs” debuggable.

  • New Features
    • nats-stream-buffer: init logs ready/degraded (js=null)/skipped; warn when pump() or createTailStream() no-op due to missing JetStream; per-run publish counts behind DECOPILOT_STREAM_TRACE=1.
    • dispatch-run: warn when the direct-drain fallback is used (producer-fallback-no-pump).
    • /stream route: always log null-tail 204 (tail-unavailable-204); with DECOPILOT_STREAM_TRACE=1 log deliverPolicy, run age, and delivered chunk counts (tail-open/tail-closed).
    • All logs share msg: "decopilot-stream-diag" for easy grepping.

Written for commit 1af9fe5. Summary will update on new commits.

Review in cubic

The live /stream path has several silent forks where a degraded JetStream
client makes a run complete + persist (consumeHarnessStream is upstream of
the NATS pump) while delivering ZERO chunks to the client and emitting no
error — matching 'stream stuck, message saved, no logs' reports.

Instrument every blind spot:
- nats-stream-buffer: log init ready/degraded/skipped; warn when pump or
  createTailStream no-op because the JetStream client is null; per-run
  published-chunk count behind DECOPILOT_STREAM_TRACE.
- dispatch-run: warn when dispatchRunAndWait takes the direct-drain fallback
  (createTailStream null) and never pumps to the subject.
- routes /stream: always log the null-tail 204 (degraded buffer); behind
  DECOPILOT_STREAM_TRACE log deliverPolicy + run age + delivered chunk count
  to confirm the deliverPolicy/cross-run replay race.

No behavior change — logging only.
@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) June 16, 2026 15:44
@pedrofrxncx
pedrofrxncx merged commit f7e771c into main Jun 16, 2026
15 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/decopilot-stream-silent-failure-diagnostics branch June 16, 2026 15:48
decocms Bot pushed a commit that referenced this pull request Jun 16, 2026
PR: #3951 fix(decopilot): instrument silent failure points in /stream publish path
Bump type: patch

- decocms (apps/mesh/package.json): 3.27.1 -> 3.27.2
@pedrofrxncx

Copy link
Copy Markdown
Collaborator Author

Branch now also carries the actual fix (commit 94a9cbb8): preserveCreatedAt in thread-connection.ts stops a deliverPolicy:"all" replay from stripping a DB-seeded message's created_at on reconnect (root cause of the turn-1-renders-under-turn-2 reorder + empty slot). The decopilot-stream-diag logs confirmed the publish path itself is healthy (35/35 delivered, 0 errors) — the reorder is client-side ordering, triggered by the server's full-subject replay. Tests added in thread-connection.test.ts.

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.

1 participant