Skip to content

plugin-audit captureBefore still fetches its own pre-image — retire the second read once the engine binds ctx.previous before every before* dispatch #6656

Description

@os-zhuang

Part of #5846 (the retirement its (a) half makes possible). Filed by the engine-core seat per multi-repo rule 3 (linkage chores are issues, not memory) at dispatch time of the #5574+#5846 engine half.

Blocked-by: #5574
Blocked-by: #5846

Fact (origin/main at filing)

packages/plugins/plugin-audit/src/audit-writers.tscaptureBefore (registered on beforeUpdate / beforeDelete) performs its own ql.findOne for the target id and stores the row on ctx.__previous. Its own comment states the reason: "HookContext.previous 官方有类型但引擎不总是填" (the engine does not always fill it).

That justification is expiring:

Once that lands, captureBefore's fetch is a per-write redundant engine read (full read pipeline: middleware, RLS, field masking) that no consumer needs.

Scope

Make captureBefore consume ctx.previous when bound (or retire the fetch entirely if the engine guarantee covers every registered case — claimant judges by code, not by this card). Audit output must stay byte-identical. Pin with a test that a single-id update() on an audited kernel performs no additional engine read beyond the engine's own bound one — and measure the delete side too (bound since #5272).

Non-scope

Routing

Lands in packages/plugins/plugin-audit ⇒ expected domain:identity; routing label left to the triage seat (single-producer rule).

Refs: #5846 (source), #5272, #5574, #5860 (closed), #5929.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions