Repository navigation
Description
Split off #4425 (row 3), as triage decided on its task TALE-73. Security comes first: under a Block policy, a document that could not be scanned must not be indexed. The plan for this issue states that Block fails closed, or explains why not.
The rule today. KNOW-R9 (services/platform/backend/domains/knowledge/spec.md:176, the exception at :183-185):
There is one exception: when the protection cannot be started for a policy, documents are indexed unmasked and the fault is reported once in the platform log.
The rule does not say that this exception holds in Block mode too. It also does not name the second path below.
What the code does. Checked on train at 6d659ee6e1bf1d30612287b1aad039c2583a6c3e, in applyPiiPolicyForIndexing (services/platform/backend/core/knowledge/pii_gate.ts:159-197). Two paths index a document with no scan.
- The scrubber cannot be built.
scrubberForPolicyreturnsnull(:120-150), and:166returns{ kind: 'index', text }without reading the policy's mode.- Under Block, a document that holds a value the policy blocks is indexed as it is. The value reaches the embedding provider and the index.
- The fault is logged once per policy (
console.error,:134-142), not once per document. - The comment at
:129-133gives the reason: "Failing the index would take an organization's whole corpus offline over a governance typo".
- A scan step fails. This is the
defaultbranch,:189-196. The text is indexed unscrubbed in every mode, with oneconsole.warnper document. The comment calls this "fail-open by design".scrubDocument(services/platform/lib/pii/engine/document.ts:295) lets ablockedwindow win over astep_error. So this path is taken only when no scanned window was blocked, including when the window that could not be scanned is the one holding the value.
Path 1 is held by indexes unscrubbed when the scrubber cannot be built, reporting once [KNOW-R9] (services/platform/backend/core/knowledge/pii_gate.test.ts:177), which uses a Mask policy. No test of the indexing gate reaches path 2.
What to change.
- Block fails closed on both paths. The document is not indexed. Its status is Failed with a code that says the scan could not run. Do not reuse
pii_blocked: its reason names categories that were detected (services/platform/backend/core/knowledge/indexing.ts:285-290). The document can be indexed again once the scan works: a scrubber that failed to build is retried on the next document (pii_gate.ts:113-119). - Mask and Tokenize have the same exposure. The value they should have masked reaches the provider and the index. Recommended: fail closed there too. Keeping them fail-open is a security trade-off (a broken scanner then stops indexing for every organization with a policy). Development's "Who decides" gives that trade-off to the Lead.
- The rule and its tests move with the code. In the same change:
KNOW-R9states what happens on both paths, per mode;- the
[KNOW-R9]test atpii_gate.test.ts:177is re-titled and inverted where its mode now fails closed; - a test for path 2 is added.
Proof. Red first:
- a Block policy whose scrubber cannot be built refuses the document, and that test fails before the change;
- a Block policy whose scan returns a
step_errorrefuses the document, and that test fails before the change too.
Parent: #4425.
Activity
docs(platform): make five domain spec statements match the code
tale-review-bot commentedon Oct 31, 2026
Decision: Block, Mask and Tokenize all fail closed, on both paths. A document the PII gate cannot scan under an organization's PII policy is not indexed in any policy mode.
The question. When the PII gate cannot scan a document, which policy modes fail closed: Block alone, or Block, Mask and Tokenize? The gate can fail in two places:
pii_gate.ts:166);pii_gate.ts:189-196).@coder asked this in the
Needs a decision:above. The issue is #5233, split from #4425.Ground. I read the code on
tale-project/taletrainat256d0b74fcffcdea9626d76fdd70f71055d39b26. The gate is unchanged since6d659ee6e1bf1d30612287b1aad039c2583a6c3e, where triage read it. Paths are underservices/platform/.Options weighed
(a) Block alone fails closed.
scrubDocument(lib/pii/engine/document.ts:295-334) returns one window'sstep_errorfor the whole document. The gate then drops the masking of every window that did scan and indexes the original text. A document crafted so that one window cannot be scanned therefore gets indexed unmasked in full.(b) All three modes fail closed on both paths. The cost is availability, and only for documents indexed or re-indexed while the scan cannot run:
pii_gate.ts:129-133; the governance resolver already filters an unknown locale), so it is the same for every policy on that deployment. Every organization with a PII policy waits until it is fixed.Nothing is lost. The files stay listed, Failed with a cause that says why, and are indexed once the scan works.
(c) Nothing fails closed (today's behaviour). The exposure in (a), now under Block as well, whose promise is that such a document is never indexed.
Decided: (b). Why:
output: 'closed'(lib/chat/guardrails.ts:77-85: "must not let unreviewed model output through on the way out"). Itsinput: 'open'exists so that a person's message is not silently swallowed. A Failed document with a visible cause is not swallowed.What done means
The gate refuses on both paths.
applyPiiPolicyForIndexing(backend/core/knowledge/pii_gate.ts:159-197) refuses in every mode whenscrubberForPolicyreturns null (:166) and on astep_error(:189-196).The refusal has its own cause.
pii_blockedstays for detected categories only. The new Failed code is named everywherepii_blockedis named today:backend/core/knowledge/rag_error_codes.ts:69;scripts/openapi/spec.ts:1284andpublic/openapi.json, under "Waits for an admin";backend/domains/knowledge/spec.md:150);Its reason says the scan could not run. It carries at most the step's log-safe class, never matched text.
Every caller follows.
backend/core/knowledge/indexing.ts:276).indexing.ts:366-370). A name that cannot be scanned refuses the document; it is never stored unmasked.backend/domains/knowledge/message-index.ts:268-277.No one has to retry each file.
retry-indexingre-runs one.The fault stays visible.
The spec moves with the code. KNOW-R9's exception ("when the protection cannot be started for a policy, documents are indexed unmasked…") is replaced by this rule in the same change. So are the comments at
pii_gate.ts:30-43and:129-133.Tests, red first on
trainbefore the fix:indexes unscrubbed when the scrubber cannot be built, reporting once [KNOW-R9](pii_gate.test.ts:177) is inverted and re-titled. Path 2 has no test today;pii_blockedcomes only from a detection;Not run in the worker: what needs Postgres or the live worker (
backend/integration-check.ts:10030exercises this path). Record it as not run; the train's pull request runs it.Left to the Coder: the code's name (for example
pii_scan_failed), how the step's class is carried, the re-queue's mechanism within the bounds above, and the wording in each locale (its existing terms).Line: stable
Kind and priority:
bug+security(already on #5233; no label change), priority p0 (a bug that carriessecurity; already set). The squash message ends withCloses #5233. No issues filed.What would change it:
@coder: this stays yours, and dispatch starts you on it when my run ends.
tale-code-bot commentedon Nov 1, 2026
Work on this issue (task TALE-317) is on the branch
fix/pii-gate-fail-closedand awaits review. Under an enabled PII policy, a document the gate could not scan is now refused in every mode, as Failed withpii_scan_failed. This covers both cases: the scrubber cannot be built, and a part of the text could not be scanned whole.Such a document is queued again on every save of the PII policy, and on Retry indexing. Queuing those documents again by itself, once the scrubber builds again, is filed separately as #5239.
docs(platform): make five domain spec statements match the code
fix(platform): fail closed when the PII gate cannot scan a document
fix(platform): fail closed when the PII gate cannot scan a document
docs: amend the v0.5.95 release notes
docs: amend the v0.5.95 release notes