Repository navigation
fix(platform): keep a governance switch from reverting a newer save - #4057
Merged
Merged
Conversation
A governance policy write carries the whole file, built from the config its caller last read. The header switch and the section's Save each wrote the file on their own, and the network decided which write landed last. A slow switch write could arrive after a Save made while it was pending and silently put the previous settings back (#4048). - One policy's writes from a tab now go out one at a time, in the order they were made, each once the one before it has settled. - The switch's `isToggling` becomes `isSettling`. It stays true while any write of the policy is in flight, and until the policy's read is no longer being fetched after a write, even when a live hint replaces that fetch. So the switch never builds its write from a config that a newer write replaced. This covers a Save, the rule tables' instant saves (whose switches had no such guard) and the read right after either. All ten editors on useGovernancePolicyToggle get this through the shared adapter and hook.
GOV-B20 throttles the network, saves the session idle timeout beside its switch's pending write, and checks that the Save lands and that the switch waits for the read-back after it (#4048). Its pin and its automated half are recorded, and the governance count goes from 79 to 80 boxes (1067 in all).
Contributor
Author
|
Independent review: accepted at
Verdict: the fix holds for #4048 and for the two gaps found in the sweep: a Save made while the switch's write is pending now lands last, and the switch waits for the re-read. Local checks on the exact head
CI at the exact head (merge ref onto
Non-blocking (P3), for follow-up
Also documented by the author and left open: cross-tab last-writer-wins, and Standard agent's stale "switched off" line while the switch's write is pending. Not covered: no production contact. I didn't drive the other eight editors in a browser; the shared adapter, the hook tests and the agent's reading cover them. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changed
A governance policy write carries the whole file, built from the config its caller last read. The header switch (
useGovernancePolicyToggle) and the section's Save each wrote that file on their own, and the network decided which write landed last. A slow switch write therefore landed after a Save made while it was pending, and silently put the old settings back (#4048).app/lib/backend/policy-write-order.ts, used by thegovernance/file_actions:saveGovernancePolicyadapter row). One policy's writes from a tab leave one at a time, in the order they were made, each once the one before it has settled. A failed write doesn't hold back the next one, and other policies don't wait. A Save made while the switch's write is in flight now waits for it, and its header Save shows busy meanwhile.isTogglingbecomesisSettling. It is true while any write of the policy from this tab is in flight, and until the policy's read is no longer being fetched after a write. The second part counts a refetch that a live hint replaced mid-flight. So the switch never builds its write from a config a newer write replaced. That closes two more gaps of the same kind, found in the sweep:editor.isSaving.isSettlingto their switch (a mechanical rename).editor.isSavingstays on the form editors' switches, so the reverse-order guard is untouched.GOV-B20(a throttled-network check) plus its pin and its automation row. Governance goes from 79 to 80 boxes, 1067 in all, counted withtools/lint-manual's parser.No new strings, no backend change and no API change.
expectedHashstays unused. In the reported order the switch's stale write had in effect been applied by the Save, so refusing it would have told the admin something false.How I verified it
Regression tests, each failing on
d6dd53ae0:app/features/settings/governance/hooks/use-governance-policy-toggle.race.test.tsxruns the real hook, react-query and adapter row.fetchstands in for a server that applies each POST as it arrives. The cases:On
d6dd53ae0all 4 fail: "expected 2 to be 1" (the Save overtook the held write) and "expected false to be true" (withisTogglingread in place ofisSettling).app/lib/backend/settings-governance.test.tsadds 5 adapter cases: order, failure, another policy, settling until the read is idle (with a hint replacing the fetch), and no hold for an unread policy.Local checks on these files:
single-failure-toast,error-message-descriptionandintegration-scope: all pass.oxlint: clean.oxfmt: clean.tscover the changed files: only 3 errors, inconversation-routing-policy-editor.tsxat lines this PR doesn't touch (theHistoryStateaugmentation inapp/router.tsx). They are identical with the same config ond6dd53ae0.lint:manualandcheck-guide.tson the governance suite: OK.Real browser. Local stack only, with its own Postgres and synthetic orgs. Headless Chromium 1208 at 1280×900. Playwright held one request 6 s, then passed it on unchanged. Write order is from
app.audit_logs.d6dd53ae086e1f9be9){false, 30}{false, 15}CI
6e9d795b5a8232783df62bb21027372084e98bda: 49 checks pass, 0 fail.ytdlp_liveincluded, 25/25 tasks.test:ui: 564 files, the race test among them, with no act warning.790dac2e1and2cba748c5, Unit failed only inbackend/core/video_links/ytdlp_live.test.ts: itsbeforeAlltimed out at 600 s while the video toolchain was installing from apt.2cba748c5, Playwright 6/16 also timed out after 12 min installing Chromium's apt dependencies, before any test ran.main36881739455 had passed that suite.chore:commits09541ca7e(green) and6e9d795b5(green) re-triggered the checks.2cba748c5is test only: two plain waits in the race test now run insideact(). This removes an "update … not wrapped in act" warning that printed only in CI.Not in this PR
Closes #4048