Skip to content

service-layer.md documents permission → mutate → audit → side effects, but actual code consistently does audit last #267

Description

@brylie

docs/specifications/service-layer.md documents the fixed order as permission check → mutate → logAudit → any other required side effect. In practice, nearly every write service function does logAudit last, after its other side effects, not third — consistently, across files:

  • documents.ts createDocument: mutate (:175-186) → recordCatalogDocumentCreated (:188-196) → access grant (:198-204) → logAudit (:206)
  • collections.ts createCollection: mutate (:124-130) → recordCatalogCollectionCreated (:132-138) → grant (:140-145) → logAudit (:147)
  • records.ts deleteRecord: mutate (:751) → releaseRecordLocator (:757-761) → logAudit (:762)

This is internally consistent across the codebase, so it reads as the spec's wording being imprecise rather than N independent implementation bugs — correcting the spec's text to describe actual (working, consistent) practice is far cheaper and lower-risk than reordering every write function for a pure documentation mismatch with no behavior change.

Surfaced during the 2026-09-12 architecture audit (code-level scan of src/lib/services).

  • Update service-layer.md's documented order to: permission check → mutate → other required side effects → logAudit (audit last, capturing the fully-completed operation) — or, if there's a real reason audit should come before side effects that the code is currently violating, flag that as a genuine bug instead and fix the code, not the spec
  • Spot-check a few more service functions beyond the three cited here to confirm the "audit last" pattern holds broadly before finalizing the spec wording

Done when: service-layer.md's documented order matches actual, verified practice, with no remaining files found to contradict it.

Priority: P2 — documentation accuracy, no behavior change expected (pending the spot-check confirming no real bug exists). Added to 0.5.0 — Stability, Reliability, and QA as part of this release's service-layer consolidation work.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions