Repository navigation
fix(platform): close the #3803 and #3808 review findings - #3931
Merged
Merged
Conversation
The RAG watchdog wrote rag_error without rag_error_code. A retried row keeps its previous failure's sentence and code while queued (markRagQueued leaves both until the job's first write), so a lost retry of a file that had failed for want of an embedding model settled as "interrupted" under the code embedding_not_configured: the failed dialog showed the Settings deep link beneath the interrupted sentence, and REST's indexing.errorCode disagreed with indexing.error. - Every failure the sweep writes (the corpus's error or the interrupted text) clears rag_error_code in the same statement. The sweep classifies nothing, and indexer_error would promise a retry no job will run. - A failed row that carries a code is the app's classified pair and is left alone whatever the corpus copy says; that copy is best-effort and can be an earlier attempt's sentence. The text correction of a codeless row also clears the code and is guarded by rag_error_code IS NULL. - The failed tier is read in rotation. Migration 0138 adds rag_reconciled_at_ms; each tick stamps the failed candidates it read (FOR NO KEY UPDATE SKIP LOCKED, best-effort, no status clock, no hint) and reads never-stamped rows first, then the stalest stamp. Ranked by queue time, the same oldest settled failures filled every batch until they left the 48 h window, and a false failure queued after them was never reached. - The REST contract and the API reference (EN/DE/FR) say what a failed row without an errorCode means: a run the platform settled after its job stopped, which nothing retries by itself. Descriptions only; the contract fingerprint does not move. Refs #3803
A file named `.md` or `.pdf` passes the Documents upload allowlist, which
reads the dotfile's name as its extension, but the indexer reads no
extension from it (Node's extname), so the upload and replace dialogs
showed "not indexed for search (legacy format)" — true that it is not
indexed, false that the format is legacy.
- file-types.ts exports hasIndexedExtension, the indexer's own reading
of a name; a name ending in its dot (`notes.`) has none either now,
which changes no caller's answer.
- UploadFileRow picks upload.storedButNotIndexedNoExtension ("the file
name is only an extension", EN/DE/FR) for such a name and keeps the
legacy-format hint for a format no extractor reads.
The upload itself is unchanged: the file is stored and downloadable, as
before, and the allowlist still admits it.
Refs #3803
subtreeDocumentFolderPaths feeds syncRagFolderSubtree on a folder rename or move, and reads each shared ref's holder alone (NOT EXISTS over a lower-id active document), as the other scope writers do. No CI-run test covered that clause: removing it kept every unit test green, and only the checkScopeRefHolder lane, which no workflow runs, noticed. scope-reconcile.test.ts now drives syncRagFolderSubtree over a fake whose subtree read answers the twin only when the statement lacks the clause: two twins under the renamed folder write the holder's path alone, a twin whose holder sits outside it writes nothing, and a rename of the holder's own folder writes its path. The real folderTreePaths runs inside paths.ts against the same fake. Refs #3808
A shared ref's corpus row carries its holder's scope: the lowest-id
active document holding it. A write that moves the holder without editing
any scope re-stamped nothing, so the row kept the old holder's scope until
the nightly scope pass rewrote it (and counted it as a failed sync), and a
scope-filtered search from the new holder's team or folder missed it.
- knowledge/service.ts: syncRagRefHolderScopes(sql, orgId, refs) reads
each ref's holder with the clause every scope writer uses and writes its
scope; a ref no active document holds is left to the release seam, or
to its trashed document. Best-effort, after commit, like the per-edit
syncs. The batch writers (the reconcile page, syncRagDocumentScopes and
the new helper) now share one corpus write, writeScopeStamps.
- Called after the commit of every write that moves a holder here:
- the WebDAV COPY of a document or a folder, a DELETE of either (a
folder cascade, and a destination a MOVE or COPY overwrote, too), and
a PUT that moved a document off its old bytes (handlers.ts collects
the refs through the transaction);
- a restore from the governance Trash (syncRagDocumentScope of the
restored document);
- purgeDocument, the funnel of every hard delete (user and REST delete,
folder cascade, retention sweep, erasure, sync prune);
- a cloud sync update that replaced a document's bytes, and a
knowledge-entry delete: their old ref, a twin may still hold it.
- scope-holder.integration.ts proves it on real Postgres: the helper after
each holder move, the real purgeDocument, and the real WebDAV COPY and
DELETE handlers.
Left to the nightly pass (named in the PR): a controlled-record
replacement, a knowledge-entry version and an agent rewrite moving off a
shared ref, a twin bound through the upload or workflow doors, a
retention expiry flip and a project delete cascade.
Refs #3808
warnReleaseFailures logged a release's corpus-stage failures and skipped its blob-stage ones, which requeueBlobFailures logged and re-queued to knowledge.release_refs. Every caller had to pipe the outcome through both: all three did, but one that used the first alone would have dropped a failed byte delete without a log line or a re-queue. settleReleaseOutcome(sql, organizationId, outcome) does both, in the same order and with the same lines, and every release of the reconcile goes through it: the blob walk, the stamp pass's corpus-only first walk (whose blob branch queues nothing) and its second walk. No behaviour change. Refs #3808
The nightly scope pass warned "the per-edit sync had failed for these" for every row it corrected. Two causes correct rows with no failed sync: a shared ref's holder that changed on a lane that does not re-stamp it, and, once after the upgrade that makes every scope writer write the holder (#3808), the rows older releases stamped from a copy of the ref. The first night after that upgrade reported a burst of failures that never happened. The line now names both causes and the one-off burst, and the comment beside it says why. Refs #3808
- not-a-finding.md: BL-7, the known search gap of a file two documents share. It has one index row, stamped with its holder's scope, so a search scoped to a team or folder where only the other copy sits does not find it; the trigger to pay it off, and the one drift count a COPY that becomes the holder costs on a lane that does not re-stamp. - automation.md: the RAG watchdog row names the failed-row rotation and the error codes it writes; the knowledge row names a code-less watchdog failure, the holder re-stamps after a write that moves the holder, and links BL-7. - MIGRATION.md: the watchdog row and the knowledge row say the same, including the one-off drift burst the first night after the release that ships #3808. Refs #3803, #3808
An adversarial review of this branch found: - A lost retry usually meets a failed corpus row: recordIndexingFailure upserts it with the same sentence. Writing that copy with no code dropped the Settings link and the embedding save's re-queue, which is scoped by the code. A row that carries a code now fails with its own pair, guarded by that code; a row without one takes the corpus copy with none, guarded by rag_error_code IS NULL. A lost retry whose corpus row recorded nothing still settles as interrupted, without the code. - Never-read rows first let a burst of fresh failures starve the rows read before it. The failed tier now reads the row read longest ago first, a row not read yet counting as read when its run was queued: coalesce(rag_reconciled_at_ms, rag_queued_at_ms, created_at_ms). - The stamp could hold the lock of a file parked by a bad search index while index health re-queues it under SKIP LOCKED and stops at a short batch, leaving it parked. Parked files (INDEX_PARKED_RAG_ERROR_CODES, now shared with index-health.ts) are left out of the sweep. - A failed row without an errorCode is described as a failure settled without a classified cause, usually a run that stopped (spec, openapi.json, API reference EN/DE/FR). - The drift warning names an edit whose sync writes less than the whole scope (a WebDAV folder MOVE into a team folder re-stamps paths alone) and no longer repeats the one-off upgrade note every night; MIGRATION.md keeps it. - BL-7 says who misses a shared file (a member outside the holder's team, in every search) and names a first pay-down step; automation.md and MIGRATION.md follow the rules above and cite the upload hint's test. The unit tests cover the kept pair on a same-sentence and an older corpus copy, the codeless copy, the parked exclusion and the ordering; the restore test proves the re-stamp runs after commit; the holder fake reads the NOT EXISTS literally; the lanes gain the realistic fixture, a codeless row and a parked row. Refs #3803, #3808
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 #3803 (TALE-102) and #3808 (TALE-103), from their reviews. I re-checked each item on current
mainbefore changing it.The branch has one commit per item or pair of items, and one commit for the registers. The last commit settles the findings of an independent read-only review of the first seven. The PR squash-merges, so the list below describes the final state.
What changed
1. The watchdog keeps an error code with its text (
file_metadata/watchdogs.ts, medium)markRagQueuedkeeps a retried row's oldrag_errorandrag_error_codewhile it waits. The watchdog used to writerag_erroron its own, so a lost retry could settle under the previous failure's code. The failed dialog then showed the Settings → Data residency link under the wrong sentence, and REST'sindexing.errorCodedisagreed withindexing.error.rag_error_code = NULLin the same statement. That covers two writes:embedding_not_configuredis not kept;AND rag_error_code IS NULL.AND rag_error_code = <its code>.recordIndexingFailureupserts the corpus row with the same sentence, so this is the usual shape of a lost retry. Writing that copy without a code dropped the Settings link, and the embedding save's re-queue (scoped by the code) stopped picking the file up. The review caught this.failedrow without anerrorCode: the platform settled it without a classified cause, usually because a run stopped; request aretry-indexing. This is in theindexingschema ofscripts/openapi/spec.tsandpublic/openapi.json, and in a new row of the API reference's error-code table (EN/DE/FR). Only descriptions changed, so the contract fingerprint does not move.2. Settled failures no longer take every slot of a watchdog batch (
watchdogs.ts, migration0138, low)0138_file_metadata_rag_reconciled.sqladds a nullablerag_reconciled_at_ms, with no index and no backfill. The previous image never reads it. I renumbered it from 0135 after main took 0135–0137; no open PR claims 0138.FOR NO KEY UPDATE SKIP LOCKED,AND rag_status = 'failed', best-effort. It moves nostatus_changed_at_ms(the clock of the 48 h window) and emits no hint.coalesce(rag_reconciled_at_ms, rag_queued_at_ms, created_at_ms). A row not read yet counts as read when its run was queued, so a row is read again once every row read or queued before it has had its turn, however many fail meanwhile.rag_reconciled_at_ms NULLS FIRST: the review showed that a burst of fresh failures would starve the older rows.index_rebuilding,index_repair_failed) is left out of the sweep. Index health re-queues it underSKIP LOCKEDand stops at a short batch, so a stamp holding the row's lock would leave the file parked. The two codes are now one list inrag_error_codes.ts, shared withindex-health.ts.3. The upload dialogs give the right reason for
.md(lib/shared/file-types.ts,upload-file-row.tsx, low). I chose option (b).hasIndexedExtensionreads a name the way the indexer does. A name that ends in its dot (notes.) now has no extension either; that changes no caller's answer.UploadFileRowshowsupload.storedButNotIndexedNoExtensionfor a name that is only an extension: "Stored and downloadable, but not indexed for search: the file name is only an extension." (EN/DE/FR). It keeps the legacy-format hint for a format no extractor reads..mdwith the allowlist's "Unsupported file type. Supported extensions: …, md, …", which is wrong for that name too.5. A CI-run test pins the holder clause of the folder subtree re-stamp (
knowledge/scope-reconcile.test.ts, low)syncRagFolderSubtreeover a fake whose subtree read returns the twin only when the statement lacksNOT EXISTS … o.id < d.id. The realfolderTreePathsruns insidepaths.tsagainst the same fake.6. A write that moves a shared ref's holder re-stamps its corpus row (
knowledge/service.ts, low)syncRagRefHolderScopes(sql, organizationId, refs)reads each ref's holder with the clause every scope writer uses, and writes that scope. A ref that no active document holds is left to the release seam, or to its trashed document. The call is best-effort and runs after commit.writeScopeStamps).handlers.tscollects the refs through the transaction, and re-stamps nothing for a rolled-back one).purgeDocument, the funnel of every hard delete.7. The drift log stops blaming a failed sync for every row (
knowledge/release.ts, low)MIGRATION.md's knowledge row records the one-off burst on the first night after the release that ships fix(platform): close the #3785 mail stamp pass review findings #3808 (not in v0.5.63). The log line would repeat it every night, so it stays out of the line.8. One settle step for a reconcile release (
release.ts, low)settleReleaseOutcomereplaceswarnReleaseFailuresandrequeueBlobFailures: the same lines, in the same order.releaseCorpusRefsthe blob branch queues nothing.9. The shared-ref search gap is on record (
tests/manual/reference/not-a-finding.md, low)BL-7says which member misses a shared file: one outside the holder's team finds it in no search, even with access to the copy, and a search scoped to the copy's folder or team misses it. It also records that a COPY into a team folder can narrow the original to that team, and that it costs one drift count on a lane that does not re-stamp.automation.mdlinks it. I did not file a tracking issue.How I verified it
Unit tests (CI runs these). They fail against the old sources.
watchdogs.test.tshas 32 cases. They cover code pairing (interrupted text, corpus copy, kept pair with the same or an older sentence, codeless copy, the correction guard), rotation (stamp, ordering, parked exclusion) and the existing lock and fault cases.scope-reconcile.test.ts: the subtree holder clause andsyncRagRefHolderScopes(the fake reads itsNOT EXISTSliterally).webdav/handlers.holder-scope.test.ts(COPY, DELETE, MOVE and PUT, each after commit and never after a rollback) andretention/purge-document.test.ts.governance/routes.test.ts, which proves the call runs after commit.onedrive/service.import-deps.test.ts,knowledge_entries/service.delete.test.tsandrelease.reconcile.test.ts(settle step, drift line).file-types.test.tsandupload-file-row.test.tsx(.md).Mutation checks: 26 mutations, all killed, each by the test named for it. They cover:
rag_error_codeclause, the kept-pair branch, the correction guard, the parked exclusion, the rotation order, the stamp (removed, or stamping stuck rows);hasIndexedExtension, and the row's key.Related suites (server and client,
--maxWorkers=1), all passed:onedrive,knowledge_entries,retention,governance,webdav,knowledge,file_metadata,documents,erasure,backend/jobs,core/knowledge,lib/shared, RESTv1-core/v1-projectsand both document dialogs: 163 files, 2,372 tests;file_metadata,knowledge, governance routes,scripts/openapiandbackend/db: 34 files, 677 tests;backend/db, 7 files and 325 tests.subaddress.test.ts, came from four agents sharing the host; that file passes on its own.services/docslocale and structure tests: 8 files and 41 tests passed.bun run lint:manualis green.Real Postgres 16 with pgvector (no ParadeDB),
ITEST_LANES=checkRagWatchdogBatch,checkScopeRefHolder, on this branch rebased on main. CI does not run this suite.pg_search.0138; the column is nullablebigint.embedding_not_configuredpair;purgeDocumenteach re-stamp from the new holder;watchdogs.ts,handlers.tsandretention/service.ts: 24/31. The six new checks fail:embedding_not_configuredunder the interrupted text;Review. An independent read-only review of the first seven commits confirmed:
activeDocumentHoldingRef;rag_errorwithout its code.Its findings are settled in the last commit: the kept pair, the fair order, the parked exclusion, wording, BL-7 and two test fakes. The migration renumber was done in the rebase.
Lint, types, format.
oxlint --type-aware --type-checkon every changed TypeScript file: clean.oxfmtapplied.public/openapi.jsonwas regenerated;spec.test.tspasses.Left open
Item 4:
backend:integrationin CI. I did not add the job: CI workflows are infrastructure, outside what this task may change. It also needs decisions I cannot make here:pg_search: on plainpostgres:16the knowledge schema fails, and withoutpg_searchthe boot BM25 check fails;Until then, the real-Postgres proofs of this PR run only locally:
checkRagWatchdogBatch(the rotation's effect on a real batch, the codes on real rows) andcheckScopeRefHolder(holder moves, WebDAV COPY and DELETE). The CI-run unit tests carry each item, but for item 2 they pin the statement rather than its effect.Lanes that move a holder but still leave the row to the nightly pass. The drift line names this cause:
documents/replacement.ts);knowledge_entriesattachEntryDocument);document.createdoor (documents/agent-write.ts);createDocumentFromUpload). Its queued index run heals it, unlessskipRagIndexingis set;sweepDocuments) and a project delete cascade (deleteProject).Pre-existing, found in review, not changed here:
team_tags, but only their folder path in the corpus (syncRagFolderSubtree), until the nightly pass. The drift line andMIGRATION.mdname it.erroranderrorCode(indexingStateFrom).updated_atwithrag_queued_at_mscould settle it as interrupted instead. I did not, because it compares the clocks of two databases.BL-7: no tracking issue filed. Its pay-off trigger names the cheapest first step: a holder order that a copy cannot win.
Refs #3803, #3808