Skip to content

refactor(auditor): share audit dispatch logic between control plane and CAS#3191

Open
migmartri wants to merge 1 commit into
mainfrom
feat/cas-reuse-audit-dispatcher
Open

refactor(auditor): share audit dispatch logic between control plane and CAS#3191
migmartri wants to merge 1 commit into
mainfrom
feat/cas-reuse-audit-dispatcher

Conversation

@migmartri

Copy link
Copy Markdown
Member

Follow-up to #3189 addressing @jiparis's review comment asking whether the CAS could reuse the control plane's audit dispatcher instead of carrying its own copy of the dispatch logic.

The truly shared part — generate the audit event, publish it, and report failures to the log and Sentry — is now extracted into a new auditor.Dispatcher in the importable app/controlplane/pkg/auditor package. Both the control plane's biz.AuditorUseCase and the Artifact CAS AuditDispatcher delegate to it.

Each caller keeps only what genuinely differs between them: actor and organization resolution. The control plane resolves the actor from the request context (user, API token or system) and the CAS uses a SYSTEM actor with the organization taken from the JWT claims. The CAS does not import biz directly, which would pull the full control-plane dependency graph into the CAS binary; the reusable seam is the lower-level dispatcher in pkg/auditor.

AI disclosure

This contribution was developed with AI assistance (Claude Code).

cc @jiparis

🤖 Posted by Maximus bot (Claude Code) on behalf of @migmartri

…nd CAS

Extract the generate -> publish -> error-reporting flow shared by the
control plane's biz.AuditorUseCase and the Artifact CAS AuditDispatcher
into a new auditor.Dispatcher in the importable pkg/auditor package. Both
callers now delegate the common machinery and keep only their own actor and
organization resolution (request context vs JWT claims).

Assisted-by: Claude Code
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>

Chainloop-Trace-Sessions: 645d8cdc-ff37-4ed7-a529-055bc20b46e7
@chainloop-platform

chainloop-platform Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

AI Session Analysis

Avg score Sessions Failing policies Attribution Files Lines Total Duration
🟡 85% 1 ✅ 0 100% AI / 0% Human 5 +294 / -82 25m39s

🟡 85% — 100% AI — ✅ All policies passing

Jun 11, 2026 13:05 UTC · 25m39s · $14.07 · 118.3k in / 126.6k out · claude-code 2.1.173 (claude-opus-4-8)

View session details ↗

Change Summary

  • Adds auditor.Dispatcher in pkg/auditor for the shared generate-and-publish flow.
  • Refactors control-plane biz.AuditorUseCase and CAS AuditDispatcher to delegate while keeping actor and org resolution local.
  • Adds dispatcher tests, updates CAS auditor tests, and commits the follow-up on a new branch.

AI Session Overall Score

🟡 85% — Focused refactor, but setup and verification were only partial.

AI Session Analysis Breakdown

🟢 94% · alignment

🟢 AI turned a vague follow-up into an explicit multiple-choice scope confirmation. · High Impact

🟢 92% · scope-discipline

No notes.

🟢 91% · solution-quality

🟢 It extracted shared dispatch logic at the pkg/auditor layer instead of duplicating it. · High Impact

🟢 86% · user-trust-signal

No notes.

🟡 76% · verification

🟢 Dispatcher and CAS tests were updated and run to passing outcomes. · High Impact

🟠 The biz refactor ended on compile-only verification after the slow full test was stopped. · Medium Severity

💡 When a package has slow integration coverage, keep one targeted runtime test for the changed path instead of compile-only.

🟡 68% · context-and-planning

🟠 A thin PR-follow-up prompt turned into a five-file refactor without a visible plan or TODO. · Medium Severity

💡 For multi-file refactors, write three bullets before editing so the AI has a shared plan to follow.


File Attribution

████████████████████ 100% AI / 0% Human

Status Attribution File Lines
created ai app/controlplane/pkg/auditor/dispatcher_test.go +131 / -0
modified ai app/artifact-cas/internal/service/auditor_test.go +50 / -34
created ai app/controlplane/pkg/auditor/dispatcher.go +80 / -0
modified ai app/artifact-cas/internal/service/auditor.go +18 / -30
modified ai app/controlplane/pkg/biz/auditor.go +15 / -18

Policies (4)

Status Policy Material Messages
✅ Passed ai-config-ai-agents-allowed ai-coding-session-645d8c -
✅ Passed ai-config-no-dangerous-commands ai-coding-session-645d8c -
✅ Passed ai-config-no-secrets ai-coding-session-645d8c -
✅ Passed ai-config-mcp-servers-allowed ai-coding-session-645d8c -

Powered by Chainloop and Chainloop Trace

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

Re-trigger cubic

@migmartri migmartri requested a review from a team June 11, 2026 13:45
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