Repository navigation
Conversation
Discovery of a referrer that many attestations share, such as an identical scanner report, read and sorted every reference of the root to return one page. A production root with 12.7k references touched ~131k buffers per page and timed out when the pages were not cached (PFM-8116). The references edge becomes an Ent edge schema with a created_at column that copies the creation time of the referenced referrer, indexed as (referrer_id, created_at DESC, referred_by_id DESC). A page is now read in index order, visibility is checked per row with a correlated EXISTS, and the scan stops when the page is full. Ordering and cursors keep the same semantics. The migration renames the foreign keys instead of recreating them, adds the column with a non-rewriting default, backfills it outside the schema-change transaction, and builds the index concurrently. Refs: PFM-8116, PFM-7062 Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev> Chainloop-Trace-Sessions: 42d5f922-ec91-4438-a233-0546f874e1b4
PR validation — ✅ 3 passing
AI Session Checks — 🟡 85% · ✅ 0 failing
|
| Status | Attribution | File | Lines |
|---|---|---|---|
| created | ai | app/controlplane/pkg/data/referrer_references_integration_test.go |
+389 / -0 |
| modified | ai | app/controlplane/pkg/data/referrer.go |
+165 / -49 |
| created | ai | app/controlplane/pkg/data/ent/schema/referrerreference.go |
+93 / -0 |
| modified | ai | app/controlplane/pkg/data/ent/migrate/schema.go |
+47 / -28 |
| modified | ai | app/controlplane/pkg/data/referrer_visibility_integration_test.go |
+23 / -14 |
| created | ai | app/controlplane/pkg/data/ent/migrate/migrations/20261116124543.sql |
+36 / -0 |
| created | ai | app/controlplane/pkg/data/ent/migrate/migrations/20261116124542.sql |
+9 / -0 |
| modified | ai | app/controlplane/pkg/data/ent/schema/referrer.go |
+3 / -2 |
| modified | ai | app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum |
+3 / -1 |
Policies (4)
| Status | Policy | Material | Messages |
|---|---|---|---|
| ✅ Passed | ai-config-ai-agents-allowed |
ai-coding-session-42d5f9 |
- |
| ✅ Passed | ai-config-no-dangerous-commands |
ai-coding-session-42d5f9 |
- |
| ✅ Passed | ai-config-no-secrets |
ai-coding-session-42d5f9 |
- |
| ✅ Passed | ai-config-mcp-servers-allowed |
ai-coding-session-42d5f9 |
- |
Security Checks — ✅ 5 passing
✅ secret-scan
| Status | Policy | Messages |
|---|---|---|
| ✅ Passed | secrets-detection |
- |
✅ sast-scan
| Status | Policy | Messages |
|---|---|---|
| ✅ Passed | owasp-top10-2025 |
- |
| ✅ Passed | sast |
- |
| ✅ Passed | cwe-top25 |
- |
| ✅ Passed | cwe-top26-40-cusp |
- |
Scans not applied (3)
| Scan | Reason |
|---|---|
vulnerability-scan |
no manifest/lockfile changed |
github-actions-scan |
no workflow files changed |
iac-scan |
no IaC files changed |
Powered by Chainloop and Chainloop Trace
There was a problem hiding this comment.
No issues found across 26 files
This PR changes a database schema or migrates data. Ultrareviews find 2.4x more serious bugs than standard reviews. Comment @cubic-dev-ai ultrareview to run one.
View guided diff | Re-trigger cubic
…amp default Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev> Chainloop-Trace-Sessions: 42d5f922-ec91-4438-a233-0546f874e1b4
…ead of skipping it Drop IF NOT EXISTS from the concurrent index build, so an invalid index left by a failed build stops the migration instead of being kept. Also cover the visibility filter inside the references page query. Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev> Chainloop-Trace-Sessions: 42d5f922-ec91-4438-a233-0546f874e1b4
Store on each referrer reference the organization of the attestation that stored it, and index it before the page order. A page reads one index range per caller organization, plus the references with no organization, so a caller that sees a small share of a shared material no longer walks past the references of other organizations. A reference stored again from another organization loses its organization, so that it is read in every organization. The backfill takes the organization that both ends of a reference share, or leaves it NULL when they share more than one. Refs PFM-7062 Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev> Chainloop-Trace-Sessions: 42d5f922-ec91-4438-a233-0546f874e1b4
…reSQL limit The generated name was longer than the 63 characters PostgreSQL keeps, so the database stored a truncated name that differs from the one in the migration. Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev> Chainloop-Trace-Sessions: 42d5f922-ec91-4438-a233-0546f874e1b4
…n the same references Stop rewriting references that have no organization when they are stored again. Keep the next-page cursor when a referenced referrer is deleted while a page is read. Check project membership on the same references the pages read. Read the references table once less in the backfill, and vacuum it before the index build. Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev> Chainloop-Trace-Sessions: 42d5f922-ec91-4438-a233-0546f874e1b4
…visibility Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev> Chainloop-Trace-Sessions: 42d5f922-ec91-4438-a233-0546f874e1b4
Summary
Discovery (
ReferrerService/DiscoverPrivate,chainloop discover) was slow, and sometimes timed out, for referrers that many attestations share, such as an identical scanner report. To return one page of references, the control plane read and sorted every reference of the root. In production, one such material has 12.7k references: each page touched about 131k buffers, took 155 ms with a warm cache, about 5 s with a cold one, and hit the request deadline in the worst cases.This change reads a page of references directly in page order, from the references of the caller's organizations only:
referencesedge ofReferrerbecomes an Ent edge schema (ReferrerReference) on the existingreferrer_referencestable. The table gets two columns and an index on(referrer_id, organization_id, created_at DESC, referred_by_id DESC):created_atcopies the creation time of the referenced referrer, which is the page order.organization_idis the organization of the attestation whose ingestion stored the reference.EXISTS, and each range stops when the page is full. So the cost no longer grows with the number of references of the root, or with the share of them stored in other organizations. Order and cursor semantics stay the same.Behavior change
An attestation used as a material of an attestation in another organization is linked to that organization too. Until now, that organization also saw it through references that the first organization stored, for example under a material the two organizations share. Now it sees it as a root and through the references its own attestation stored, but not through references stored by the first organization.
Migration
Out of scope
Closes PFM-8116
Related to PFM-7062
AI assistance: this change was written with Claude Code.