Skip to content

Commit 2144f25

Browse files
authored
fix(runner/fetchData): guard fetch-data updates during edit retry (#1831)
* fix(runner/fetchData): guard fetch-data updates during edit retry + force sync Move the run-staleness check into the editWithRetry callback so a new run that starts while we await runtime.idle() prevents older responses from overwriting fresher state. Force sync of result helper cells, as some are otherwise never read and that can force conflicts.
1 parent 6bf8982 commit 2144f25

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/runner/src/builtins/fetch-data.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ export function fetchData(
7878
error.setSourceCell(parentCell);
7979
requestHash.setSourceCell(parentCell);
8080

81+
// Kick off sync in the background
82+
pending.sync();
83+
result.sync();
84+
error.sync();
85+
requestHash.sync();
86+
8187
sendResult(tx, {
8288
pending,
8389
result,
@@ -134,22 +140,22 @@ export function fetchData(
134140
})
135141
.then(processResponse)
136142
.then(async (data) => {
137-
if (thisRun !== currentRun) return;
138-
139143
await runtime.idle();
140144

141145
await runtime.editWithRetry((tx) => {
146+
if (thisRun !== currentRun) return;
147+
142148
pending.withTx(tx).set(false);
143149
result.withTx(tx).set(data);
144150
requestHash.withTx(tx).set(hash);
145151
});
146152
})
147153
.catch(async (err) => {
148-
if (thisRun !== currentRun) return;
149-
150154
await runtime.idle();
151155

152156
await runtime.editWithRetry((tx) => {
157+
if (thisRun !== currentRun) return;
158+
153159
pending.withTx(tx).set(false);
154160
result.withTx(tx).set(undefined);
155161
error.withTx(tx).set(err);

0 commit comments

Comments
 (0)