Skip to content

The rule that only an independent human administrator accepts a proposal is one shared helper - #2197

Open
zlareb1 wants to merge 1 commit into
mainfrom
refactor/reviewer-rule
Open

zlareb1 wants to merge 1 commit into
mainfrom
refactor/reviewer-rule

Conversation

@zlareb1

@zlareb1 zlareb1 commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

Part of: #1143

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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):

None. No op, field, message or status changes.

Why

memory.proposal_decide accepts a proposal only from an authenticated person who administers the namespace, acts under their own name and is not the proposer. The rule lived in server/memory/app/proposals.py as two private functions. Reviewing a skill revision, which can have several authors, needs the same rule. One helper holds it, so the two reviews cannot drift apart.

The design, in server/identity/app/reviewers.py:

  • person() -> AuthInfo | None: the request's principal when it is authenticated, has a subject and is not a service account.
  • independent(reviewers, authors) -> bool: false when authors is empty or when any author, case-folded, is in reviewers.
  • async reviewer_subjects(org, namespace, actor) -> set[str]: the case-folded subject and aliases of the caller. The aliases are read under sequential_reads(), and a failed read raises. It raises NotAReviewer(reason), where reason is the first test failed, in this order: signed_out (no principal, or no subject), service_account, actor (actor is not writer_actor()), role (no admin role on the namespace).

The helper raises a typed reason and the calling op words its answer, so the rule names no kind of content.

In server/memory/app/proposals.py:

  • _reviewer_subjects is deleted. _accepting_reviewer calls reviewer_subjects and maps every NotAReviewer to the 403 AUTH_INSUFFICIENT body memory.proposal_decide answers on main ("A human administrator must review the proposal."). decide() keeps its 48 statements.
  • _approval_refusal keeps its valid-actor test and its content-hash test, and calls independent(reviewers, {subject_of(proposer)}) for the comparison.

Choices made while writing it:

  • reviewer_subjects starts from person(). A principal that has a subject and is no person is a service account, which gives the second reason. If person() gains a test, a reviewer is held to it too.
  • A proposal a pipeline wrote keeps an independent reviewer. subject_of gives '' for a pipeline's actor, and {''} is an author set with one member that names no reviewer. This is what main does; test_a_human_administrator_can_accept_what_a_pipeline_proposed pins it.
  • The new module imports server.auth at module level, as server/identity/app/caller_home.py and its neighbours do, and calls context.current_auth() and aliases.read_aliases() through their modules. proposals.py imports the helper at module level. No module under server/ imports proposals.py at module level, so no import cycle forms; the import check under Tests covers twelve entry orders.

Scope and risk

Touches:

  • server/identity/app/reviewers.py (added): the three functions and NotAReviewer.
  • server/memory/app/proposals.py: _reviewer_subjects is replaced by _accepting_reviewer, and one condition of _approval_refusal calls independent.
  • tests/unit/test_reviewer_rule.py (added) and one test added to tests/unit/test_proposals.py. No existing test is edited.

Left alone: decide() beyond the one renamed call, the content-hash test, the automatic policy, the wire models, the transports, the SDKs, the CLI and the dashboard. Reviewing a skill revision, and its messages, is a later change. Stopping a person from accepting what their own token proposed is a behaviour change and is not made here.

What could break:

  • Auth: the rule is the security boundary of proposal acceptance. The order of the tests and each refusal are pinned by the tests below. A refused caller gets the same 403 for every reason, so the answer does not say which test failed.
  • Fail closed: an empty author set is never independent, and a failed alias read raises before a reviewer set exists (test_an_unreadable_alias_directory_cannot_establish_an_independent_reviewer, which is unchanged).
  • Identity tuple: the recorded actor is still tied to the token through writer_actor().
  • Import time: server.memory.app.proposals loads server.auth.authz, server.auth.aliases and server.auth.context when it is first imported, where main loads them on the first accepted decision.
  • Stored data, concurrency and tenant isolation: no statement, row or scope changes.

Compatibility, rollout and rollback

  • Wire: no op, field, table, column, migration or setting is added, changed or removed. memory.proposal_decide answers the same status, code and message for the same request over HTTP, MCP, the SDKs and loom call.
  • Operator steps: none.
  • Rolling upgrade: no stored or wire shape changes; two builds side by side decide a proposal the same way.
  • Rollback: a revert leaves nothing behind.

Tests

The tests were written before the code. tests/unit/test_reviewer_rule.py failed at import while the module did not exist. With the helper written and proposals.py still as on main, test_proposal_refusal_is_unchanged and the test added to test_proposals.py passed: they pin the answers main gives.

tests/unit/test_reviewer_rule.py, with real AuthInfo principals in the request context, the gate answered from the token's role claim, and an alias read that records whether it ran sequentially:

  • test_each_refusal_has_its_reason (8 cases): no principal, a principal with no subject, a service account, an actor other than the token's, and a writer each raise NotAReviewer with their reason and make no alias read. Three more cases fail several tests at once and get the first reason in the order above.
  • test_another_actor_is_refused: a human administrator under their own actor gets {subject, alias} case-folded, from one sequential alias read. The same administrator passing another name, the process: kind, their own name in another case, a bare subject or '' is refused with actor.
  • test_no_author_is_not_independent: an empty author set is not independent, and neither is an author equal to the reviewer's alias in another case, alone or beside an unrelated author.
  • test_a_person_is_signed_in_and_not_a_service_account: person() returns the principal for a signed-in person and None with no principal, with no subject, and for a service account.
  • test_proposal_refusal_is_unchanged (the same 8 cases through proposals.decide): each raises a 403 whose detail is {"code": "AUTH_INSUFFICIENT", "message": "A human administrator must review the proposal."} and runs no statement.

tests/unit/test_proposals.py::test_a_human_administrator_can_accept_what_a_pipeline_proposed: a proposal whose actor is a pipeline's is accepted by a human administrator.

Each of these thirteen one-line defects, applied alone, fails at least one of the tests above: the role tested before the actor; a service account admitted by person(); the actor test removed; the role test removed; an empty author set independent; authors not case-folded; reviewer subjects not case-folded; the alias read not sequential; signed_out given to a service account; the 403 message, status or code changed; the independence comparison removed from _approval_refusal.

What ran at this head, with pytest -n 2:

  • The focused unit files (test_reviewer_rule.py, test_proposals.py, test_definition_draft_access.py, test_proposals_read_scope.py, test_graded_runs.py, test_proposal_triage.py, test_badge_reads.py, test_memory_import.py) under three random seeds: 184 passed, 9 skipped each time. The skipped cases need a clickhouse binary, which this machine does not have.
  • The repository-wide scans in one run: test_package_contracts.py (unchanged), test_op_transport_contract.py, test_tunable_constants.py, test_store_names_refused.py, test_degraded_unnoted.py, test_public_copy.py, test_doc_links.py, test_agent_instructions.py, test_test_inventory.py, test_coverage_floors.py, test_integration_suite_targets.py, test_clickhouse_mutation_inventory.py, and the 54 unit files that scan the tree's Python files: 1853 passed, 10 skipped. The skipped cases are in test_store_names_refused.py and need the clickhouse binary.
  • Import order: python -P -c "import <module>" in a fresh interpreter for server.auth.authz, server.auth.context, server.auth.aliases, server.memory.app.provenance, server.operations.registry, server.memory.app.proposals_ops, server.tasks.app.run, server.identity.app.reviewers, server.memory.app.proposals, server.memory.api.ops_proposals, server.transport.gates and server.workers.registry: each imports.
  • pytest tests/analyzer against a ClickHouse started for this task (dev/ci_start_clickhouse.sh, make migrate): 12 passed, and tests/analyzer/shapes.txt has no diff.
  • Integration, against a server run from this head on that ClickHouse: test_proposal_independent_review.py (unchanged), test_graded_runs_proposals.py and test_proposal_triage.py: 4 passed. test_sdk_example_knowledge_factory.py, whose example accepts proposals: 17 passed.
  • ruff check on the paths make lint names, ruff format --check on server and tests, make typecheck, the function-length gate (decide() has 48 statements here and on main), the secret gate, and the generator checks docs_reference and op_reach_census pass.
  • Not run: make format as a whole and the Rust, Go and shell formatters (rustfmt, gofmt and shfmt are not installed on this machine), and Biome. This change touches no op, field, setting, shell file or frontend file, so no generator has new output.
  • Stress or load run: none. The change adds no statement and no loop.
  • Left to CI: the full unit suite, the full integration suite and the mixed-version gate.

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 wrote the diff and ran the checks listed under Tests.

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

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump), the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py) and the standalone skill bundles (python3 scripts/codegen/standalone_skills.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ 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.
  • I signed the Contributor License Agreement (CLA) if CLA assistant requested a signature.

Unticked: this change has no migration, no plugin file and no frontend file, so those three checks did not run; the CLA line is the committer's to confirm. No generated file changes: the generator checks listed under Tests report every generated file current. No page under docs/ names the two private functions, so no page changes.

🤖 Generated with Claude Code


Note

Medium Risk
Refactors the security boundary for proposal acceptance without intended wire or behavior changes; correctness depends on preserved check order and refusal mapping, which new tests pin.

Overview
Extracts who may accept proposed content into server/identity/app/reviewers.py so memory proposal acceptance and future skill-revision review can use the same rule without duplicating checks.

The new module exposes person(), case-folded independent(reviewers, authors), and reviewer_subjects(org, namespace, actor), which enforces signed-in human (not service account), actor matches writer_actor(), namespace ADMIN, and sequential alias reads. Failures raise NotAReviewer with ordered reasons (signed_out → service_account → actor → role).

In proposals.py, private _reviewer_subjects becomes _accepting_reviewer, which calls the shared helper and still maps every refusal to the same 403 AUTH_INSUFFICIENT message. _approval_refusal uses independent() for the proposer-vs-reviewer check (including empty author sets and alias case-folding).

Adds test_reviewer_rule.py and pins that a human admin can accept proposals whose actor is a pipeline (process:…).

Reviewed by Cursor Bugbot for commit e8138bf. Bugbot is set up for automated code reviews on this repo. Configure here.

…sal is one shared helper

server/identity/app/reviewers.py owns the rule: a person who administers the
namespace, acts under their own name and wrote none of what they review. A
second review of proposed content, with several authors, needs the same rule;
one helper keeps the two from drifting.

reviewer_subjects() refuses with a typed reason (signed_out, service_account,
actor, role) and the calling op words its answer. memory.proposal_decide maps
every reason to its one 403 AUTH_INSUFFICIENT body, so no status, code or
message changes.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vercel

vercel Bot commented Dec 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Dec 5, 2026 2:33am UTC
loom-telemetry Ready Ready Preview Dec 5, 2026 2:33am UTC

Request Review

This branch has not been deployed

No deployments
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