Skip to content

code.blame_range reads the trunk ledger and a sibling branch head only when the caller may read them - #241

Merged
zlareb1 merged 11 commits into
mainfrom
fix/blame-trunk-readable
Nov 4, 2026
Merged

zlareb1 merged 11 commits into
mainfrom
fix/blame-trunk-readable

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Critical Bug Fix (data loss, cross-tenant read, auth bypass)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

code.blame_range on a release-branch namespace no longer returns the trunk namespace's PR titles, authors and merge shas to a caller who cannot read the trunk, and a release version in the window no longer resolves through a branch namespace the caller cannot read.

Why

Failing case: a principal can view code-x-26-4 (a release branch) but not code-x (its trunk). code.blame_range(namespace="code-x-26-4", ...) passes the transport's gate on code-x-26-4. _ledger_leg then adds the trunk entry and runs pr_history_in_window on code-x, so the candidates carry the trunk ledger's PR numbers, titles, authors and merge shas. _resolve_ref does the same for a release minor (to_version="26.4" addressed at the trunk): it reads the branch namespace's recorded git_head without a check.

Pattern: a namespace Loom adds on its own (trunk or sibling) is read under the gate of the namespace the caller addressed. code.verify_citations already handles this with search_fanout.readable_subset (citations._readable_namespaces).

Fix: both reads go through readable_subset. An unreadable trunk is left out of the ledger leg (the answer keeps the addressed namespace's rows and the blame leg). An unreadable sibling's head is skipped and the window end resolves through the mirror's branch or -new tag, as it does when no branch namespace is configured.

Scope and risk

Touches server/code/app/blame.py (the two gates and legs.ledger.skipped), the legs comment in server/code/api/models_history.py (and its generated row in docs/reference/operations/code.md), the readable_subset docstring in server/code/app/search_fanout.py, a paragraph of docs/features/code-index/history-and-prs.md, and the tests in tests/unit/test_code_blame_range.py and tests/unit/test_code_repos_trunk.py. Nothing changes for a caller who can read the trunk, or with no auth context (row_in_scope answers true). One extra grant check per call for each added namespace; the grant map is cached. Left alone on purpose: the git mirror is shared by every namespace of one repository, so the mirror-ref fallback (refs/heads/26.4) still blames the branch's public git history; what is gated is Loom's indexed rows of the other namespace (its ledger and recorded head).

Compatibility, rollout and rollback

  • Wire: no op or field change. A caller without trunk access gets fewer ledger candidates, and the free-form legs.ledger gains an additive skipped: [{namespace, reason: "not_readable"}] key naming the trunk it left out (the same shape code.search uses for an unreadable fan-out namespace).
  • Operator steps: none.
  • Rollback: a revert leaves nothing behind.

Tests

tests/unit/test_code_blame_range.py::test_trunk_and_sibling_namespaces_are_read_only_when_the_caller_may_read_them stubs row_in_scope to refuse one namespace. It failed before the fix (the ledger read code-clickhouse for a caller who can read only code-clickhouse-26-3) and passes after; it also checks that an unreadable sibling's head is not read and the window end comes from mirror_ref. Ran the blame, trunk and package-contract unit tests, make format lint typecheck, test_public_copy.py and test_doc_links.py.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. Checked the gate against citations._readable_namespaces and the test's failure before the fix.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 11 commits November 4, 2026 00:45
…y when the caller may read them

The transport gates only the addressed namespace. The trunk ledger leg and
the release-minor window resolution now pass the namespace Loom adds on its
own through search_fanout.readable_subset: an unreadable trunk is left out of
the ledger, and an unreadable sibling's head falls through to the mirror ref.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… readable trunk

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit b8114b2 into main Nov 4, 2026
39 of 40 checks passed
@zlareb1
zlareb1 deleted the fix/blame-trunk-readable branch November 4, 2026 09:22
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
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.

1 participant