Skip to content

Refactor browser runtime ownership boundaries - #514

Merged
max-sixty merged 18 commits into
mainfrom
codex/browser-ownership
Sep 9, 2026
Merged

max-sixty merged 18 commits into
mainfrom
codex/browser-ownership

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

This reorganizes the browser runtime around explicit owners so high-level modules no longer reach through one another for shared operations. Conversation projection is now a pure value fold with one installed current reading, failed state application rerenders the prior reading and restores active reply focus and selection, and small dependency-floor modules own shared focus, child reconciliation, coordinates, identity, and repaint scheduling.

leaf.js now assembles the cross-owner boot graph. A single repaint coordinator orders scope reflection, standing content, layout, optional page shift, and standing geometry in one frame. Keyboard commands capture their semantic return origin before execution and pass that value to the return stack, while navigation and composing operations live with the regions and surfaces they control.

The targeted ownership cuts move conversation/model.js, keyboard/return-stack.js, and chrome.js out of the largest static-import component. Its size falls from 50 modules to 47; this is a partial improvement with the remaining component left for separately motivated work. The presentation profile remains at 12/16/37 JavaScript requests across the measured pages.

Validation:

  • uv run pytest tests — 2,358 passed
  • full pre-commit suite — passed
  • tests/test_render_pages.py — 62 passed after the final conversation recovery changes
  • focused browser coverage for repaint ordering, keyboard return behavior, refused conversation rollback, stale revision reads, and semantic selection — passed

This was written by Codex on behalf of @max-sixty

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_a_failed_agent_root_restores_the_focused_first_message_composer[empty] fails deterministically. The parametrization arranges the empty composer with setSelectionRange(0, 0, "none") and then asserts the restored reading equals that same literal, but Chromium reports a collapsed selection as forward whichever direction set it — so the assertion compares [0, 0, 'forward'] against [0, 0, 'none']. The rollback path itself round-trips correctly: retainConversationFocus captures input.selectionDirection (already forward) and hands it back unchanged. It is the test's literal that the browser never produces.

Reproduction
$ uv run pytest --run-nightly -q -n0 tests/test_render_pages.py::test_a_failed_agent_root_restores_the_focused_first_message_composer
E  AssertionError: assert [0, 0, 'forward'] == [0, 0, 'none']
1 failed, 1 passed in 3.65s

Playwright 1.62.0's bundled Chromium, directly:

set(0,0,'none')            -> [0, 0, 'forward']
set(3,12,'backward')       -> [3, 12, 'backward']
empty textarea after focus -> [0, 0, 'forward']

The [draft] case passes because backward on a non-collapsed range is preserved. With the inline suggestion applied both parametrizations pass.

test_render_pages.py is nightly-marked, so the PR's test job never reaches it — this lands green and reddens the daily complete-suite run instead.

Separately, three moves drop their rationale rather than carrying it. bringForward and commentOnItem arrive in composing/surface.js with three lines in place of the ~40 they had in navigation.js, which recorded why the composer does not reach for the widget's own conversation seat ("that was the wrong shape … five separate questions"), why the travel is gated on any visible part rather than an unclipped box, and why it is instant and precedes measurement. The skip link and watchDisclosures land in leaf.js with none of the paragraphs that explained why the button is prepended to body instead of the chrome root, and why disclosures are watched as an attribute rather than heard as a toggle event. Each of those comments exists to stop the rejected shape being re-derived, and this is a pure move — nothing about the reasoning changed. Worth carrying across with the code.

Comment thread tests/test_render_pages.py Resolved
@max-sixty
max-sixty merged commit cab8eb0 into main Sep 9, 2026
4 checks passed
@max-sixty
max-sixty deleted the codex/browser-ownership branch September 9, 2026 20:13
max-sixty added a commit that referenced this pull request Sep 17, 2026
…ruled out (#768)

The cutover list scored its candidates from a survey's estimates. Six of
the rows ranked next were measured against the code, and every one was
stale or overstated; an independent review then confirmed the six
verdicts and corrected three of the reasons behind them. The rows now
carry what was measured, and the ones the measurements ruled out have
moved to the survey note, whose table is now named Rejected.

What the measurements found:

- **`html` as the page scroller** was already done: `26feec8b` made the
switch on 2026-08-29, `theme.css` holds the rule, and the runtime reads
`document.scrollingElement`. The row is gone.
- **Same-document View Transitions** claimed ~150 lines against a
`motion.js` of 87. The update applies after the old state is captured,
later than the gesture's own turn; pointer input misses the page while
it animates; a fold collapses height so later content slides, which a
root cross-fade does not draw; and board cards move inside their own
scroller, whose clip a snapshot escapes under the Chrome 125 floor. #666
removed the paint-boundary transition version travel used, which also
leaves `theme.css`'s `lf-versioning` rule dead — deleted here.
- **idiomorph for the version patch**: a live-tree diff keeps only the
reader state an exclusion names, while `dom-children.js` compares
authored source with authored source and keeps all of it. It has needed
no fix since #514 split it out.
- **`tsc --checkJs`** runs in under a second, but a bug-back over six
runtime fixes (#404, #448, #625, #660, #676, #757) found no error that
the fix removed from the files it touched, and the errors it does report
are inference artifacts.
- **Browser-owned anchoring** was spiked on `agent-a4111d25e33d466d2`.
All three capture paths cut over and the anchors matched the Python
capture exactly, but Python grew by 168 lines, a quoted `leaf comment`
went from 0.2 s to 1.3 s and now needs Chrome, and the anchor tests went
from 8 s to 37 s: the refusals and the diagnostics for a quote the page
does not show read authored source the rendered page no longer holds.
- **The user-level daemon** nets roughly zero lines. The browser already
receives pushes over `EventSource`, the 70 µs stat loop serves CLI
writers in other processes, pid probing and most locks stay, Windows is
not a goal, and a user-level database stops the page directory being the
deployment unit.

Two rows are new. A size-first sweep of the largest hand-written
mechanisms found one candidate the defect-led survey missed: serving
each page through starlette and uvicorn, which `mcp` already installs,
keeping one process per page. And the keyboard system becomes item #24
under architecture simplification: the reader keeps every key, sequence,
hint, and the one-press-per-layer Escape, while the code that infers
which surfaces are open — where ten of the last 24 keyboard fixes landed
— gives way to a layer stack that openers push and closes pop. No
library owns that; the ones that came closest are in Rejected.

The preamble now says effort and confidence are estimates unless a row
cites a measurement.

Checks: the everyday suite (1,135) and
`test_a_revision_navigates_without_the_view_transition_api`, which
exercises activation with the View Transition API switched off, both
pass; pre-commit is green on the changed files.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

2 participants