Skip to content

fix(plugin-audit): a comment write leaves a ledger row and an activity row, stamped when the author was impersonated - #31128

Merged
objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/project-thread-nbg9qq
Nov 7, 2026
Merged

objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/project-thread-nbg9qq

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by 田騏 · project thread

Fixes #30979

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:评论(sys_comment)不再在审计镜像的跳过名单里。新建、编辑、删除评论现在和其他记录一样,各写一行审计(sys_audit_log)和一行动态(sys_activity);管理员模拟员工时写的评论,两行都带上「谁代谁」的标记。
  • 为什么改:按你在 [Decision] Actions taken while impersonating a user are recorded only under that user #30213 选的 A(「A 评论也记审计和动态」)。之前模拟时写的评论和员工本人写的完全分不出来。
  • 风险与回滚:每条评论多两行数据;这两行只给能读这条评论(即能读评论所在记录)的人看,复用评论自己的读权限,没有新判断。记录详情页的动态流不会重复显示(它只读记录本身的动态)。回滚即撤销本 PR,已写下的行保留。
  • 先看:packages/plugins/plugin-audit/src/audit-writers.ts(跳过名单那一处);src/activity-read-visibility.integration.test.ts 末尾新增的读可见性用例。
  • 两分钟验证:pnpm --filter @objectstack/plugin-audit exec vitest run src/activity-actor-name.test.ts src/activity-read-visibility.integration.test.ts,预期全部通过(34 条)。
  • 需要你做的:无,席位落地。

What changes

  • packages/plugins/plugin-audit/src/audit-writers.ts: 'sys_comment' leaves SKIP_OBJECTS, so AUDIT_EXCLUDED_OBJECTS (derived from it) no longer lists it. A comment insert, update and delete now pass through writeAudit like any other object: one ledger row, one activity row, and PR feat(audit): record the administrator on writes made while impersonating a user #30800's impersonation stamp (metadata.impersonated_by on both, impersonated_by_name on the activity row) when the write came from an impersonation session. A comment above the list says why comments are not on it. Two stale code comments that said comments are skipped are corrected. No new column, no migration (option B was not chosen).
  • Readers of AUDIT_EXCLUDED_OBJECTS, checked:
    • the hook registrations' excludeObjects (the same list): comment writes now open the global after-phase hooks;
    • parent-record-read-gate.ts enumerateParentObjects: the activity and ledger gates now enumerate sys_comment as a parent. sys_comment carries an object-scoped read middleware (installCommentReadVisibility), so the planner routes it to the bounded probe (ADR-0139 D5.2), which reads sys_comment as the caller under that same comment gate. That is the read visibility the card asks for, with no second judgment;
    • comment-access-hooks.ts commentThreadGate().namedParents: it shrinks by sys_comment, which the comment gate already skips as its own gated object (name === gate.object is tested first), so the comment gate's parent set is unchanged.
  • Recursion: the "(1) recursion" group is about the audit and activity tables themselves, which stay listed. The writer writes only sys_audit_log and sys_activity; nothing it writes is a comment.
  • .changeset/30979-comment-writes-audited.md: patch for @objectstack/plugin-audit.

Step 1 measurement: no timeline duplication (read at origin/main 5f00374)

  • The record page's 动态 stream reads sys_activity filtered to the RECORD's own pair: ui RecordDetailView activityWindowQuery (object_name: objectName, record_id: recordId), and the server record-page payload and timeline count (packages/rest/src/record-page-routes.ts, where: { object_name: object, record_id: id } and ofRecord).
  • The mirror writes a comment's activity row with object_name: 'sys_comment' and record_id the comment's id (activityRow.object_name = ctx.object), so it never matches the parent record's filter. No writer emits the commented activity type.
  • So a comment shows once on its record (from sys_comment), as before. Its new activity row appears only in the object-agnostic feeds (home recent activity, the bell's Activity tab, the sys_activity list) as a created/updated/deleted Comment entry, where no comment entry existed. No UI change is needed.

Tests

  • activity-actor-name.test.ts, new describe "a comment written from an impersonation session is recorded like any other write": an impersonated comment insert writes one ledger row and one activity row, both stamped with the administrator; an impersonated edit and delete are stamped too; CONTROL: the user's own comment writes both rows, unstamped.
  • activity-read-visibility.integration.test.ts, new describe "a comment's ledger and activity rows are served only to a reader of the comment" (real kernel, real AuditPlugin, SQLite): each member is served the activity and ledger rows of the comment on its own record and neither row of the other member's comment (list, id-scoped find, count); controls: both comments' rows exist (system read), the comment gate answers each member its own comment, the admin is served both.
  • audit-hook-object-scope.test.ts: the two assertions that pinned sys_comment as excluded now pin the reverse (not in excludeObjects; the comment insert has a create ledger row).

Acceptance notes

  • A holder of the ledger's audit capability (view_all_audit_log) keeps reading every ledger row of the organization, comment rows included, as for every other object (the gate's declared exemption). The activity stream has no exemption.
  • Comments written before this change have no rows; nothing is backfilled.
  • os migrate comment-parent-pair --apply boots AuditPlugin and updates unstamped comments through the engine as the system, so each stamped comment now also leaves one system-actor update ledger row and activity row. Raised for the seat in the report; not changed here (outside this card's file surface and a separate decision).
  • identity-objects-feeds-off.test.ts boots a single posture without a Default Organization, so its comment writes now print the writer's own one-time Audit write FAILED ... ERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED error line. That suite still passes; the line is the writer correctly reporting its harness.

Verification

All readings at head 8bc2feca4 (merge base 5f0037449 = current origin/main; no main commits since).

  • bash scripts/pm/os-verify-lock.sh -c "pnpm --filter @objectstack/plugin-audit test" :: exit 0 — Test Files 76 passed (76), Tests 1201 passed (1201).
  • pnpm --filter @objectstack/plugin-audit typecheck :: exit 0 (tsc src + scripts + test-typecheck).
  • eslint --no-inline-config over the four touched source and test files :: exit 0 (the package declares no lint script; the repo-wide pnpm lint is CI's).
  • Ablation 1, writer (node scripts/ablation-replace.mjs, anchor hit 1, restored blob == HEAD): 'sys_comment' put back on SKIP_OBJECTS → activity-actor-name.test.ts + activity-read-visibility.integration.test.ts: 6 failed / 28 passed (all three impersonation pins, the CONTROL pin, the rows-exist control, the visibility pin and the admin control). Restored: green.
  • Ablation 2, read visibility: the comment read gate's registration (engine.registerMiddleware(gate, { object: COMMENT_OBJECT }) in comment-access-hooks.ts) deleted → 2 failed / 14 passed: the comment-gate control and "a reader without read access to the comment's record is served neither of its rows" (expected [ two comment ids ] to deeply equal [ one ]: the other member's comment rows were served). Restored: green. So the rows' visibility is the comment gate's own answer, read through the probe.
Derived gates: 65 / 65 exit 0 on the final head; `dispatch-gates --ran`: 65 derived, 65 run, 0 NOT-MEASURED, 0 UNRUN

Three gates first answered exit 3 (PREREQUISITE NOT MET) and were re-run after the prerequisite: check-plugin-teardown-shape --self-test after fetching its pinned fixture commit, check:dual-build-cjs-loads and check:i18n after a full pnpm build. check:query-options-erasure first counted one new test-surface options cast; the cast was removed (8bc2feca4) and the whole list re-run on that head:

node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0
node scripts/check-adr-0087-registration.mjs --self-test :: exit 0
node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0
node scripts/check-closing-keyword-parity.mjs :: exit 0
node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0
node scripts/check-comment-mask-adoption.mjs :: exit 0
node scripts/check-comment-mask-adoption.mjs --self-test :: exit 0
node scripts/check-comment-mask-corpus.mjs :: exit 0
node scripts/check-dts-emitted.mjs --self-test :: exit 0
node scripts/check-empty-changeset.mjs --base origin/main :: exit 0
node scripts/check-empty-changeset.mjs --self-test :: exit 0
node scripts/check-issue-citations.mjs :: exit 0
node scripts/check-plugin-teardown-shape.mjs :: exit 0
node scripts/check-plugin-teardown-shape.mjs --self-test :: exit 0
node scripts/check-tenant-audit-census.mjs :: exit 0
node scripts/check-tenant-audit-census.mjs --self-test :: exit 0
node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0
node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0
node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0
node scripts/ci/snapshot-next.mjs --self-test :: exit 0
node scripts/docs-audit/check-affected-docs.mjs :: exit 0
node scripts/docs-audit/check-drift-comment.mjs :: exit 0
node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0
node scripts/release-pending-publish.mjs --self-test :: exit 0
pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0
pnpm check:changeset-gate-self-tests :: exit 0
pnpm check:ci-filter-parity :: exit 0
pnpm check:closed-ceremony-text :: exit 0
pnpm check:cross-package-test-inputs :: exit 0
pnpm check:dispatcher-error-vocabulary :: exit 0
pnpm check:doc-authoring :: exit 0
pnpm check:driver-memory-census :: exit 0
pnpm check:dts-closure :: exit 0
pnpm check:dual-build-cjs-loads :: exit 0
pnpm check:durability-log-level :: exit 0
pnpm check:engine-double-contract :: exit 0
pnpm check:error-status-conformance :: exit 0
pnpm check:gitlink-declared :: exit 0
pnpm check:i18n :: exit 0
pnpm check:i18n-stale-fill :: exit 0
pnpm check:issue-citations :: exit 0
pnpm check:keyed-text-bounds :: exit 0
pnpm check:lean-entry-closure :: exit 0
pnpm check:logger-receiver-detach :: exit 0
pnpm check:nul-bytes :: exit 0
pnpm check:objectql-double-limit :: exit 0
pnpm check:org-identifier :: exit 0
pnpm check:page-declaration-shape :: exit 0
pnpm check:platform-object-tenancy-census :: exit 0
pnpm check:published-files :: exit 0
pnpm check:query-options-erasure :: exit 0
pnpm check:refd-timer-probe :: exit 0
pnpm check:registry-log-declared :: exit 0
pnpm check:rest-log-spy-declared :: exit 0
pnpm check:slot-lookup :: exit 0
pnpm check:sourcemap-no-sources-content :: exit 0
pnpm check:system-context-census :: exit 0
pnpm check:test-source-alias :: exit 0
pnpm check:tier-file-adoption :: exit 0
pnpm check:type-check-coverage :: exit 0
pnpm check:type-check-debt :: exit 0
pnpm check:undeclared-dep-imports :: exit 0
pnpm check:vouch-for-reference-callers :: exit 0
pnpm check:watch-hint-literal :: exit 0
pnpm check:where-matcher :: exit 0

🤖 Generated with Claude Code

@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/plugin-audit, touching 3 documentable anchor(s).

8 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/api/data-api.mdx (via sys_comment (literal, a string literal in SKIP_OBJECTS))
  • content/docs/deployment/cli.mdx (via sys_comment (literal, a string literal in SKIP_OBJECTS))
  • content/docs/frontend/plugins/plugin-detail.mdx (via sys_comment (literal, a string literal in SKIP_OBJECTS))
  • content/docs/kernel/contracts/data-engine.mdx (via sys_comment (literal, a string literal in SKIP_OBJECTS))
  • content/docs/permissions/attachments-access.mdx (via sys_comment (literal, a string literal in SKIP_OBJECTS))
  • content/docs/permissions/system-context.mdx (via sys_comment (literal, a string literal in SKIP_OBJECTS))
  • content/docs/plugins/packages.mdx (via sys_comment (literal, a string literal in SKIP_OBJECTS))
  • content/docs/upgrading.mdx (via sys_comment (literal, a string literal in SKIP_OBJECTS))

⛔ 7 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/v14.mdx (via sys_comment (literal, a string literal in SKIP_OBJECTS))
  • content/docs/releases/v16.mdx (via sys_comment (literal, a string literal in SKIP_OBJECTS))
  • content/docs/releases/v17/17-0.mdx (via sys_comment (literal, a string literal in SKIP_OBJECTS))
  • content/docs/releases/v17/17-1.mdx (via sys_comment (literal, a string literal in SKIP_OBJECTS))
  • content/docs/releases/v17/17-5.mdx (via sys_comment (literal, a string literal in SKIP_OBJECTS))
  • content/docs/releases/v17/17-6.mdx (via sys_comment (literal, a string literal in SKIP_OBJECTS))
  • content/docs/releases/v18/18-0.mdx (via sys_comment (literal, a string literal in SKIP_OBJECTS))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

What this run could not see
  • the SDK route bridge reached 63 of 226 client-bound route-ledger rows — the other 163 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 163: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 104 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 10 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 5f0037449256ccb0855e258ffc4fd4bff84d1a67 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from d780ece0b6710e45c3ca433dfadc185d402b0e0f — the merge of head 8bc2feca437e2a223aaac449bee0f169c22b265a into base 5f0037449256ccb0855e258ffc4fd4bff84d1a67, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin d780ece0b6710e45c3ca433dfadc185d402b0e0f && git checkout d780ece0b6710e45c3ca433dfadc185d402b0e0f
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 5f0037449256ccb0855e258ffc4fd4bff84d1a67 8bc2feca437e2a223aaac449bee0f169c22b265a && git checkout -B drift-repro 5f0037449256ccb0855e258ffc4fd4bff84d1a67 && git merge --no-ff 8bc2feca437e2a223aaac449bee0f169c22b265a

node scripts/docs-audit/affected-docs.mjs --json 5f0037449256ccb0855e258ffc4fd4bff84d1a67

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 5f0037449256ccb0855e258ffc4fd4bff84d1a67 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#3 · marchtian · session_017ihL2dFb2QdZEHEJ83cR2B

维护者速读

  • 改了什么: 评论不再被审计跳过:新建、修改、删除评论都会写一行审计和一行动态;管理员模拟员工时写的评论,会带上「谁代谁」的标记。
  • 为什么改: 按你在 [Decision] Actions taken while impersonating a user are recorded only under that user #30213 选的 A「评论也记审计和动态」。以前模拟时写的评论和员工本人写的完全分不出来。
  • 风险与回滚: 看不到原记录的人也看不到这条评论的审计和动态(沿用评论自己的读权限);记录页的时间线不会重复显示。回滚即 revert。
  • 先看: audit-writers.ts 的 SKIP_OBJECTS;activity-read-visibility.integration.test.ts 的可见性用例。
  • 两分钟验证: 见 PR 正文同名行。
  • 需要你做的: 无,席位落地(非受管面)。
  • 席位意见: ACCEPT。迁移命令 os migrate comment-parent-pair --apply 回填存量评论时,每条会多一行系统审计,席位选择保留(如实记录系统改动)。

席位核对

ACCEPT · Head-sha: 8bc2feca437e2a223aaac449bee0f169c22b265a · 2026-11-07T14:09Z

  1. Shape: draft → main, Fixes #30979; Clause-②: no / Metadata-protocol: none match the claim 6706945594. 5 files, all in packages/plugins/plugin-audit/** plus the changeset; check-governed-merges --pr 31128: NOT governed.
  2. Premise measured: SKIP_OBJECTS listed sys_comment at origin/main 5f0037449; PR feat(audit): record the administrator on writes made while impersonating a user #30800 (the stamp) merged. The ruling's measure-first stop (timeline duplication) was taken before any edit: comment rows name sys_comment as parent, the record timeline reads the parent record's own pair, so no duplicate and no UI change.
  3. Gates (check-runs at this head): 48 runs, 35 success, 13 skipped, 0 failure, 0 pending. Dev's local reading: plugin-audit 1201/1201, 65/65 derived gates exit 0, 0 NOT-MEASURED (report 6707614483).
  4. Accepted, read in the diff: the only production change is sys_comment leaving SKIP_OBJECTS (plus comments); the @mention hook is unchanged. Read visibility reuses the comment's own read gate through the existing parent-record probe (no second judgment), pinned on a real kernel: a member is served only its own record's comment rows, ledger and activity, find and count; two ablations red (comment back on the skip list: 6 failed; comment read gate removed: visibility pin red). Impersonated insert/update/delete stamped, CONTROL unstamped. Open question answered A: a comment-parent-pair backfill leaves one system-actor update row per comment, kept as an honest record.
  5. Out of scope: none filed. Skills-docs: n/a.
  6. Landing: seat lands it (pr_ready + automerge_enable via the relay). On MERGED it checks that plugin-audit: a comment written while impersonating writes no audit or activity row, so it can't be told from the employee's own (#30213 comments fork, ruling A) #30979 closed and removes pm:dispatched.

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

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

2 participants