Skip to content

fix(decopilot): stop purging the run stream on RUN_FAILED — the consume step still projects it - #4337

Merged
viktormarinho merged 1 commit into
mainfrom
viktormarinho/slide-gen-hang-selfhost
Jul 6, 2026
Merged

viktormarinho merged 1 commit into
mainfrom
viktormarinho/slide-gen-hang-selfhost

Conversation

@viktormarinho

@viktormarinho viktormarinho commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Self-host report (b2g): a slide-generation run "executed for a very long time"; after F5 the thread showed Error: missing seq 1 as the assistant's reply.

Root cause

run-reactor.ts purged decopilot.stream.<runId> on every RUN_FAILED. That purge is a leftover from the pre-#4179 architecture — its own comment/test said "failed runs are NOT projected, so the reactor purges as explicit cleanup". Since the unified consume step (#4179), every dispatched run is projected (consumeRunProjection's entry guard deliberately ignores terminal status), and projection asserts a contiguous seq 1..N log.

The purge beheads that log in two live ways:

  1. Reaper mid-run (the reported incident): the hung slide tool stops chunk flow → no progress bumps for 10 min (RUN_IDLE_TIMEOUT_MS) → reaper FORCE_FAIL → reactor purges seq 1..K while the producer is still alive (abort isn't forwarded to the hung tool). When the tool finally returns, chunks resume at seq K+1; dispatch completes; the consume step reads the beheaded log → missing seq 1 → markRunFailed + the raw error persisted as a visible error part.
  2. In-band failure race: a hosted run that fails in-band fires RUN_FAILED right before the gate workflow's consume step reads the subject; the purge is fire-and-forget, so it races the DeliverPolicy.All read and can produce the same poisoned projection on an otherwise ordinary failure.

Fix

Remove the purge from the reactor and drop streamBuffer from RunReactorDeps entirely, so "the reactor never purges" is structural. Purge ownership is now single-owner, matching the projection design:

  • runProjectorWorkflowBody purges after a terminal projection (already the case),
  • dispatchRun clears the previous turn's remnants at turn start (already the case),
  • the stream's 24h max_age bounds never-projected runs (the documented backstop).

With this, the incident scenario projects the run's real content once the producer finishes (thread status stays failed from the reaper — completeRunIfNotCompleted only flips from in_progress), instead of destroying the log and fabricating missing seq 1.

Known separate edges (not this PR)

  • Genuine retention eviction (>24h / 4GB / 500K-msg caps) can still behead a log; rare, documented SLA.
  • Internal projection errors (missing seq N, idle-timeout) are still persisted verbatim as user-visible error parts when they do happen — sanitizing that is a separable change in consume-harness-stream.

Testing

  • bun test apps/mesh/src/api/routes/decopilot/ apps/mesh/src/dispatch-queue/ — unit suites pass (458 pass; the only failures are the (real Postgres) integration specs when no local PG is up).
  • Integration suites (run-reactor.integration.test.ts, run-registry.integration.test.ts) pass against a disposable postgres:16 + migrations: 13 pass / 0 fail.
  • bun run check clean; bun run lint 0 errors (7 pre-existing warnings, none in touched files); bun run fmt applied.

🤖 Generated with Claude Code


Summary by cubic

Stop purging the run’s JetStream subject on RUN_FAILED in Decopilot. This prevents beheading the stream and fixes “missing seq 1” projections from reaped or raced failures.

  • Bug Fixes

    • Do not purge on RUN_FAILED. The consume step projects every run and needs a contiguous seq 1..N log.
    • Prevents “missing seq 1” when the reaper force-fails a still-running producer or when failure races the consume read.
  • Refactors

    • Moved purge ownership to the projector (after terminal projection) and dispatchRun (previous turn cleanup). The 24h max_age remains the backstop.
    • Removed streamBuffer from RunReactorDeps and related wiring/tests. Updated comments to reflect the new ownership.

Written for commit bca0724. Summary will update on new commits.

Review in cubic

…me step still projects it

The run-reactor purged `decopilot.stream.<runId>` on every RUN_FAILED,
under the pre-#4179 assumption that failed runs skip the projector. Since
the unified consume step, EVERY dispatched run is projected (its entry
guard deliberately ignores terminal status), and projection requires the
contiguous seq 1..N log. The purge beheads that log in two live ways:

- The 10-min idle reaper force-fails a run whose producer is still alive
  (e.g. a hung long tool); the purge wipes seq 1..K, late chunks resume at
  K+1, and the consume step then poisons the thread with a persisted
  "Error: missing seq 1" as the user-visible assistant message.
- An ordinary in-band failure fires RUN_FAILED right before the consume
  step reads the subject; the fire-and-forget purge races that read.

Purge ownership now lives solely with the projector (terminal projection)
plus the dispatch-start cleanup of the previous turn; the stream's 24h
max_age bounds never-projected runs. `RunReactorDeps` drops `streamBuffer`
so the guarantee is structural.

Co-Authored-By: Claude Fable 5 <[email protected]>
@viktormarinho
viktormarinho merged commit 4dda869 into main Jul 6, 2026
15 checks passed
@viktormarinho
viktormarinho deleted the viktormarinho/slide-gen-hang-selfhost branch July 6, 2026 17:56
decocms Bot pushed a commit that referenced this pull request Jul 6, 2026
PR: #4337 fix(decopilot): stop purging the run stream on RUN_FAILED — the consume step still projects it
Bump type: patch

- decocms (apps/mesh/package.json): 3.99.0 -> 3.99.1

Deploy-Scope: server
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