@@ -1336,8 +1336,7 @@ export function useRunColumn({ workspaceId, tableId }: RowMutationContext) {
13361336 queryClient . getQueryData < TableDefinition > ( tableKeys . detail ( tableId ) ) ?. schema
13371337 . workflowGroups ?? [ ]
13381338 const groupsById = new Map ( groups . map ( ( g ) => [ g . id , g ] ) )
1339- // Tally cells flipped to pending per row so we can bump the run-state
1340- // counter in lockstep with the optimistic cell stamps below.
1339+ // Tally cells stamped per row to bump the run-state counter in lockstep.
13411340 const stampedByRow : Record < string , number > = { }
13421341 const snapshots = await snapshotAndMutateRows ( queryClient , tableId , ( r ) => {
13431342 if ( targetRowIds && ! targetRowIds . has ( r . id ) ) return null
@@ -1377,11 +1376,10 @@ export function useRunColumn({ workspaceId, tableId }: RowMutationContext) {
13771376 return { ...r , data : nextData , executions : next }
13781377 } )
13791378
1380- // Bump the run-state counter to match the cells we just stamped. Without
1381- // this the top-right "X running" badge and per-row gutter Stop button
1382- // stay at zero until a refetch: the optimistic stamp marks the cell
1383- // in-flight in the rows cache, so the dispatcher's real `pending` SSE
1384- // event sees no `wasInFlight` transition and never bumps the counter.
1379+ // Bump the counter to match the stamped cells. Without it the "X running"
1380+ // badge + gutter Stop stay at zero until a refetch: the optimistic stamp
1381+ // already marks the cell in-flight, so the dispatcher's `pending` SSE
1382+ // sees no `wasInFlight` transition and never bumps the counter.
13851383 const runStateSnapshot = queryClient . getQueryData < TableRunState > (
13861384 tableKeys . activeDispatches ( tableId )
13871385 )
@@ -1404,23 +1402,18 @@ export function useRunColumn({ workspaceId, tableId }: RowMutationContext) {
14041402 } ,
14051403 onError : ( _err , _variables , context ) => {
14061404 if ( context ?. snapshots ) restoreCachedWorkflowCells ( queryClient , context . snapshots )
1407- // Roll back the optimistic counter bump to its pre-mutation value
1408- // (possibly undefined, which clears the entry we created).
1405+ // Roll back the optimistic counter bump (snapshot may be undefined).
14091406 if ( context ?. didBumpRunState ) {
14101407 queryClient . setQueryData ( tableKeys . activeDispatches ( tableId ) , context . runStateSnapshot )
14111408 }
14121409 } ,
14131410 onSuccess : ( data , { groupIds, runMode = 'all' , rowIds } , context ) => {
1414- // Seed the dispatch into the overlay list (drives resolveCellExec's
1415- // queued overlay for ahead-of-cursor rows). Upsert directly from the
1416- // response instead of refetching — a refetch would reset the
1417- // optimistic counter to the server's still-zero count (the dispatcher
1418- // hasn't stamped cells yet).
1411+ // Seed the dispatch into the overlay (drives resolveCellExec for
1412+ // ahead-of-cursor rows) from the response — refetching would reset the
1413+ // optimistic counter to the server's still-zero count.
14191414 const dispatchId = data ?. data ?. dispatchId
14201415 if ( ! dispatchId ) {
1421- // No dispatch was created (e.g. no matching groups / eligible rows).
1422- // No SSE will arrive to reconcile the optimistic counter bump, so roll
1423- // it back to its pre-mutation value.
1416+ // No dispatch created → no SSE to reconcile the bump; roll it back.
14241417 if ( context ?. didBumpRunState ) {
14251418 queryClient . setQueryData ( tableKeys . activeDispatches ( tableId ) , context . runStateSnapshot )
14261419 }
0 commit comments