Skip to content

Access LOWs: list_roles grants in one bounded snapshot, Recreate audit id pinned, audit log hides a role's unchanged name, ChangeList min-w-0 pinned (#67) - #71

Merged
doxuta merged 8 commits into
mainfrom
slice/access-lows-67
Oct 27, 2026

Conversation

@doxuta

@doxuta doxuta commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Closes #67 — the five LOW follow-ups the #66 verifier left.

What changed

  1. list_roles {grants: true} loads grants in one query. New auth.RoleRepository.ListRoleGrants: acl_roles LEFT JOIN acl_role_actions, pinned to tenant_id, parameterized. It replaces ListRoles + one ListActionsForRole (which re-reads the role) per role: 2 queries per role become 1 query in total.
  2. A role deleted in the middle of the read is skipped instead of failing it. One statement reads one snapshot, so a role deleted meanwhile is just not in it. Before, the read returned ROLES_READ_FAILED: role "ops": auth: role not found.
  3. The output is bounded, and says what it cut, the way snapshot_model does: at most 40 roles and 60 grants per role. A cut sets rolesTruncated/rolesTotal or, per role, grantsTruncated/grantsTotal, plus a note that points at explain_access. The issue's example tenant (20 roles × 100 tables × 4 actions) produced 544,932 bytes before; now under 100 KB. Grants are sorted by table. "*" sorts before every table name only because table names start with a letter (in utf8mb4_unicode_ci, _ sorts before *), so a role's every-table grants are the last to be cut. The caps count rows, not bytes: at the caps with the longest names the schema allows, the result is 275 KB. It's still read-only over MCP, the tenant still comes from the executor, and no tool or argument was added, so the cassettes are untouched.
  4. RoleService.Recreate audit row: a new test pins record_id = the role's id on the __role__ create row that undoing a delete writes.
  5. AuditLog no longer shows a role's unchanged name as a rename. Access follow-ups: propose_access asks only for named roles' admins, role audit rows name the role, list_roles grants (also MCP), ?app= ghost cell, ChangeList wraps (#23) #66 writes the role's name on both sides of a role update, so a grants-only save drew a name | X | X row that read as a rename. buildDiffRows now drops that one key only: name on a __role__ row when its value did not change. A rename still shows, and a role save that changed nothing has no diff to open. Every other row draws every key the server wrote. That includes a sensitive (PII) field, which is written "[redacted]" on both sides on purpose (audit_redact.go keeps the key: who changed what field, when). The role is still named: a __role__ row's record column shows the role's name where its short id was, and the cell's title reads <name> · <full record id>, so the id is still there to cross-reference.
  6. ChangeList min-w-0: a new test pins the class, and a real-browser check (below) measures it at 390 px.

propose_access still reads ListRoles + ListActionsForRole. It is unchanged and out of scope.

Proof each test is not vacuous (broke the fix, saw red, restored)

Fix Break Red
one snapshot old per-role loop (the code before this PR) ROLES_READ_FAILED: role "ops": auth: role not found
bound per-role cap disabled 20 roles × 100 tables × 4 actions = 544932 bytes; want at most 100 KB · big role: 400 grants, truncated false
tenant pin (integration) Where("acl_roles.tenant_id = ?") removed role "rg_foreign" carries tenant …; want …
Recreate record id id → "" in its emitMetaAuditFor event = create __role__/"" in "t1"; want … "rid-gone"
AuditLog role name (vitest) role-name filter disabled a grants-only role update shows the grants, no name row… and a save that changed nothing has no diff to open red
AuditLog keeps [redacted] keys (vitest) the round-0 filter (every key equal on both sides) a sensitive field redacted on both sides is still drawn as a change and an update of a sensitive field only still has a diff to open red
AuditLog keeps [redacted] keys (real Chrome, HMR) the round-0 filter 12 of 26 checks red: the PII-only update has no toggle, the mixed update draws only last_name
record cell title (vitest) title = name only expected title "crm_sales_rep · 4f1c0de0-…" received "crm_sales_rep"
worst-case size maxListedGrantsPerRole 60 → 80 40 roles × 80 grants with the longest names = 363392 bytes; want at most 300 KB
ChangeList min-w-0 (vitest) class removed a long snake_case token may shrink and break inside the row red
ChangeList min-w-0 (real Chrome, HMR) class removed @390: token span right edge 526 > row right edge 349 (liScroll 464 > liClient 287)

verify-ui (own API :18467 on a throwaway DB nexus_wt_access67, own next dev --webpack :13467, seed-demo, system Chrome)

Seeded through the API: a role whose name and label are one long snake_case token (crm_customer_support_ticket_escalation_history_entries_reviewer), then a grants-only PUT of that role, with its name sent again unchanged.

Result: verify-ui: 20/20 checks passed, at widths 390 and 1440:

  • Builder, bao-tri/lich-su: unfolded the newest entry ("Vai · "). The token wraps onto 3 lines inside its row: span right edge 337 ≤ row right edge 349, liScroll 287 = liClient 287, page overflow 0, no page error.
  • Builder, /admin/audit and the Studio's van-hanh/nguoi-dung/nhat-ky: the grants-only role update's diff has only actions, with no name row. The record column reads the role's name. Page overflow 0, no page error.
  • Rep (non-admin test@example.com): /admin/audit and bao-tri/lich-su both land on /home, with no diff and no role entry.
  • acceptance-acl.py --expect crm_accounts,crm_contacts as the rep: ✅ ĐẠT — người thứ ba đọc được cả 2 entity yêu cầu.
  • Live MCP nexus_list_roles {grants:true} with a real MCP token: the 3 seeded roles come back whole (36 and 25 grants for the pack roles, uncut, 4.6 KB). After adding 43 roles (one with 400 grants): roles shown 40 | rolesTruncated True rolesTotal 46, bulk_role_00 grants 60 grantsTruncated True grantsTotal 400, plus the note (17 KB).

Round 1 (verifier findings on #71)

  • MEDIUM, fixed. In round 0, buildDiffRows hid every key whose value was the same on both sides. That also hid a sensitive field written "[redacted]" on both sides, so /admin/audit stopped showing that a PII field changed. The hiding is now scoped to the one key that a writer pads: name on a __role__ row. Red first: the verifier's two cases (a mixed update and a PII-only update) failed on the round-0 head and pass now.
  • LOW, fixed. The record cell's title carries the full record id again (<name> · <id>).
  • LOW, fixed. The caps count rows, not bytes. The comment now gives the measured worst case (275 KB, with a 26-character table, a 32-character field: level, a 100-character role name and a 150-character label), and a subtest keeps it under 300 KB.
  • LOW, fixed. The collation claim now says why "*" sorts first (table names start with a letter). The integration test orders a "*" grant and an a_first table on real MySQL.
  • LOW, made honest. The deleted-meanwhile tests' comments now say what they cover: the fake stands in for InnoDB's consistent read, the integration test deletes the role before the read, and a delete racing the one SELECT is not exercised.
  • LOW, not changed. The list_roles tool description still does not mention rolesTruncated/grantsTruncated. Changing it would change the tool definitions the cassettes were recorded with, and existing cassettes must not change. The model learns about a cut from the note in the result.

verify-ui, round 1

Same throwaway DB nexus_wt_access67, own API :18467 (binary built from this head), own next dev --webpack :13467, system Chrome, widths 390 and 1440. Seeded through the API: a sensitive field so_cccd_v67 on crm_contacts; then, as the rep, a contact, an update of the sensitive value only, and an update of it plus last_name; then a grants-only role update that changes one grant.

Result: verify-ui: 26/26 checks passed, on /admin/audit and on the Studio's van-hanh/nguoi-dung/nhat-ky:

  • The rep's PII-only update has a toggle and draws so_cccd_v67 | [redacted] | [redacted].
  • The mixed update draws both last_name and so_cccd_v67.
  • The grants-only role update draws only actions. The two role saves that changed nothing have no toggle. All three role rows' record cells are titled <name> · ed692eaf-….
  • No page error, page overflow 0.
  • The rep is sent from /admin/audit to /home, with no diff and no audit row.

With the round-0 filter put back (HMR), the same script fails 12 of 26 checks: the PII-only update has no toggle, and the mixed update draws only last_name.

Gates

Ran in nexus-platform/ and nexus-web/ on head 3846600:

  • gofmt -l . → empty · go vet ./... → clean · go build ./cmd/server/ → ok
  • go test ./... → 42 packages ok, exit 0
  • bash scripts/run-integration.sh -timeout 50m -run 'TestListRoleGrants_' ./internal/auth/ → run-integration: PASS=1 SKIP=0 go-test-exit=0 (round 1; the round-0 run of ./internal/auth/ ./internal/ai/ ./internal/mcpserver/ ./internal/services/ ./internal/handlers/ → PASS=7869 SKIP=0 go-test-exit=0; round 1 changed no Go code outside tests and comments)
  • python3 scripts/check-orphan-endpoints.py --strict → ✅ Không có endpoint mồ côi.
  • python3 scripts/acceptance-acl.py --expect crm_accounts,crm_contacts (rep) → ✅ ĐẠT — người thứ ba đọc được cả 2 entity yêu cầu.
  • npx tsc --noEmit → exit 0 · npx vitest run (all) → Test Files 585 passed (585), Tests 6276 passed (6276) · npx eslint on the touched files → exit 0 · npm run build → exit 0

🤖 Generated with Claude Code

doxuta and others added 8 commits October 27, 2026 12:43
…rants in one query (#67)

list_roles {grants: true} read the role list, then each role's grants
(ListActionsForRole re-reads the role first): two queries per role, and a role
deleted in between failed the whole read. ListRoleGrants is acl_roles LEFT JOIN
acl_role_actions pinned to tenant_id: one statement, one snapshot, so a role
deleted meanwhile is simply absent. Roles by name, grants by entity then
action; a role without a grant has an empty, non-nil list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… what it cut (#67)

It now reads ListRoleGrants (one query) instead of two reads per role, so a
role deleted between the list and its grants is skipped instead of failing
with ROLES_READ_FAILED. The output is capped like snapshot_model's: at most 40
roles and 60 grants per role; a cut sets rolesTruncated/rolesTotal or
grantsTruncated/grantsTotal and a note pointing at explain_access. The issue's
tenant (20 roles x 100 tables x 4 actions) was 545 KB in one result; it is now
under 100 KB. Still a read, tenant pinned from the executor, also over MCP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…le id (#67)

The undo of a role delete (publish revert) writes a create row on __role__;
its record_id is the role's id, so the audit log keeps the role's whole life
under one id. Nothing pinned it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… names a role row's role (#67)

A role update's diff carries the role's name on both sides (#66) so the row
names the role; drawn as "name | X | X" it read as a rename on every grants-only
save. buildDiffRows now drops a key present on both sides with the same stored
value (compared as JSON, not as drawn: two amounts can both read "1,2 tr"), so a
save that changed nothing has no diff to open. The role's name moves to the
record column of a __role__ row, where the short id stood.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aks inside the row (#67)

A token with no space cannot wrap at a space; the text is a flex item whose
minimum width is its longest word unless min-w-0 lets it shrink. Nothing pinned
the class; jsdom cannot measure, so the width is checked in a real browser too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n both sides (#67)

Round 1 of #71's verifier: buildDiffRows dropped every key whose value was
the same before and after. The server writes a changed sensitive (PII)
field as "[redacted]" on both sides on purpose (audit_redact.go keeps the
key: who changed what field, when), so /admin/audit stopped showing that
such a field changed: a PII-only update had no diff to open and a mixed
update lost the field's row.

Only the role writer pads an unchanged key (#66 puts the role's name on
both sides so the row names the role). buildDiffRows now drops just that
one: `name` on a __role__ row when it did not change. A rename still shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…#67)

A __role__ row's record cell shows the role's name instead of the short id
(#67), and its title carried only the name, so the role id was nowhere on
screen to cross-reference. The title is now "<name> · <full record id>",
for layout rows too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mments say what they rest on (#67)

The caps count rows, not bytes: 40 roles x 60 grants with the longest names
the schema allows measure 275 KB, not "about 160 KB"; a subtest now pins
that under 300 KB. "*" sorts before every table name only because a table
name starts with a letter (in utf8mb4_unicode_ci "_" sorts before "*");
the integration test now orders a "*" grant and an "a_first" table on real
MySQL. The deleted-meanwhile comments say the fake stands in for InnoDB's
consistent read and that a delete racing the SELECT is not exercised.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@doxuta doxuta changed the title Access LOWs: list_roles grants in one bounded snapshot, Recreate audit id pinned, audit log hides unchanged keys, ChangeList min-w-0 pinned (#67) Access LOWs: list_roles grants in one bounded snapshot, Recreate audit id pinned, audit log hides a role's unchanged name, ChangeList min-w-0 pinned (#67) Oct 27, 2026
@doxuta
doxuta merged commit f336104 into main Oct 27, 2026
7 checks passed
@doxuta
doxuta deleted the slice/access-lows-67 branch October 27, 2026 07:34
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.

Access follow-ups from #66 (LOW)

1 participant