Repository navigation
fix(platform): close the RAG watchdog review round after #3782 - #3803
Merged
Merged
Conversation
The RAG watchdog rewrote a failed row whose corpus row held the same error on every tick. Each rewrite moved status_changed_at_ms, the clock of the failed window, so the row never left the window, and its document lists refetched every five minutes. The candidate read ranked those rows with the stuck ones by queue time alone, so two hundred of them filled the batch and a row that got stuck after them was never reached. A failed row that already reads its corpus row's error is now left as it is, with no write and no hint. Another corpus error is written in place without moving the status clock, and a corpus row that failed without an error leaves the row its own. Stuck rows are read ahead of every failed row, as the 0.4 sweep read them.
The app pool sets no lock timeout, so a settle write whose row another transaction held waited as long as that transaction ran. The per-row isolation only ever saw writes that threw, so the whole tick stalled behind the lock, and every organization after it went unswept until pg-boss expired the job at 600 s. Each settle write (adopt, corpus failure, text correction, revival, interrupted run) now runs in a transaction of its own under SET LOCAL lock_timeout = '2s'. A row held past that throws lock_not_available, which defers that row alone to the next tick. The rest of the pool keeps its waits.
isRagIndexableFile and shouldRagIndexOnUpload fell back to the content type's extension when a file name had none, a relic of an upload helper that appended one before the old RAG service saw the file. The indexer decides by the name alone, so an extension-less README stored as text/plain was queued by the register door, a replacement, the sync scheduler and the chat backstop, and promised by the dialogs and the composer, and its run then ended unsupported_type. Both gates now read the extension the way the indexer's router does, Node's extname rule: no content-type fallback, and a dotfile such as .md has none. isRagIndexableFile loses its unused content-type parameter, and the sync scheduler no longer reads content_type. A parity test runs names and types through both gates and unsupportedByName, and every extension either side lists.
The scheduler reads a synced document's file_ref and nothing else, and decides on the stored file's name. The test still answered the document read with a title and a mime type, and took the stored file's name and type from them by default, so most cases set the stored file only through a document title the code never reads. The fake now takes the stored file directly and answers the document read with the blob reference alone. One case pins the columns each read selects, so the fake cannot drift from the reads again. The retitled and reverse cases, which could no longer inject a title, become cases on the stored name, and an extension-less stored name joins the terminal lane.
yannickmonney
added a commit
that referenced
this pull request
Sep 29, 2026
This was referenced Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #3782 (TALE-92), from its review. I re-checked every item on current
mainbefore changing it. The Convex original of the watchdog (convex/file_metadata/rag_watchdog.tsat 94135ac) had both the same-error skip and a stuck-rows-first read. The Postgres port (fd5c009) dropped both.What changed
1. Settled failures no longer starve stuck rows (
file_metadata/watchdogs.ts, medium)failed, the corpus-failure branch rewrote the row every tick. Each rewrite movedstatus_changed_at_ms, which is also the clock of the 48 h failed window, so a job-failed row never left the window, and its document lists refetched every five minutes. The candidate read ranked those rows with the stuck ones by queue time alone underLIMIT 200.rag_error. A failed row that already reads its corpus row's error returnsnull: no write, no hint, not counted.UPDATE … SET rag_errorfixes it, guarded byAND rag_status = 'failed'(a retry may have re-queued the row since the read). It leavesstatus_changed_at_msalone. It is still hinted and not counted.failedwith a NULL error on the corpus row, while the file row carries the refusal's sentence. Main (and the brief'sstatus.error ?? RAG_INTERRUPTED_MESSAGE) would overwrite that sentence with the generic "interrupted, use Retry indexing" text. That breaks the module's own rule that an already-failed row keeps its real error. Such a row now keeps its own error. Only a failed row with no error at all gets the generic text.ORDER BY (rag_status = 'failed'), coalesce(rag_queued_at_ms, created_at_ms), so stuck rows come first, as 0.4 read them.2. A held row lock no longer stalls the tick (
file_metadata/watchdogs.ts, low)settleWrite: its ownsql.beginwithSET LOCAL lock_timeout = '2s'. This follows therest/project-scope-check.tsprecedent and leavescreateSqluntouched.lock_not_availableinto fix(platform): re-queue renamed synced files and isolate watchdog faults #3782's per-row isolation, so only that row is deferred.3. The sync scheduling test feeds only what the scheduler reads (
onedrive/service.rag-scheduling.test.ts, low)fakeSqltakes the stored file directly and answers the document read with[{ fileRef }]only.README) is added and goes to the terminal lane.4. One rule for a name without an extension: option (a), name-only (
lib/shared/file-types.ts, low)isRagIndexableFileandshouldRagIndexOnUploadnow read the extension the way the indexer's router does (Node'sextname). There is no MIME fallback, and a dotfile such as.mdhas no extension either:extractExtension('.md')ismd, butextname('.md')is''.markRagUnsupportedIfNoExtractor, therag_fetchmiss and data migrations 0128/0129 already decide by name. The fallback's justification (ensureExtension) no longer exists. The Documents upload allowlist (isAllowedDocumentUpload) already refuses an extension-less name.unsupported_typebefore and still does. It just gets there without a job, and without the dialogs or composer promising an index first.isRagIndexableFileloses its unused content-type parameter; the call sites are the two dialogs,replacement.tsand the sync scheduler. The sync scheduler no longer readscontent_type.backend/core/knowledge/rag_unsupported.test.tsruns both gates againstunsupportedByName: a table of (name, type) pairs that includes the four named in the brief, plus every extension either list knows. That last check also enforces the "MUST stay in sync" comment onRAG_INDEXABLE_EXTENSIONS.Other changes:
tests/manual/reference/automation.mdrows 155–157 are updated. The new lanebackend/domains/file_metadata/watchdogs.integration.ts(checkRagWatchdogBatch) is registered inbackend/integration-check.ts.How I verified it
watchdogs.test.tshas 22 cases. The 6 new ones fail on main'swatchdogs.tsand pass here. The fake gainedbegin(statements carry their transaction) and now answers only the columns the candidate read selects.SET LOCAL,SETon the pool, not selectingrag_error, counting the text fix, and adopt or revive bypassingsettleWrite.extractExtension's dotfile rule, and a leading-dot slip. A scheduler mutation re-addingtitle, mime_typeto the document read is killed.--project serveroverdocuments/replacement*,files/,knowledge/,onedrive/,google_drive/,file_metadata/,core/knowledge/, the extraction router,lib/shared/anddb/data-migrations: 119 files, 1729 tests, all passed.--project clientover both dialogs,shared/files/and the chat hooks: 15 files, 166 tests, all passed.backend:integration, a filtered run on a local PG 16 + pgvector + pg_search cluster with moto; not a CI job):checkFiles,checkDocuments,checkOneDriveSync,checkRecoverySweeps,checkRagStatusHintScope,checkRagWatchdogBatch: 81/82. The one failure isfiles upload/serve/delete … blobGone=false: moto keeps the deleted blob. That check fails on every local moto run, and nothing here touches blob deletion.runningrow: the row is failed in one tick;FOR UPDATEheld on the middle of three rows: the tick returns after 2015 ms, first and last rows failed, the held row stillrunning.watchdogs.tsfailed 4/4:runningafter a tick;tscover every changed file andintegration-check.tspassed.oxlint --type-awareon each changed file andoxfmt --checkare clean. The workspace-wide gates are left to CI.Left open
.md) that the upload allowlist admits now shows the dialog's "stored but not indexed (legacy format)" hint. "Not indexed" is correct, since the indexer refuses it. "(legacy format)" is not a fitting reason, but that is an odd edge and I left the message alone.