Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(tables): reliable stop-all, accurate "X running", and rate/usage gating for cell runs#4838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
aca010b
fix(tables): reliable stop-all, accurate "X running", and rate/usage …
TheodoreSpeaks b00dbfa
fix(tables): dedupe usage-limit event + release rate-limited cells on…
TheodoreSpeaks 1e42819
fix(tables): jitter rate-limit retry backoff to avoid thundering herd
TheodoreSpeaks 877600d
Merge remote-tracking branch 'origin/staging' into fix/table-stop-wor…
TheodoreSpeaks 8bd4694
fix(tables): unstick cells + resync counter on usage-limit halt
TheodoreSpeaks aee1374
fix(tables): don't emit stale dispatching event after a mid-window halt
TheodoreSpeaks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8 apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/table-grid.tsx
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
33 changes: 32 additions & 1 deletion
33 apps/sim/app/workspace/[workspaceId]/tables/[tableId]/hooks/use-table-event-stream.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| 'use client' | ||
| import { useEffect } from 'react' | ||
| import { useEffect, useRef } from 'react' | ||
| import { createLogger } from '@sim/logger' | ||
| import { useQueryClient } from '@tanstack/react-query' | ||
| import type { ActiveDispatch } from '@/lib/api/contracts/tables' | ||
| @@ -44,6 +44,9 @@ interface UseTableEventStreamArgs { | ||
| tableId: string | undefined | ||
| workspaceId: string | undefined | ||
| enabled?: boolean | ||
| /** Fired when the server halts a dispatch because the billed account is over | ||
| * its usage limit. The page surfaces an upgrade prompt + redirect. */ | ||
| onUsageLimitReached?: (event: { dispatchId?: string; message: string }) => void | ||
| } | ||
| /** | ||
| @@ -59,9 +62,14 @@ export function useTableEventStream({ | ||
| tableId, | ||
| workspaceId, | ||
| enabled = true, | ||
| onUsageLimitReached, | ||
| }: UseTableEventStreamArgs): void { | ||
| const queryClient = useQueryClient() | ||
| // Ref so a changing callback identity doesn't tear down + reconnect the SSE. | ||
| const onUsageLimitReachedRef = useRef(onUsageLimitReached) | ||
| onUsageLimitReachedRef.current = onUsageLimitReached | ||
| useEffect(() => { | ||
| if (!enabled || !tableId || !workspaceId) return | ||
| @@ -205,6 +213,28 @@ export function useTableEventStream({ | ||
| scheduleDispatchInvalidate() | ||
| } | ||
| const applyUsageLimit = (event: Extract<TableEvent, { kind: 'usageLimitReached' }>): void => { | ||
| // Drop the halted dispatch from the overlay so the "running" UI clears | ||
| // immediately (the dispatcher was marked complete server-side). Cascade / | ||
| // auto-fire events carry no dispatchId — nothing to remove. | ||
| if (event.dispatchId) { | ||
| queryClient.setQueryData<TableRunState>(tableKeys.activeDispatches(tableId), (prev) => { | ||
| if (!prev) return prev | ||
| const filtered = prev.dispatches.filter((d) => d.id !== event.dispatchId) | ||
| return filtered.length === prev.dispatches.length | ||
| ? prev | ||
| : { ...prev, dispatches: filtered } | ||
| }) | ||
| } | ||
| // Blocked cells are left `queued` in the DB with no terminal cell event, | ||
| // so `runningByRowId` would otherwise stay non-zero (stale "X running"). | ||
| // Re-sync the server counts, and refetch rows so cells whose pre-stamps | ||
| // the server cleared drop their "Queued" state. | ||
| scheduleDispatchInvalidate() | ||
| void queryClient.invalidateQueries({ queryKey: tableKeys.rowsRoot(tableId) }) | ||
| onUsageLimitReachedRef.current?.({ dispatchId: event.dispatchId, message: event.message }) | ||
| } | ||
greptile-apps[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const handlePrune = (payload: PrunedEvent): void => { | ||
| logger.info('Table event buffer pruned — full refetch', { tableId, ...payload }) | ||
| void queryClient.invalidateQueries({ queryKey: tableKeys.rowsRoot(tableId) }) | ||
| @@ -253,6 +283,7 @@ export function useTableEventStream({ | ||
| savePointer(tableId, lastEventId) | ||
| if (entry.event?.kind === 'cell') applyCell(entry.event) | ||
| else if (entry.event?.kind === 'dispatch') applyDispatch(entry.event) | ||
| else if (entry.event?.kind === 'usageLimitReached') applyUsageLimit(entry.event) | ||
| } catch (err) { | ||
| logger.warn('Failed to parse table event', { tableId, err }) | ||
| } | ||
16 changes: 13 additions & 3 deletions
16 apps/sim/app/workspace/[workspaceId]/tables/[tableId]/table.tsx
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
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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.