Skip to content

fix(platform): order watchdog visit locks - #4518

Merged
yannickmonney merged 1 commit into
mainfrom
fix/watchdog-visit-lock-order
Oct 8, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
fix/watchdog-visit-lock-order

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

Summary

Overlapping sandbox watchdog passes could update their visited rows in opposing scan orders, deadlock after lifecycle work had committed, and report a zero result for that pass. The shared stamp helper now locks immutable row IDs in order before updating, preserving each complete visited set and the existing parallel lifecycle work.

This fixes the PostgreSQL 40P01 failure observed in main Checks 37716403767. No retry, skipped row, schema change or scheduler-limit change is introduced.

Checklist

  • bun run check --concurrency=2 — 49/49 tasks passed (43 cached, six executed), pinned Bun 1.4.2 with CI environment.
  • bun run lint:sast — passed, zero findings.
  • Translations: N/A; no product strings change.
  • Product docs: N/A; internal locking correction. Automated coverage is mapped in the platform manual reference.
  • READMEs: N/A; no setup or public contract changes.

Test plan

  • A deterministic real-PostgreSQL regression forces overlapping heap/index scan orders. Before the fix: 30/31 lane checks, with the new case reporting 40P01. After the fix: 31/31, including complete stamps and the original rendered-session cleanup assertion.
  • The existing watchdog unit suite passes 27/27. The final full check, Knip and SAST pass.
  • The local native run is the filtered checkWatchdogs lane against a fresh owned cached-image database. Hosted Backend integration must still run all required lanes against the image built from this PR.

Acquire sandbox watchdog visit rows in immutable primary-key order before stamping them. Preserve complete batches and parallel lifecycle probes, and reproduce opposing scan-order contention in the existing real-Postgres lane. No user-facing strings, configuration or schema changes.
@yannickmonney
yannickmonney merged commit c274de1 into main Oct 8, 2026
@yannickmonney
yannickmonney deleted the fix/watchdog-visit-lock-order branch October 8, 2026 05:02
@yannickmonney

Copy link
Copy Markdown
Contributor Author

ACCEPT — reviewed exact head c6f081ea51a8beeec8f975f9be5ee939831c66dd (read 2026-10-08 UTC). I did not author this PR.

Criterion Evidence / judgment
1. Root cause and lock order PASS. services/platform/backend/domains/sandbox/watchdogs.ts changes stampVisited to a materialized SELECT ... ORDER BY id FOR NO KEY UPDATE before the update. Every four watchdog lanes that stamp visits calls this shared helper, so opposing scan plans acquire row locks in the same primary-key order. No remaining changed path in these five files inverts that order; the helper is the sole stamp implementation.
2. Real regression PASS. The new watchdog-visits.integration.ts forces Seq Scan vs Index Scan, reverses candidate order for one transaction, checks the blocker, and asserts both transactions complete with both rows stamped. At this head, Backend integration job 113154950861 logged PASS: waitedForFirst=true, outcomes=ok,ok, stamped=2/2. The parent/main job 113113753840 logged the pre-fix FAIL with PostgresError: deadlock detected, code 40P01, and released=0.
3. Scope PASS. All five changed files are directly related: (1) watchdog-visits.integration.ts real-Postgres opposing-plan regression; (2) watchdogs.ts ordered shared lock/update helper; (3) watchdogs.test.ts two SQL-statement expectation updates for the changed query shape; (4) integration-check.ts registers the integration lane; (5) tests/manual/reference/automation.md records the automated coverage row.
4. CI-ready aggregators PASS (read 2026-10-08 UTC; exact head). Build=success (113156997778), Checks=success (113156702462), E2E=success (113156109800), SAST=success (113156069794), Commitlint=success (113155065836), Security=success (113154914239), CLI=success (113154906643).
5A. User impact N/A for direct UI; this is backend watchdog reliability. Indirect impact is recovery of abandoned render sessions and continued sandbox watchdog progress instead of a deadlocked sweep.
5B. Engineering risk PASS. Concurrency is covered by opposing physical scan plans and blocker observation; row updates remain transactional and preserve both visited timestamps; statement timeout is 8s and cleanup awaits started operations; ordered row locks add bounded serialization only around the stamp/update phase, after remote probes; Backend integration and all CI-ready aggregators are green.

No path in the reviewed change still acquires these visit row locks in a different order.

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.

1 participant