Skip to content

fix(store): preserve concurrent local saves during polling and clear stale error on reconnect - #6338

Open
CrowAleksito wants to merge 1 commit into
tscircuit:mainfrom
CrowAleksito:fix/polling-preserve-concurrent-saves-5619
Open

CrowAleksito wants to merge 1 commit into
tscircuit:mainfrom
CrowAleksito:fix/polling-preserve-concurrent-saves-5619

Conversation

@CrowAleksito

Copy link
Copy Markdown

Re-opens #6137 (originally submitted Nov 7 2026-11-07T02:29:19Z and endorsed by #6157; auto-closed by stale bot while awaiting maintainer review, rebased cleanly onto latest main).

Summary

Fixes #5619
/claim #5619
Addresses tscircuit/tscircuit#5368

Problem

  1. Concurrent local saves overwritten during polling (Polling overwrites independent local saves while requests are pending (repro + patch) #5619): In useRunFrameStore.startPolling(), state is captured before await getEvents(state.lastEventTime) and const updates = new Map(state.fsMap) clones the stale file map before awaiting getFileApi(event.file_path). When upsertFile or manual-edit saves finish while either request is in flight, set({ fsMap: updates }) replaces fsMap with the stale clone, losing newly added or updated local files.
  2. Stale connection error never cleared on reconnect (tsci dev UI doesn't recover after dev-server restart tscircuit#5368): Once a poll fails and sets error, subsequent successful polls never reset error back to null, leaving ApiStatusIndicator stuck showing "Dev server disconnected" after tsci dev restarts.

Solution

  • Record only the current poll batch's file updates and deletions (Map<FilePath, FileContent | null>, with null marking FILE_DELETED) and merge them functionally against currentState.fsMap (set((currentState) => ...)).
  • Read get().lastManualEditsChangeSentAt at check time rather than from the pre-await snapshot.
  • Clear error to null when a poll cycle completes without throwing (if (get().error !== null) set({ error: null })).

Validation

  • Added tests/runframe-polling-concurrent-files.test.ts covering:
    • Concurrent upsertFile updates and additions while /events/list is pending.
    • Concurrent upsertFile updates and additions while /files/get is pending.
    • Automatic recovery of error state to null when a subsequent poll succeeds after a connection failure.
  • Verified with bun test tests/runframe-polling-concurrent-files.test.ts (3/3 pass), bunx tsc --noEmit, and biome format.

@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
runframe Ready Ready Preview Nov 20, 2026 6:20pm UTC

Request Review

@CrowAleksito

Copy link
Copy Markdown
Author

Rebased cleanly onto latest main (f4ab919) — ready for review.

@CrowAleksito

Copy link
Copy Markdown
Author

Rebased cleanly onto latest main (b16ccf16 -> 37a7b1c9, behind_by: 0). Ready for review whenever convenient!

This branch was successfully deployed

1 active deployment
Preview — 37a7b1c9 Deployed Nov 20, 2026 by vercel[bot]
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.

Polling overwrites independent local saves while requests are pending (repro + patch)

1 participant