fix: tabular review streams auto-resume after network drops - #33
Open
amal66 wants to merge 1 commit into
Open
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEguyEgXa9JjCciXCcVemC
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
When a tabular review is generating and the network blips (laptop sleeps, Wi-Fi drops, a proxy kills the idle connection), the SSE stream dies and the grid freezes with cells stuck on "generating" — even though the server keeps extracting and writing results to the database. With this change the client notices the drop, reconnects (up to 5 times with linear backoff), and catches up on the remaining cells from the database, so the table keeps filling in instead of requiring a manual page refresh.
Changes
frontend/src/app/components/tabular/TabularReviewView.tsx— the generate stream reader is factored into an idempotentapplyFrame+consume(response)helper that reports whether the terminal[DONE]was seen; if the stream drops first, a bounded resume loop (5 attempts, linear backoff) reconnects and keeps consuming.frontend/src/app/lib/mikeApi.ts— newresumeTabularGeneration(reviewId)client call:GET /tabular-review/:reviewId/generate/stream.backend/src/routes/tabular.ts— newGET /:reviewId/generate/streamresume endpoint: a pure observer that never re-triggers extraction. It computes the still-pending cells (targetPendingCells, exported for tests), then pollstabular_cells(the source of truth the generate run keeps writing to) every 3s, forwarding each newly terminal cell as the samecell_updateSSE frame, until all targeted cells are terminal, the client disconnects, or a 15-minute cap elapses. Replayed frames are safe: the client matches cells by(document_id, column_index).backend/tests/tabularGenerateStream.test.ts— unit tests fortargetPendingCells(placed underbackend/tests/so they are outside thetscbuild'ssrcinclude; they run under the vitest harness).Why
Long generate runs are exactly the streams most likely to hit an idle-timeout or transient network failure. The extraction work already survives the disconnect server-side (each finished cell is persisted before the frame is written), so the only missing piece was a way for the client to re-attach and observe the remaining progress. This ports the auto-resume behaviour from amal66/mike main, translated into this codebase's inline SSE consumption style.
Left out deliberately:
: keepalivecomments across the SSE endpoints (the fork's heartbeat matches what that PR does; no point duplicating it).@mike/api-clientreadSSE transport — out of scope per the port rules; the delta is expressed in the existing inline reader style instead.Testing
cd backend && npm install && npm run build— green as committed.cd frontend && npm install && npm run build— green as committed (with.env.localcopied from.env.local.example).upstream-pr/test-harness) merged locally:cd backend && npm test→ 2 files, 15 tests passed (3 of them from this PR);cd frontend && npm test→ 1 file, 8 tests passed (none added here).Provenance
All changes are mechanical ports of code in amal66/mike@origin/main (commit b3166dd) —
apps/web/src/app/components/tabular/TabularReviewView.tsx,packages/api-client/src/index.ts(resumeTabularGeneration),apps/api/src/modules/tabular/tabular.generateStream.ts(targetPendingCells,tailTabularRun,streamTabularRunView),apps/api/src/modules/tabular/tabular.routes.ts(the GET route), andapps/api/src/modules/tabular/__tests__/tabular.generateStream.test.ts. The resume endpoint's request-prep block is copied from this repo's ownPOST /:reviewId/generateprep. Exceptions (adaptations forced by upstream structure): (1) Redis pub/sub subscription,startSseHeartbeat, and theafterSubscribeenqueue hook are omitted from the tail loop — no Redis/queue infra exists here and heartbeats are deferred to olp#170 — leaving the fork's DB-poll reconcile as the only frame source; (2)attachActiveVersionPathsis dropped from the copied prep (the observer never reads storage paths); (3) client call rewritten from the fork'sclientConfig.fetchImpl/apiUrlto this repo'sfetch/API_BASEidiom; (4) fork comments referencing the async queue mode were reworded to describe this repo's synchronous run; (5) the test file drops the fork'svi.mock("lib/env")(only needed for the fork's queue import chain) and imports fromroutes/tabular;targetPendingCells' column parameter type is inlined as{ index: number }[].Credits & prior art
🤖 Generated with Claude Code
https://claude.ai/code/session_01CEguyEgXa9JjCciXCcVemC