fix: clear stale check rows when docs readiness scoring fails (IN-1305) - #4743
Conversation
…ails (IN-1305) Signed-off-by: Gašper Grom <gasper.grom@gmail.com>
PR SummaryLow Risk Overview Instead of only upserting an Reviewed by Cursor Bugbot for commit dcdff35. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Concurrent scheduled and on-demand workflows can still leave readiness status inconsistent with check rows.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
What changed in this PR
Makes failure persistence clear stale documentation-readiness checks alongside the failed score record.
Changes:
- Wraps failure updates in a transaction.
- Clears stale checks and updates unit coverage.
| File | Description |
|---|---|
scoring.ts |
Clears checks when recording failure. |
scoring.test.ts |
Verifies transactional failure persistence. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| ok: false, | ||
| error: errorMessage, | ||
| await writerQx.tx(async (tx) => { | ||
| await replaceProjectDocReadinessChecks(tx, projectId, []) |

Summary
recordFailureupserts anok=falserow onprojectDocReadinessbut never touchedprojectDocReadinessChecks— so a project that scored successfully on an earlier run (writing realpass/fail/skip/warncheck rows) and then fails discovery/scoring on a later run keeps last run's stale check details sitting under it, with nothing marking them as no longer current. Found during the post-launch data-quality audit of the first production incremental sweep: 1 of 1103 projects already had this after just one run.Fix mirrors the transaction pattern already used in
scoreProject:recordFailurenow wraps its upsert in atxand clears the project's check rows (replaceProjectDocReadinessChecks(tx, projectId, [])) at the same time, soprojectDocReadinessChecksalways reflects the currentokstate instead of drifting from it.Part of the IN-1305 docs-readiness epic (subticket to be filed — will update this PR's title with the real ticket key once created).
Test plan
npx vitest run services/apps/docs_readiness_worker/src/activities/scoring.test.ts— 8/8 passing (updated the existingrecordFailuretest that had asserted checks were untouched, since that was the exact behavior being fixed; added assertion that checks are cleared via the same transaction)npx oxlinton changed files — cleannpx oxfmt --checkon changed files — clean