Skip to content

test(platform): keep the RAG sweep's clock off the watchdog lanes - #4145

Merged
yannickmonney merged 1 commit into
mainfrom
test/rag-watchdog-lock-lane-ordering
Oct 3, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
test/rag-watchdog-lock-lane-ordering

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

What failed, and why

The RAG watchdog lock lane (rag watchdog: a row lock held past the settle lock timeout defers that row alone) read locked=failed (want running) with tick={"adopted":0,"failed":2,"revived":0} (#4113, run 37097165795, job 111129366409).

It is neither of the two readings in the issue:

  • Not (a), a settle failing a row whose lock it never got. The lane's own tick waited out its 2 s lock timeout and deferred the row. The log has exactly one lock-timeout line, for the lane's org (rag settle failed for file 8189aabd… in org itest-rag-lock-7effa7e9; deferring it: canceling statement due to lock timeout). The tick's failed: 2 is first + after.
  • Not (b), the lock holder missing. The tick came back after 2007 ms, which is the lock timeout: the holder was in place.
  • What happened instead: a second sweep. The harness boots pg-boss with every production schedule (registerSchedules) and switches off only automation.trigger_scan. watchdog.rag_indexing fires on 2-59/5, and its handler is in the task list the harness's worker runs.
    • Both CI sightings fall in that slot: 2026-10-03 04:42:26Z (run 37097165795) and 2026-10-02 10:37:27Z (run 36995996798, attempt 1; its re-run passed).
    • In both, a second [watchdog] rag reconcile: adopted 0, failed 2, revived 0 line follows the FAIL line. No lane prints it.
    • The scheduled tick read the lane's rows. They are queued before the epoch, so they lead every batch.
    • It queued its write behind the held row, within its own 2 s lock timeout. When the lane let go, it failed the row before the lane read it back.

Deterministic reproduction (local only, not committed)

Real Postgres 16 + pgvector, ITEST_LANES=checkRagWatchdogBatch, with barriers instead of sleeps. The patch is attached to TALE-494.

  1. The lane holds the row and its tick starts.
  2. Barrier 1: the tick is blocked on the holder's pid (pg_blocking_pids).
  3. The clock's slot is fired the way pg-boss's timekeeper fires it: one watchdog.rag_indexing job per schedule registered for that queue.
  4. Barrier 2: the scheduled tick is queued behind the same row.
  5. The lane then runs as written.
  6. Barrier 3: before the read-back, the scheduled job has completed.
tree outcome
main 5ee0436 + repro 6/6 FAIL, with the CI line verbatim (…after 2019 ms…, first=failed locked=failed (want running) after=failed, tick={"adopted":0,"failed":2,"revived":0}) and the scheduled tick's own rag reconcile: adopted 0, failed 2 line. While the lock is held, the locked row still reads running, and the only backend still waiting on it is the scheduled tick's.
this branch + repro 5/5 PASS. No schedule is left to fire, so the clock sends 0 jobs.
the lane change alone (harness change reverted) + repro 2/2 FAIL, on the new checks: schedules=1 (want 0) and still waiting on the lock=1 (want 0).

The change

  • integration-check.ts: the harness now switches off the watchdog.rag_indexing clock at boot, beside automation.trigger_scan, and cancels any tick already queued. The two are now one list.
  • watchdogs.integration.ts: the lane's ordering is explicit.
    • Precondition check: a first check reads that no watchdog.rag_indexing schedule and no queued or running tick of it are left. A clock that comes back fails by name, not as a row another sweep settled. This is the regression: it fails on main (schedules=1) and passes here.
    • Lock check: before letting go of the lock, the lock check reads that nothing still waits on the row once its tick is back. A write left behind the lock now fails the lane on every run, whether it is the tick's own (reading (a)) or another sweep's. Before, it failed the lane only when it beat the read-back.
  • No assertion is weakened and there is no retry. There is no product change, so no migration and no docs.

Verified

  • On this head, the lane and its neighbours (checkRecoverySweeps,checkRagStatusHintScope,checkRagWatchdogBatch,checkPolicySweeps) ran 10× locally: 10/10 green, 42/43 checks each. The one failure is knowledge BM25 indexes verified at boot, which fails on any host without pg_search; CI's tale-db has it.

  • tsc --noEmit scoped to the two files and everything they import: 0 errors.

  • oxlint --type-aware: 0 diagnostics. oxfmt: clean.

  • vitest: integration-scope.guard and integration-skips.guard pass, 9/9.

  • CI at this head (7c7de6c2c): 50 pass, 12 skipped by design, 0 fail. Backend integration passed 1504/1504 checks across 222/222 lanes (job 111226456099). The new check reads schedules=0 (want 0), queued or running ticks=0 (want 0). The lock lane reads still waiting on the lock=0 (want 0), locked=running.

Not in this PR

Other lanes are exposed to their own crons in the same way: watchdog.transcriptions, watchdog.erasures, governance.revoke_idle_sessions, watchdog.conversation_sends, watchdog.deferred_sends, watchdog.object_storage, watchdog.task_agents, tasks.repeat_on_due, websites.scan_due, and others. Each calls the sweep directly and asserts what its own call did. None has a known sighting, so they stay out of this fix. The survey is on TALE-494, and each one is a one-line addition to the new list if wanted.

Closes #4113

The lock lane's tick deferred the locked row as designed. The row was then
failed by a second sweep: the harness boots pg-boss with every schedule, and
`watchdog.rag_indexing` fires on 2-59/5. The CI failure is in the 04:42 slot.
The candidate read is global, and the lane's rows lead every batch, so that
tick queued its write behind the held row within its own two-second lock
timeout. It failed the row as soon as the lane let go, before the lane read
it back. Its own `rag reconcile: adopted 0, failed 2` line follows the FAIL
line in the job log.

The harness now takes that clock off at boot beside
`automation.trigger_scan`, and cancels a tick already queued. The RAG
watchdog lane reads that no schedule or tick of the sweep is left. The lock
check also reads, before letting go, that nothing still waits on the row
once its tick is back. That way a write left behind the lock fails every
run, not only when it wins the race against the read-back.

Closes #4113
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent review of PR #4145 at 7c7de6c2c14fdd2032b4e38c5d20c609c2629cdf: accepted.

Root cause: confirmed from source.

  • The harness boots pg-boss with the cron clock on (createBoss passes no schedule option) and registers every schedule.
  • watchdog.rag_indexing fires on 2-59/5, and the in-process worker runs it.
  • Its candidate read is global and led by the lane's rows. A tick that queued behind the held lock settled the row within its own 2 s timeout once the lane let go.
  • Both CI sightings (minutes 42 and 37) fall in that slot, and only rag_indexing among the file_metadata sweeps matches both.
  • No product bug is hidden. Two overlapping ticks are a legitimate production interleaving, and the code handles them: single-row transactions and SKIP LOCKED stamps. A second tick that fails a stale row is correct; the lane's locked=running only holds when its tick is the only sweep.

Runtime (mine; PG 16.14 + pgvector, no pg_search)

Tree checkRagWatchdogBatch
head 25/26. The new "no scheduled sweep runs beside the ticks these checks count" check passes (schedules=0), and so does the lock check.
main 5ee043679's harness, with the head's lane file 24/26. The new check fails (schedules=1). The lock check passed this time, as the flake is timing-dependent.
local composition: main 9fa2bf23e + #4144 + #4145 29/30 across the bell, RAG watchdog, collab and #4144 lanes.

The one failure in every run is BM25.

The lane changes only add checks: a new record, and waiting === '0' read through pg_blocking_pids. There is no retry, and no assertion is weakened.

Your point 4: I choose a follow-up, and don't extend the list here.

  • No other schedule has a sighting, and the exposures I found have millisecond windows:
    • automation.liveness, every minute, against the lane that seeds an overdue run and then sweeps (integration-check.ts:12662-12672,12830);
    • watchdog.transcriptions against its exact-count lane (:23367-23412).
  • Suggested follow-up: one harness-wide switch. Pass pg-boss schedule: false to the harness's boss through a new createBoss option. registerSchedules/getSchedules keep working, but no cron tick ever fires. It needs one full run to show no lane relies on a tick; automation.liveness is the one to watch.

INFO, not from this PR:

  • The settle writes match on id alone (watchdogs.ts:477,566,584-593). A markRagQueued that commits between the candidate read and the write gets overwritten to failed, until the job rewrites it. Guarding with AND rag_status IN ('queued','running') would close this.
  • The boot cancel doesn't cover pg-boss's internal cron forward. In practice that window is closed by the timekeeper's start order.

Whole-PR CI at the exact head (merge ref 613ad2e, onto 1ba77ed61)

  • Workflows: all five ran at attempt 1 and succeeded: Checks 37130230729, Build 37130230725, E2E 37130230683, SAST 37130230635 and Commitlint 37130230939.
  • Check runs: 50 success, 11 skipped by design and Trivy neutral.
  • Backend integration: 1504/1504 across 222/222 lanes.

Merge: squash with --match-head-commit through my gate, which dry-runs first.

@yannickmonney
yannickmonney merged commit 2409912 into main Oct 3, 2026
@yannickmonney
yannickmonney deleted the test/rag-watchdog-lock-lane-ordering branch October 3, 2026 17:18
tale-code-bot added a commit that referenced this pull request Oct 30, 2026
The harness unscheduled two recurring jobs at boot, automation.trigger_scan
and watchdog.rag_indexing (#4145); every other schedule kept ticking beside
lanes that assert exact state: automation.liveness every minute beside the
lane that seeds an overdue run and sweeps it, watchdog.transcriptions
beside its exact-count lane.

createBoss and startBoss take `schedule`, on unless a caller turns it off
(spelled out: pg-boss reads a `schedule` key it is handed as undefined as
off), and the harness starts pg-boss with it off. pg-boss then starts no
clock at all: no cron pass, no __pgboss__send-it forward, so no tick can be
queued before a worker starts. schedule() and getSchedules() stay plain
SQL: every declared schedule is registered and read back at boot. The
per-name list goes.

After the lanes, jobs/cron-clock.integration.ts fails the run if a cron
pass ran (pgboss.version.cron_on moved) or a tick was forwarded since boot.
The RAG lanes' first check now reads only that no sweep job waits or runs.
No lane waits for a tick: each drives its recurring job's work itself.

Refs #4158
tale-review-bot pushed a commit that referenced this pull request Oct 30, 2026
The RAG indexing watchdog read its stuck rows, then settled each one by
id alone. A Retry that queued a row again between that read and the
write was overwritten with the sweep's verdict, mostly failed, until its
job rewrote the row. Each of the sweep's six settle writes now also
matches the status and the queue stamp (rag_queued_at_ms) it read, with
IS NOT DISTINCT FROM for a run never stamped. A row queued again in the
meantime keeps its new state, and the sweep counts only the writes that
landed. Matching the status alone would still undo a Retry of a stale
queued row, which stays queued; every re-queue stamps rag_queued_at_ms
afresh, and no job write touches it. FMETA-R6 states the rule. Unit
tests hold each write's guard and the race, and a real-Postgres lane
holds a sweep between its read and its writes, queues four of its rows
again, and reads them back queued under the Retry's stamp, while a row
nobody queued again still settles.

The Backend integration harness ran pg-boss with its cron clock on and
unscheduled only automation.trigger_scan and watchdog.rag_indexing
(#4145). Every other recurring job still ticked beside the lanes that
drive its work and assert exact state: automation.liveness beside the
overdue-run sweep, watchdog.transcriptions beside its exact count.
createBoss and startBoss now take schedule, on unless a caller turns it
off (main.ts is unchanged), and the harness boots with it off. Every
schedule is still registered and checked against SCHEDULES, none ticks,
and the per-name list goes. After the lanes, a guard fails the run if
pg-boss ran a cron pass or forwarded a tick since boot.

Closes #4158
Task: TALE-66
tale-code-bot added a commit that referenced this pull request Oct 31, 2026
The RAG indexing watchdog read its stuck rows, then settled each one by
id alone. A Retry that queued a row again between that read and the
write was overwritten with the sweep's verdict, mostly failed, until its
job rewrote the row. Each of the sweep's six settle writes now also
matches the status and the queue stamp (rag_queued_at_ms) it read, with
IS NOT DISTINCT FROM for a run never stamped. A row queued again in the
meantime keeps its new state, and the sweep counts only the writes that
landed. Matching the status alone would still undo a Retry of a stale
queued row, which stays queued; every re-queue stamps rag_queued_at_ms
afresh, and no job write touches it. FMETA-R6 states the rule. Unit
tests hold each write's guard and the race, and a real-Postgres lane
holds a sweep between its read and its writes, queues four of its rows
again, and reads them back queued under the Retry's stamp, while a row
nobody queued again still settles.

The Backend integration harness ran pg-boss with its cron clock on and
unscheduled only automation.trigger_scan and watchdog.rag_indexing
(#4145). Every other recurring job still ticked beside the lanes that
drive its work and assert exact state: automation.liveness beside the
overdue-run sweep, watchdog.transcriptions beside its exact count.
createBoss and startBoss now take schedule, on unless a caller turns it
off (main.ts is unchanged), and the harness boots with it off. Every
schedule is still registered and checked against SCHEDULES, none ticks,
and the per-name list goes. After the lanes, a guard fails the run if
pg-boss ran a cron pass or forwarded a tick since boot.

Closes #4158
Task: TALE-66
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.

test(platform): the RAG watchdog lock-timeout lane sometimes fails the locked row instead of deferring it

1 participant