Repository navigation
feat(audit): attribute workflow audits to their run and merge a run's repeated row audits - #9404
Conversation
… repeated row audits
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
[Medium impact] The PR appears safe to merge; the updated test matches the actor produced by the deployment code. SummaryAdds workflow and run details to delegated audit actors and merges repeated table-row changes and server-side credential accesses.
|
There was a problem hiding this comment.
2 issues found across 14 files
Confidence score: 3/5
writePendinginpackages/audit/src/rollup.tsstarts all row inserts at once, which can create connection and actor-lookup pressure on large flushes. Write rows in batches, aslog.tsdoes.- The process-global flush in
execution-core.tscan drain another workflow’s pending rollup and split events that should be grouped within the two-second window. Scope the flush to the current executor.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/audit/src/rollup.ts">
<violation number="1" location="packages/audit/src/rollup.ts:167">
P2: `writePending` starts every row's insert at once. A flush of up to 1000 rows can open many pooled connections and actor lookups concurrently, which the batch writer in `log.ts` was written to avoid. Write rows in bounded chunks, for example through `insertAuditLogBatch` or a small concurrency limit.</violation>
</file>
<file name="apps/sim/lib/workflows/executor/execution-core.ts">
<violation number="1" location="apps/sim/lib/workflows/executor/execution-core.ts:621">
P2: This flush is process-global, so one workflow can prematurely drain another workflow's pending rollup and split events that occur within the two-second window into separate rows. Flush only rollups owned by this execution, or make the rollup state/run boundary explicit instead of draining the global map here.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Turn on auto-fix | Re-trigger cubic
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
Summary
workflowIdandexecutionId, so a workflow-made audit entry traces back to its workflow and run (before, only a per-calldelegationIdwas recorded)recordAuditRollup/flushAuditRollupsin@sim/audit: repeats of the same event within a 2s window (max 100 per row) become one row. Nothing is dropped:rowIds,delegationIds), and recordsrollup: { entries, firstAt, lastAt }table.updatedfrom insert/update/delete/upsert/replace) opt in, but only for an executor delegation that names its run and has no client request. They merge only within the same execution, table, op, and metadata; session, API key, CLI, and copilot writes are unchangedcredential.accessed(no client request, e.g. a run refreshing a token per tool call) merges per actor + credential; requests with a client still write one row eachexecuteWorkflowCoreawaitsflushAuditRollups()before returning, so a background run's process can't freeze or exit with rows pending; the flush also waits for writes already in flightcreated_atstays the DB default, so drains' 5-minute stability cursor can't skip a delayed rowType of Change
Testing
row-audit.integration.ts(real Postgres): 3 new casesprincipal.test.ts,token-resolution.test.ts(negative cases now also assert no rollup),authorized-workspace-use-case.test.ts,execution-core.test.ts,rows.test.ts, selectors (427 tests)bun run lint; type-check andcheck:auditsleft to CIChecklist
test-auditauthoring gate)