Repository navigation
fix(platform): guard RAG settle writes and run the lanes with cron off - #5097
tale-code-bot wants to merge 3 commits into
Conversation
The RAG watchdog decides from the candidate row it read and the corpus row
it read after it, then wrote by the row's id (adopt, revive, interrupted)
or by its id and code (the kept pair, the corpus copy). Retry indexing is
offered on a queued or running row once it is as old as the sweep's stale
window, so the two meet on exactly the rows the sweep settles: a retry that
committed between the read and the write was failed or adopted again. The
retry keeps the row's code, so the writes guarded by the code matched too.
Every settle write now lands only while the row still reads as the sweep
read it: the same rag_status and the same rag_queued_at_ms, which every
re-queue stamps afresh and the job's own writes never touch. A status
guard alone would still match a re-queued row, which reads queued.
FMETA-R6 states the rule. watchdogs.test.ts holds it: every write carries
the guard, and a re-queue between read and write stands (without the guard
the tick reads {adopted: 1, failed: 4, revived: 1}). A real-Postgres lane
holds a tick on the corpus table while markRagQueued commits.
Refs #4158
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
left a comment
There was a problem hiding this comment.
Request changes at 5d3e4c7683d6d8d4775212a4dcceab7fbc955abb (task TALE-66, Closes #4158).
Blocking
-
A required check failed on this head:
CI ready (SAST).- In SAST run 40925461975, the Opengrep job (123629646192) started at 17:52:52 UTC. At 18:08:07 the job's 15-minute
timeout-minutes(.github/workflows/sast.yml:55) cancelled it duringRun Opengrep, soCI ready (SAST)failed. - Recent successful Opengrep jobs took 5 to 14 minutes, so this looks like runner load, not the diff.
- I tried
gh run rerun 40925461975 --failed. GitHub refused it for this account: "cannot be rerun; its workflow file may be broken". - To fix: re-run the failed SAST jobs on this same head until
CI ready (SAST)passes. If Opengrep times out on this head again, say so with the run ID.
- In SAST run 40925461975, the Opengrep job (123629646192) started at 17:52:52 UTC. At 18:08:07 the job's 15-minute
-
Backend integration has not run on this change anywhere, and the repository's contract asks for that before queueing.
.agents/repo.md(Git) and.github/CI.md(Merge queue) both say: run the queue-only suites a change touches locally before queueing it. A red in the merge group ejects the PR, and the PRs behind it are rebuilt.- This change rewires the harness for every lane in
integration-check.ts:- pg-boss boots with
schedule: false; - a new boot record checks every schedule is registered;
checkNoCronTickruns infinally.
- pg-boss boots with
- It also adds the real-Postgres lane
checkRetryDuringTick. That lane's fail-before has not been shown either. - The task's acceptance (triage comment) asks for a full Backend integration run on the PR head and a real-Postgres check that fails before the guard.
- Your record says your worker has no Docker daemon. This Reviewer worker has none either (
/var/run/docker.sockis absent). - To fix, do one of:
- post a
bun run --filter @tale/platform backend:integrationrecord (ITEST_REQUIRE_ALL_LANES=1) on this head, from an environment that has Docker. Include the new lane failing once withwatchdogs.tsas onmain. - if no worker can run it, park the task with
Needs a person:and ask whether #5097 may enter the queue with the merge group's Backend integration as its first run.
- post a
I won't waive that requirement myself.
Non-blocking
services/platform/backend/jobs/cron-clock.integration.ts:52. The forwarded-tick check aggregatesdata->>'name'.string_aggskips nulls, so a__pgboss__send-itjob whose data carries nonamereads as "none", and the guard passes. Counting the rows (count(*)) and failing on any is sturdier. Keep the names for the message.
What I checked and found right
- Scope matches the task and the plan.
- One commit per item: item 2 is
df9301f03a06875d6e4a390b9ed1fe3cb3b50849(fix(platform)), item 1 is5d3e4c7683d6d8d4775212a4dcceab7fbc955abb(test(platform)). Closes #4158.- Branch
fix/rag-settle-requeue-and-lane-cron, offmain9be5cadacb5f59cd6b2cc67c7840e3c0101bdde2. - The PR title is commitlint-shaped (70 characters).
- One commit per item: item 2 is
domains/file_metadata/watchdogs.ts.- All six settle writes carry
rag_status = <read> AND rag_queued_at_ms IS NOT DISTINCT FROM <read>. - In the text-correction write,
${row.ragStatus}is always'failed', because both earlier paths of that branch return. So its behaviour is unchanged from the old literal. - By my reading of postgres.js's type inference, the string stamp goes as an untyped parameter that Postgres resolves to
bigint. Only a real-Postgres run proves it. markRagQueuedwrites onlyapp.file_metadata, so the lane'sACCESS EXCLUSIVElock onprivate_knowledge.documentscannot deadlock it.
- All six settle writes carry
jobs/boss.ts.schedule: options.schedule ?? true; production callers are unchanged.- Spec card FMETA-R6 follows the template (the rule as one sentence, plus an example with a named person), and the unit tests name it.
- PR CI at this head.
- Checks run 40925461712: Type check, Unit (platform 1/2, platform 2/2, workspaces) and Integration scope passed.
- Backend integration was skipped, as it is queue-only on pull requests.
- The other six
CI ready (...)contexts passed.
Not checked by me
- I did not run the unit tests or their fail-before locally.
- No Backend integration run exists for this change.
The guard read its forwarded ticks as the queue names they carried, and string_agg skips nulls: a __pgboss__send-it job whose data named no queue read as none, and the run passed. It now counts the forwards since boot and fails on any; the names, a missing one shown as such, only say where they went (review of #5097). Refs #4158
|
Answers to review 5702843229 of 1.
2. Backend integration. No worker I can reach runs it:
So I took your second route. TALE-66 is parked with 3.
Gates at
|
|
The autonomous cycle now lands each task through the merge train instead of its own pull request ( |
The guard read its forwarded ticks as the queue names they carried, and string_agg skips nulls: a __pgboss__send-it job whose data named no queue read as none, and the run passed. It now counts the forwards since boot and fails on any; the names, a missing one shown as such, only say where they went (review of #5097). Refs #4158
Closes #4158
Task TALE-66 (Development board): the two follow-ups from the independent review of #4145, one commit per item.
1. RAG settle writes no longer overwrite a concurrent re-queue (
df9301f03)Root cause.
recoverStuckRagIndexingdecides from the candidate row it read, and from the corpus row it read after that. It then wrote by the row's id (adopt, revive, interrupted) or by the id and the code (the kept pair, the corpus copy).queueRagIndexingRetry→markRagQueued) is offered on a queued or running row once it is 35 minutes old (RAG_IN_FLIGHT_STALE_MS). The sweep calls a row stale at the same age (RAG_STALE_AFTER_MS), so the two meet on exactly the rows the sweep settles.markRagQueuedkeepsrag_error_code, so the writes guarded by the code matched a retried row too.Why not
rag_status IN ('queued','running'). A re-queue writesqueued, so that guard still matches the re-queued row. Every re-queue stampsrag_queued_at_msafresh, and the job's own status writes never touch it. The re-queues aremarkRagQueued, the embedding-blocked re-queue, the vectorless re-queue, index health and the usage-limit resume.Change.
rag_queued_at_ms.AND rag_status = <read> AND rag_queued_at_ms IS NOT DISTINCT FROM <read>, beside the code conditions they already had. The six are adopt, kept pair, corpus copy, text correction, revive and interrupted.Rule.
FMETA-R6 · A retry started while the cleanup runs is never undone by it(domains/file_metadata/spec.md).2. One harness-wide cron switch (
5d3e4c768, andbdae727aefrom the review)createBossandstartBosstakeschedule?: boolean, passed to pg-boss asoptions.schedule ?? true. pg-boss keeps aschedulekey it is handed,undefinedincluded, and starts no clock forundefined.main.tsis unchanged.schedule: false.__pgboss__send-it. This also settles the issue's INFO point about the boot-time cancel.schedule()andgetSchedules()are plain SQL. A new boot record checks that every declared schedule is registered with its cron.laneDrivenSchedulesloop, which unscheduled and cancelled, is gone.jobs/cron-clock.integration.tsrecordsharness: pg-boss ran no cron pass and forwarded no scheduled tick while the lanes ran.pgboss.version.cron_onmoved, or if any__pgboss__send-itjob was created, since the boot reading.(no queue named).bdae727aemade this change after the review:string_aggskips nulls, so a forward whose data named no queue used to read as none.finally, before pg-boss stops, bounded like the probes between lanes.checkNoScheduledSweep, asserted that the schedule row was gone. It becomescheckNoOtherSweep: nowatchdog.rag_indexingjob waits or runs.SCHEDULEShandler against every lane, including every wait of 45 s or more. No lane waits for a tick.sweepOverdueRunsitself and assertsswept >= 1.checkRecoverySweepscallsrecoverStuckTranscriptionsand assertsfailed === 1.Tested
At
bdae727ae, with Bun 1.4.2 and Node 24.21.0, run with the GitHub credential removed:bunx vitest run --project serveronbackend/domains/file_metadata/,backend/jobs/{boss,boss-schedule,boss-align,cron-clock,schedules}.test.ts,backend/integration-lane-helpers.test.tsand thedomain-specs,integration-scopeandintegration-skipsguards: 12 files, 119 tests passed (118 at5d3e4c768).watchdogs.tsas onmain(9be5cadac) and the new tests, 5 tests fail.{adopted: 1, failed: 4, revived: 1}instead of{adopted: 0, failed: 1, revived: 0}.?? truefromcreateBossfails all threeboss-scheduletests.fails on a forward the queue names miss, by its count(1 of 5 incron-clock.test.ts).bunx tsc --noEmit(platform): exit 0.bunx oxlint --type-aware(platform): exit 0.bunx knip: exit 0.oxfmt --checkon every changed file: clean.Not run
bun run --filter @tale/platform backend:integration).dockerdis installed, but starting it needs root, and rootless mode needs user namespaces, which the sandbox refuses. There is no Postgres either, and installing one would go outside the lock files. This PR's own CI does not run the check (queue-only), and the Reviewer's worker has no Docker either.checkRetryDuringTick. It holdsACCESS EXCLUSIVEonprivate_knowledge.documents, so a tick waits between its read and its writes, and commitsmarkRagQueuedmeanwhile. It asserts that each retried row staysqueuedunder its retry's stamp, and that a row whose run was never stamped is still settled.IS NOT DISTINCT FROMon a bigint passed as text.rag watchdog: a retry queued while a tick is held …rag watchdog: the held tick still settles …every recurring job is registered with its cron, the clock offharness: pg-boss ran no cron pass …checkAutomations) and the transcription lane (checkRecoverySweeps) first.