Skip to content

feat: add backfill script (CM-1218) - #4193

Merged
ulemons merged 1 commit into
mainfrom
feat/backfill-stewardship-script
Jun 11, 2026
Merged

feat: add backfill script (CM-1218)#4193
ulemons merged 1 commit into
mainfrom
feat/backfill-stewardship-script

Conversation

@ulemons

@ulemons ulemons commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds stewardship tables and a backfill script to seed the initial state required by the OSSPREY Self Serve program (v1). In v1 the stewardship program is read-only: every critical package gets one unassigned row in the new stewardships table. Write flows (claim, assign, status transitions) land in v2. The backfill script is the one-time (and safely re-runnable) job that populates those rows for the ~358K currently-critical packages.

Changes

  • Migration V1781094067__stewardship-tables.sql — creates stewardships and five satellite tables (stewardship_stewards, stewardship_activity, stewardship_assessments, stewardship_findings, stewardship_remediation_actions). Only stewardships is populated in v1; the rest are schema-only.

  • services/libs/data-access-layer/src/osspckgs/stewardships.ts — two DAL query functions: listCriticalPackagesWithoutStewardship (cursor-paginated LEFT JOIN anti-join) and insertUnassignedStewardships (batch INSERT with ON CONFLICT DO NOTHING and is_critical re-check at insert time to guard against concurrent criticality flips).

  • packages_worker/src/stewardship/runStewardshipBackfill.ts — idempotent loop over DAL functions; cursor-based pagination by package.id; supports graceful shutdown via isStopping callback designed for future Temporal activity wiring.

  • packages_worker/src/bin/stewardship-backfill.ts — entry point; validates STEWARDSHIP_BACKFILL_BATCH_SIZE env var (fails fast on NaN/non-positive); SIGINT/SIGTERM handled gracefully.

  • package.json — adds backfill:stewardship and backfill:stewardship:local npm scripts (mirrors backfill:maven:local pattern).

  • backend/src/api/public/v1/packages/types.ts — extracts StewardshipStatus, Lifecycle, SeverityLevel, OpenVulns, Steward, StewardshipSummary into a shared types file; removes inline duplicates from batchGetStewardship.ts.

  • mockData.ts / openapi.yaml — adds stewardship block to MockPackageDetail; fixes steward → stewards field rename; adds openVulns to OpenAPI required fields; adds PackageDetail.stewardship schema.

    Type of change

    • Bug fix
    • New feature
    • Refactor / cleanup
    • Performance improvement
    • Chore / dependency update
    • Documentation

JIRA ticket

ticket


Note

Medium Risk
One-time bulk writes to stewardships at large scale (~358K rows); mitigated by idempotent inserts and conflict-safe re-runs, but still a production data migration job.

Overview
Adds an idempotent stewardship backfill for OSSPREY v1: it creates one unassigned / auto_imported row in stewardships for each critical package that does not already have one.

New data-access-layer helpers paginate critical packages missing stewardship (listCriticalPackagesWithoutStewardship) and batch-insert with ON CONFLICT DO NOTHING, re-checking is_critical at insert time. runStewardshipBackfill loops in cursor-sized batches, supports graceful stop via an isStopping callback (for future Temporal use), and reports inserted/skipped totals.

A stewardship-backfill bin entry connects to packages-db, validates STEWARDSHIP_BACKFILL_BATCH_SIZE (default 10k), handles SIGINT/SIGTERM after the current batch, and wires backfill:stewardship / backfill:stewardship:local npm scripts (same pattern as maven backfill).

Reviewed by Cursor Bugbot for commit 4e73636. Bugbot is set up for automated code reviews on this repo. Configure here.

@ulemons ulemons self-assigned this Jun 10, 2026
Copilot AI review requested due to automatic review settings June 10, 2026 16:13
@ulemons ulemons changed the title feat: add backfill script feat: add backfill script (CM-1218) Jun 10, 2026

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 399b9ba. Configure here.

inserted += batchInserted
skipped += batchSkipped
batches++
lastId = ids[ids.length - 1]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor skips newly critical packages

Medium Severity

The backfill advances lastId and only lists packages with p.id > afterId. Critical packages whose is_critical flips to true after that id was passed are never selected in that run, yet the loop still exits when no higher ids remain. Those packages stay without a stewardships row until the job is run again from the start.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 399b9ba. Configure here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds the initial “stewardship” backfill capability for OSSPREY Self Serve v1 by introducing DAL queries to find critical packages missing stewardship rows, plus a packages-worker script/runner to insert those rows in idempotent batches.

Changes:

  • Add @crowd/data-access-layer stewardship DAL functions to (a) page through critical packages lacking stewardship rows and (b) batch-insert unassigned/auto_imported stewardships with ON CONFLICT DO NOTHING.
  • Add a packages-worker backfill runner with cursor pagination + batch-level logging and a CLI entrypoint with SIGINT/SIGTERM graceful shutdown.
  • Add pnpm scripts to run the stewardship backfill (including a :local variant mirroring existing patterns).

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
services/libs/data-access-layer/src/osspckgs/stewardships.ts Adds cursor-paginated selector for missing stewardships + idempotent batch insert with criticality re-check.
services/libs/data-access-layer/src/osspckgs/index.ts Re-exports stewardship DAL module from the osspckgs index.
services/libs/data-access-layer/src/index.ts Re-exports stewardship DAL module from the package root.
services/apps/packages_worker/src/stewardship/runStewardshipBackfill.ts Implements the batched backfill loop using the new DAL functions, with graceful-stop support.
services/apps/packages_worker/src/bin/stewardship-backfill.ts Adds CLI entrypoint: connects to packages-db, validates batch size env var, handles shutdown signals.
services/apps/packages_worker/package.json Adds backfill:stewardship and backfill:stewardship:local scripts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

joanagmaia
joanagmaia previously approved these changes Jun 11, 2026
@ulemons
ulemons force-pushed the feat/backfill-stewardship-script branch from 399b9ba to a739c9f Compare June 11, 2026 08:33
@ulemons
ulemons force-pushed the feat/stewardship-tables branch from f1421c2 to 03acaab Compare June 11, 2026 11:17
Base automatically changed from feat/stewardship-tables to main June 11, 2026 11:26
@ulemons
ulemons dismissed joanagmaia’s stale review June 11, 2026 11:26

The base branch was changed.

Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
@ulemons
ulemons force-pushed the feat/backfill-stewardship-script branch from a739c9f to 4e73636 Compare June 11, 2026 11:34
@ulemons
ulemons merged commit 920d0dc into main Jun 11, 2026
16 checks passed
@ulemons
ulemons deleted the feat/backfill-stewardship-script branch June 11, 2026 11:43
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.

3 participants