@happyvertical/smrt-ingestion 0.60.5 → 0.60.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.js CHANGED
@@ -1,8 +1,8 @@
1
- import { C as storedFailureCapture, D as generationSnapshotRead, O as listReadGate, T as completeWithFailureCapture, _ as HandlerArgumentsInvalidError, b as FAILURE_CAPTURE_MAX_BYTES, c as HANDLER_ARGUMENT_ISSUE_LIMIT, g as GenerationSourceStaleError, h as GenerationSnapshotStaleError, l as HANDLER_ARGUMENT_PATH_LIMIT, m as redactedCeiling, p as UNFINISHED_ACTION_STATES, v as ProposalsNotConfiguredError, w as analysisLeaseRemaining, x as assertFailureCapture, y as FAILURE_CAPTURE_DEFAULT_MAX_BYTES } from "./chunks/execution-Clcmi0sj.js";
1
+ import { C as storedFailureCapture, D as generationSnapshotRead, O as listReadGate, T as completeWithFailureCapture, _ as HandlerArgumentsInvalidError, b as FAILURE_CAPTURE_MAX_BYTES, c as HANDLER_ARGUMENT_ISSUE_LIMIT, g as GenerationSourceStaleError, h as GenerationSnapshotStaleError, l as HANDLER_ARGUMENT_PATH_LIMIT, m as redactedCeiling, p as UNFINISHED_ACTION_STATES, v as ProposalsNotConfiguredError, w as analysisLeaseRemaining, x as assertFailureCapture, y as FAILURE_CAPTURE_DEFAULT_MAX_BYTES } from "./chunks/execution-ySzcTXW3.js";
2
2
  import "./models.js";
3
3
  import { c as storableJSONText, l as storableText, r as extractWithProviders, s as normalizeObservedImageRegions } from "./chunks/extraction-providers-DoD7M-Lm.js";
4
4
  import { d as extractAnalysis, f as proposeDocumentSplits, i as assertGenerationBounds, l as SplitGroupError, n as assertProposalLimits, t as proposalReadConfiguration, u as createSDKExtractionAdapter } from "./chunks/proposal-contracts-DREPLG56.js";
5
- import { i as reviewerInstructionView, n as ReviewerInstructionInvalidError, r as ReviewerInstructionStaleError, t as REVIEWER_INSTRUCTION_MAX_LENGTH } from "./chunks/reviewer-instruction-BeOYVCVk.js";
5
+ import { i as reviewerInstructionView, n as ReviewerInstructionInvalidError, r as ReviewerInstructionStaleError, t as REVIEWER_INSTRUCTION_MAX_LENGTH } from "./chunks/reviewer-instruction-Bst9wIak.js";
6
6
  import { detectEngine, isEmbeddedDatabase, isTransientDatabaseError, withEmbeddedWriteTransaction } from "@happyvertical/smrt-core";
7
7
  import { withTenant } from "@happyvertical/smrt-tenancy";
8
8
  import { createCipheriv, createDecipheriv, createHash, randomBytes, randomUUID } from "node:crypto";
@@ -1279,7 +1279,7 @@ var IngestionService = class {
1279
1279
  return (await this.proposalReader()).preview(input);
1280
1280
  }
1281
1281
  async feedback() {
1282
- const { IntakeFeedbackService } = await import("./chunks/feedback-hDSMYjiG.js").then((n) => n.r);
1282
+ const { IntakeFeedbackService } = await import("./chunks/feedback-CSi5pVUI.js").then((n) => n.r);
1283
1283
  return new IntakeFeedbackService(this.options);
1284
1284
  }
1285
1285
  async recordFeedback(input) {
@@ -3,21 +3,21 @@
3
3
  "sensitiveFieldsExcluded": true,
4
4
  "generatedAt": "1970-01-01T00:00:00.000Z",
5
5
  "packageName": "@happyvertical/smrt-ingestion",
6
- "packageVersion": "0.60.5",
6
+ "packageVersion": "0.60.7",
7
7
  "sourceManifestPath": "dist/manifest.json",
8
8
  "agentDocPath": "AGENTS.md",
9
9
  "sourceHashes": {
10
- "manifest": "4f34edf9e256202ac84619733cb3c7aadbfff221a06ac7049063aab500b01271",
11
- "packageJson": "ff3345931f2cfe35568ecb431cf22a30cf5632356674dbb8f7861aa5f4fed320",
10
+ "manifest": "13538afde7145f825db44d71721a43d8aa56f719b4a8dfdfc0c0aa565a56f80b",
11
+ "packageJson": "fa47da4676a36efd261331cff2b29acfd6c762b8a018bce22233048864205ae0",
12
12
  "agents": "dea14442054ec1de798cba9be1fbdd955f44b0e4672639cbf3db8101d290c1fb",
13
13
  "moduleDoc:agents/execution.md": "8a7c3384e90a41eb0c6f89e5bdafddd57db5e93f0c015849c764716b86ced97f",
14
14
  "moduleDoc:README.md": "d4dfdb4a4c1af3e1def6cf038e315e5bf66ab8d5942dee12a014527737a69748",
15
15
  "moduleDoc:EXTRACTION.md": "7aebb8ab51149e406938502935a46fe96174aa83975bbe5b913940f9b11053e9",
16
- "moduleDoc:PROPOSALS.md": "c20953df4742042e8988b19eec54f6757f50567bfee0502c8b0fe29a3a1ae204",
17
- "moduleDoc:FEEDBACK.md": "121555edc7e88208a509aa1e983b22a5dfd01d22b600e1ff694799af2aa5ad90",
16
+ "moduleDoc:PROPOSALS.md": "d038a93e383cfead6594c778019eea63fa05d88330879579bd1a1a8a34863877",
17
+ "moduleDoc:FEEDBACK.md": "8ee851f333857981a71f83066c5a5a476830bd06b7a76ded1cd35d6b9eb98bca",
18
18
  "moduleDoc:REVIEW.md": "4fe42050be02055f43ba56fdbc09b3651fc277ac257f4a44709906d594699ae7",
19
19
  "agentSurface:src/test-support/execution.ts": "cc72288b2605fc687b820da558fa862da1bab799cebe4ee88b32be9e902618b8",
20
- "agentSurface:src/test-support/proposals.ts": "8fdf02efbba774ad34c786c0699140703e4fc1822f4fec1bb06dc789fbe7d923"
20
+ "agentSurface:src/test-support/proposals.ts": "bdc8c3e87f5074a325f4219e39ef1f804387377fe987453248a29c55b988a30e"
21
21
  },
22
22
  "exports": [
23
23
  ".",
@@ -1720,12 +1720,12 @@
1720
1720
  {
1721
1721
  "path": "PROPOSALS.md",
1722
1722
  "module": "PROPOSALS",
1723
- "content": "# Application-aware proposal generation\n\n`@happyvertical/smrt-ingestion/proposals` is server-only. Configure\n`IngestionOptions.proposals` and the existing `execution.handlers` catalog.\nHandlers opt into discovery with `discovery.mediaTypes`, `references`, and an\noptional `candidates` callback. There is one catalog: the same operation or\nordered playbook adapter is discovered, validated, previewed, and later applied\nby the execution service. Generation never approves or applies.\n\nCredential-free review hosts may configure `IngestionOptions.proposalRead` with\n`ProposalReadConfiguration`: public generator/decision identities, version,\nprompt version, limits and thresholds only. It reads completed proposals,\npreserves current authority and snapshot validation, and permits human preview;\nit never accepts a generator or provider client. If a process supplies both\nsettings, their public configuration must match exactly. Preparing or generating\nproposals still requires `proposals` with a real generator.\n\n## Discovery and authority\n\n`listHandlers(itemId)` returns a bounded detached catalog. The owning execution\nservice checks the current principal, captured permissions/handler/operation\nceiling, policy, confidential scope, public registered operation facts, and\nordered playbook definition. Every configured provider must occur in the current\npolicy's `providers` allowlist. Missing grants remove handlers before model input.\nAn authorized catalog larger than the configured bound is rejected; the host must\nnarrow it explicitly instead of relying on silent truncation.\n\n`findCandidates({itemId,handlerId,handlerVersion,query,limit})` returns\n`{items,truncated}`. Its trusted handler callback receives `HandlerContext` with\nthe authorized transaction executor. Query by tenant and confidential scope\n**before** selecting, ranking, or building labels. Use a bounded query (often\n`limit + 1`) and report `hasMore`. The service projects candidate identity, model,\nrevision and label, then checks every target with the owning execution callback.\nThere are no hidden counts or pagination tokens. Truncated discovery forces\n`needs_review`; a person may still preview it explicitly, and automation never\nbecomes eligible.\n\nCompleted generation reload checks process authority, the current attempt, and\nowner/candidate visibility in the same final transaction. Database-backed grant\ncallbacks must use the supplied executor. The owning retention lifecycle encloses\nthat transaction so a denied read cannot roll back an authorized shorter privacy\nceiling; restoration starts only after the outer transaction has rolled back.\n\nCandidate callbacks perform bounded database reads only: no provider I/O, network,\nor domain mutations. Target locks and existing retention enforcement remain\nowned by execution. Hosts configure their database's statement deadlines; an\narbitrary trusted callback is not a sandbox. Each existing-record argument must\nbe a declared top-level `references` field of kind `candidate` with its qualified\nmodel, or `evidence`. Closed JSON argument schemas are required. The host owns\nthat declaration and its target authorization semantics.\n\n## Durable stages\n\n1. Complete extraction through the existing analysis ledger.\n2. Call `prepareGeneration(itemId, extractionAttemptId)`. It reads the current\n completed/partial immutable extraction and returns configuration with\n `stage: 'interpret'`, pinned source attempt/revision/input/output/evidence\n digests, prompt/configuration/catalog/provider versions, limits and thresholds.\n3. Pass that configuration to `analyze(itemId, configuration, requestKey)` and\n claim its new revision with `claimAnalysis`.\n4. The host's existing job callback routes on the frozen `configuration.stage`:\n extraction invokes `extractAnalysis`; interpretation invokes\n `generateProposals(lease)`.\n5. Reload the current completed generation using `getCompletedAnalysis(itemId)`,\n or pass an explicit attempt ID to additionally reject stale client state.\n Queued/running revisions never return an older completed attempt.\n\n`analyze` refuses an interpretation configuration whose pinned source is not\nthe item's latest extraction, checked under the item lock before anything is\nsuperseded (`GenerationSourceStaleError`, nothing appended). A preparation\nsuperseded by a later extraction therefore fails at append time rather than\nafter a revision was created.\n\nA generation revision does not rewrite terminal extraction. Reprocessing starts\nwith a new extraction revision, followed by interpretation, while the host keeps\nthe same business intention keys. An interrupted still-current generation lease\ncan be retried; terminal generation output remains immutable. `getGenerationInput`\nreads historical extraction only through the current generation lease and its\nfrozen source pin. It verifies same-item scope, immutable hashes, durable evidence,\nand current process permission before returning detached data. The source must be\nthe immediately preceding revision, so an intervening reprocess invalidates a\nprepared generation. Completed generation reads additionally recheck current\ncatalog and target visibility before disclosing persisted candidate labels.\nExpired, cancelled, revoked, retried or superseded workers cannot read or publish late output. The\ncurrent lease and each offered handler/candidate are rechecked immediately before\neach outbound generative/decision boundary and before publication.\n\n### Inline interpretation\n\nReceipts created with `dispatch: 'inline'` (text/structured parts only) run the\nsame stages in-process through `interpretInline(itemId, { requestId, extraction\n})`: an immutable extraction revision claimed under a fenced lease and extracted\nwith the built-in UTF-8 extractor, then `prepareGeneration` and a fenced\ninterpretation revision generated by `generateProposals`. The analysis lease,\ncatalog digest and live catalog/candidate checks, source pin, provenance and\n`StageFailure` categories are identical to the job path; no dispatch intent is\never deliverable and nothing is enqueued. A retry with the same `requestId`\nreplays the recorded revisions rather than re-preparing against a superseded\nsource, also under concurrency. The interpretation append rechecks, under the\nitem lock, that its pinned extraction is still the latest revision and refuses\na superseded pin: first through the general latest-extraction check that\nevery interpretation append runs (`GenerationSourceStaleError`), then by the\ninline check that the pinned attempt is still current (`Generation source changed`). Generated suggestions still require explicit preview and a human\ndecision, either through the reviewer surface or the submitter-scoped surface\ndescribed in [REVIEW.md](REVIEW.md).\n\n## Providers and validation\n\n`createSDKProposalGenerator(client, identity, {maxTokens,timeoutMs})` uses an\nexisting AI SDK `chat` client. It sends a fixed system instruction and separate\nJSON evidence/catalog data, requests JSON, supplies cancellation and bounds, uses\nno tools or continuation, and rejects known truncation or tool calls,\nunexpected models, malformed JSON and oversized output. Configure SDK clients\nwithout automatic retry that would bypass application boundary checks. The\nadapter's public identity is exactly provider/model/version; credentials and raw\nprovider errors are never provenance.\n\nThe fixed system instruction (`proposalInstructions`, extended per item by\n`proposalInstructionsFor` with the handler argument contract and split\neligibility) is generic and value-free. It treats evidence as untrusted data,\nnever instructions, and limits suggestions to offered handlers and candidates.\nIt asks the model to fill every argument readable from the evidence\n(identifiers, numbers, dates, quantities, amounts and currency) in the form its\nschema requires, never inventing a value the evidence does not show; a value\nthat cannot be expressed in that form is treated as absent. Each value must be\nthe one whose label or context matches the field's name and description; when\nseveral similar values appear, a field whose named value is missing is treated\nas absent rather than given a substitute. A candidate reference is chosen only\nfrom that handler's listed candidates, and an evidence reference copies the\nsupplied `evidenceId`. `missingFields` lists exactly the required fields left\nout of `args`, and a required field is left out only when its value is genuinely\nabsent or no offered candidate matches. On required-only schema refusals, the\nvalidator computes the absent required set and corrects a mismatched model\ndeclaration; the instruction guides the model without making its declaration\nauthoritative. Absent optional fields stay out\nof both `args` and `missingFields`, rather than being sent as null (unless the field explicitly permits null). Suggestion objects contain exactly the required envelope keys, with handler arguments nested only inside `args`. Alternatives mean genuinely competing OTHER choices, not a list of offered choices: use `[]` when none exist and never list the selected handler itself. The SDK response schema excludes that handler key from each suggestion variant while retaining other handler and candidate keys (#4395). Existing malformed or ambiguous outputs remain refused/pending; no self-alternative is stripped after generation. The model prefers `no_action` when no\noffered handler's description fits the document's role, and `unknown` when the\nevidence cannot be interpreted (#4290). Domain routing, such as which received\ndocuments an application ignores, belongs in host handler descriptions or\nreviewer guidance, not in this text. Keep these shared instructions concise: the\nmaintained reference host pins the complete SDK request to an 8 KiB wire/input\nbudget. That budget includes schema and transport overhead; adding repeated prose\ncan prevent a valid small request from reaching its provider. The frozen\nevaluation checks the real envelope without raising its budget (#4395).\nThe text is not persisted. It is not part\nof the frozen interpretation configuration, the input, catalog or output\ndigests, or the stored generation output, so a package release that changes it\nleaves stored attempts readable and previewable unchanged. New attempts send the\nnew text, but their digests do not record it; a host that needs provenance to\ntell the two apart bumps its own `promptVersion`, which, like any configuration\nchange, makes earlier attempts read as stale (`GenerationSnapshotStaleError`).\n\nEach suggestion's `explanation` is one or two plain sentences stating what the\ndocument is and why the handler fits, with no deliberation, self-correction or\nrestating of the rules, and is bounded at 300 code points (#4331,\n`PROPOSAL_EXPLANATION_LIMIT`). Two such sentences run about 150-250\ncharacters; the bound keeps a verbose model from spending its output budget\n(and hitting the `length` finish reason) on prose instead of arguments. A\nreply cut at the token limit is still refused (`finish_reason`) and partial\nJSON is never salvaged; the grammar bound and the instruction are what keep\nreplies under the limit. The provider schema and the validator carry the same `maxLength`, so the provider\ncopy still accepts a superset of the validator (#4261), and a grammar backend\nenforces the bound while decoding. In the provider schema `explanation` is the\nlast suggestion property, after `handlerId`, `handlerVersion`, `args`,\n`evidence`, `alternatives` and `missingFields`, and the top-level keys are\n`outcome`, `suggestions`, `splits` in that order; `required` lists the same\norder. That order predates #4331 and is now pinned by a test, so explanation\nprose cannot precede the arguments. xgrammar emits object properties in schema `properties` order unless\n`any_order` is set (its default is `false`, and vLLM does not set it), and\nllguidance fixes property order to the `properties` map, then `required`. A provider\nthat ignores the schema can still return a longer explanation: fresh output is\nnormalized after the list deduplication above and before validation, cutting\nit to 299 code points plus `…` on a code-point boundary, so a long explanation\nnever fails validation (the raw output-size and SDK `output_limit` checks\nstill run first). The value-free count is recorded as\n`provenance.explanationsTruncated`, absent when zero and removed with\n`duplicatesRemoved` whenever the suggestions are discarded. It counts only\nreplies from providers that ignore the schema: on a grammar backend such as\nvLLM the string closes at 300 code points with no marker, and nothing is\ncounted. The cut happens\nbefore the invented-target echo check, so an echo beyond the bound is no\nlonger seen; explanation text is never a target or authority.\n\nReplay: the bound, the property order and the instruction text feed no digest.\nThe response schema is built per request and never persisted; the frozen\ninterpretation configuration holds versions, identities, the catalog digest and\n`limits`, none of which include the explanation bound. Stored attempts are read\nas persisted, never re-validated or re-cut, so an earlier attempt with an\nexplanation of up to 2000 characters still reads, previews and replays with\nits original `output_digest`. New attempts' digests cover the bounded form.\n\nA trusted custom `ProposalGenerator` must likewise honor cancellation, bound its\nresponse, and explicitly declare validated `complete` or `unknown` completion.\nThe SDK currently normalizes missing/unknown finish reasons to `stop`\n([owning SDK follow-up](https://github.com/happyvertical/sdk/issues/1381)), so its\nadapter conservatively declares `unknown`, persisted as\n`generation_completion_unknown`. Otherwise valid suggestions remain available\nfor human preview; automatic eligibility always remains false. The service\ndeadline aborts requests and prevents late publication; it does not claim to terminate computation at a remote\nprovider or isolate native allocations. Extractor process limits remain separate.\n\nWhen the pinned extraction carries an authenticated reviewer instruction\n(REVIEW.md), `prepareGeneration` copies it into the interpretation configuration\nand `generateProposals` verifies that copy against the extraction record and its\nown digest before provider disclosure (`integrity` otherwise). The prompt then\ncarries it in its own **trusted reviewer guidance** section after the fixed\nsystem instruction and handler contract: the guidance is named as authenticated\nhuman input, limited to the offered catalog, and the evidence remains untrusted\ndata. `GenerativeProposalInput.reviewerInstruction` exposes `{id, text}` to custom\ngenerators; `provenance.reviewerInstruction` records `{id, digest}`. The\ninstruction never changes `offered`, `catalogDigest`, argument schemas,\npermissions or `automaticActionEligible`; a reply that follows guidance outside\nthe catalog fails validation like any other hostile output. **Budget cost:** the instruction counts once against the input budget\n(`maxInputBytes`, each offered handler's `maxBytes` and the live policy\nceiling), as its JSON-escaped text inside the prompt's guidance section — up\nto 4,000 characters plus escaping and the fixed guidance sentence. The\n`reviewerInstruction` field duplicated for custom generators is not counted\nagain. The decision stage also carries it once: its request state holds the\nevidence-side input with the un-guided base instructions under `evidence`, and\nthe guidance only under a separate `reviewerGuidance` key, never under\n`evidence`; the decision budget measures that serialized request as sent. Size `maxInputBytes` with that headroom. Learned examples are\nstill retrieved for an instructed generation; only a logical split correction\nsuppresses them. Every instruction costs a fresh extraction revision before the\nnew interpretation: the predecessor-pin contract above (source = immediately\npreceding revision, current-revision reads) is deliberately left intact rather\nthan reused for a same-source second interpretation, so OCR/speech hosts budget\none extraction per instruction, as for split corrections.\n\nModel output can contain only offered handler versions, schema-valid arguments,\nretained evidence locations and offered alternative handler/candidate keys.\nCandidate IDs must occur in the offered set, and evidence IDs in retained source\nresults. Unknown enums, invented IDs, extra authority/tool/approval fields and\nmalformed structures fail closed (an invented candidate target alone is dropped\nfor review instead, see below). Missing required fields are retained as\n`missingFields`, with `needs_review`; values are never invented to satisfy a\nschema. Observed page/time/source granularity is preserved. Logical scan splits\nuse `proposeDocumentSplits`; originals and hashes remain intact.\n\nWhen a suggestion's arguments fail the handler schema **only** on `required`\n(#4284), the suggestion is kept rather than rejecting the attempt: its\narguments stay exactly as generated and `missingFields` names every missing\nrequired argument. The schema, not the model, decides what is missing. A\ndeclaration that matches the computed set (in any order) is kept exactly as the\nmodel wrote it, so an already valid reply is unchanged byte for byte and replay\nstays deterministic. A declaration that differs (unlisted misses, or listed\nfields that are present or optional) is replaced by the sorted computed set and\nthe suggestion is `needs_review` even when nothing is left missing;\n`provenance.missingFieldsCorrection` then records `{suggestions, added,\nremoved}` counts only, and is absent otherwise and dropped whenever the\nsuggestions are discarded. A miss at the\nargument root is the bare property name; a miss inside a present nested object\nor array item is an RFC 6901 JSON Pointer relative to the arguments, such as\n`/vendor/name` or `/lines/0/sku`. An entry starting with `/` is therefore a\npointer, so a handler should not declare a root property whose name itself\nstarts with `/`. Names come from the handler schema's own `required` lists,\nnever from argument values or model-chosen keys; `required` inside `allOf` or\ninside object-form `dependencies` (`{a: {required: ['b']}}`) counts like any\nother. The schema walk does not follow `$ref`: a miss directly at a property\nwhose schema is a `$ref` is kept, but a miss deeper inside the referenced\ndefinition cannot be named from the schema and rejects (fail-safe). The attempt still rejects as before when any other\nkeyword fails beside or instead of `required`: type, enum, pattern, bounds,\n`additionalProperties`, an `anyOf`/`oneOf` branch, an `if`/`then`/`else` branch\n(Ajv adds an `if` error), `not`, or array-form `dependencies` (its own keyword,\nalthough it names the missing property). It also rejects when a miss lies under\na key the schema does not declare, or when more than 30 fields are missing.\nHandler schemas compile in Ajv strict mode, so draft-2019 keywords such as\n`dependentRequired` are refused at compile time. Such a suggestion is ordinary\n`needs_review` output: the decision gate can only withhold readiness, never\ngrant it, `automaticActionEligible` stays false, and generated preview of\nincomplete arguments fails the handler schema (see Explicit preview below).\n\nA generated split whose groups fail that check is dropped, not the whole reply\n(#4288): the suggestions and any other splits are validated as before, the\ndropped split is never published or applied, and `provenance.splitsDropped`\nrecords `{count, checks: ['split_groups']}`, never pages or evidence ids. Any\nother split error still fails the attempt. If every split is dropped, the reply\nhas no split; a reviewer can still split through `reviseLogicalSplit`, and a\nrecorded split correction the reply no longer matches ends as\n`human_split_not_respected`. A split for unknown or repeated evidence is still\nrejected, even when the earlier split on that evidence was dropped. Like\n`duplicatesRemoved`, `splitsDropped` is kept only on a published, validated\nreply. Stored output is never re-validated, so earlier attempts and their\ndigests replay unchanged.\n\nAn invented target — a value in an offered handler's candidate reference field\nthat is not among the offered candidates for that field's model — no longer\nrejects the attempt (#4289). The validator drops the key from the arguments\n(no placeholder) and revalidates what remains through the required-only path\nabove: a dropped required field becomes a computed `missingFields` entry, a\ndropped optional field is simply absent, and either way the suggestion is\n`needs_review` for the reviewer to choose an offered target.\n`provenance.unofferedTargetsDropped` records `{suggestions, fields}` counts\nonly, never IDs, labels or field names; it is absent when nothing was dropped\nand removed whenever the suggestions are discarded. Every candidate field that\nstays in the arguments has been checked against the offered set, so no\nunoffered value survives as a target. The attempt still rejects as before for\nan unoffered handler or alternative, unknown evidence (argument or reference),\na non-string target, a target field the handler schema does not declare in\n`properties`, any other argument error, or a drop that exposes a refusal other\nthan `required`.\n\nThe exact dropped value is also searched for in the kept suggestions and splits\n(JSON-escaped, keys included); an exact echo, such as the ID repeated in an\nexplanation or another argument, rejects the attempt. This guard fails closed\non short or common values: a dropped `\"1\"` or `\"a\"` almost always occurs\nsomewhere else in the output, so such a reply rejects rather than being kept.\nIt is an exact-match check, not a general leak filter: a case variant, a\nreformatted copy or a fragment of the ID in free text (an explanation or a\ntext argument) is not detected and may reach the reviewer as ordinary model\nprose. Free text is never a target and never authority; only the checked\ncandidate fields are.\n\nA rejected reply ends the attempt as `provider_error` with the `malformed_output`\nwarning and a bounded, value-free `provenance.failure` `{category, reason}` (#4207).\nThe reason lists schema-owned paths, keywords and schema constants, for example\n`/outcome enum (allowedValues=proposals|unknown|...)` and\n`/suggestions/0 required (missingProperty=evidence)`, or the fixed internal check\nand its path, such as `Unoffered handler: /suggestions/0`. Path segments are\nkept only when they are keys declared under the schema's `properties` or\nindexes into a value that actually is an array in the rejected reply; any other\nsegment, numeric or not (for example a key under an open\n`additionalProperties` argument sub-schema, or a numeric key of an object),\nbecomes `?`, and an extra property's name is never echoed.\nIt never contains document text, argument values, evidence content or\nmodel-chosen keys, is cut at 1000 characters,\nand is dropped before the output-limit fallback. Hosts read it from the\ncompleted/partial analysis at `analysis.result.output.proposals.provenance.failure`.\nThe SDK adapter constrains replies with a `json_schema` response format built\nfrom the validator's schema and the fixed instructions describe the shape; a\ncustom `ProposalGenerator` receives no schema, so its raw reply meets the\nvalidator directly and the same reason is recorded.\nThe provider-facing schema is made portable (`portableResponseSchema`, #4260):\nkeywords that common OpenAI-compatible structured-output backends reject are\nremoved at schema positions, including inside handler argument schemas\n(`uniqueItems`, `contains`, `multipleOf`, `format`, `patternProperties`,\n`propertyNames`, `min`/`maxProperties`, `not`, `if`/`then`/`else`,\n`dependent*`, `unevaluated*`, and the `default`/`examples` annotations; the\nfull list and reasons are in `src/proposal-sdk.ts`). With `uniqueItems`, for\nexample, vLLM's xgrammar feature check flags the schema, its auto mode routes\nit to llguidance, and llguidance answers\n`400 Grammar error: Unimplemented keys: [\"uniqueItems\"]`. This only loosens the\ngrammar: the validator still enforces the constraints, including unique\n`alternatives` and `missingFields`, and the fixed instructions ask for distinct\nentries. The exception is `format`, which is advisory: the validator runs Ajv\nwith `validateFormats: false`, so `format` is enforced nowhere. Because a model\ncan still repeat an entry, fresh generator output is normalized first (#4286):\nwithin each suggestion, repeated `alternatives` and `missingFields` entries\n(equal by canonical JSON) are dropped, keeping the first. Nothing else is\nrewritten, and `uniqueItems` still applies to the result. The count, never the\nvalues, is recorded as `provenance.duplicatesRemoved`, present only when\nnon-zero and only on a published, validated reply. The published output, and so\nits digest, is the normalized form. Stored attempts are read and replayed as\npersisted; they are never renormalized. When\n`patternProperties` is removed, the same object's `additionalProperties` is\nremoved too, so the grammar does not shrink to `{}`. The `contentSchema` annotation is omitted as well, so nested unsupported\nconstraints cannot leak through an unvisited schema position. A backend may\nrecursively inspect typed schema-like objects even inside `enum` or `const`\ndata. When such data contains an unsupported keyword, the whole containing\n`enum`/`const` constraint is omitted conservatively; literal data is never\nrewritten. Harmless property names and ordinary enum/const data stay intact.\nThe original validator remains authoritative for omitted literal constraints.\nThere is no automatic `json_object` fallback.\n\nInvariant: the provider copy only ever accepts a superset of what the original\naccepts. Each removed keyword is a conjunct, so removing it only widens. The two\nplaces where removal would narrow are rewritten:\n- every `oneOf` becomes `anyOf` (or joins an existing `anyOf` through `allOf`),\n because loosened `oneOf` branches could both match and reject a value the\n original accepted;\n- an object that loses `patternProperties` also loses `additionalProperties`.\n\nProvider-only `$ref`, `$dynamicRef`, and `$recursiveRef` constraints are also\nremoved. Rewriting or deleting a subschema can invalidate pointer or anchor\ntargets, including targets inside nested `$id` resources. Dropping references\nconservatively widens the grammar without resolving untrusted schema resources;\nproperty names and enum/const data named `$ref` remain unchanged. Referenced\nconstraints, recursion, and dynamic scope remain enforced by the original\nvalidator, so provider guidance for reference-based arguments is less precise.\n\nThe validator still checks the original, including `oneOf` exclusivity. A\nproperty-style regression checks original-valid ⇒ portable-valid across the\nremoved keywords. Handler argument schemas may still carry `allOf` through\nunchanged; its support across backends is unverified, so check such a handler\nagainst the deployed backend.\n\nA generator call that throws ends the attempt as `provider_error` with the\n`unavailable` warning and `provenance.failure` `{category: 'unavailable',\nreason}`. The reason is value-free by construction: a provider's own text can\nquote the prompt or document, so it is never copied. The reason is built only\nfrom a fixed phrase and:\n\n- for an SDK `AIError` only, the HTTP status (from a structured field, or from\n the exact `<status> ...` / `TypeSafe request failed (<status>): ...` shapes\n the SDK produces), the SDK error code (from the closed list of codes the SDK\n raises), for a schema rejection the quoted tokens that are JSON Schema\n keywords, and the OpenAI SDK's exact fixed transport messages\n (`Connection error.`, `Request timed out.`, `Request was aborted.`,\n `(no status code or body)`), which its `mapError` keeps without a cause;\n- for the SDK adapter's own refusal of a reply it did receive, a fixed problem:\n finish reason other than `stop` (named from the closed list `stop`, `length`,\n `tool_calls`, `content_filter`, otherwise `other`), truncation, tool calls,\n an unexpected response model, no text content, an empty reply, a reply over\n the output limit, or a reply that is not valid JSON (#4285);\n- for any other error (#4285), the code-defined constructor name (an\n identifier ending in `Error` or `Exception`; never the settable `name`),\n an `AbortError`/`TimeoutError` name, a network `code` from a closed list\n (`ECONNREFUSED`, `ECONNRESET`, `ETIMEDOUT`, `ENOTFOUND`, `EAI_AGAIN`,\n `UND_ERR_*`, TLS certificate codes, ...) read from the error, up to three\n `cause` levels and an `AggregateError`'s entries, and a structured numeric\n status. A timeout or abort is named as one, except that a structured HTTP\n status always wins over an abort name or network timeout code on a non-SDK\n error, whether on the error itself or in its cause chain. An SDK error's\n abort is read only from its code or exact transport message.\n\nFor example: `provider rejected the response schema (HTTP 400, code API_ERROR);\nunsupported response-schema keywords: uniqueItems`,\n`provider response incomplete (finish reason length)`,\n`provider call failed (class TypeError, network ECONNREFUSED)`,\n`provider call aborted or timed out (class DOMException, name TimeoutError)`, or\n`provider call failed (class Error)`. It is cut at 500 characters.\n\n**Why some failures were a bare `provider call failed` (#4285).** The SDK\nadapter's own response checks threw plain `Error`s (finish reason not `stop`,\ne.g. `length` when the reply reached `maxTokens`; truncation; tool calls; an\nunexpected response model; non-text or oversized content) and `JSON.parse`\nthrew a `SyntaxError` for an empty or non-JSON reply. The reason deliberately\nreads nothing from a non-SDK error, so all of these collapsed into the fixed\nphrase. Transport failures through the OpenAI SDK already carried\n`code API_ERROR`. The adapter now raises `ProposalResponseError` with a fixed\nproblem, and other non-SDK errors contribute the transport facts above. The\ncategory is unchanged (`unavailable`).\n\n### Host suggestion review (`reviewSuggestion`)\n\nA host's own checks on a generated suggestion (a label that is not the invoice\ndate, an amount that is not in the document) can hold it and leave a record a\nreviewer sees:\n\n```ts\nproposals: {\n // ...\n reviewSuggestion: ({ suggestion, handler, evidence }) => ({\n hold: true, // optional; forces needs_review\n reasons: ['total_not_in_text'], // optional; <= 8 codes, /^[a-z][a-z0-9_.-]{0,47}$/\n prefilled: ['billDate'], // optional; names declared in handler.argsSchema.properties\n }),\n},\n```\n\nThe hook is trusted, server-only and optional. It runs once per validated\nsuggestion, after validation and before the decision gate, with deep copies of\nthe suggestion, its offered handler and the retained evidence text. It cannot\nchange `args`, `missingFields`, evidence or the outcome except through `hold`,\nand it can never upgrade: `hold` sets the suggestion (and a `proposals` outcome)\nto `needs_review`; absent or `hold: false` leaves the validator's disposition.\n\nThe result is stored as `suggestion.hostReview` (`{held, reasons, prefilled}`)\nand counted in `provenance.hostReview` (`{annotated, held}`); both are absent\nwhen the hook records nothing. Values cannot be stored: unknown keys, free-text\nor over-long reasons, `prefilled` names that are not argument names, and any\nreason code containing one of the suggestion's own argument values (3+\ncharacters) make the result invalid. An invalid result, a throw, a rejection or\na hook slower than `limits.timeoutMs` holds the suggestion with the fixed code\n`host_review_invalid` or `host_review_failed`; the error text is discarded.\n`ReviewView` shows \"Checked by the shop: ...\" under the arguments.\n\nLike `failureCapture`, the hook is not public read configuration and never enters\nfrozen configuration or digests. Hosts keep it synchronous-cheap: it runs inside\nthe generation lease.\n\n### Retry and concurrency (opt-in, #4504)\n\n```ts\nproposals: {\n // ...\n retry: {\n attempts: 3, // total calls, 1..10; default 1\n backoffMs: (attempt) => 500 * 2 ** (attempt - 2), // or a number, 0..60000; default 0\n retryable: (error) => (error as { status?: number }).status === 529,\n },\n concurrency: 4, // 1..1000; default unlimited\n},\n```\n\n`retry` retries a rejected `generator.generate` call; absent (or\n`attempts: 1`) keeps one call as before. `retryable(error, attempt)` sees the\ngenerator's rejection (default: retry every rejection; a throwing predicate\nmeans no). Each call gets its own `limits.timeoutMs` deadline; a timeout is\nfinal, as are validation failures of a returned reply. A retry is skipped when\nthe analysis lease could not cover the backoff plus another full deadline, and\na malformed `backoffMs` answer ends the retries. Only the final rejection is\nrecorded (`provider_error`, category `unavailable`, value-free reason).\n`concurrency` bounds `generate` calls in flight across every service built\nfrom the same configuration object (FIFO); a queued call's deadline starts\nwhen it gets a slot. Both are validated at `IngestionService` construction and,\nlike `reviewSuggestion`, never enter frozen configuration, digests or\n`proposalReadConfiguration`. A reviewer can still re-run a finally failed item\nwith \"Try again\" (REVIEW.md, `retryInterpretation`).\n\n### Failed-attempt capture (opt-in, #4285)\n\nThe value-free reason cannot show what the model actually sent. A host that\nneeds that for diagnosis can opt in to keeping it:\n\n```ts\nproposals: {\n // ...\n failureCapture: {\n enabled: true, // required; absent or false keeps capture off\n maxBytes: 16384, // default 16384, at most 65536 (UTF-8 bytes, after redaction)\n redact: ({ text, source }) => hostRedaction(text), // required to retain text\n },\n},\n```\n\n`ProposalConfiguration.failureCapture` is **off by default**. When enabled with\na host `redact` hook, a failed interpretation attempt (`provider_error`) keeps\none of:\n\n- `raw_response`: the reply text the SDK adapter refused (for example invalid\n JSON or a `length` finish), or\n- `generated_output`: the generator's parsed output, as JSON, that failed\n validation, the declared-completion check or the output limit.\n\nErrors without model output (transport, timeouts, authority, decision\nfailures) capture nothing. Successful attempts never store a capture.\n\nWithout a `redact` hook, only `status: 'redaction_failed'` metadata is stored,\nwith `redacted: false` and no text; the candidate text is not materialized.\nThere is no built-in sanitizer. Hosts own the hook's semantic redaction policy;\nthe service cannot verify that the returned text removes every document secret.\n\nThe text, cut to the larger of the generation `maxOutputBytes` and\n`maxBytes`, goes through the host `redact` hook, and the result is cut to\n`maxBytes` without splitting a character (`truncated: true` when either cut\napplied). NUL and unpaired surrogates are stored as U+FFFD so PostgreSQL JSON accepts the record. When\nthe hook throws, returns a non-string or exceeds its asynchronous wait budget,\nonly `status: 'redaction_failed'` is stored. The budget is the generation\n`timeoutMs`, cut to half of the analysis lease still left when the hook starts\n(no time left: the hook is not called). The hook runs after the authority\nrecheck, reserving the rest of the lease for the second recheck and publication.\nThis timer cannot preempt synchronous work or cancel the hook. Hosts must use\nbounded, nonblocking redactors. Missing or failed redaction does not replace the\nattempt's real failure or value-free reason; hook errors are discarded.\n\n**Where it lives.** In the attempt row's `data` JSON, as `failureCapture`\nbeside the result fields, never inside `result`: it needs no migration, is not\npart of `output_digest` or any configuration digest, never appears in\n`getCompletedAnalysis` or any other snapshot, and is not public read\nconfiguration (`proposalReadConfiguration` omits it, so read-only hosts still\nmatch). Proposal digests, replay and frozen generation configuration are\nunchanged by enabling it.\n\n**Reading it back.** Only\n`IngestionService.getFailedAttemptCapture(itemId, attemptId?)` returns it\n(`FailedAttemptCapture` from `/dto`, or `null` when nothing was stored). The\nattempt defaults to the item's current analysis attempt. It requires the\nexecution catalog and the current **reviewer** authority for that item (the\nsame gate as `getItemDisposition`) inside the caller's tenant and confidential\nscope; every denial, expiry, cancellation or foreign item fails closed before\nthe row is read. It is never part of a list DTO, inbox row, review page,\nlog line, checkpoint name, telemetry or error message.\nPublication and reads also reject a persisted `captured` record with\n`redacted: false`; capture text must be marked as processed by a configured\nhost hook. Persisted caps must remain within 1–65536 bytes, and captured text\nmust fit its declared UTF-8 byte cap; malformed records fail closed.\n\n**Retention and deletion.** It follows the item. There is no separate delete\nAPI: `expire`, `sweepRetention` and the `repairDeletions` retry of an\ninterrupted propagation all empty attempt `data`, which removes the capture\nwith the rest of the payload; a revoked item is unreadable before that.\n\n`createSDKProposalDecisionClient(client)` adapts an existing SDK client’s optional\ncapability without changing its errors or protocol. Optional `decision` uses public core `executeDecision` and the existing SDK\npredicate, choice, score and batch contracts. Supported-effect predicates,\nhandler classification, candidate entity matching, and action ambiguity/risk\nare distinct questions. Their validated probabilities and provenance are stored\nseparately from generative provenance and unknown OCR certainty. The complete\nserialized decision request, including suggestions and questions, must fit the\nminimum configured/current policy byte ceiling before capability probing and\nagain before deciding. A policy change between these boundaries fails closed.\nActually incomplete extraction always requires review. Unknown provider\ncompletion metadata is preserved as `source_completion_unknown`; it does not\nblock otherwise schema-valid **human** preview or imply completeness. Automatic\naction eligibility remains false. An unconfigured decision path\nis recorded explicitly. Configured errors produce a durable safe failure outcome;\nthey never silently switch to a generative decision fallback.\n\n### Decision readiness gate (#4209)\n\nFor every suggestion `i` the request asks `supported_i` (predicate),\n`route_i` (choice over the offered `handlerId@version` keys plus `none`),\n`risk_i` (ordered score over `clear`, `uncertain`, `ambiguous`) and one\n`entity_i_<field>` choice per candidate-reference argument. The validated\nanswers are always persisted under `provenance.decision.answers`. With the\ndefault `decisionReadiness: 'gate'` they are read as follows, and any failing\ncheck sets the suggestion to `needs_review` (a tie also sets the outcome to\n`ambiguous`):\n\n- `supported.probability >= minimumDecisionProbability` (default `0.8`).\n- `route.choice` equals the suggestion's own `handlerId@handlerVersion`,\n `route.confidence >= minimumDecisionProbability`, and the gap between the two\n largest route probabilities is greater than `tieMargin` (default `0.1`).\n- `risk.score < 1`: only the `clear` level passes; `uncertain` and `ambiguous`\n require review.\n- Each entity match chooses the suggested candidate's key with confidence at or\n above the threshold and a gap above `tieMargin`.\n\nThese values are provider outputs read as if they were calibrated\nprobabilities; nothing in this package calibrates them for this use. The\nteamworks-os measurement in #4209 (self-hosted Laya `typed-decisions`) found no\nseparation between right and wrong suggestions: a correctly read vendor invoice\nscored `supported` 0.37, garbage input 0.45–0.50, a wrongly proposed purchase\norder 0.51, route confidence 0.003–0.15 and `risk` ≥ 0.94, so the gate sent\nevery suggestion to review. Until a labelled sample shows separation, treat the\nanswers as diagnostics and configure:\n\n- `decisionMaxLen`: positive integer forwarded unchanged as the per-request\n `maxLen` of the decision client (the SDK Laya provider's token window; the\n checkpoint default is 1024 and the serialized evidence plus suggestions is\n otherwise truncated). Other clients ignore it.\n- `decisionReadiness: 'record'`: the decision still runs, is bounded and\n authorized exactly as before and its answers, usage, `readiness` and `maxLen`\n are recorded, but the gate never changes `outcome` or `disposition`; readiness\n comes from the validator alone (`missingFields`, outcome, source completeness).\n A client error or timeout is recorded as the `decision_unavailable`\n warning. A reply that comes back and then fails the core `executeDecision`\n identity or answer-shape check is recorded as `decision_malformed` with the\n reply's usage; this is the path for injected `DecisionClient`s. SDK clients,\n including the Laya provider behind `createSDKProposalDecisionClient`,\n validate the reply's shape inside `client.decide` and throw, so a malformed\n SDK reply is recorded as `decision_unavailable` with no usage. Every case\n records the `provenance.decision` identity. The generated suggestions stay\n as they were. The serialized request exceeding the byte budget is a\n configuration failure, not a provider answer: it ends the attempt as `limit`\n in both modes, and in `gate` mode every failure above still ends the attempt\n as `provider_error`. Lease, catalog, policy and provider-allowlist revocation\n fail closed in both modes.\n\nSuccessful output also records `provenance.decision.readiness` (`'gate'` or\n`'record'`) and `maxLen` when set; configuration digests are unchanged, but\npersisted output is therefore not byte-identical to earlier releases.\n\nBoth settings are public configuration: they are part of\n`ProposalReadConfiguration`, the frozen `GenerationStageConfiguration.proposals`\n(present only when set, so existing digests are unchanged) and the completed\nsnapshot authority check. Invalid values fail at proposal service construction.\nNeither mode affects automation: `automaticActionEligible` stays `false`, and\n`authorizeAutomatic` reads only the host's `evaluateAutomatic` callback and\npolicy, never these answers.\n\nOutput records zero, one or multiple suggestions, alternatives, missing fields,\nsource links, proposed splits, versions, allowlisted usage, warnings and explicit\n`unknown`, `ambiguous`, `no_action`, `needs_review` or `provider_error` outcomes.\n`automaticActionEligible` is always false. Provider input/output and the complete\nserialized persisted envelope are bounded by configuration, live policy and the\nreceipt ceiling. Oversized output becomes a bounded review/limit result; when\nno safe envelope fits, the owning service records fixed `failAnalysis` metadata\noutside the provider payload budget without retaining provider output.\n\n## Explicit preview and stable intentions\n\nThe host chooses persisted suggestion indexes and calls:\n\n```ts\nawait service.previewGeneratedProposals({\n itemId,\n attemptId: generationAttemptId,\n selections: [{\n index: 0,\n intentionKey: 'document:meeting-2026-10-09',\n expectedRevision: 0,\n requestId: 'review-request-1',\n }],\n});\n```\n\n`intentionKey` is the host's stable business-intention identity across generation\nrevisions. Never derive a fresh key from model output, suggestion order or a retry.\nSelections must reference current persisted validated `ready_for_review` or\n`needs_review` output (#4208); a `provider_error` attempt, an unoffered handler or\na non-interpretation stage is rejected. A `needs_review` suggestion whose\n`missingFields` are still absent fails the handler schema inside the ordinary\npreview (`HandlerArgumentsInvalidError`, `Invalid handler payload`, whose\nvalue-free `issues` name the missing schema fields, for example\n`{ path: '/title', keyword: 'required' }`; see REVIEW.md) and publishes\nnothing; the reviewer supplies\nthe missing values through the explicit human path (`previewProposal` /\n`previewPlan`, as the published review host does for `preview({args})`), and the\nhandler's `validate` and `preview` run again on the completed arguments.\nEach batch requires distinct suggestion indexes and intention keys; duplicate\nindexes are rejected before any operation or plan preview is written.\nThe service rechecks current catalog/schema/target/source provenance, then calls\nthe existing operation or plan preview. Each result still requires the ordinary\nhuman review and execution APIs. Reprocessing creates no new business identity;\nsuccessful-action replay protection stays with execution.\n\n## Evidence and limits\n\nThe test matrix is `docs/test-matrix/3673-ingestion-proposals.md`. SQLite and real\nPostgreSQL suites exercise authority, revisions, abstention, hostile output,\ncompound proposals, split provenance and reviewed domain effects. The upload\nreference composes authenticated multipart delivery of a generated embedded-text\nPDF through the actual packaged PDF child, durable interpretation, and the existing\nordered ContentDocument draft/retained-asset plan. It checks duplicate delivery,\nunauthenticated and foreign-tenant denial, explicit approval of both steps,\nidempotent execution replay, page provenance, and unchanged original bytes.\nThe compound-email case uses a declared messages-owner snapshot fixture.\n\nLocal HTTP fixtures execute the actual AI SDK transport and cancellation contract.\nGenerative responses and the separate injected PDF split boundaries establish\ndeterministic orchestration, not model accuracy or OCR quality. No held-out routing\nevaluation or automatic approval is claimed. Missing/unknown AI completion remains\nexplicit under [SDK #1381](https://github.com/happyvertical/sdk/issues/1381).\n\nProposal limits are checked at `IngestionService` construction: positive safe\nintegers, at most 20 handlers/candidates/suggestions and 2147483647 ms timeout.\nInterpretation output uses the exported `GenerationAnalysisOutput` wrapper at\n`analysis.result.output.proposals`; the published review host unwraps it.\nAn explicit feedback `retrieve` denial omits optional examples and feedback\nprovenance and continues generation. Item/execution denials, unexpected failures,\nand revocation after examples were selected still fail closed before disclosure.\n\n## Storage-safe provider text (#4393)\n\nAfter the normal output-byte ceiling, generation validates decoded JSON object\nkeys and nested string values for PostgreSQL's unsupported NUL and unpaired\nUTF-16 surrogate characters. A refusal is `malformed_output` with a fixed,\nvalue-free reason, before either accepted or refused suggestion arguments can be\nretained. Provider content is never stripped, repaired or treated as authority.\nLiteral backslash-u text and valid supplementary Unicode remain unchanged.\n\nThe generic `completeAnalysis` publication boundary independently checks the\nwhole result, including provider metadata and diagnostics. An invalid result\nrecords the exact current fenced attempt as `needs_attention/malformed_output`\non the same authorized executor and completes its dispatch; it produces no\ncompleted analysis, proposal or execution. Originals remain readable, and a\nfresh authorized analysis revision can retry without rewriting the failed one.\nExisting byte limits and current authority/fence checks still apply.\n\nOptional failed-attempt capture uses the existing private, reviewer-authorized\nhost redaction policy. Unsupported generated JSON can be retained there as its\nJSON-escaped diagnostic representation; it is never copied into a successful\nproposal or returned in ordinary snapshot payloads. Without an enabled redactor,\nno raw diagnostic text is retained. Shared foundation/proposal tests exercise\nSQLite and actual PostgreSQL JSONB writes, invalid keys and values, lone high/low\nsurrogates, valid emoji/literal escapes, source retention, retry and capture policy.\n\n\n## Descriptive candidate context\n\nA discovery candidate may include optional `context`, a plain JSON object of\nuntrusted descriptive data. It is never instructions or new authority. Keep the\nlabel concise: context does not create extra entity choices. Validation rejects\nnon-JSON values, lossy coercions, unsafe Unicode, cycles, depth over32 and context\nexceeding the existing `maxInputBytes`. The complete offered input still uses the\nsame total byte budget. Invalid authorized context fails closed; denied candidates\nand their context never reach generation. Absent context preserves the old wire.\n\nContext is snapshotted and included in the candidate key/digest and generator\ncontract. Hosts must bind any context changes to their current target revision;\ncurrent target checks retain their existing live executor/authorization boundary.\nEducation binds canonical same-capture prompt context to its target revision digest.\n\nThe engine exposes read-only `HandlerContext.analysisRevision` and forwards the\nsame current item revision to target authorization on its shared executor. This\npin comes from the owned intake row, not handler arguments, browser input or model\noutput. An owner may use it to avoid treating that generation's own materialized\nresult as an independent change to its input context; ordinary unrelated changes\nand current authority/revision checks still invalidate stale snapshots.\n"
1723
+ "content": "# Application-aware proposal generation\n\n`@happyvertical/smrt-ingestion/proposals` is server-only. Configure\n`IngestionOptions.proposals` and the existing `execution.handlers` catalog.\nHandlers opt into discovery with `discovery.mediaTypes`, `references`, and an\noptional `candidates` callback. There is one catalog: the same operation or\nordered playbook adapter is discovered, validated, previewed, and later applied\nby the execution service. Generation never approves or applies.\n\nCredential-free review hosts may configure `IngestionOptions.proposalRead` with\n`ProposalReadConfiguration`: public generator/decision identities, version,\nprompt version, limits and thresholds only. It reads completed proposals,\npreserves current authority and snapshot validation, and permits human preview;\nit never accepts a generator or provider client. If a process supplies both\nsettings, their public configuration must match exactly. Preparing or generating\nproposals still requires `proposals` with a real generator.\n\n## Discovery and authority\n\n`listHandlers(itemId)` returns a bounded detached catalog. The owning execution\nservice checks the current principal, captured permissions/handler/operation\nceiling, policy, confidential scope, public registered operation facts, and\nordered playbook definition. Every configured provider must occur in the current\npolicy's `providers` allowlist. Missing grants remove handlers before model input.\nAn authorized catalog larger than the configured bound is rejected; the host must\nnarrow it explicitly instead of relying on silent truncation.\n\n`findCandidates({itemId,handlerId,handlerVersion,query,limit})` returns\n`{items,truncated}`. Its trusted handler callback receives `HandlerContext` with\nthe authorized transaction executor. Query by tenant and confidential scope\n**before** selecting, ranking, or building labels. Use a bounded query (often\n`limit + 1`) and report `hasMore`. The service projects candidate identity, model,\nrevision and label, then checks every target with the owning execution callback.\nThere are no hidden counts or pagination tokens. Truncated discovery forces\n`needs_review`; a person may still preview it explicitly, and automation never\nbecomes eligible.\n\nCompleted generation reload checks process authority, the current attempt, and\nowner/candidate visibility in the same final transaction. Database-backed grant\ncallbacks must use the supplied executor. The owning retention lifecycle encloses\nthat transaction so a denied read cannot roll back an authorized shorter privacy\nceiling; restoration starts only after the outer transaction has rolled back.\n\nCandidate callbacks perform bounded database reads only: no provider I/O, network,\nor domain mutations. Target locks and existing retention enforcement remain\nowned by execution. Hosts configure their database's statement deadlines; an\narbitrary trusted callback is not a sandbox. Each existing-record argument must\nbe a declared top-level `references` field of kind `candidate` with its qualified\nmodel, or `evidence`. Closed JSON argument schemas are required. The host owns\nthat declaration and its target authorization semantics.\n\n## Durable stages\n\n1. Complete extraction through the existing analysis ledger.\n2. Call `prepareGeneration(itemId, extractionAttemptId)`. It reads the current\n completed/partial immutable extraction and returns configuration with\n `stage: 'interpret'`, pinned source attempt/revision/input/output/evidence\n digests, prompt/configuration/catalog/provider versions, limits and thresholds.\n3. Pass that configuration to `analyze(itemId, configuration, requestKey)` and\n claim its new revision with `claimAnalysis`.\n4. The host's existing job callback routes on the frozen `configuration.stage`:\n extraction invokes `extractAnalysis`; interpretation invokes\n `generateProposals(lease)`.\n5. Reload the current completed generation using `getCompletedAnalysis(itemId)`,\n or pass an explicit attempt ID to additionally reject stale client state.\n Queued/running revisions never return an older completed attempt.\n\n`analyze` refuses an interpretation configuration whose pinned source is not\nthe item's latest extraction, checked under the item lock before anything is\nsuperseded (`GenerationSourceStaleError`, nothing appended). A preparation\nsuperseded by a later extraction therefore fails at append time rather than\nafter a revision was created.\n\nA generation revision does not rewrite terminal extraction. Reprocessing starts\nwith a new extraction revision, followed by interpretation, while the host keeps\nthe same business intention keys. An interrupted still-current generation lease\ncan be retried; terminal generation output remains immutable. `getGenerationInput`\nreads historical extraction only through the current generation lease and its\nfrozen source pin. It verifies same-item scope, immutable hashes, durable evidence,\nand current process permission before returning detached data. The source must be\nthe immediately preceding revision, so an intervening reprocess invalidates a\nprepared generation. Completed generation reads additionally recheck current\ncatalog and target visibility before disclosing persisted candidate labels.\nExpired, cancelled, revoked, retried or superseded workers cannot read or publish late output. The\ncurrent lease and each offered handler/candidate are rechecked immediately before\neach outbound generative/decision boundary and before publication.\n\n### Inline interpretation\n\nReceipts created with `dispatch: 'inline'` (text/structured parts only) run the\nsame stages in-process through `interpretInline(itemId, { requestId, extraction\n})`: an immutable extraction revision claimed under a fenced lease and extracted\nwith the built-in UTF-8 extractor, then `prepareGeneration` and a fenced\ninterpretation revision generated by `generateProposals`. The analysis lease,\ncatalog digest and live catalog/candidate checks, source pin, provenance and\n`StageFailure` categories are identical to the job path; no dispatch intent is\never deliverable and nothing is enqueued. A retry with the same `requestId`\nreplays the recorded revisions rather than re-preparing against a superseded\nsource, also under concurrency. The interpretation append rechecks, under the\nitem lock, that its pinned extraction is still the latest revision and refuses\na superseded pin: first through the general latest-extraction check that\nevery interpretation append runs (`GenerationSourceStaleError`), then by the\ninline check that the pinned attempt is still current (`Generation source changed`). Generated suggestions still require explicit preview and a human\ndecision, either through the reviewer surface or the submitter-scoped surface\ndescribed in [REVIEW.md](REVIEW.md).\n\n## Providers and validation\n\n`createSDKProposalGenerator(client, identity, {maxTokens,timeoutMs})` uses an\nexisting AI SDK `chat` client. It sends a fixed system instruction and separate\nJSON evidence/catalog data, requests JSON, supplies cancellation and bounds, uses\nno tools or continuation, and rejects known truncation or tool calls,\nunexpected models, malformed JSON and oversized output. Configure SDK clients\nwithout automatic retry that would bypass application boundary checks. The\nadapter's public identity is exactly provider/model/version; credentials and raw\nprovider errors are never provenance.\n\nThe fixed system instruction (`proposalInstructions`, extended per item by\n`proposalInstructionsFor` with the handler argument contract and split\neligibility) is generic and value-free. It treats evidence as untrusted data,\nnever instructions, and limits suggestions to offered handlers and candidates.\nIt asks the model to fill every argument readable from the evidence\n(identifiers, numbers, dates, quantities, amounts and currency) in the form its\nschema requires, never inventing a value the evidence does not show; a value\nthat cannot be expressed in that form is treated as absent. Each value must be\nthe one whose label or context matches the field's name and description; when\nseveral similar values appear, a field whose named value is missing is treated\nas absent rather than given a substitute. A candidate reference is chosen only\nfrom that handler's listed candidates, and an evidence reference copies the\nsupplied `evidenceId`. `missingFields` lists exactly the required fields left\nout of `args`, and a required field is left out only when its value is genuinely\nabsent or no offered candidate matches. On required-only schema refusals, the\nvalidator computes the absent required set and corrects a mismatched model\ndeclaration; the instruction guides the model without making its declaration\nauthoritative. Absent optional fields stay out\nof both `args` and `missingFields`, rather than being sent as null (unless the field explicitly permits null). Suggestion objects contain exactly the required envelope keys, with handler arguments nested only inside `args`. Alternatives mean genuinely competing OTHER choices, not a list of offered choices: use `[]` when none exist and never list the selected handler itself. The SDK response schema excludes that handler key from each suggestion variant while retaining other handler and candidate keys (#4395). Existing malformed or ambiguous outputs remain refused/pending; no self-alternative is stripped after generation. The model prefers `no_action` when no\noffered handler's description fits the document's role, and `unknown` when the\nevidence cannot be interpreted (#4290). Domain routing, such as which received\ndocuments an application ignores, belongs in host handler descriptions or\nreviewer guidance, not in this text. Keep these shared instructions concise: the\nmaintained reference host pins the complete SDK request to an 8 KiB wire/input\nbudget. That budget includes schema and transport overhead; adding repeated prose\ncan prevent a valid small request from reaching its provider. The frozen\nevaluation checks the real envelope without raising its budget (#4395).\nThe text is not persisted. It is not part\nof the frozen interpretation configuration, the input, catalog or output\ndigests, or the stored generation output, so a package release that changes it\nleaves stored attempts readable and previewable unchanged. New attempts send the\nnew text, but their digests do not record it; a host that needs provenance to\ntell the two apart bumps its own `promptVersion`, which, like any configuration\nchange, makes earlier attempts read as stale (`GenerationSnapshotStaleError`).\n\nEach suggestion's `explanation` is one or two plain sentences stating what the\ndocument is and why the handler fits, with no deliberation, self-correction or\nrestating of the rules, and is bounded at 300 code points (#4331,\n`PROPOSAL_EXPLANATION_LIMIT`). Two such sentences run about 150-250\ncharacters; the bound keeps a verbose model from spending its output budget\n(and hitting the `length` finish reason) on prose instead of arguments. A\nreply cut at the token limit is still refused (`finish_reason`) and partial\nJSON is never salvaged; the grammar bound and the instruction are what keep\nreplies under the limit. The provider schema and the validator carry the same `maxLength`, so the provider\ncopy still accepts a superset of the validator (#4261), and a grammar backend\nenforces the bound while decoding. In the provider schema `explanation` is the\nlast suggestion property, after `handlerId`, `handlerVersion`, `args`,\n`evidence`, `alternatives` and `missingFields`, and the top-level keys are\n`outcome`, `suggestions`, `splits` in that order; `required` lists the same\norder. That order predates #4331 and is now pinned by a test, so explanation\nprose cannot precede the arguments. xgrammar emits object properties in schema `properties` order unless\n`any_order` is set (its default is `false`, and vLLM does not set it), and\nllguidance fixes property order to the `properties` map, then `required`. A provider\nthat ignores the schema can still return a longer explanation: fresh output is\nnormalized after the list deduplication above and before validation, cutting\nit to 299 code points plus `…` on a code-point boundary, so a long explanation\nnever fails validation (the raw output-size and SDK `output_limit` checks\nstill run first). The value-free count is recorded as\n`provenance.explanationsTruncated`, absent when zero and removed with\n`duplicatesRemoved` whenever the suggestions are discarded. It counts only\nreplies from providers that ignore the schema: on a grammar backend such as\nvLLM the string closes at 300 code points with no marker, and nothing is\ncounted. The cut happens\nbefore the invented-target echo check, so an echo beyond the bound is no\nlonger seen; explanation text is never a target or authority.\n\nReplay: the bound, the property order and the instruction text feed no digest.\nThe response schema is built per request and never persisted; the frozen\ninterpretation configuration holds versions, identities, the catalog digest and\n`limits`, none of which include the explanation bound. Stored attempts are read\nas persisted, never re-validated or re-cut, so an earlier attempt with an\nexplanation of up to 2000 characters still reads, previews and replays with\nits original `output_digest`. New attempts' digests cover the bounded form.\n\nA trusted custom `ProposalGenerator` must likewise honor cancellation, bound its\nresponse, and explicitly declare validated `complete` or `unknown` completion.\nThe SDK currently normalizes missing/unknown finish reasons to `stop`\n([owning SDK follow-up](https://github.com/happyvertical/sdk/issues/1381)), so its\nadapter conservatively declares `unknown`, persisted as\n`generation_completion_unknown`. Otherwise valid suggestions remain available\nfor human preview; automatic eligibility always remains false. The service\ndeadline aborts requests and prevents late publication; it does not claim to terminate computation at a remote\nprovider or isolate native allocations. Extractor process limits remain separate.\n\nWhen the pinned extraction carries an authenticated reviewer instruction\n(REVIEW.md), `prepareGeneration` copies it into the interpretation configuration\nand `generateProposals` verifies that copy against the extraction record and its\nown digest before provider disclosure (`integrity` otherwise). The prompt then\ncarries it in its own **trusted reviewer guidance** section after the fixed\nsystem instruction and handler contract: the guidance is named as authenticated\nhuman input, limited to the offered catalog, and the evidence remains untrusted\ndata. `GenerativeProposalInput.reviewerInstruction` exposes `{id, text}` to custom\ngenerators; `provenance.reviewerInstruction` records `{id, digest}`. The\ninstruction never changes `offered`, `catalogDigest`, argument schemas,\npermissions or `automaticActionEligible`; a reply that follows guidance outside\nthe catalog fails validation like any other hostile output. **Budget cost:** the instruction counts once against the input budget\n(`maxInputBytes`, each offered handler's `maxBytes` and the live policy\nceiling), as its JSON-escaped text inside the prompt's guidance section — up\nto 4,000 characters plus escaping and the fixed guidance sentence. The\n`reviewerInstruction` field duplicated for custom generators is not counted\nagain. The decision stage also carries it once: its request state holds the\nevidence-side input with the un-guided base instructions under `evidence`, and\nthe guidance only under a separate `reviewerGuidance` key, never under\n`evidence`; the decision budget measures that serialized request as sent. Size `maxInputBytes` with that headroom. Learned examples are\nstill retrieved for an instructed generation; only a logical split correction\nsuppresses them. Every instruction costs a fresh extraction revision before the\nnew interpretation: the predecessor-pin contract above (source = immediately\npreceding revision, current-revision reads) is deliberately left intact rather\nthan reused for a same-source second interpretation, so OCR/speech hosts budget\none extraction per instruction, as for split corrections.\n\nModel output can contain only offered handler versions, schema-valid arguments,\nretained evidence locations and offered alternative handler/candidate keys.\nCandidate IDs must occur in the offered set, and evidence IDs in retained source\nresults. Unknown enums, invented IDs, extra authority/tool/approval fields and\nmalformed structures fail closed (an invented candidate target alone is dropped\nfor review instead, see below). Missing required fields are retained as\n`missingFields`, with `needs_review`; values are never invented to satisfy a\nschema. Observed page/time/source granularity is preserved. Logical scan splits\nuse `proposeDocumentSplits`; originals and hashes remain intact.\n\nWhen a suggestion's arguments fail the handler schema **only** on `required`\n(#4284), the suggestion is kept rather than rejecting the attempt: its\narguments stay exactly as generated and `missingFields` names every missing\nrequired argument. The schema, not the model, decides what is missing. A\ndeclaration that matches the computed set (in any order) is kept exactly as the\nmodel wrote it, so an already valid reply is unchanged byte for byte and replay\nstays deterministic. A declaration that differs (unlisted misses, or listed\nfields that are present or optional) is replaced by the sorted computed set and\nthe suggestion is `needs_review` even when nothing is left missing;\n`provenance.missingFieldsCorrection` then records `{suggestions, added,\nremoved}` counts only, and is absent otherwise and dropped whenever the\nsuggestions are discarded. A miss at the\nargument root is the bare property name; a miss inside a present nested object\nor array item is an RFC 6901 JSON Pointer relative to the arguments, such as\n`/vendor/name` or `/lines/0/sku`. An entry starting with `/` is therefore a\npointer, so a handler should not declare a root property whose name itself\nstarts with `/`. Names come from the handler schema's own `required` lists,\nnever from argument values or model-chosen keys; `required` inside `allOf` or\ninside object-form `dependencies` (`{a: {required: ['b']}}`) counts like any\nother. The schema walk does not follow `$ref`: a miss directly at a property\nwhose schema is a `$ref` is kept, but a miss deeper inside the referenced\ndefinition cannot be named from the schema and rejects (fail-safe). The attempt still rejects as before when any other\nkeyword fails beside or instead of `required`: type, enum, pattern, bounds,\n`additionalProperties`, an `anyOf`/`oneOf` branch, an `if`/`then`/`else` branch\n(Ajv adds an `if` error), `not`, or array-form `dependencies` (its own keyword,\nalthough it names the missing property). It also rejects when a miss lies under\na key the schema does not declare, or when more than 30 fields are missing.\nHandler schemas compile in Ajv strict mode, so draft-2019 keywords such as\n`dependentRequired` are refused at compile time. Such a suggestion is ordinary\n`needs_review` output: the decision gate can only withhold readiness, never\ngrant it, `automaticActionEligible` stays false, and generated preview of\nincomplete arguments fails the handler schema (see Explicit preview below).\n\nA generated split whose groups fail that check is dropped, not the whole reply\n(#4288): the suggestions and any other splits are validated as before, the\ndropped split is never published or applied, and `provenance.splitsDropped`\nrecords `{count, checks: ['split_groups']}`, never pages or evidence ids. Any\nother split error still fails the attempt. If every split is dropped, the reply\nhas no split; a reviewer can still split through `reviseLogicalSplit`, and a\nrecorded split correction the reply no longer matches ends as\n`human_split_not_respected`. A split for unknown or repeated evidence is still\nrejected, even when the earlier split on that evidence was dropped. Like\n`duplicatesRemoved`, `splitsDropped` is kept only on a published, validated\nreply. Stored output is never re-validated, so earlier attempts and their\ndigests replay unchanged.\n\nAn invented target — a value in an offered handler's candidate reference field\nthat is not among the offered candidates for that field's model — no longer\nrejects the attempt (#4289). The validator drops the key from the arguments\n(no placeholder) and revalidates what remains through the required-only path\nabove: a dropped required field becomes a computed `missingFields` entry, a\ndropped optional field is simply absent, and either way the suggestion is\n`needs_review` for the reviewer to choose an offered target.\n`provenance.unofferedTargetsDropped` records `{suggestions, fields}` counts\nonly, never IDs, labels or field names; it is absent when nothing was dropped\nand removed whenever the suggestions are discarded. Every candidate field that\nstays in the arguments has been checked against the offered set, so no\nunoffered value survives as a target. The attempt still rejects as before for\nan unoffered handler or alternative, unknown evidence (argument or reference),\na non-string target, a target field the handler schema does not declare in\n`properties`, any other argument error, or a drop that exposes a refusal other\nthan `required`.\n\nThe exact dropped value is also searched for in the kept suggestions and splits\n(JSON-escaped, keys included); an exact echo, such as the ID repeated in an\nexplanation or another argument, rejects the attempt. This guard fails closed\non short or common values: a dropped `\"1\"` or `\"a\"` almost always occurs\nsomewhere else in the output, so such a reply rejects rather than being kept.\nIt is an exact-match check, not a general leak filter: a case variant, a\nreformatted copy or a fragment of the ID in free text (an explanation or a\ntext argument) is not detected and may reach the reviewer as ordinary model\nprose. Free text is never a target and never authority; only the checked\ncandidate fields are.\n\nA rejected reply ends the attempt as `provider_error` with the `malformed_output`\nwarning and a bounded, value-free `provenance.failure` `{category, reason}` (#4207).\nThe reason lists schema-owned paths, keywords and schema constants, for example\n`/outcome enum (allowedValues=proposals|unknown|...)` and\n`/suggestions/0 required (missingProperty=evidence)`, or the fixed internal check\nand its path, such as `Unoffered handler: /suggestions/0`. Path segments are\nkept only when they are keys declared under the schema's `properties` or\nindexes into a value that actually is an array in the rejected reply; any other\nsegment, numeric or not (for example a key under an open\n`additionalProperties` argument sub-schema, or a numeric key of an object),\nbecomes `?`, and an extra property's name is never echoed.\nIt never contains document text, argument values, evidence content or\nmodel-chosen keys, is cut at 1000 characters,\nand is dropped before the output-limit fallback. Hosts read it from the\ncompleted/partial analysis at `analysis.result.output.proposals.provenance.failure`.\nThe SDK adapter constrains replies with a `json_schema` response format built\nfrom the validator's schema and the fixed instructions describe the shape; a\ncustom `ProposalGenerator` receives no schema, so its raw reply meets the\nvalidator directly and the same reason is recorded.\nThe provider-facing schema is made portable (`portableResponseSchema`, #4260):\nkeywords that common OpenAI-compatible structured-output backends reject are\nremoved at schema positions, including inside handler argument schemas\n(`uniqueItems`, `contains`, `multipleOf`, `format`, `patternProperties`,\n`propertyNames`, `min`/`maxProperties`, `not`, `if`/`then`/`else`,\n`dependent*`, `unevaluated*`, and the `default`/`examples` annotations; the\nfull list and reasons are in `src/proposal-sdk.ts`). With `uniqueItems`, for\nexample, vLLM's xgrammar feature check flags the schema, its auto mode routes\nit to llguidance, and llguidance answers\n`400 Grammar error: Unimplemented keys: [\"uniqueItems\"]`. This only loosens the\ngrammar: the validator still enforces the constraints, including unique\n`alternatives` and `missingFields`, and the fixed instructions ask for distinct\nentries. The exception is `format`, which is advisory: the validator runs Ajv\nwith `validateFormats: false`, so `format` is enforced nowhere. Because a model\ncan still repeat an entry, fresh generator output is normalized first (#4286):\nwithin each suggestion, repeated `alternatives` and `missingFields` entries\n(equal by canonical JSON) are dropped, keeping the first. Nothing else is\nrewritten, and `uniqueItems` still applies to the result. The count, never the\nvalues, is recorded as `provenance.duplicatesRemoved`, present only when\nnon-zero and only on a published, validated reply. The published output, and so\nits digest, is the normalized form. Stored attempts are read and replayed as\npersisted; they are never renormalized. When\n`patternProperties` is removed, the same object's `additionalProperties` is\nremoved too, so the grammar does not shrink to `{}`. The `contentSchema` annotation is omitted as well, so nested unsupported\nconstraints cannot leak through an unvisited schema position. A backend may\nrecursively inspect typed schema-like objects even inside `enum` or `const`\ndata. When such data contains an unsupported keyword, the whole containing\n`enum`/`const` constraint is omitted conservatively; literal data is never\nrewritten. Harmless property names and ordinary enum/const data stay intact.\nThe original validator remains authoritative for omitted literal constraints.\nThere is no automatic `json_object` fallback.\n\nInvariant: the provider copy only ever accepts a superset of what the original\naccepts. Each removed keyword is a conjunct, so removing it only widens. The two\nplaces where removal would narrow are rewritten:\n- every `oneOf` becomes `anyOf` (or joins an existing `anyOf` through `allOf`),\n because loosened `oneOf` branches could both match and reject a value the\n original accepted;\n- an object that loses `patternProperties` also loses `additionalProperties`.\n\nProvider-only `$ref`, `$dynamicRef`, and `$recursiveRef` constraints are also\nremoved. Rewriting or deleting a subschema can invalidate pointer or anchor\ntargets, including targets inside nested `$id` resources. Dropping references\nconservatively widens the grammar without resolving untrusted schema resources;\nproperty names and enum/const data named `$ref` remain unchanged. Referenced\nconstraints, recursion, and dynamic scope remain enforced by the original\nvalidator, so provider guidance for reference-based arguments is less precise.\n\nThe validator still checks the original, including `oneOf` exclusivity. A\nproperty-style regression checks original-valid ⇒ portable-valid across the\nremoved keywords. Handler argument schemas may still carry `allOf` through\nunchanged; its support across backends is unverified, so check such a handler\nagainst the deployed backend.\n\nA generator call that throws ends the attempt as `provider_error` with the\n`unavailable` warning and `provenance.failure` `{category: 'unavailable',\nreason}`. The reason is value-free by construction: a provider's own text can\nquote the prompt or document, so it is never copied. The reason is built only\nfrom a fixed phrase and:\n\n- for an SDK `AIError` only, the HTTP status (from a structured field, or from\n the exact `<status> ...` / `TypeSafe request failed (<status>): ...` shapes\n the SDK produces), the SDK error code (from the closed list of codes the SDK\n raises), for a schema rejection the quoted tokens that are JSON Schema\n keywords, and the OpenAI SDK's exact fixed transport messages\n (`Connection error.`, `Request timed out.`, `Request was aborted.`,\n `(no status code or body)`), which its `mapError` keeps without a cause;\n- for the SDK adapter's own refusal of a reply it did receive, a fixed problem:\n finish reason other than `stop` (named from the closed list `stop`, `length`,\n `tool_calls`, `content_filter`, otherwise `other`), truncation, tool calls,\n an unexpected response model, no text content, an empty reply, a reply over\n the output limit, or a reply that is not valid JSON (#4285);\n- for any other error (#4285), the code-defined constructor name (an\n identifier ending in `Error` or `Exception`; never the settable `name`),\n an `AbortError`/`TimeoutError` name, a network `code` from a closed list\n (`ECONNREFUSED`, `ECONNRESET`, `ETIMEDOUT`, `ENOTFOUND`, `EAI_AGAIN`,\n `UND_ERR_*`, TLS certificate codes, ...) read from the error, up to three\n `cause` levels and an `AggregateError`'s entries, and a structured numeric\n status. A timeout or abort is named as one, except that a structured HTTP\n status always wins over an abort name or network timeout code on a non-SDK\n error, whether on the error itself or in its cause chain. An SDK error's\n abort is read only from its code or exact transport message.\n\nFor example: `provider rejected the response schema (HTTP 400, code API_ERROR);\nunsupported response-schema keywords: uniqueItems`,\n`provider response incomplete (finish reason length)`,\n`provider call failed (class TypeError, network ECONNREFUSED)`,\n`provider call aborted or timed out (class DOMException, name TimeoutError)`, or\n`provider call failed (class Error)`. It is cut at 500 characters.\n\n**Why some failures were a bare `provider call failed` (#4285).** The SDK\nadapter's own response checks threw plain `Error`s (finish reason not `stop`,\ne.g. `length` when the reply reached `maxTokens`; truncation; tool calls; an\nunexpected response model; non-text or oversized content) and `JSON.parse`\nthrew a `SyntaxError` for an empty or non-JSON reply. The reason deliberately\nreads nothing from a non-SDK error, so all of these collapsed into the fixed\nphrase. Transport failures through the OpenAI SDK already carried\n`code API_ERROR`. The adapter now raises `ProposalResponseError` with a fixed\nproblem, and other non-SDK errors contribute the transport facts above. The\ncategory is unchanged (`unavailable`).\n\n### Host suggestion review (`reviewSuggestion`)\n\nA host's own checks on a generated suggestion (a label that is not the invoice\ndate, an amount that is not in the document) can hold it and leave a record a\nreviewer sees:\n\n```ts\nproposals: {\n // ...\n reviewSuggestion: ({ suggestion, handler, evidence }) => ({\n hold: true, // optional; forces needs_review\n reasons: ['total_not_in_text'], // optional; <= 8 codes, /^[a-z][a-z0-9_.-]{0,47}$/\n prefilled: ['billDate'], // optional; names declared in handler.argsSchema.properties\n }),\n},\n```\n\nThe hook is trusted, server-only and optional. It runs once per validated\nsuggestion, after validation and before the decision gate, with deep copies of\nthe suggestion, its offered handler and the retained evidence text. It cannot\nchange `args`, `missingFields`, evidence or the outcome except through `hold`,\nand it can never upgrade: `hold` sets the suggestion (and a `proposals` outcome)\nto `needs_review`; absent or `hold: false` leaves the validator's disposition.\n\nThe result is stored as `suggestion.hostReview` (`{held, reasons, prefilled}`)\nand counted in `provenance.hostReview` (`{annotated, held}`); both are absent\nwhen the hook records nothing. Values cannot be stored: unknown keys, free-text\nor over-long reasons, `prefilled` names that are not argument names, and any\nreason code containing one of the suggestion's own argument values (3+\ncharacters) make the result invalid. An invalid result, a throw, a rejection or\na hook slower than `limits.timeoutMs` holds the suggestion with the fixed code\n`host_review_invalid` or `host_review_failed`; the error text is discarded.\n`ReviewView` shows \"Checked by the shop: ...\" under the arguments.\n\nLike `failureCapture`, the hook is not public read configuration and never enters\nfrozen configuration or digests. Hosts keep it synchronous-cheap: it runs inside\nthe generation lease.\n\n### Retry and concurrency (opt-in, #4504)\n\n```ts\nproposals: {\n // ...\n retry: {\n attempts: 3, // total calls, 1..10; default 1\n backoffMs: (attempt) => 500 * 2 ** (attempt - 2), // or a number, 0..60000; default 0\n retryable: (error) => (error as { status?: number }).status === 529,\n },\n concurrency: 4, // 1..1000; default unlimited\n},\n```\n\n`retry` retries a rejected `generator.generate` call; absent (or\n`attempts: 1`) keeps one call as before. `retryable(error, attempt)` sees the\ngenerator's rejection (default: retry every rejection; a throwing predicate\nmeans no). Each call gets its own `limits.timeoutMs` deadline; a timeout is\nfinal, as are validation failures of a returned reply. A retry is skipped when\nthe analysis lease could not cover the backoff plus another full deadline, and\na malformed `backoffMs` answer ends the retries. Only the final rejection is\nrecorded (`provider_error`, category `unavailable`, value-free reason).\n`concurrency` bounds `generate` calls in flight across every service built\nfrom the same configuration object (FIFO); a queued call's deadline starts\nwhen it gets a slot. Both are validated at `IngestionService` construction and,\nlike `reviewSuggestion`, never enter frozen configuration, digests or\n`proposalReadConfiguration`. A reviewer can still re-run a finally failed item\nwith \"Try again\" (REVIEW.md, `retryInterpretation`).\n\nIndependently of `retry`, a PostgreSQL deadlock (`40P01`) or serialization\nfailure (`40001`) in the database reads around the provider call (candidate\ndiscovery, feedback retrieval and the provider-boundary re-checks) re-runs that\nread up to five times with a short jittered pause (#4651). It is never\npublished as a failed attempt: one that outlasts those runs is thrown from\n`generate`, leaving the attempt unpublished for the next lease claim.\n\n### Failed-attempt capture (opt-in, #4285)\n\nThe value-free reason cannot show what the model actually sent. A host that\nneeds that for diagnosis can opt in to keeping it:\n\n```ts\nproposals: {\n // ...\n failureCapture: {\n enabled: true, // required; absent or false keeps capture off\n maxBytes: 16384, // default 16384, at most 65536 (UTF-8 bytes, after redaction)\n redact: ({ text, source }) => hostRedaction(text), // required to retain text\n },\n},\n```\n\n`ProposalConfiguration.failureCapture` is **off by default**. When enabled with\na host `redact` hook, a failed interpretation attempt (`provider_error`) keeps\none of:\n\n- `raw_response`: the reply text the SDK adapter refused (for example invalid\n JSON or a `length` finish), or\n- `generated_output`: the generator's parsed output, as JSON, that failed\n validation, the declared-completion check or the output limit.\n\nErrors without model output (transport, timeouts, authority, decision\nfailures) capture nothing. Successful attempts never store a capture.\n\nWithout a `redact` hook, only `status: 'redaction_failed'` metadata is stored,\nwith `redacted: false` and no text; the candidate text is not materialized.\nThere is no built-in sanitizer. Hosts own the hook's semantic redaction policy;\nthe service cannot verify that the returned text removes every document secret.\n\nThe text, cut to the larger of the generation `maxOutputBytes` and\n`maxBytes`, goes through the host `redact` hook, and the result is cut to\n`maxBytes` without splitting a character (`truncated: true` when either cut\napplied). NUL and unpaired surrogates are stored as U+FFFD so PostgreSQL JSON accepts the record. When\nthe hook throws, returns a non-string or exceeds its asynchronous wait budget,\nonly `status: 'redaction_failed'` is stored. The budget is the generation\n`timeoutMs`, cut to half of the analysis lease still left when the hook starts\n(no time left: the hook is not called). The hook runs after the authority\nrecheck, reserving the rest of the lease for the second recheck and publication.\nThis timer cannot preempt synchronous work or cancel the hook. Hosts must use\nbounded, nonblocking redactors. Missing or failed redaction does not replace the\nattempt's real failure or value-free reason; hook errors are discarded.\n\n**Where it lives.** In the attempt row's `data` JSON, as `failureCapture`\nbeside the result fields, never inside `result`: it needs no migration, is not\npart of `output_digest` or any configuration digest, never appears in\n`getCompletedAnalysis` or any other snapshot, and is not public read\nconfiguration (`proposalReadConfiguration` omits it, so read-only hosts still\nmatch). Proposal digests, replay and frozen generation configuration are\nunchanged by enabling it.\n\n**Reading it back.** Only\n`IngestionService.getFailedAttemptCapture(itemId, attemptId?)` returns it\n(`FailedAttemptCapture` from `/dto`, or `null` when nothing was stored). The\nattempt defaults to the item's current analysis attempt. It requires the\nexecution catalog and the current **reviewer** authority for that item (the\nsame gate as `getItemDisposition`) inside the caller's tenant and confidential\nscope; every denial, expiry, cancellation or foreign item fails closed before\nthe row is read. It is never part of a list DTO, inbox row, review page,\nlog line, checkpoint name, telemetry or error message.\nPublication and reads also reject a persisted `captured` record with\n`redacted: false`; capture text must be marked as processed by a configured\nhost hook. Persisted caps must remain within 1–65536 bytes, and captured text\nmust fit its declared UTF-8 byte cap; malformed records fail closed.\n\n**Retention and deletion.** It follows the item. There is no separate delete\nAPI: `expire`, `sweepRetention` and the `repairDeletions` retry of an\ninterrupted propagation all empty attempt `data`, which removes the capture\nwith the rest of the payload; a revoked item is unreadable before that.\n\n`createSDKProposalDecisionClient(client)` adapts an existing SDK client’s optional\ncapability without changing its errors or protocol. Optional `decision` uses public core `executeDecision` and the existing SDK\npredicate, choice, score and batch contracts. Supported-effect predicates,\nhandler classification, candidate entity matching, and action ambiguity/risk\nare distinct questions. Their validated probabilities and provenance are stored\nseparately from generative provenance and unknown OCR certainty. The complete\nserialized decision request, including suggestions and questions, must fit the\nminimum configured/current policy byte ceiling before capability probing and\nagain before deciding. A policy change between these boundaries fails closed.\nActually incomplete extraction always requires review. Unknown provider\ncompletion metadata is preserved as `source_completion_unknown`; it does not\nblock otherwise schema-valid **human** preview or imply completeness. Automatic\naction eligibility remains false. An unconfigured decision path\nis recorded explicitly. Configured errors produce a durable safe failure outcome;\nthey never silently switch to a generative decision fallback.\n\n### Decision readiness gate (#4209)\n\nFor every suggestion `i` the request asks `supported_i` (predicate),\n`route_i` (choice over the offered `handlerId@version` keys plus `none`),\n`risk_i` (ordered score over `clear`, `uncertain`, `ambiguous`) and one\n`entity_i_<field>` choice per candidate-reference argument. The validated\nanswers are always persisted under `provenance.decision.answers`. With the\ndefault `decisionReadiness: 'gate'` they are read as follows, and any failing\ncheck sets the suggestion to `needs_review` (a tie also sets the outcome to\n`ambiguous`):\n\n- `supported.probability >= minimumDecisionProbability` (default `0.8`).\n- `route.choice` equals the suggestion's own `handlerId@handlerVersion`,\n `route.confidence >= minimumDecisionProbability`, and the gap between the two\n largest route probabilities is greater than `tieMargin` (default `0.1`).\n- `risk.score < 1`: only the `clear` level passes; `uncertain` and `ambiguous`\n require review.\n- Each entity match chooses the suggested candidate's key with confidence at or\n above the threshold and a gap above `tieMargin`.\n\nThese values are provider outputs read as if they were calibrated\nprobabilities; nothing in this package calibrates them for this use. The\nteamworks-os measurement in #4209 (self-hosted Laya `typed-decisions`) found no\nseparation between right and wrong suggestions: a correctly read vendor invoice\nscored `supported` 0.37, garbage input 0.45–0.50, a wrongly proposed purchase\norder 0.51, route confidence 0.003–0.15 and `risk` ≥ 0.94, so the gate sent\nevery suggestion to review. Until a labelled sample shows separation, treat the\nanswers as diagnostics and configure:\n\n- `decisionMaxLen`: positive integer forwarded unchanged as the per-request\n `maxLen` of the decision client (the SDK Laya provider's token window; the\n checkpoint default is 1024 and the serialized evidence plus suggestions is\n otherwise truncated). Other clients ignore it.\n- `decisionReadiness: 'record'`: the decision still runs, is bounded and\n authorized exactly as before and its answers, usage, `readiness` and `maxLen`\n are recorded, but the gate never changes `outcome` or `disposition`; readiness\n comes from the validator alone (`missingFields`, outcome, source completeness).\n A client error or timeout is recorded as the `decision_unavailable`\n warning. A reply that comes back and then fails the core `executeDecision`\n identity or answer-shape check is recorded as `decision_malformed` with the\n reply's usage; this is the path for injected `DecisionClient`s. SDK clients,\n including the Laya provider behind `createSDKProposalDecisionClient`,\n validate the reply's shape inside `client.decide` and throw, so a malformed\n SDK reply is recorded as `decision_unavailable` with no usage. Every case\n records the `provenance.decision` identity. The generated suggestions stay\n as they were. The serialized request exceeding the byte budget is a\n configuration failure, not a provider answer: it ends the attempt as `limit`\n in both modes, and in `gate` mode every failure above still ends the attempt\n as `provider_error`. Lease, catalog, policy and provider-allowlist revocation\n fail closed in both modes.\n\nSuccessful output also records `provenance.decision.readiness` (`'gate'` or\n`'record'`) and `maxLen` when set; configuration digests are unchanged, but\npersisted output is therefore not byte-identical to earlier releases.\n\nBoth settings are public configuration: they are part of\n`ProposalReadConfiguration`, the frozen `GenerationStageConfiguration.proposals`\n(present only when set, so existing digests are unchanged) and the completed\nsnapshot authority check. Invalid values fail at proposal service construction.\nNeither mode affects automation: `automaticActionEligible` stays `false`, and\n`authorizeAutomatic` reads only the host's `evaluateAutomatic` callback and\npolicy, never these answers.\n\nOutput records zero, one or multiple suggestions, alternatives, missing fields,\nsource links, proposed splits, versions, allowlisted usage, warnings and explicit\n`unknown`, `ambiguous`, `no_action`, `needs_review` or `provider_error` outcomes.\n`automaticActionEligible` is always false. Provider input/output and the complete\nserialized persisted envelope are bounded by configuration, live policy and the\nreceipt ceiling. Oversized output becomes a bounded review/limit result; when\nno safe envelope fits, the owning service records fixed `failAnalysis` metadata\noutside the provider payload budget without retaining provider output.\n\n## Explicit preview and stable intentions\n\nThe host chooses persisted suggestion indexes and calls:\n\n```ts\nawait service.previewGeneratedProposals({\n itemId,\n attemptId: generationAttemptId,\n selections: [{\n index: 0,\n intentionKey: 'document:meeting-2026-10-09',\n expectedRevision: 0,\n requestId: 'review-request-1',\n }],\n});\n```\n\n`intentionKey` is the host's stable business-intention identity across generation\nrevisions. Never derive a fresh key from model output, suggestion order or a retry.\nSelections must reference current persisted validated `ready_for_review` or\n`needs_review` output (#4208); a `provider_error` attempt, an unoffered handler or\na non-interpretation stage is rejected. A `needs_review` suggestion whose\n`missingFields` are still absent fails the handler schema inside the ordinary\npreview (`HandlerArgumentsInvalidError`, `Invalid handler payload`, whose\nvalue-free `issues` name the missing schema fields, for example\n`{ path: '/title', keyword: 'required' }`; see REVIEW.md) and publishes\nnothing; the reviewer supplies\nthe missing values through the explicit human path (`previewProposal` /\n`previewPlan`, as the published review host does for `preview({args})`), and the\nhandler's `validate` and `preview` run again on the completed arguments.\nEach batch requires distinct suggestion indexes and intention keys; duplicate\nindexes are rejected before any operation or plan preview is written.\nThe service rechecks current catalog/schema/target/source provenance, then calls\nthe existing operation or plan preview. Each result still requires the ordinary\nhuman review and execution APIs. Reprocessing creates no new business identity;\nsuccessful-action replay protection stays with execution.\n\n## Evidence and limits\n\nThe test matrix is `docs/test-matrix/3673-ingestion-proposals.md`. SQLite and real\nPostgreSQL suites exercise authority, revisions, abstention, hostile output,\ncompound proposals, split provenance and reviewed domain effects. The upload\nreference composes authenticated multipart delivery of a generated embedded-text\nPDF through the actual packaged PDF child, durable interpretation, and the existing\nordered ContentDocument draft/retained-asset plan. It checks duplicate delivery,\nunauthenticated and foreign-tenant denial, explicit approval of both steps,\nidempotent execution replay, page provenance, and unchanged original bytes.\nThe compound-email case uses a declared messages-owner snapshot fixture.\n\nLocal HTTP fixtures execute the actual AI SDK transport and cancellation contract.\nGenerative responses and the separate injected PDF split boundaries establish\ndeterministic orchestration, not model accuracy or OCR quality. No held-out routing\nevaluation or automatic approval is claimed. Missing/unknown AI completion remains\nexplicit under [SDK #1381](https://github.com/happyvertical/sdk/issues/1381).\n\nProposal limits are checked at `IngestionService` construction: positive safe\nintegers, at most 20 handlers/candidates/suggestions and 2147483647 ms timeout.\nInterpretation output uses the exported `GenerationAnalysisOutput` wrapper at\n`analysis.result.output.proposals`; the published review host unwraps it.\nAn explicit feedback `retrieve` denial omits optional examples and feedback\nprovenance and continues generation. Item/execution denials, unexpected failures,\nand revocation after examples were selected still fail closed before disclosure.\n\n## Storage-safe provider text (#4393)\n\nAfter the normal output-byte ceiling, generation validates decoded JSON object\nkeys and nested string values for PostgreSQL's unsupported NUL and unpaired\nUTF-16 surrogate characters. A refusal is `malformed_output` with a fixed,\nvalue-free reason, before either accepted or refused suggestion arguments can be\nretained. Provider content is never stripped, repaired or treated as authority.\nLiteral backslash-u text and valid supplementary Unicode remain unchanged.\n\nThe generic `completeAnalysis` publication boundary independently checks the\nwhole result, including provider metadata and diagnostics. An invalid result\nrecords the exact current fenced attempt as `needs_attention/malformed_output`\non the same authorized executor and completes its dispatch; it produces no\ncompleted analysis, proposal or execution. Originals remain readable, and a\nfresh authorized analysis revision can retry without rewriting the failed one.\nExisting byte limits and current authority/fence checks still apply.\n\nOptional failed-attempt capture uses the existing private, reviewer-authorized\nhost redaction policy. Unsupported generated JSON can be retained there as its\nJSON-escaped diagnostic representation; it is never copied into a successful\nproposal or returned in ordinary snapshot payloads. Without an enabled redactor,\nno raw diagnostic text is retained. Shared foundation/proposal tests exercise\nSQLite and actual PostgreSQL JSONB writes, invalid keys and values, lone high/low\nsurrogates, valid emoji/literal escapes, source retention, retry and capture policy.\n\n\n## Descriptive candidate context\n\nA discovery candidate may include optional `context`, a plain JSON object of\nuntrusted descriptive data. It is never instructions or new authority. Keep the\nlabel concise: context does not create extra entity choices. Validation rejects\nnon-JSON values, lossy coercions, unsafe Unicode, cycles, depth over32 and context\nexceeding the existing `maxInputBytes`. The complete offered input still uses the\nsame total byte budget. Invalid authorized context fails closed; denied candidates\nand their context never reach generation. Absent context preserves the old wire.\n\nContext is snapshotted and included in the candidate key/digest and generator\ncontract. Hosts must bind any context changes to their current target revision;\ncurrent target checks retain their existing live executor/authorization boundary.\nEducation binds canonical same-capture prompt context to its target revision digest.\n\nThe engine exposes read-only `HandlerContext.analysisRevision` and forwards the\nsame current item revision to target authorization on its shared executor. This\npin comes from the owned intake row, not handler arguments, browser input or model\noutput. An owner may use it to avoid treating that generation's own materialized\nresult as an independent change to its input context; ordinary unrelated changes\nand current authority/revision checks still invalidate stale snapshots.\n"
1724
1724
  },
1725
1725
  {
1726
1726
  "path": "FEEDBACK.md",
1727
1727
  "module": "FEEDBACK",
1728
- "content": "# Explicit ingestion feedback\n\nConfigure `IngestionOptions.feedback` to opt in. The existing `intake_feedback`\nledger owns these records; no new schema, embedding service or provider is added.\n`FeedbackConfiguration` sets a version, maximum examples, scan count, serialized\nbytes and lexical similarity threshold, plus a live scoped authorization callback.\nHard ceilings are 20 examples, 1,000 scanned records and 1 MB. Choose substantially\nsmaller application limits. The proposal's complete serialized request, including\nexamples, must also fit the current minimum application/source/provider budget.\n\n`recordFeedback` accepts the exact displayed action revision, review version and\nbinding hash, an explicit correct/incorrect judgment, optional reason text and a\nrequest ID. The server resolves reviewer, tenant/confidential scope, retained\nsource evidence, extraction/generation versions and current handler arguments.\nA replay returns the same immutable receipt; changed payloads conflict.\n`supersedesId` appends a replacement for the specified prior interpretation\njudgment. A second successor conflicts. Revised actions make old bindings\nineligible. Approval and successful execution never imply that extracted fields\nare correct.\n\nOptional `feedback.onRecorded({ db, scope, receipt, input })` (#4522) runs\ninside the transaction that stores an explicit judgment, on the same executor,\nafter the judgment row (and its `supersedesId` link) is written and before the\nfinal `capture` recheck. Write the host's own activity entry there: it commits\nor rolls back with the judgment, and a throw rolls the judgment back and\nrejects `recordFeedback` with that error. `receipt` and `input` are copies. It\nis not called for an idempotent replay (already committed) or for\n`observeFeedback`; like `policy.adopt`, it must write only host-owned rows.\n\nDecision and downstream execution facts are captured inside their owning\ntransaction, keyed by immutable event ID and signal, when the configured capture\nauthority allows the optional memory projection and it fits the configured byte\ncap. Denial or an oversized automatic projection leaves the underlying\nauthoritative decision/outcome intact, including failure and reconciliation.\nExplicit `recordFeedback` and `observeFeedback` requests still reject invalid or\noversized writes; actual database failures still propagate and roll back. Failed/rolled-back domain\nwork and unknown external outcomes remain distinct. `observeFeedback` can replay\nan authorized existing event; it cannot supply a correctness label or fabricate\nan execution result. An initial denial does not mutate retention. Once authorized,\na narrowed privacy ceiling survives business rollback and later revocation.\n\nObserved `action_decision` events carry the decision's `decisionMode`\n(`review` or `review_own`) and `selfDecision` flag from the durable decision\nrecord; `selfDecision` is true whenever the decider submitted the item, in\neither mode. A submitter confirming their own proposal (#4085) is observed as a\ndecision by that actor, never as reviewer correctness evidence; consumers that\nderive reviewer agreement must exclude `selfDecision: true` events, and nothing\nin this package turns them into automation eligibility.\n\nGenerated-output validity is not a feedback signal. A suggestion kept because\nits arguments missed only required fields (#4284, PROPOSALS.md) is recorded as\nincomplete — `needs_review` with those fields in `missingFields` — not as an\ninvalid reply with a `provenance.failure`. It produces no feedback record by\nitself; only the reviewer's explicit judgment or approval of the completed\narguments does, through the paths above.\n\n## Reviewer routing choices\n\nA `reviewer_routing` record is appended inside the owning transaction when\nfeedback is configured and `capture` is authorized, at the moment the choice is\nfinal: `resolveItem` (REVIEW.md) records `choice: 'none'` keyed\n`routing:<requestId>`, and `submitDecision` records `choice: 'handler'` keyed\n`routing:<decision requestId>` when a reviewer **approves** a reviewer-selected\naction. Handler-choice capture requires `mode: 'review'`: a `review_own`\nsubmitter approval authorizes normally but appends no reviewer-routing example or\nrule support. A reviewer using the reviewer path may still record an explicit\nrouting choice for their own receipt; it does not judge any model suggestion.\nStarting an action records nothing; rejecting or deferring it never produces an\nexample. The record needs no model suggestion: it binds the current\ncompleted/partial attempt (`attemptId`, output digest, analysis revision, frozen\nevidence hashes and the extracted text as `query`), the acting reviewer\n(`reviewer`, also `approvedBy` for a handler choice), the actor who started the\naction (`startedBy`), the start reason, and for a handler choice the\n`handlerId@version`, exact approved arguments and the approved action binding\n(revision and binding hash). Denied or oversized capture, an unavailable source\npin or malformed evidence skip the projection and leave the authoritative\ndecision or disposition intact; database write failures still roll everything\nback. There is no\nsupersession: a correction after approval (`previewProposal` on the current\nrevision) changes the revision, which retires the old record from retrieval and\nsupport until the new revision is approved and captured again; a correction\nbefore approval records nothing until that revision is approved.\n\nSettledness is a selection-time condition. Once a generation used an example,\nor a rule suggestion stored its support, the lineage re-checks (reading the\ngeneration, reviewing or deciding its actions, reading or adopting the rule,\nand replaying `suggestRoutingRule`, which returns the stored suggestion) verify:\n\n- every record: its digest, that it is not superseded, retention (no\n redaction or deletion), the unchanged source attempt digest and frozen\n evidence hashes, and live `retrieve` authority in the same tenant and\n confidential scope with every generation recipient allowed by the source's\n provider policy;\n- an `interpretation` record (unchanged from #3676): its action's current\n revision, binding hash, attempt, handler@version and arguments; the action's\n target preconditions at their recorded revisions unless the action\n `succeeded`; the prompt, configuration and model versions; and that the action\n is not reviewer-selected;\n- a `reviewer_routing` record with `choice: 'handler'`: its action's current\n revision, binding hash, attempt, handler@version and arguments, that the\n action is still reviewer-selected, and that its targets are still accessible\n (not their revisions: the record means the handler choice, not target state);\n- a `reviewer_routing` record with `choice: 'none'`: it has no action, so the\n source item is re-checked under the first currently offered receiving handler\n that still authorizes it.\n\nRule support (`suggestRoutingRule`, and on read, adoption and replay of a stored\nsuggestion) additionally requires: at least two records from distinct source\nitems; `judgment: 'correct'` with matching prompt/configuration/model versions\nfor an interpretation record; `choice: 'handler'` for a routing record; each\nrecord's handler@version equal to the receiving binding's; and each source's\nlive routing projection (or full arguments when no projection is configured)\nequal to the receiving action's. Settledness of a routing source is checked only\nwhen the support is first selected.\n\nA later disposition, approval lapse, outcome change or target write of a routing\nsource never revokes it.\n\nRetrieval scans `interpretation` and `reviewer_routing` records together under\nthe same bounds and lexical matcher. A routing example is returned only when its\ndigest verifies, its attempt and evidence hashes are unchanged, the source item\nis still readable in the same tenant and confidential scope, every generation\nrecipient is allowed by the source's live provider policy, and (for a chosen\nhandler) the action is still reviewer-selected and settled — applied\n(`executing`, `succeeded`) or `authorized` with an unexpired approval, on an item\nwithout a disposition — its binding is still the current revision, and the handler with its candidate\nreferences is currently offered to the receiver. A `none` choice is\nrevalidated under the first currently offered receiving handler the source item\nauthorizes. Routing examples carry `kind: 'reviewer_routing'`,\n`judgment: 'correct'`, `routing: { choice, reason }`, `handlerId: 'none'` with an\nempty action for closed items, and no model/prompt/configuration versions, since\nno suggestion was judged. They are included in provider input and selection\nprovenance exactly like interpretation examples and are rechecked by the same\nlineage gates.\n\n`suggestRoutingRule` accepts `reviewer_routing` support only for `choice: 'handler'`\nrecords whose action is settled in the same sense when the support is chosen\n(a lapsed, unapplied approval or a disposition excludes it) and whose handler, version and\nfull arguments match the receiving binding and each other, from distinct source\nitems, under the live routing projection; `none`, rejected, deferred and\nre-corrected records never support a rule. Suggestions and adoptions keep every existing #3676\nrule: no catalog, candidate, permission or automation expansion, and\n`automaticActionEligible: false`. Reviewer-selected actions themselves are refused\nby `authorizeAutomatic`. They are routing choices, never labels for a model\nsuggestion: `recordFeedback` refuses an interpretation judgment on one (even\nwhen the item also carries a generation, and whatever its decision), retrieval\nand rule support ignore interpretation records bound to one, and `ActionReview`\nhides the correctness buttons for them. A disposition says nothing about\nwhether a suggestion was right, so interpretation judgments on a resolved item\nstill count. Only\n`startReviewerAction` mints that origin; `createAction` refuses it.\n\n## Retrieval and provider boundaries\n\n`retrieveFeedback({ itemId, query })` derives the current offered catalog,\ncandidates and model/prompt/configuration versions on the server. Callers cannot\nprovide candidate authority. The deterministic matcher uses lowercase Unicode\nword-set Jaccard similarity (minimum 0.2), then immutable record ID for ties.\nScanning, recursive provenance checks and returned examples are bounded; a limited scan does not promise an\nexhaustive history search. Both positive and negative explicit examples are kept.\n\nEvery selected source must still be readable in the same tenant and confidential\nscope, with its current action/analysis binding, target grants, handler version,\nmodel/prompt/configuration compatibility and retention. Each source's current\nprovider policy must allow the generation recipient and any configured decision\nrecipient; the source owner rechecks that policy on both initial and final live\ncontexts. Receiving checks cover every offered handler, before and after source\nchecks, using each live grant, actual provider recipients and the narrowest byte\nceiling. Both retrieval and reference revalidation budget the full reconstructed\nexamples. A receiving item's provider grant cannot substitute for a source grant.\nSuperseded, revoked, deleted or incompatible sources are excluded. Current explicit human corrections\ntake precedence: a generation carrying one does not retrieve learned examples.\n\nA judgment recorded on an action whose generation ran under a reviewer\ninstruction (REVIEW.md) stores only a reference, `instruction: {id, digest}`,\nafter verifying the generation's provenance against the authenticated\nextraction record. **Write side:** the reference is ~100 bytes, so instruction\ntext never counts against the judgment's write budget (`feedback.maxBytes` /\n`policy.maxBytes`) and cannot make `recordFeedback` fail with `Feedback\nlimit`. `retrieve` re-verifies the source record and joins the text, returning\n`{id, digest, text}`; a stored reference that no longer matches the source's\nrecord excludes the example. Because one long instruction joined at read time\ncould otherwise push every selection that ranks it over budget and deny\ngeneration scope-wide, `recordFeedback` also builds that single joined example\nexactly as `retrieve` would and refuses with `Feedback instruction exceeds\nretrieval budget` (nothing is written) when it alone exceeds\n`min(feedback.maxBytes, handler policy.maxBytes)`. An example that fits exactly\nrecords and retrieves. **This guard covers only the single-example case** on the\njudged handler's own budget: retrieval still sums up to `maxExamples` examples\nand takes the minimum across *every* offered handler of the receiving item, so a\nmulti-example selection, or a receiving item with a narrower handler budget, can\nstill exceed the budget and fails closed as below. It is returned as part of the example so comparable later items see the guidance\nthat produced the judged suggestion. It is example content only: it does not\ntransfer to the receiving generation's configuration or prompt section, and it\nexpands no catalog, candidate, permission or automation eligibility. **Read-side budget\nimpact:** joined instruction text (up to 4,000 characters, more bytes for\nnon-ASCII) counts toward the exact serialized selection budget — the narrowest\nof `feedback.maxBytes` and each offered handler's `policy.maxBytes` — like any\nother example field. The existing fail-closed rule is unchanged: an over-budget\nselection rejects with `Feedback limit` and generation records\n`provider_error` without provider I/O; examples are not silently trimmed. Hosts\nthat enable reviewer instructions together with feedback should size\n`feedback.maxBytes` (and the policy ceilings) for at least\n`maxExamples × (4,000 characters of instruction + the example's own fields)`,\nor lower `maxExamples`.\n\nFull examples exist only in the authorized provider request. The SDK proposal\nadapter includes that typed selection in its serialized user message when\npresent; disabled feedback leaves the original request shape unchanged. Saved generation\nprovenance contains the receiving query, selection configuration digest and\nimmutable feedback IDs/digests, not copied source example content. Selected\nreferences are rechecked before generation, capability probing, decision calls,\npublication and completed-result reads. A newly added example does not invalidate\nan older selection; a revoked or superseded selected example does. Feedback\nlineage is bounded and fails closed. Saved-action reads and pending decisions,\nautomatic authorization, preview publication/replay and execution also revalidate\nselected lineage under the\nowning transaction. Revoking, deleting or superseding a selected example blocks\npending actions; regenerate their proposals and obtain fresh approval to recover.\nA preview replay checks the exact persisted proposal it returns, including its\nanalysis attempt; a newer action revision cannot supply replacement lineage.\nPlan replay and final sealed plan-step publication use the same gate.\nFor already successful actions, current-authorized durable outcomes remain\nreadable/replayable, but invalid learned lineage suppresses saved proposal\ndisplay, arguments and plan payload. An empty selection carries no learned source\nand does not turn optional feedback-capture denial into action denial. Examples\nnever expand the offered catalog, candidate IDs, operation permissions or\nautomation eligibility.\n\nAll durable feedback belongs to the source item's existing retention/redaction\nlifecycle. There is no separate memory store or delayed indexing writer to clean\nup. Hosts using other derived stores still implement the existing `purgeDerived`\ncontract. Core `LearningMemory` is intentionally not used here: its success/failure\nreinforcement and default ancestor-scope fallback do not represent separate\ncorrectness/decision/outcome signals and strict confidential-scope eligibility.\n\n## Routing suggestions and adoption\n\n`suggestRoutingRule` requires repeated current explicit positive judgments\nfrom distinct source items with matching handler/version and arguments, and returns supporting immutable IDs,\nshared query terms and the policy owner's preview/version. Suggestions cannot\nexecute or modify policy. `getRoutingRule` rechecks the displayed binding and all\nsupporting examples. Arguments are routing preferences, never executable grants.\n\nBy default matching compares **all** action arguments, preserving existing host\nbehavior. Create handlers commonly have per-document content and idempotency\nkeys, which must remain distinct. Such hosts can explicitly declare a routing-only\nsubset in trusted server configuration before capturing judgments:\n\n```ts\nfeedback: {\n // ...existing limits, authorize and policy owner\n routing: [{\n handlerId: 'host:create-document',\n handlerVersion: '1',\n version: 'routing-fields-1',\n fields: ['destinationId', 'category'],\n }],\n}\n```\n\nEach declaration must name a configured handler/version and a nonempty, unique\nallowlist of its top-level `argsSchema.properties`; duplicate declarations,\nunknown properties and prototype keys reject. There are no dotted paths,\ncaller-supplied selectors or implicit exclusions (including request IDs).\nOptional absent fields stay absent and differ from explicit `null`; at least one\nselected value must be present. The host must select preferences only, never\ngrants, provider permissions or automation controls.\n\nCapture retains the full immutable action arguments and binding plus the\nversioned subset. For opted-in handlers `RoutingRule.args` contains only selected\nvalues and `RoutingRule.projection` carries the canonical sorted fields and\nversion. Independent support must match that entire contract and those values;\nfull original source arguments, provenance and current access are still checked.\nExisting unprojected feedback is not retroactively reinterpreted: record fresh\nexplicit judgments after enabling or changing a declaration. Changing a version,\nfield list or selected value invalidates old suggestions on reads, adoption and\nreplay, including changes inside policy-owner callbacks. Full argument feedback\nretrieval remains unchanged; hosts may present matching examples from\n`retrieveFeedback`, but suggestion creation revalidates every supplied ID.\n\n`adoptRoutingRule` requires the exact suggestion digest and expected policy\nversion plus current reviewer and adoption authority. The configured policy owner\nmust perform its version compare-and-swap and audit on the supplied database\nexecutor. The ingestion transaction records the exact returned version/audit ID.\nReplays do not adopt twice. Revocation or permission/policy widening rolls back\nboth changes. The host callback may store routing preferences only: it must not\nchange grants, provider permissions or automation controls. Adoption always\nreturns `automaticActionEligible: false`; subsequent proposals retain normal\ncurrent policy and explicit review requirements.\n\n## Review UI and evidence\n\nThe optional `IntakeReviewHost.feedback` callback carries the exact displayed\nrevision and binding. Correct/incorrect controls are explicit and independent of\nApprove/Apply. Unsaved argument edits disable correctness controls until the\ndisplayed binding is current again. Hosts must authenticate that callback and connect it to\n`recordFeedback`; client-supplied reviewer/scope fields are not accepted. The\nmaintained browser fixture demonstrates this transport with CSRF protection and\nrejects substituted revisions.\n\nWith `enableFeedback`, `createIntakeReviewHost` also loads each action's\n`ReviewAction.feedback` (#4503): this reviewer's own current (not superseded)\njudgment at the displayed revision and binding (`id`, `judgment`, `comment`,\n`recordedAt`), read through `IngestionService.listOwnFeedback`. The chosen\nbutton is `aria-pressed`, `ingestion.feedbackSent` shows after a judgment, and\na further judgment sends `supersedesId` (the loaded id, else the receipt id the\ncallback returned). Another reviewer's judgment is never shown as pressed; a\nfailed read only leaves the pressed state off.\n\nSee [the behavior matrix](../../docs/test-matrix/3676-ingestion-feedback.md) for\nvalidation and the frozen learning protocol, and the\n[routing projection matrix](../../docs/test-matrix/3732-ingestion-routing-projection.md)\nfor the optional subset contract. The small authored deterministic\ncohort demonstrates contract-level influence, not provider quality or measured\nproduction improvement. Real-provider evaluation belongs to #3677. There are no\nsampled automatic outcomes in this feature; reporting that stratum as unavailable\navoids inventing correctness labels from successful jobs.\n\n`authorize` distinguishes two read operations (#4504). `retrieve` covers\npicking new examples and revalidating a selection at the provider boundary.\n`verify` covers re-checking the stored lineage of an existing generation (the\nexamples it was produced with) whenever its actions are read, reviewed,\nlabelled or applied, including `getAction`/`listReviews`, and whenever the\nstored generation snapshot is read (`getCompletedAnalysis`, the review host's\n`load`, instructions, splits and Try again). A host that switches\nlearning off refuses `retrieve` and keeps allowing `verify`, so items analysed\nwhile learning was on still load. Fail-safe for authorizers that predate\n`verify`: when `verify` returns `false` the same check is asked as `retrieve`,\nand only a refusal of both fails closed (\"Feedback unavailable\") as before.\n\nWhen interpretation requests optional examples, an explicit denial of feedback\nretrieval degrades to generation without examples or feedback provenance. Direct\n`retrieveFeedback` calls still reject denied reads. Other authorization errors\nare not swallowed, and already selected examples must pass the normal live\nprovider-boundary checks; revocation does not silently preserve selected data.\n"
1728
+ "content": "# Explicit ingestion feedback\n\nConfigure `IngestionOptions.feedback` to opt in. The existing `intake_feedback`\nledger owns these records; no new schema, embedding service or provider is added.\n`FeedbackConfiguration` sets a version, maximum examples, scan count, serialized\nbytes and lexical similarity threshold, plus a live scoped authorization callback.\nHard ceilings are 20 examples, 1,000 scanned records and 1 MB. Choose substantially\nsmaller application limits. The proposal's complete serialized request, including\nexamples, must also fit the current minimum application/source/provider budget.\n\n`recordFeedback` accepts the exact displayed action revision, review version and\nbinding hash, an explicit correct/incorrect judgment, optional reason text and a\nrequest ID. The server resolves reviewer, tenant/confidential scope, retained\nsource evidence, extraction/generation versions and current handler arguments.\nA replay returns the same immutable receipt; changed payloads conflict.\n`supersedesId` appends a replacement for the specified prior interpretation\njudgment. A second successor conflicts. Revised actions make old bindings\nineligible. Approval and successful execution never imply that extracted fields\nare correct.\n\nOptional `feedback.onRecorded({ db, scope, receipt, input })` (#4522) runs\ninside the transaction that stores an explicit judgment, on the same executor,\nafter the judgment row (and its `supersedesId` link) is written and before the\nfinal `capture` recheck. Write the host's own activity entry there: it commits\nor rolls back with the judgment, and a throw rolls the judgment back and\nrejects `recordFeedback` with that error. `receipt` and `input` are copies. It\nis not called for an idempotent replay (already committed) or for\n`observeFeedback`; like `policy.adopt`, it must write only host-owned rows.\n\nDecision and downstream execution facts are captured inside their owning\ntransaction, keyed by immutable event ID and signal, when the configured capture\nauthority allows the optional memory projection and it fits the configured byte\ncap. Denial or an oversized automatic projection leaves the underlying\nauthoritative decision/outcome intact, including failure and reconciliation.\nExplicit `recordFeedback` and `observeFeedback` requests still reject invalid or\noversized writes; actual database failures still propagate and roll back. Failed/rolled-back domain\nwork and unknown external outcomes remain distinct. `observeFeedback` can replay\nan authorized existing event; it cannot supply a correctness label or fabricate\nan execution result. An initial denial does not mutate retention. Once authorized,\na narrowed privacy ceiling survives business rollback and later revocation.\n\nObserved `action_decision` events carry the decision's `decisionMode`\n(`review` or `review_own`) and `selfDecision` flag from the durable decision\nrecord; `selfDecision` is true whenever the decider submitted the item, in\neither mode. A submitter confirming their own proposal (#4085) is observed as a\ndecision by that actor, never as reviewer correctness evidence; consumers that\nderive reviewer agreement must exclude `selfDecision: true` events, and nothing\nin this package turns them into automation eligibility.\n\nGenerated-output validity is not a feedback signal. A suggestion kept because\nits arguments missed only required fields (#4284, PROPOSALS.md) is recorded as\nincomplete — `needs_review` with those fields in `missingFields` — not as an\ninvalid reply with a `provenance.failure`. It produces no feedback record by\nitself; only the reviewer's explicit judgment or approval of the completed\narguments does, through the paths above.\n\n## Reviewer routing choices\n\nA `reviewer_routing` record is appended inside the owning transaction when\nfeedback is configured and `capture` is authorized, at the moment the choice is\nfinal: `resolveItem` (REVIEW.md) records `choice: 'none'` keyed\n`routing:<requestId>`, and `submitDecision` records `choice: 'handler'` keyed\n`routing:<decision requestId>` when a reviewer **approves** a reviewer-selected\naction. Handler-choice capture requires `mode: 'review'`: a `review_own`\nsubmitter approval authorizes normally but appends no reviewer-routing example or\nrule support. A reviewer using the reviewer path may still record an explicit\nrouting choice for their own receipt; it does not judge any model suggestion.\nStarting an action records nothing; rejecting or deferring it never produces an\nexample. The record needs no model suggestion: it binds the current\ncompleted/partial attempt (`attemptId`, output digest, analysis revision, frozen\nevidence hashes and the extracted text as `query`), the acting reviewer\n(`reviewer`, also `approvedBy` for a handler choice), the actor who started the\naction (`startedBy`), the start reason, and for a handler choice the\n`handlerId@version`, exact approved arguments and the approved action binding\n(revision and binding hash). Denied or oversized capture, an unavailable source\npin or malformed evidence skip the projection and leave the authoritative\ndecision or disposition intact; database write failures still roll everything\nback. There is no\nsupersession: a correction after approval (`previewProposal` on the current\nrevision) changes the revision, which retires the old record from retrieval and\nsupport until the new revision is approved and captured again; a correction\nbefore approval records nothing until that revision is approved.\n\nSettledness is a selection-time condition. Once a generation used an example,\nor a rule suggestion stored its support, the lineage re-checks (reading the\ngeneration, reviewing or deciding its actions, reading or adopting the rule,\nand replaying `suggestRoutingRule`, which returns the stored suggestion) verify:\n\n- every record: its digest, that it is not superseded, retention (no\n redaction or deletion), the unchanged source attempt digest and frozen\n evidence hashes, and live `retrieve` authority in the same tenant and\n confidential scope with every generation recipient allowed by the source's\n provider policy;\n- an `interpretation` record (unchanged from #3676): its action's current\n revision, binding hash, attempt, handler@version and arguments; the action's\n target preconditions at their recorded revisions unless the action\n `succeeded`; the prompt, configuration and model versions; and that the action\n is not reviewer-selected;\n- a `reviewer_routing` record with `choice: 'handler'`: its action's current\n revision, binding hash, attempt, handler@version and arguments, that the\n action is still reviewer-selected, and that its targets are still accessible\n (not their revisions: the record means the handler choice, not target state);\n- a `reviewer_routing` record with `choice: 'none'`: it has no action, so the\n source item is re-checked under the first currently offered receiving handler\n that still authorizes it.\n\nRule support (`suggestRoutingRule`, and on read, adoption and replay of a stored\nsuggestion) additionally requires: at least two records from distinct source\nitems; `judgment: 'correct'` with matching prompt/configuration/model versions\nfor an interpretation record; `choice: 'handler'` for a routing record; each\nrecord's handler@version equal to the receiving binding's; and each source's\nlive routing projection (or full arguments when no projection is configured)\nequal to the receiving action's. Settledness of a routing source is checked only\nwhen the support is first selected.\n\nA later disposition, approval lapse, outcome change or target write of a routing\nsource never revokes it.\n\nRetrieval scans `interpretation` and `reviewer_routing` records together under\nthe same bounds and lexical matcher. A routing example is returned only when its\ndigest verifies, its attempt and evidence hashes are unchanged, the source item\nis still readable in the same tenant and confidential scope, every generation\nrecipient is allowed by the source's live provider policy, and (for a chosen\nhandler) the action is still reviewer-selected and settled — applied\n(`executing`, `succeeded`) or `authorized` with an unexpired approval, on an item\nwithout a disposition — its binding is still the current revision, and the handler with its candidate\nreferences is currently offered to the receiver. A `none` choice is\nrevalidated under the first currently offered receiving handler the source item\nauthorizes. Routing examples carry `kind: 'reviewer_routing'`,\n`judgment: 'correct'`, `routing: { choice, reason }`, `handlerId: 'none'` with an\nempty action for closed items, and no model/prompt/configuration versions, since\nno suggestion was judged. They are included in provider input and selection\nprovenance exactly like interpretation examples and are rechecked by the same\nlineage gates.\n\n`suggestRoutingRule` accepts `reviewer_routing` support only for `choice: 'handler'`\nrecords whose action is settled in the same sense when the support is chosen\n(a lapsed, unapplied approval or a disposition excludes it) and whose handler, version and\nfull arguments match the receiving binding and each other, from distinct source\nitems, under the live routing projection; `none`, rejected, deferred and\nre-corrected records never support a rule. Suggestions and adoptions keep every existing #3676\nrule: no catalog, candidate, permission or automation expansion, and\n`automaticActionEligible: false`. Reviewer-selected actions themselves are refused\nby `authorizeAutomatic`. They are routing choices, never labels for a model\nsuggestion: `recordFeedback` refuses an interpretation judgment on one (even\nwhen the item also carries a generation, and whatever its decision), retrieval\nand rule support ignore interpretation records bound to one, and `ActionReview`\nhides the correctness buttons for them. A disposition says nothing about\nwhether a suggestion was right, so interpretation judgments on a resolved item\nstill count. Only\n`startReviewerAction` mints that origin; `createAction` refuses it.\n\n## Retrieval and provider boundaries\n\n`retrieveFeedback({ itemId, query })` derives the current offered catalog,\ncandidates and model/prompt/configuration versions on the server. Callers cannot\nprovide candidate authority. The deterministic matcher uses lowercase Unicode\nword-set Jaccard similarity (minimum 0.2), then immutable record ID for ties.\nScanning, recursive provenance checks and returned examples are bounded; a limited scan does not promise an\nexhaustive history search. Both positive and negative explicit examples are kept.\n\nEvery selected source must still be readable in the same tenant and confidential\nscope, with its current action/analysis binding, target grants, handler version,\nmodel/prompt/configuration compatibility and retention. Each source's current\nprovider policy must allow the generation recipient and any configured decision\nrecipient; the source owner rechecks that policy on both initial and final live\ncontexts. Receiving checks cover every offered handler, before and after source\nchecks, using each live grant, actual provider recipients and the narrowest byte\nceiling. Both retrieval and reference revalidation budget the full reconstructed\nexamples. A receiving item's provider grant cannot substitute for a source grant.\nSuperseded, revoked, deleted or incompatible sources are excluded. Current explicit human corrections\ntake precedence: a generation carrying one does not retrieve learned examples.\n\nA judgment recorded on an action whose generation ran under a reviewer\ninstruction (REVIEW.md) stores only a reference, `instruction: {id, digest}`,\nafter verifying the generation's provenance against the authenticated\nextraction record. **Write side:** the reference is ~100 bytes, so instruction\ntext never counts against the judgment's write budget (`feedback.maxBytes` /\n`policy.maxBytes`) and cannot make `recordFeedback` fail with `Feedback\nlimit`. `retrieve` re-verifies the source record and joins the text, returning\n`{id, digest, text}`; a stored reference that no longer matches the source's\nrecord excludes the example. Because one long instruction joined at read time\ncould otherwise push every selection that ranks it over budget and deny\ngeneration scope-wide, `recordFeedback` also builds that single joined example\nexactly as `retrieve` would and refuses with `Feedback instruction exceeds\nretrieval budget` (nothing is written) when it alone exceeds\n`min(feedback.maxBytes, handler policy.maxBytes)`. An example that fits exactly\nrecords and retrieves. **This guard covers only the single-example case** on the\njudged handler's own budget: retrieval still sums up to `maxExamples` examples\nand takes the minimum across *every* offered handler of the receiving item, so a\nmulti-example selection, or a receiving item with a narrower handler budget, can\nstill exceed the budget and fails closed as below. It is returned as part of the example so comparable later items see the guidance\nthat produced the judged suggestion. It is example content only: it does not\ntransfer to the receiving generation's configuration or prompt section, and it\nexpands no catalog, candidate, permission or automation eligibility. **Read-side budget\nimpact:** joined instruction text (up to 4,000 characters, more bytes for\nnon-ASCII) counts toward the exact serialized selection budget — the narrowest\nof `feedback.maxBytes` and each offered handler's `policy.maxBytes` — like any\nother example field. The existing fail-closed rule is unchanged: an over-budget\nselection rejects with `Feedback limit` and generation records\n`provider_error` without provider I/O; examples are not silently trimmed. Hosts\nthat enable reviewer instructions together with feedback should size\n`feedback.maxBytes` (and the policy ceilings) for at least\n`maxExamples × (4,000 characters of instruction + the example's own fields)`,\nor lower `maxExamples`.\n\nFull examples exist only in the authorized provider request. The SDK proposal\nadapter includes that typed selection in its serialized user message when\npresent; disabled feedback leaves the original request shape unchanged. Saved generation\nprovenance contains the receiving query, selection configuration digest and\nimmutable feedback IDs/digests, not copied source example content. Selected\nreferences are rechecked before generation, capability probing, decision calls,\npublication and completed-result reads. A newly added example does not invalidate\nan older selection; a revoked or superseded selected example does. Feedback\nlineage is bounded and fails closed. Saved-action reads and pending decisions,\nautomatic authorization, preview publication/replay and execution also revalidate\nselected lineage under the\nowning transaction. Revoking, deleting or superseding a selected example blocks\npending actions; regenerate their proposals and obtain fresh approval to recover.\nA preview replay checks the exact persisted proposal it returns, including its\nanalysis attempt; a newer action revision cannot supply replacement lineage.\nPlan replay and final sealed plan-step publication use the same gate.\nReading examples (retrieval and every selection re-check) takes no exclusive\nlock on a source item (#4651): each source is loaded before and after its\nchecks, both loads must agree (review binding and analysis revision), and a\nretention narrowing writes the row only when it actually narrows. Parallel\nreads therefore cannot deadlock on PostgreSQL by visiting source items in\ndifferent orders. A database error inside an example check is never treated as\nan excluded example: it propagates and ends the read.\nFor already successful actions, current-authorized durable outcomes remain\nreadable/replayable, but invalid learned lineage suppresses saved proposal\ndisplay, arguments and plan payload. An empty selection carries no learned source\nand does not turn optional feedback-capture denial into action denial. Examples\nnever expand the offered catalog, candidate IDs, operation permissions or\nautomation eligibility.\n\nAll durable feedback belongs to the source item's existing retention/redaction\nlifecycle. There is no separate memory store or delayed indexing writer to clean\nup. Hosts using other derived stores still implement the existing `purgeDerived`\ncontract. Core `LearningMemory` is intentionally not used here: its success/failure\nreinforcement and default ancestor-scope fallback do not represent separate\ncorrectness/decision/outcome signals and strict confidential-scope eligibility.\n\n## Routing suggestions and adoption\n\n`suggestRoutingRule` requires repeated current explicit positive judgments\nfrom distinct source items with matching handler/version and arguments, and returns supporting immutable IDs,\nshared query terms and the policy owner's preview/version. Suggestions cannot\nexecute or modify policy. `getRoutingRule` rechecks the displayed binding and all\nsupporting examples. Arguments are routing preferences, never executable grants.\n\nBy default matching compares **all** action arguments, preserving existing host\nbehavior. Create handlers commonly have per-document content and idempotency\nkeys, which must remain distinct. Such hosts can explicitly declare a routing-only\nsubset in trusted server configuration before capturing judgments:\n\n```ts\nfeedback: {\n // ...existing limits, authorize and policy owner\n routing: [{\n handlerId: 'host:create-document',\n handlerVersion: '1',\n version: 'routing-fields-1',\n fields: ['destinationId', 'category'],\n }],\n}\n```\n\nEach declaration must name a configured handler/version and a nonempty, unique\nallowlist of its top-level `argsSchema.properties`; duplicate declarations,\nunknown properties and prototype keys reject. There are no dotted paths,\ncaller-supplied selectors or implicit exclusions (including request IDs).\nOptional absent fields stay absent and differ from explicit `null`; at least one\nselected value must be present. The host must select preferences only, never\ngrants, provider permissions or automation controls.\n\nCapture retains the full immutable action arguments and binding plus the\nversioned subset. For opted-in handlers `RoutingRule.args` contains only selected\nvalues and `RoutingRule.projection` carries the canonical sorted fields and\nversion. Independent support must match that entire contract and those values;\nfull original source arguments, provenance and current access are still checked.\nExisting unprojected feedback is not retroactively reinterpreted: record fresh\nexplicit judgments after enabling or changing a declaration. Changing a version,\nfield list or selected value invalidates old suggestions on reads, adoption and\nreplay, including changes inside policy-owner callbacks. Full argument feedback\nretrieval remains unchanged; hosts may present matching examples from\n`retrieveFeedback`, but suggestion creation revalidates every supplied ID.\n\n`adoptRoutingRule` requires the exact suggestion digest and expected policy\nversion plus current reviewer and adoption authority. The configured policy owner\nmust perform its version compare-and-swap and audit on the supplied database\nexecutor. The ingestion transaction records the exact returned version/audit ID.\nReplays do not adopt twice. Revocation or permission/policy widening rolls back\nboth changes. The host callback may store routing preferences only: it must not\nchange grants, provider permissions or automation controls. Adoption always\nreturns `automaticActionEligible: false`; subsequent proposals retain normal\ncurrent policy and explicit review requirements.\n\n## Review UI and evidence\n\nThe optional `IntakeReviewHost.feedback` callback carries the exact displayed\nrevision and binding. Correct/incorrect controls are explicit and independent of\nApprove/Apply. Unsaved argument edits disable correctness controls until the\ndisplayed binding is current again. Hosts must authenticate that callback and connect it to\n`recordFeedback`; client-supplied reviewer/scope fields are not accepted. The\nmaintained browser fixture demonstrates this transport with CSRF protection and\nrejects substituted revisions.\n\nWith `enableFeedback`, `createIntakeReviewHost` also loads each action's\n`ReviewAction.feedback` (#4503): this reviewer's own current (not superseded)\njudgment at the displayed revision and binding (`id`, `judgment`, `comment`,\n`recordedAt`), read through `IngestionService.listOwnFeedback`. The chosen\nbutton is `aria-pressed`, `ingestion.feedbackSent` shows after a judgment, and\na further judgment sends `supersedesId` (the loaded id, else the receipt id the\ncallback returned). Another reviewer's judgment is never shown as pressed; a\nfailed read only leaves the pressed state off.\n\nSee [the behavior matrix](../../docs/test-matrix/3676-ingestion-feedback.md) for\nvalidation and the frozen learning protocol, and the\n[routing projection matrix](../../docs/test-matrix/3732-ingestion-routing-projection.md)\nfor the optional subset contract. The small authored deterministic\ncohort demonstrates contract-level influence, not provider quality or measured\nproduction improvement. Real-provider evaluation belongs to #3677. There are no\nsampled automatic outcomes in this feature; reporting that stratum as unavailable\navoids inventing correctness labels from successful jobs.\n\n`authorize` distinguishes two read operations (#4504). `retrieve` covers\npicking new examples and revalidating a selection at the provider boundary.\n`verify` covers re-checking the stored lineage of an existing generation (the\nexamples it was produced with) whenever its actions are read, reviewed,\nlabelled or applied, including `getAction`/`listReviews`, and whenever the\nstored generation snapshot is read (`getCompletedAnalysis`, the review host's\n`load`, instructions, splits and Try again). A host that switches\nlearning off refuses `retrieve` and keeps allowing `verify`, so items analysed\nwhile learning was on still load. Fail-safe for authorizers that predate\n`verify`: when `verify` returns `false` the same check is asked as `retrieve`,\nand only a refusal of both fails closed (\"Feedback unavailable\") as before.\n\nWhen interpretation requests optional examples, an explicit denial of feedback\nretrieval degrades to generation without examples or feedback provenance. Direct\n`retrieveFeedback` calls still reject denied reads. Other authorization errors\nare not swallowed, and already selected examples must pass the normal live\nprovider-boundary checks; revocation does not silently preserve selected data.\n"
1729
1729
  },
1730
1730
  {
1731
1731
  "path": "REVIEW.md",
@@ -1765,7 +1765,7 @@
1765
1765
  "code": "not-module-scope",
1766
1766
  "helper": "definePlaybook",
1767
1767
  "message": "`definePlaybook()` must be called at module scope to be emitted into the manifest and knowledge graph. A declaration the scanner cannot read without evaluating it is not emittable — use `useWebMcpTool` for a tool set derived from computed or fetched data.",
1768
- "line": 2612,
1768
+ "line": 2764,
1769
1769
  "column": 9,
1770
1770
  "sourceFile": "src/test-support/proposals.ts"
1771
1771
  },
@@ -1773,7 +1773,7 @@
1773
1773
  "code": "not-module-scope",
1774
1774
  "helper": "definePlaybook",
1775
1775
  "message": "`definePlaybook()` must be called at module scope to be emitted into the manifest and knowledge graph. A declaration the scanner cannot read without evaluating it is not emittable — use `useWebMcpTool` for a tool set derived from computed or fetched data.",
1776
- "line": 3397,
1776
+ "line": 3549,
1777
1777
  "column": 9,
1778
1778
  "sourceFile": "src/test-support/proposals.ts"
1779
1779
  },
@@ -1781,7 +1781,7 @@
1781
1781
  "code": "not-module-scope",
1782
1782
  "helper": "definePlaybook",
1783
1783
  "message": "`definePlaybook()` must be called at module scope to be emitted into the manifest and knowledge graph. A declaration the scanner cannot read without evaluating it is not emittable — use `useWebMcpTool` for a tool set derived from computed or fetched data.",
1784
- "line": 9355,
1784
+ "line": 9512,
1785
1785
  "column": 9,
1786
1786
  "sourceFile": "src/test-support/proposals.ts"
1787
1787
  },
@@ -1789,7 +1789,7 @@
1789
1789
  "code": "not-module-scope",
1790
1790
  "helper": "definePlaybook",
1791
1791
  "message": "`definePlaybook()` must be called at module scope to be emitted into the manifest and knowledge graph. A declaration the scanner cannot read without evaluating it is not emittable — use `useWebMcpTool` for a tool set derived from computed or fetched data.",
1792
- "line": 9987,
1792
+ "line": 10144,
1793
1793
  "column": 7,
1794
1794
  "sourceFile": "src/test-support/proposals.ts"
1795
1795
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happyvertical/smrt-ingestion",
3
- "version": "0.60.5",
3
+ "version": "0.60.7",
4
4
  "description": "Durable tenant-scoped intake and evidence foundations",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -50,32 +50,32 @@
50
50
  }
51
51
  },
52
52
  "dependencies": {
53
- "@happyvertical/smrt-core": "0.60.5",
54
- "@happyvertical/smrt-types": "0.60.5",
55
- "@happyvertical/smrt-tenancy": "0.60.5",
56
- "@happyvertical/smrt-assets": "0.60.5",
57
- "@happyvertical/smrt-jobs": "0.60.5",
53
+ "@happyvertical/smrt-core": "0.60.7",
54
+ "@happyvertical/smrt-types": "0.60.7",
55
+ "@happyvertical/smrt-tenancy": "0.60.7",
56
+ "@happyvertical/smrt-assets": "0.60.7",
57
+ "@happyvertical/smrt-jobs": "0.60.7",
58
58
  "@happyvertical/sql": "^0.111.3",
59
59
  "@happyvertical/pdf": "^0.65.9",
60
60
  "@happyvertical/ocr": "^0.62.1",
61
61
  "@happyvertical/speech": "^0.111.3",
62
62
  "@happyvertical/ai": "^0.111.3",
63
63
  "sharp": "^0.35.5",
64
- "@happyvertical/smrt-agents": "0.60.5",
65
- "@happyvertical/smrt-playbooks": "0.60.5",
64
+ "@happyvertical/smrt-agents": "0.60.7",
65
+ "@happyvertical/smrt-playbooks": "0.60.7",
66
66
  "ajv": "8.20.0",
67
- "@happyvertical/smrt-ui": "0.60.5"
67
+ "@happyvertical/smrt-ui": "0.60.7"
68
68
  },
69
69
  "devDependencies": {
70
- "@happyvertical/smrt-vitest": "0.60.5",
70
+ "@happyvertical/smrt-vitest": "0.60.7",
71
71
  "@types/node": "24.13.6",
72
72
  "typescript": "6.0.3",
73
73
  "vite": "8.1.6",
74
74
  "vitest": "4.1.10",
75
- "@happyvertical/smrt-content": "0.60.5",
76
- "@happyvertical/smrt-messages": "0.60.5",
75
+ "@happyvertical/smrt-content": "0.60.7",
76
+ "@happyvertical/smrt-messages": "0.60.7",
77
77
  "@happyvertical/email": "^0.111.3",
78
- "@happyvertical/smrt-users": "0.60.5",
78
+ "@happyvertical/smrt-users": "0.60.7",
79
79
  "@sveltejs/package": "^2.5.8",
80
80
  "@sveltejs/vite-plugin-svelte": "^7.3.0",
81
81
  "svelte": "^5.57.1",