Skip to content

fix(audit): attribute manual agent-token management to the user (#149) - #157

Merged
LeoStehlik merged 4 commits into
masterfrom
fix/149-audit-attribution
Nov 21, 2026
Merged

LeoStehlik merged 4 commits into
masterfrom
fix/149-audit-attribution

Conversation

@LeoStehlik

@LeoStehlik LeoStehlik commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #149

Fixes: audit entries for manually created/revoked agent tokens rendered as "Leo, via Francis" although the agent performed no action.

Findings

The stored row was already correct (actorId = the human, actorType: 'user'); the defect was in rendering: the audit table appended ", via " for any event carrying metadata.agentName, which includes token-management events where the name merely identifies the connection being created. Genuine agent actions (MCP tools, agent page edits) carry the same field, so display text alone couldn't distinguish them.

Changes

  • New shared helpers apps/server/src/common/audit/agent-audit.ts:
    • agentPerformedAuditMetadata() → viaAgent: true (used by agent.create_page, agent.add_comment, agent.page_edited);
    • agentConnectionManagedAuditMetadata() → managedConnection: true (used by agent.token_created, and now also agent.token_revoked, which previously stored no metadata at all).
  • Client getAuditAttribution() renders ", via Agent" only for viaAgent events; manual token events show the agent as a separate dimmed "For agent: …" detail under the human actor. Stored metadata and rendering now both encode the distinction.
  • Comments and page history already only carry agentName on genuinely agent-performed actions — unchanged.

Tests

  • New jest specs: manual create/revoke record the human actor with managedConnection and no viaAgent; token secrets never reach audit rows; helper semantics pinned. Full server suite: 32 suites / 226 tests pass; client tsc clean.
  • Browser E2E (disposable stack): manual creation row shows QA Leo + For agent: Francis (no "via"); a real create_page call with the token shows QA Leo, via Francis; manual revocation shows For agent: Francis.

Compatibility note

Historical agent.token_created rows (pre-this-change) have agentName but no viaAgent, so they will render as "For agent: …" — the conservative direction (never over-attribute to the agent).

Review follow-up: preserve historical attribution for the known agent.create_page, agent.add_comment and agent.page_edited events that predate viaAgent. Unknown metadata is not treated as either actor or connection attribution. Added client-helper regression tests and CI coverage for both stored metadata and presentation. No historical rows are rewritten.

Creating or revoking an agent token is performed by the human user;
the configured agent name only identifies the connection. The audit
table already stored the user as actor, but the audit log renderer
showed "User, via Agent" for any event carrying metadata.agentName,
which made manual token management look agent-performed.

- Add shared audit metadata helpers: agent-performed actions are
  marked viaAgent, manual connection management is marked
  managedConnection.
- Mark MCP and collaboration agent edits with viaAgent; mark token
  created/revoked with managedConnection and record the agent name on
  revocation too.
- Render ", via Agent" only for viaAgent events; manual token events
  show the agent as a separate "For agent:" detail.

Refs #149

Signed-off-by: Leo Stehlik <[email protected]>
…ution

Signed-off-by: Leo Stehlik <[email protected]>

# Conflicts:
#	apps/client/src/wrenlore/audit/components/audit-logs-table.tsx
@LeoStehlik
LeoStehlik merged commit 6f2841e into master Nov 21, 2026
2 checks passed
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.

Audit log misattributes manual token creation to the configured agent

1 participant