Skip to content

fix(settings): keep a reopened Settings open when a step back lands late - #2023

Merged
devswha merged 1 commit into
mainfrom
fix/settings-close-flake
Oct 26, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/settings-close-flake

Conversation

@devswha

@devswha devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Change

Refs #2000. This fixes two of the three ways the check fails; a third is still being traced (see "Still open") and gets its own PR, which will close #2000. These two are proven and reviewed, so they ship now and take most of these flakes off other PRs' CI.

scripts/settings-pages-demo-regression.ts timed out on CI waiting for Settings to open (openSettings, line 29, from the settings search check). The check was right: two history traversals asked for before Settings opened could land after it and close it, a race any slow device has too, so the fix is in the app.

  1. Settings' own step back (src/lib/settingsHistory.ts). Closing Settings steps back off its entries, and the browser lands that traversal later. In the same commit the app's address bar rewrites the address on the entry being left (replaceState on the same entry). The module took any foreign write as a reason to let go of its pending step. So when Settings opened again before the step landed, the late popstate looked like a Back of the user's and closed the reopened dialog. A replaceState now lets go of the step only when it changes the Settings entry or the opening it belongs to; a pushState still always does.
  2. A phone sheet's step back (src/lib/sheetHistory.ts, src/lib/historyKeys.ts). On a phone, the palette is a sheet with its own entry; closed by Escape, it steps back off that entry with a deferred history.back(). Settings opened from the shortcut before that step landed took over the sheet's entry, and the step landed on the entry under it, which Settings read as Back to where it opened. sheetHistory now answers whether a popstate is such a step through a small shared query in historyKeys.ts, so neither module imports the other and their load order is unchanged. When the step lands on the entry that the sheet Settings took over opened over, Settings stays and makes its entries again. The check is anchored to that sheet: a sheet closing above an open Settings (a lightbox in a preview over Settings, a sheet over a #hash entry) is not taken for one.

A trace of every history call, popstate, key press and dialog change, captured in failing runs under load, showed each race.

The one-second landing deadline (#630) is unchanged: Settings' own step that lands more than a second after it was asked for is still taken for the user's Back, as one may be. DESIGN.md now says so.

Tests

  • src/lib/settingsHistory.test.ts: the address written on the entry the step leaves keeps the step Settings' own; a write that changes the Settings entry still lets go of it; a closed sheet's step landing under Settings keeps it open (and closes it when it is no such step).
  • src/lib/sheetHistory.test.ts: sheetStep.lands answers before and after this module handles the event. A test with both real modules, loaded in the app's order, covers a peek under the palette, the palette's late step and Settings' X, then a lightbox closed in a preview over Settings, which must not bring Settings back. The fake history now dispatches one event per traversal, as browsers do.
  • scripts/settings-pages-demo-regression.ts, new lateCloseStep: at 1440 and 390px, Settings is closed and opened again with its step held, and at 390px the palette is closed by Escape with its step held before Settings opens. Each held step goes to the entry it named when it was asked for (Navigation API traverseTo), as a browser does. The page's timers set meanwhile start only once the step has landed, so the check does not depend on the runner's speed.

Validation

  • 4×30 of bun scripts/settings-pages-demo-regression.ts at once, in four checkouts, pinned to two cores under dori heavy: 28 of 29 runs passed before the run was stopped; the one failure is the third path below, not either race fixed here. Before the second fix, the same load (four copies in one checkout) failed 5 of 8 runs: 4 traced to the palette's late step, 1 timed out closing Settings in the settings search, without a trace.
  • Each fix is needed. In separate checkouts, the script passes as is. Without the sheet-step branch it fails at "the palette's late step back"; without the same-entry check it fails at "the late step back at 1440px". Each unit case fails under the mutation it names.
  • The browser check holds only through the paused timers: a variant that waits 1.5 s of real time before the release passes with them and fails without them.
  • bun run check fast: pass.
  • Reviews: omo-native-code-reviewer approved after its findings were fixed. Those were: the browser check first held the back() call, choosing its target late; the guard first keyed on the previous state, which a peek's remade entry overwrites; and the guard first matched a sheet closing above Settings. Codex Sol raised the same last two from its own traversal harness, and found nothing on the final commit, where both of its repros pass.

Still open

A third path fails about once in 30 runs under the same load: in the settings search check (Korean, in the failing run), Settings opened from a palette result does not detach within 30 s after its X is clicked. The failing run logged the dialog still visible 63 times. It appeared once, untraced, before the second fix too. I am tracing it with a history dump on failure; its fix goes in a follow-up PR that closes #2000.

Not in this PR

  • Concurrent demo builds race on the shared xterm cache (MISSING_EXPORT) #2021: four demo builds at once in one checkout can fail with MISSING_EXPORT from the shared xterm cache. I hit it while stress-testing this, and CI's parallel browser workers may too.
  • The reviewer noted that a lightbox closed inside a preview opened over Settings still closes Settings (useSettingsDialog on that popstate). That predates this PR, and I have not reproduced it in a browser.

Two history traversals asked for before Settings opened could land after it
and close it, so on a slow runner the demo regression waited 30 s for a
dialog that was gone (#2000), and a fast close and reopen on a slow phone did
the same:

- Closing Settings steps back off its entries. Meanwhile the app's address
  bar writes the address on the entry being left, and that replaceState
  released Settings' claim on its step, so the late landing looked like a
  Back of the user's. A replaceState now lets go of the step only when it
  changes the Settings entry or the opening it belongs to.
- A phone's sheet (the palette) closed by Escape steps back off its own
  entry. Settings opened before that step landed pushed over the sheet's
  entry, and the landing under it read as Back to the entry the sheet opened
  over. sheetHistory now answers whether a popstate is such a step
  (historyKeys' sheetStep, so neither module imports the other or changes
  their load order), and Settings then stays and makes its entries again.

The demo regression holds each step until Settings is open again, and the
page's timers with it, so it no longer depends on the runner's speed.

Refs #2000
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between e49276d and 1e528fe.

Files selected for processing: 8
  • DESIGN.md
  • changelog.d/settings-reopen-late-step-back.md
  • scripts/settings-pages-demo-regression.ts
  • src/lib/historyKeys.ts
  • src/lib/settingsHistory.test.ts
  • src/lib/settingsHistory.ts
  • src/lib/sheetHistory.test.ts
  • src/lib/sheetHistory.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Settings now stays open when reopened before a previous close action finishes, including when reopening after closing a phone sheet.
    • A delayed close step no longer causes a later Back action to be mistaken for part of the earlier close.
  • Tests
    • Added regression coverage for these delayed navigation scenarios on desktop and phone.

Settings history now distinguishes delayed Settings-owned traversals from user Back actions and coordinates with pending phone-sheet steps. Unit and browser regressions cover reopening Settings before those steps land. The design and changelog describe the late-step behavior.

Changes: Settings history traversal

Layer / File(s) Summary
Sheet-step event coordination
src/lib/historyKeys.ts, src/lib/sheetHistory.ts, src/lib/sheetHistory.test.ts
sheetHistory exposes whether a popstate event belongs to a sheet step. Tests cover event delivery and step-state reporting.
Settings entry reconciliation
src/lib/settingsHistory.ts, src/lib/settingsHistory.test.ts, src/lib/sheetHistory.test.ts
settingsHistory tracks the sheet entry beneath Settings, preserves pending traversal for same-entry replacements, and handles matching sheet steps without treating them as user Back actions. Tests cover these traversal cases.
Late-step regression and documentation
scripts/settings-pages-demo-regression.ts, DESIGN.md, changelog.d/settings-reopen-late-step-back.md
The browser regression holds history traversal while reopening Settings at desktop and phone widths. The design and changelog describe the late-step behavior.

Priority: Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

  • devswha/ovis#1947: Changes Settings traversal ownership; this PR continues that behavior with pending traversal release rules and delayed sheet-step coordination.
  • devswha/ovis#1754: Moves the Settings history consumer into useSettingsDialog; this PR changes traversal semantics used by that navigation hook.
Merge Risk: Minimal · up to 1e528

The late-step behavior is ready to merge after normal checks. The separately reported palette-result failure remains planned for a follow-up.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning #2000 remains an active flaky regression requirement. The PR implements and tests two delayed-history traversal fixes in settingsHistory.ts and sheetHistory.ts. However, openSettings still sends… Add and test the follow-up fix for the remaining settings-search failure. Address the single shortcut attempt described by #2000 if that path is confirmed. Demonstrate that scripts/settings-pages-demo-regression.ts no longer has the repor…
Docstring Coverage Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 6 files. (2 skipped: 2… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preventing a reopened Settings dialog from closing when a delayed history step lands.
Description check Passed The description includes the required Change and Validation sections. It explains the problem, resulting behavior, implementation scope, tests, validation results, and known follow-up work.
Out of Scope Changes check Passed The changed application code, shared history query, unit tests, regression coverage, design note, and changelog all support the two history-race fixes or document their behavior. The supplied changes …
Full details: Out of Scope Changes check

Explanation

The changed application code, shared history query, unit tests, regression coverage, design note, and changelog all support the two history-race fixes or document their behavior. The supplied changes do not show unrelated implementation such as the excluded #2021 cache failure or the pre-existing lightbox behavior.

Full details: Linked Issues check

Explanation

#2000 remains an active flaky regression requirement. The PR implements and tests two delayed-history traversal fixes in settingsHistory.ts and sheetHistory.ts. However, openSettings still sends one shortcut press, and the PR reports a third failure path in which Settings remains visible after its X is clicked. The PR therefore does not establish a complete fix for the linked issue.

Resolution

Add and test the follow-up fix for the remaining settings-search failure. Address the single shortcut attempt described by #2000 if that path is confirmed. Demonstrate that scripts/settings-pages-demo-regression.ts no longer has the reported failure paths under the relevant load.

Full details: Docstring Coverage

Explanation

Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 6 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Merge pass: the Astra gate approved 1e528fe. Both late-traversal races are fixed, and real Back/Forward and the one-second deadline are unchanged. 70 focused tests pass, and three full settings-pages browser runs passed, including two pinned to two CPUs under load. Each relevant test fails when the production code is mutated. It merges once its CI is green and its turn comes in the queue.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Merge pass review report. Overall: PASSED. This client change fixes two of the three races behind flake #2000. The Astra gate (omo-native-gate-reviewer, gpt-6-astra) approved 1e528fe.

What it does. settings-pages-demo-regression.ts timed out waiting for Settings to open. The app was at fault, not the test: a step back taken before Settings opened could land after it and close it. Two races are fixed:

  • Race 1 (settingsHistory.ts): a replaceState on the entry being left, such as the address bar rewriting it, no longer makes Settings let go of its pending step back. A late popstate therefore no longer closes a reopened Settings. A pushState still always drops the step.
  • Race 2 (sheetHistory.ts, historyKeys.ts): a phone sheet closed with Escape takes a deferred history.back(). If Settings is opened before that lands, the landing step no longer reads as Back. The check is anchored to that sheet, so a sheet closing above Settings behaves as before. The two modules don't import each other, and load order is unchanged.

Gate verification:

Overlap. DESIGN.md is shared with #1995, #1977 and #1969. Each of them still merges cleanly on top of main plus this PR (checked with git merge-tree).

@devswha
devswha merged commit aea938a into main Oct 26, 2026
11 checks passed
@devswha
devswha deleted the fix/settings-close-flake branch October 26, 2026 14:41
devswha added a commit that referenced this pull request Oct 26, 2026
## Change

Fixes #2000, together with #2023 (merged).

#2023 fixed the two app races behind #2000's timeout. The third way the
check failed is in the test, not the app: on a phone, Settings is a
sheet that rises from the bottom edge over 360 ms, and on a loaded
runner the settings search check clicked Settings' X while it was still
rising. The click landed where the X had been, on the header under it,
so Settings never closed and the check waited 30 s for it to (`close()`
in the settings search, about once in 30 runs under load).

Evidence, from a traced run of the check under load (390px, Korean,
palette query "OpenAI API 키"): the close click's target was the dialog's
header, whose only text is the title "음성 입력". In every earlier close the
target was the X's icon. Sampling the X's position every frame after
Settings opens from that result shows it moves only vertically, during
the sheet's rise (y 860 → 83.5 over about 360 ms, with a long spring
tail). Neither the dialog, its body nor the page scrolls under it. The
failing click came about 140 ms after the dialog appeared.

The regression now clicks in a phone sheet only once its own animations
have ended, through `sheetRisen(page, selector)` in
`scripts/settings-page.ts`:

- Settings, once opened (`openSettings`), and before each click on its
X;
- the command palette, before a result is clicked (it is a sheet on a
phone too);
- `openSettingsPage`, shared with other scripts, before it clicks a
page. At desktop width there is no animation and the wait returns at
once; on a phone it adds at most the rise.

The wait reads the dialog's own animations, not its children's (an
endless spinner inside cannot hold it), and is bounded by Playwright's
timeout.

The stress run of that first version failed once more, with a bare
`waitForFunction` timeout in the desktop theme checks: the script
reopened Settings right after closing it, before the close's step back
had landed. A step landing over a second late is taken for the user's
Back (`settingsHistory`'s landing deadline, kept on purpose since #630)
and closes the Settings opened meanwhile. A scratch probe at 1280px
showed it: with the step held 200 ms Settings stays open, held 1.5 s it
closes. Every close followed by a reopen now waits for the step to land,
as `closeSettings` already did: Escape in the theme checks, the X in the
settings search, and the reload made with Settings open (through
`historyHolds`, so a timeout there reports the history).

Test-only: no app code changes.

## Validation

- 4×30 of `bun scripts/settings-pages-demo-regression.ts` at once, in
four separate checkouts, pinned to two cores under `dori heavy`, with
#2023 underneath: 120 of 120 passed. Before these fixes, the same load
failed 1 of 29 runs at the sheet's rise, and the first version failed 1
of 50 at a reopen before the close's step landed.
- `bun run check fast`: pass.
- Reviews: omo-native-code-reviewer approved after its findings were
fixed: the X click right after `openSettings` in the late-step check and
the palette's result clicks still raced the rise, and the reload with
Settings open lacked the wait. Codex Sol found the same X click and the
same reload, both fixed.

Co-authored-by: mp <mp@local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky: settings pages demo regression never sees the Settings dialog open on CI

1 participant