Skip to content

Commit 17f3db8

Browse files
fix(studio): Save waits for the CEL verdict to reach the page before it reads the hold (#36636)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ82MfFjFxvJRAyoku6XCvWt4)_ Fixes #36619 ## What changes `studioSaveBar.tsx`: the top bar's Save, after its existing wait past the lint debounce, now also awaits a render of its own at **transition** priority (`useRendersSettled`) before it reads the buffers' `held`. React commits that render only once no default-priority render is left, so the verdict's whole effect chain has reached the buffer's Save entry when Save reads it. No test file changes; the test is not skipped, retried, narrowed or slowed. ## Why — root cause (product race, not test timing) Both red cases fail on the **first** Save, before the tab is ever left: under load, all 4 red runs failed at `DataPillar.panelHold-27629.test.tsx:233` (`expect(save).not.toHaveBeenCalled()` right after typing `record.status ==` and pressing Save). Case (b)'s `studio-held-message` miss is the same race one step later: that Save already sent the broken text, the draft is clean, so no hold is left to name. The Save read `held` a fixed 50 ms past `LINT_DEBOUNCE_MS` (`VERDICT_SETTLE_MS`). An action predicate's verdict reaches the object's Save entry through four effect-driven renders after the lint resolves: `CelPredicateField` → `ConditionBuilder` (`onBlockingIssuesChange` effect) → `ActionDefaultInspector` (effect) → `ObjectActionsPanel` (`onCelVerdictsChange` effect) → `DataPillar` (`held`, copied into the entry ref by a layout effect). On a busy main thread the lint timer and Save's timer come due in the same timer pass, so Save's continuation runs before any of those renders and reads the pre-edit verdict (`count: 0`, judged on `true`), then sends `visible: "record.status =="`. That is the product sending a formula its check has not judged, the invariant the Save bar's header states; the rule-guard cases have a shorter chain and stayed green. Out of scope (Acceptance notes): the fix covers verdicts already reported when Save's timer fires. A lint still in flight then (a first-load dynamic import of the CEL engine on a slow network) is not awaited; closing that needs a pending-check signal from `metadata-admin/CelPredicateField.tsx`, outside this card's file surface. Not reproduced; recorded here only. ## Verification Loaded box: 4-core container, 4 busy-loop CPU stressors, `vitest run --maxWorkers=2` on the file alone, consecutive runs. | | runs | red | where | |:--|:--|:--|:--| | before (`origin/main` 9e2a4ac) | 7 | 4 | all at :233, case (a) | | after (head ff094d2) | 20 | 0 | 20 of 20 green in a row, all 5 cases each run | Every app-shell test file that saves through the top bar (27 files, 155 tests, the ones using `pressStudioSave` or `useStudioSaveCoordinator`): green locally. Local `tsc --noEmit` on app-shell reports no error in the changed file beyond the container's unbuilt `@object-ui/*` module resolution, which every file shares; the type-check lanes are CI's. Clause-②: no Metadata-protocol: none ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (not touched) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxbXCSJnUMMhWxyBmuqA <!-- signed: repo:objectstack#1 · os-warren · session_01JQwxbXCSJnUMMhWxyBmuqA --> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 99ece3c commit 17f3db8

2 files changed

Lines changed: 62 additions & 3 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(studio): Save waits for an expression's check to reach the page before it sends, so a predicate that does not parse is held, not saved, on a busy machine too
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Studio's top-bar Save reads whether an edit is held (a formula, rule guard or action predicate that does not parse) once the expression checks of the last keystroke have run. It waited a fixed 50 ms past the check's delay, but an action predicate's verdict reaches the object's Save through several renders (the expression field, the condition builder, the action inspector, the actions panel, then the Data pillar), and on a busy main thread those renders came after the 50 ms: Save read the verdict from before the edit and sent the unparsable predicate. Save now also waits until every render already queued has run, so it reads the verdict of the text it is about to send. A Save pressed after the check has reported is not slower; one pressed while renders are pending waits for them.

‎ui/packages/app-shell/src/views/studio-design/studioSaveBar.tsx‎

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,17 @@
2020
* - A buffer that holds an edit it cannot send yet (`held`) refuses the whole
2121
* Save before anything is written, naming what it needs. The held state is
2222
* read once the expression checks of the last keystroke have run (they run
23-
* {@link LINT_DEBOUNCE_MS} after it): a Save pressed at once never sends a
24-
* formula its check has not judged yet (objectui#4306).
23+
* {@link LINT_DEBOUNCE_MS} after it) AND their verdicts have reached the
24+
* buffers: a Save pressed at once never sends a formula its check has not
25+
* judged yet (objectui#4306).
26+
* - A verdict climbs to its buffer through effects, one render per hop (an
27+
* action predicate's: the CEL field, the condition builder, the action
28+
* inspector, the actions panel, then the Data pillar's `held`). Those
29+
* renders run at default priority, so Save waits for a render of its own
30+
* at transition priority ({@link useRendersSettled}): React commits it only
31+
* once no default-priority render is left, the last hop included. A fixed
32+
* margin past the debounce lost that race on a busy main thread and sent
33+
* the unparsable text (objectstack#36619).
2534
* - Cancel drops every dirty buffer's edits: each goes back to what the
2635
* server holds.
2736
*/
@@ -116,12 +125,50 @@ export interface StudioSaveCoordinator {
116125
cancel: () => void;
117126
}
118127

128+
/**
129+
* objectstack#36619 — an answer that resolves once React has no render more
130+
* urgent than a transition left: the caller's component renders at transition
131+
* priority, and React reaches that render only after every default-priority
132+
* one, including those scheduled by the effects of the renders before it. So
133+
* an effect chain already under way (a CEL verdict climbing to the buffer that
134+
* holds it) has run to its end when the answer resolves. Unmounted first, it
135+
* resolves at once: nothing is left to wait for.
136+
*/
137+
function useRendersSettled(): () => Promise<void> {
138+
const [tick, setTick] = React.useState(0);
139+
const seq = React.useRef(0);
140+
const waiters = React.useRef<Array<{ tick: number; resolve: () => void }>>([]);
141+
React.useEffect(() => {
142+
const due = waiters.current.filter((w) => w.tick <= tick);
143+
if (due.length === 0) return;
144+
waiters.current = waiters.current.filter((w) => w.tick > tick);
145+
for (const w of due) w.resolve();
146+
}, [tick]);
147+
React.useEffect(
148+
() => () => {
149+
for (const w of waiters.current) w.resolve();
150+
waiters.current = [];
151+
},
152+
[],
153+
);
154+
return React.useCallback(
155+
() =>
156+
new Promise<void>((resolve) => {
157+
const next = ++seq.current;
158+
waiters.current.push({ tick: next, resolve });
159+
React.startTransition(() => setTick(next));
160+
}),
161+
[],
162+
);
163+
}
164+
119165
/** The surface's side: the registered buffers, and the Save and Cancel over them. */
120166
export function useStudioSaveCoordinator(locale: string): StudioSaveCoordinator {
121167
const entriesRef = React.useRef(new Map<number, React.MutableRefObject<StudioSaveEntry | null>>());
122168
const [dirty, setDirty] = React.useState(false);
123169
const [saving, setSaving] = React.useState(false);
124170
const savingRef = React.useRef(false);
171+
const rendersSettled = useRendersSettled();
125172
const readDirty = React.useCallback(() => {
126173
for (const ref of entriesRef.current.values()) if (ref.current?.dirty) return true;
127174
return false;
@@ -152,6 +199,8 @@ export function useStudioSaveCoordinator(locale: string): StudioSaveCoordinator
152199
savingRef.current = true;
153200
setSaving(true);
154201
await new Promise((settled) => setTimeout(settled, VERDICT_SETTLE_MS));
202+
// The checks have run; their verdicts may still be climbing to the buffers.
203+
await rendersSettled();
155204
const entries = dirtyEntries();
156205
const held = entries.find((e) => e.held !== null);
157206
if (held || entries.length === 0) {
@@ -189,7 +238,7 @@ export function useStudioSaveCoordinator(locale: string): StudioSaveCoordinator
189238
} else if (saved.length > 0) {
190239
toast.success(tFormat('engine.studio.save.done', locale, { items: names(saved) }), { id: STUDIO_SAVE_TOAST_ID });
191240
}
192-
}, [dirtyEntries, locale, readDirty]);
241+
}, [dirtyEntries, locale, readDirty, rendersSettled]);
193242
const cancel = React.useCallback(() => {
194243
if (savingRef.current) return;
195244
for (const entry of dirtyEntries()) entry.cancel();

0 commit comments

Comments
 (0)