Skip to content

[Bug] Security scan task can run before publish transaction commits #612

Description

@XiaoSeS

Summary

SecurityScanService.triggerScan is transactional, but it publishes the Redis Stream scan task inline before the database transaction commits.

The consumer can receive the task before the new skill_version / security_audit rows are visible. It then fails with SkillVersion not found or SecurityAudit not found. The current stream consumer retries immediately and acknowledges each failed message; all retries can be exhausted while the publishing transaction is still open, leaving the committed version stuck in SCANNING.

Current code:

Steps To Reproduce

  1. Enable the security scanner and Redis Stream consumer.
  2. Add a transaction delay after triggerScan publishes the task but before the publish transaction commits, or run with a fast consumer and a slow database transaction.
  3. Publish a public or namespace-only skill version.
  4. Observe the consumer receive the task before the version/audit rows are committed.
  5. The consumer retries the same task immediately; under a sufficiently long transaction, all retries fail.
  6. The publish request commits, but the version remains SCANNING with no successful scan result.

A deterministic regression test can use a transaction barrier/latch and assert that ScanTaskProducer.publishScanTask is not called until after commit.

Expected Behavior

The scan task should become visible only after the transaction that creates/updates the version and audit rows commits.

Typical options:

  • register an afterCommit synchronization before publishing; or
  • use an outbox/event mechanism with commit-coupled delivery.

When no transaction is active, immediate publishing can remain supported.

Environment

  • Branch: main
  • Commit: 9f602f8184f23347124b3606ffce1a6ac5f19c0a
  • Scanner mode: both local and upload modes are affected by task timing

API Contract Impact

No API shape change. This fixes an asynchronous lifecycle race after publish.

Logs Or Screenshots

Representative errors:

SkillVersion not found: <versionId>
SecurityAudit not found for versionId=<versionId>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingeffort/l大改动或高风险改动,需要 maintainer 负责 / Large or risky change requiring maintainer ownership.priority/p1高优先级 / High priority triage bucket.risk/high涉及安全、鉴权、迁移或公共契约 / Touches security, auth, migrations, or public contracts.triage/core交由 core maintainer 结合 AI 协同处理 / Issue should be handled by a core maintainer with AI support.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions