Repository navigation
Give the document checks, publication and two pages functions their owners, ending three packages' import cycles - #7218
Merged
Merged
Conversation
Each cycle came from code that sat in the wrong module, and each cut moves that code to the module that owns its concern. The moved definitions are byte-identical apart from imports, cross-module references in their docstrings, one name, and two deferred imports that existed only to dodge the cycles. No behaviour changes. - `records.authored_checks.documents` (new) holds the gates an authored document passes: a page's document (`authored_document_checks`, from `source._authored_document_checks`), a message's HTML and Markdown (`message_markup_findings`, `text_media_errors`, `split_preformatted`, from `admission`), each live sample's child (`sample_errors`, `uncaptured_sample_errors`, from `source`), and the history a sample's page starts from (all of `records/sample_content.py`, which is deleted, and `initial_data_document_readings`, from `page_data`, whose only callers were samples). The gates recurse into one another, since a message may declare samples and a sample's history may hold messages, so they were spread across three modules joined by a deferred import in `admission._message_stages`. In one module the recursion is in plain sight, and `source` and `admission` are left as the doors that call it. - `records.revision_publication` (new) holds the steps that publish a checked source under a transaction the caller holds, and the finishing of an interrupted publication, from `revisioning`. None of them opens a transaction, so the transaction now imports what it finishes without a cycle. `revisioning` keeps `activate_source`, which opens one, and the answer it holds between reads. The transaction still imports the publication only when one is unfinished: loading it at module level would add about 38 ms and 85 modules to every cold hook that opens a transaction. - `pages.vendoring` takes `follow_copy` from `hosting`. It renews the page's layer and then restarts the server, so it belongs with the renewals it calls, above `hosting`'s restart. - `pages.render_gate.version` takes `_render_page` from `scheme`. Its only caller is the version attempt there, and `scheme` keeps the lifecycle and trusted inputs its header names. Tests that patched names in the old modules now patch the same names where the moved code reads them, and prose that pointed at the old homes now points at the new ones. > _This was written by Claude Code on behalf of max-sixty_
`server _follow` imported `vendoring`, which now holds `follow_copy`, before it answered the server that asked, so an import failure there would send that server back through its launch retries, where before the answer came first. `_follow` now answers before it loads the follow, and `follow_copy` no longer takes the handshake. The answer also comes before `hosting` loads, which fits what it says: only that this copy runs. Also, from review of the previous commit: - `validation.md` names the current homes of the static rules, `documents.py` among them. - `revision_publication.py`'s header says which first revision has no prerequisite: one a read activates. A first stamp's note names its bundle, so the next transaction finishes it. - `authored_document_checks` drops the `page_dir` it never read. - `planned_activation` calls `files.latest_revision` instead of repeating it. No other behaviour changes. > _This was written by Claude Code on behalf of max-sixty_
leaf-agent
approved these changes
Nov 26, 2026
This was referenced Nov 26, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 26, 2026
After a Leaf update that moves the page protocol, a page server from the old copy asks the new copy to take it over (`leaf server _follow`), which renews the page and restarts its server. If another start, such as a checkout's `leaf server start`, had put its own server on the page in between, the renewal's restart stopped that replacement: on a page no live session held, the session server stayed down and the open tab lost its server; otherwise the server came back under the follow's Leaf instead of the one that started it. `follow_copy` checked which server was running only after the renewal. `follow_copy` now passes the renewal a condition, that no server but the one that asked serves the page, and `renew_layer` and `renew_held` ask it with each reading they already take again under the page lock and transaction (`still`). A page no server serves still passes, since the renewal's own restart stops the asking server before its last reading. One window remains, between the locked reading and the restart's stop, the same one the follow's own restart already accepts after its last check; closing it would need the stop itself to compare server ids. Codex found this while reviewing #7218, which moved `follow_copy` from `hosting` to `vendoring`; the bug predates the move. Tests: `test_a_stale_follow_leaves_the_server_that_took_its_place`, which fails without the fix; `test_server_lifetime`, `test_revendoring`, and the renewal and follow cases of `test_hooks` and `test_interact_layer`; `lint-imports` and pre-commit. > _This was written by Claude Code on behalf of max-sixty_
max-sixty
added a commit
that referenced
this pull request
Nov 26, 2026
…a cycle (#7230) import-linter's layers contract checks only the imports between `src/leaf`'s eight packages, so the modules inside a package could import each other in a cycle, and six groups did. The cuts that ended them have landed (#7216, #7217, #7218, #7222, #7224). This adds import-linter's own `acyclic_siblings` contract over every package (`ancestors = leaf.*`). It recurses into subpackages such as `served_state` and `render_gate`, so a new cycle fails pre-commit as an upward import does, naming the import that closes it. A planted deferred import from `presence` into `delivery`, and one from `served_state.context` into `served_state.page`, each fail the contract; the tree as it stands passes. The config's header now says how to fix a cycle, and that a deferred import counts like any other, so deferring one ends no cycle; `src/AGENTS.md` states the rule beside the layering one. The maintainer asked for the cycles inside `agents` to be broken; this widens that to every package and keeps them broken. The two allowances the layers contract still lists are cut by #7223 and the PR after it. Tests: `lint-imports` (both contracts), pre-commit, and the two planted cycles above. > _This was written by Claude Code on behalf of max-sixty_
max-sixty
added a commit
that referenced
this pull request
Nov 26, 2026
… holds it (#7235) `leaf page check` reported one data-binding conflict inside a sample twice, and the same cause misreported three other cases. A conflict exists within one document, so each document's gate now checks only the document it reads: the conflict check moves into `instance_errors` (`markup_checks/instances.py`), which every gate already runs on exactly one document: the page's source, a sample's child, a message's HTML, a fixture message, a registry example. The page's reading still descends into samples, for the data inventory only. What an author sees now: - **A conflict in a sample's template** gives one finding, on the sample (`samples=("practice",)`), where it gave two (three for a sample nested in a sample). It no longer also refuses every fixture message in the template's `data-sample-events` as "event 2 … doesn't validate". - **An agent's message** is refused only for its own bindings, not because the saved `index.html` holds a conflict, which `check_source` checks first when a message publishes saved edits. - **A conflict inside a message's sample** names that sample. - **A message a sample copies from a thread** (`data-sample-threads`) is checked once more under the child's registry, at `page check` and at allocation alike, so a contract that changed since the message was posted refuses the sample, naming it and the copied message, rather than creating a child whose `page state` fails. - **Each side of a conflict** names its widget's id (`<lf-text-document id=more>`), so two consumers on one line are two findings an author can tell apart. A conflict's location no longer repeats the document's name, which the gate's `sample '…':` prefix already gives. - **A registry example** now checks the children of the samples it declares, so a widget pair that `invalid-example` refused written directly is refused wrapped in a named sample template too. Codex found the double report while reviewing #7218 and reviewed this fix; its findings, among them the copied-thread case, are folded in. Tests: new regression tests for the root, template and fixture cases on one page, for a message's own bindings, for copied messages under the child's registry, for the widget ids, and for the example's samples, each failing before its fix; `lint-imports`, pre-commit, and 679 covering model tests, the bundled-examples check among them. > _This was written by Claude Code on behalf of max-sixty_
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.
Ends the import cycles inside
src/leaf'srecords,pagesandpages.render_gatepackages, each by moving code to the module that owns it:authored_checks/source.py,authored_checks/admission.pyandsample_content.py, joined by a deferred import that only dodged the cycle. They now sharerecords/authored_checks/documents.py, withinitial_data_document_readings, whose only callers were samples.sample_content.pygoes;source.pyandadmission.pystay the doors that call the checks.revisioningheld bothactivate_source, which opens a transaction, and the steps that publish a checked source under one the caller already holds, which the transaction itself needs to finish an interrupted publication. The second set moves torecords/revision_publication.py. The transaction still imports it inside__enter__, now for start-up cost, which its comment says.pages.follow_copymoves fromhostingtovendoring, beside the layer renewal it runs before restarting the server.leaf server _followstill answers the old server before it loads either.pages.render_gate._render_pagemoves fromschemetoversion, its only caller.The moved functions are unchanged apart from imports, cross-references in docstrings, the dropped unused
page_dirargument ofauthored_document_checks, andplanned_activationcallingfiles.latest_revisionrather than repeating it. Behaviour is unchanged.To weigh: the names
documents.py(gates.pywas the other candidate) andrevision_publication.py, which sits beside the unrelatedpublishing.py(version stamps).This is one of the cuts the maintainer asked for to end the cycles inside
src/leaf's packages. Codex reviewed it and its findings are folded in. It also found two pre-existing bugs in the moved code, a stale_followthat can restart the server that replaced it and a conflict in a sample's bindings reported twice; both reproduce, and each gets its own PR after this one.Tests:
lint-imports, pre-commit, and 606 covering model tests across the checks, publication, activation, follow, the render gate and vendoring.