Skip to content

fix: clear stale check rows when docs readiness scoring fails (IN-1305) - #4743

Merged
gaspergrom merged 1 commit into
mainfrom
fix/IN-1305-clear-stale-checks-on-failure
Sep 24, 2026
Merged

gaspergrom merged 1 commit into
mainfrom
fix/IN-1305-clear-stale-checks-on-failure

Conversation

@gaspergrom

Copy link
Copy Markdown
Contributor

Summary

recordFailure upserts an ok=false row on projectDocReadiness but never touched projectDocReadinessChecks — so a project that scored successfully on an earlier run (writing real pass/fail/skip/warn check 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: recordFailure now wraps its upsert in a tx and clears the project's check rows (replaceProjectDocReadinessChecks(tx, projectId, [])) at the same time, so projectDocReadinessChecks always reflects the current ok state 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 existing recordFailure test 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 oxlint on changed files — clean
  • npx oxfmt --check on changed files — clean

…ails (IN-1305)

Signed-off-by: Gašper Grom <gasper.grom@gmail.com>
@gaspergrom
gaspergrom requested review from epipav and themarolt and a balanced review from Copilot September 23, 2026 22:06
@cursor

cursor Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Localized data-consistency fix in the docs readiness worker’s failure path; behavior aligns with the existing success-path transaction and reduces stale UI/data risk.

Overview
recordFailure now clears stale docs-readiness check rows when a run fails, matching the transactional pattern already used in scoreProject.

Instead of only upserting an ok=false projectDocReadiness row, it runs inside writerQx.tx and calls replaceProjectDocReadinessChecks(tx, projectId, []) before the upsert so prior pass/fail check details are not left under a failed run. The recordFailure unit test was updated to assert the empty check replace and that both writes use the same transaction handle.

Reviewed by Cursor Bugbot for commit dcdff35. Bugbot is set up for automated code reviews on this repo. 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.

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 High severity

Open (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, [])

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

lgtm

@gaspergrom
gaspergrom merged commit b742877 into main Sep 24, 2026
16 checks passed
@gaspergrom
gaspergrom deleted the fix/IN-1305-clear-stale-checks-on-failure branch September 24, 2026 01:55
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