Skip to content

Fix SCAN Limit wire-width mismatch with the fitz broker - #33

Merged
smiggleworth merged 1 commit into
mainfrom
fix/scan-limit-wire-width
Sep 18, 2026
Merged

smiggleworth merged 1 commit into
mainfrom
fix/scan-limit-wire-width

Conversation

@smiggleworth

@smiggleworth smiggleworth commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • KvScanQuery.Limit was ulong?, written on the wire with WriteU8 + WriteU64 (8 bytes) in KvTransaction.ScanAsync. The fitz broker's SCAN decoder (read_optional_limit in src/protocol/kv_codec/mutation_parsers.rs) only reads a u32 (4 bytes) for that field -- consistent with every other broker-side limit (MAX_SCAN_ITEMS: usize = 1_024).
  • The extra 4 bytes the client wrote shifted every subsequent field (reverse, optional start_exclusive), which the broker's ensure_complete check correctly flagged as Trailing data in SCAN payload.
  • This meant every KvDirectory<T,TKey>.QueryAsync/ScanAllAsync call against a real broker failed with Cntryl.Fitz.KvException: SCAN failed: Invalid request: Trailing data in SCAN payload. Point reads/writes (GetAsync/InsertAsync) were unaffected -- only Scan.
  • Found via manual end-to-end verification of a downstream app (list endpoints backed by KvDirectory) against a live broker -- never caught by InMemoryKvClient-backed tests, since that double doesn't encode wire bytes at all.

Root cause confirmation

Rebuilt the fitz broker from its own current main (07eb3a23) via its Dockerfile and reproduced the identical error against the freshly built broker, ruling out a stale Docker image -- this is a genuine field-width mismatch between fitz HEAD and fitz-dotnet HEAD.

Fix

  • Fitz.Abstractions/Domains/Kv/KvTypes.cs: KvScanQuery.Limit -> uint?
  • Fitz.Core/Domains/Kv/KvTransaction.cs: WriteU64 -> WriteU32
  • Fitz.Extensions/KvDirectory.cs: three (ulong)(limit + 1) casts -> (uint)(limit + 1)
  • Two test assertions updated to the new type (25UL/(ulong)3/(ulong)4 -> 25U/(uint)3/(uint)4)
  • PackageVersion bumped 1.3.0 -> 1.3.1

Test plan

  • dotnet build clean, 0 warnings
  • dotnet test on Fitz.Extensions.Tests (23/23), Fitz.Testing.Tests (32/32), Fitz.Analyzers.Tests (16/16) -- all passing
  • End-to-end verified against a live broker in a downstream app (Compliance): packed these changes as local 1.3.1 packages, confirmed listTeams/listTeamMembers (SCAN-backed reads) went from 500 Trailing data in SCAN payload to 200 with real data, then reverted the downstream app back to the published 1.3.0 packages since that verification was local-only

KvScanQuery.Limit was declared ulong? and written on the wire with
WriteU64 (8 bytes), but the fitz broker's SCAN decoder
(read_optional_limit) only reads a u32 (4 bytes) -- matching
MAX_SCAN_ITEMS and every other broker-side limit. The extra 4 bytes
shifted every subsequent field (reverse, optional start_exclusive),
which the broker's decoder correctly flagged as trailing data:

  Cntryl.Fitz.KvException: SCAN failed: Invalid request: Trailing
  data in SCAN payload

This meant every KvDirectory<T,TKey>.QueryAsync/ScanAllAsync call
against a real broker failed -- point reads/writes were unaffected,
only Scan. Root-caused by rebuilding the fitz broker from its own
current main and reproducing the identical error locally, confirming
this is a genuine field-width bug rather than a stale broker image.

Fixes it by changing KvScanQuery.Limit to uint?/WriteU32 to match the
broker's u32, updating the three (ulong) call sites in KvDirectory
that constructed it, and the two tests that asserted on the old type.
@smiggleworth
smiggleworth force-pushed the fix/scan-limit-wire-width branch from 96901e5 to fb1e864 Compare September 17, 2026 23:32
@smiggleworth
smiggleworth merged commit 701dd29 into main Sep 18, 2026
6 checks passed
@smiggleworth
smiggleworth deleted the fix/scan-limit-wire-width branch September 18, 2026 15:42
smiggleworth added a commit to bdgrz/compliance that referenced this pull request Sep 19, 2026
* Add Role management: backend CRUD, read models, and UI

Team management shipped without Role management alongside it -- the
backend had DefineRole/AssignRolePermission/AssignTeamRole aggregate
handlers but no HTTP/MCP routes, no DeleteRole, no RemoveRolePermission
or RemoveTeamRole, and no read model, so "can I manage roles" was
still no. This closes that gap, mirroring the Team management slice's
pattern throughout:

- New RolePermissionRemoved/TeamRoleRemoved events and
  DeleteRole/RemoveRolePermission/RemoveTeamRole commands, wired into
  PermissionProjectionState and PermissionProjector so revoking a
  permission or unassigning a role from a team actually takes effect
  in materialized grants (previously only additive assignment was
  reachable).
- Three new KvDirectory-backed read models: RoleDirectory (list/get
  roles by name), RolePermissionDirectory (list a role's permissions),
  and RoleTeamDirectory (list the teams holding a role, materialized
  role-first from the same TeamRoleAssigned/Removed events
  rbac-team-roles already emits, so a role's detail page doesn't need
  a substring-search fallback over an unrelated index).
- RoleCleanupReactor, mirroring TeamCleanupReactor: deleting a role
  removes its orphaned permission and team assignments instead of
  leaving them to rot.
- Full HTTP + MCP surface for all of the above, and a /roles,
  /roles/{roleId} UI (create/delete roles; add/remove permissions and
  team grants) following the same pages/routing pattern as Teams.

Verified end to end against a real Fitz broker: DefineRole, GetRole,
and AssignRolePermission (all point reads/writes) work correctly.
ListRoles/ListRolePermissions/ListRoleTeams hit the same already-
tracked SCAN wire-protocol bug (cntryl/fitz-dotnet#33) that blocked
ListTeams before that fix -- not a new regression, the identical
pre-existing upstream limitation surfacing on a new read path.

* Fix MCP tool-list regression from Role management

Adding Role's MCP tools in Program.cs broke
TeamMcpScenarioTests.ShouldListTeamToolsAndDenyAnUnprivilegedCall,
which asserted an exact tool list scoped to Team alone. Renamed to
RbacMcpScenarioTests and updated the expected list to the full RBAC
surface (Team + Role); the exact-match style is kept deliberately so
future tool registrations force a visible review here rather than
silently drifting.

* Align broker integration test namespace with folder
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