Skip to content

sync_lane_feed: overlapping ingests can lose or tear data/lanes.json #262

Backlog

Description

@MaxGhenis

The second round of independent review on #261 found this.

scorecard_db.ingest_harvest.sync_lane_feed reads data/lanes.json, updates the lanes it was given, and writes the whole file back with Path.write_text. 26 modules call it, each after its SQLite transaction has committed, so nothing serializes the file:

  • Lost update: two ingests that overlap can both read the old feed, so the second write drops the first one's lane.
  • Torn read: an ingest that reads between another's truncation and its write sees an empty or partial file and fails to parse it.

build_db runs the ingests one after another in one process, so the committed feed is safe today. The risk is two standalone ingests run at the same time. #261's overlap test stubs the mirror, so it covers only the database rows.

Fixing it in sync_lane_feed would cover every caller:

  • hold an exclusive lock on a sibling lock file across the read, merge and write;
  • write through a temporary file in the same folder, then os.replace.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions