@happyvertical/smrt-ingestion 0.57.44 → 0.57.46

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.
Files changed (79) hide show
  1. package/FEEDBACK.md +30 -0
  2. package/PROPOSALS.md +29 -0
  3. package/REVIEW.md +79 -0
  4. package/agents/execution.md +3 -1
  5. package/dist/chunks/{execution-DKWz2cz0.js → execution-Clcmi0sj.js} +2 -2
  6. package/dist/chunks/{execution-DKWz2cz0.js.map → execution-Clcmi0sj.js.map} +1 -1
  7. package/dist/chunks/{feedback-DHcSKgVU.js → feedback-hDSMYjiG.js} +94 -34
  8. package/dist/chunks/feedback-hDSMYjiG.js.map +1 -0
  9. package/dist/chunks/{proposal-contracts-CPH3ckgH.js → proposal-contracts-DREPLG56.js} +75 -2
  10. package/dist/chunks/proposal-contracts-DREPLG56.js.map +1 -0
  11. package/dist/chunks/{reviewer-instruction-Deoe4NPv.js → reviewer-instruction-BeOYVCVk.js} +2 -2
  12. package/dist/chunks/{reviewer-instruction-Deoe4NPv.js.map → reviewer-instruction-BeOYVCVk.js.map} +1 -1
  13. package/dist/execution-contracts.d.ts +7 -0
  14. package/dist/execution-contracts.d.ts.map +1 -1
  15. package/dist/execution.js +1 -1
  16. package/dist/feedback-contracts.d.ts +32 -3
  17. package/dist/feedback-contracts.d.ts.map +1 -1
  18. package/dist/feedback.d.ts +28 -0
  19. package/dist/feedback.d.ts.map +1 -1
  20. package/dist/generation-retry.d.ts +45 -0
  21. package/dist/generation-retry.d.ts.map +1 -0
  22. package/dist/manifest.json +1 -1
  23. package/dist/models.js +1 -1
  24. package/dist/models.js.map +1 -1
  25. package/dist/proposal-contracts.d.ts +15 -0
  26. package/dist/proposal-contracts.d.ts.map +1 -1
  27. package/dist/proposal-dto.d.ts +6 -0
  28. package/dist/proposal-dto.d.ts.map +1 -1
  29. package/dist/proposals.d.ts +7 -0
  30. package/dist/proposals.d.ts.map +1 -1
  31. package/dist/proposals.js +61 -18
  32. package/dist/proposals.js.map +1 -1
  33. package/dist/review-dto.d.ts +56 -0
  34. package/dist/review-dto.d.ts.map +1 -1
  35. package/dist/review-host.d.ts +14 -1
  36. package/dist/review-host.d.ts.map +1 -1
  37. package/dist/server.d.ts +27 -1
  38. package/dist/server.d.ts.map +1 -1
  39. package/dist/server.js +127 -5
  40. package/dist/server.js.map +1 -1
  41. package/dist/smrt-knowledge.json +16 -16
  42. package/dist/svelte/argument-fields.d.ts +48 -0
  43. package/dist/svelte/argument-fields.d.ts.map +1 -0
  44. package/dist/svelte/argument-fields.js +96 -0
  45. package/dist/svelte/components/ActionReview.svelte +81 -11
  46. package/dist/svelte/components/ActionReview.svelte.d.ts +30 -1
  47. package/dist/svelte/components/ActionReview.svelte.d.ts.map +1 -1
  48. package/dist/svelte/components/ArgumentFields.svelte +176 -0
  49. package/dist/svelte/components/ArgumentFields.svelte.d.ts +27 -0
  50. package/dist/svelte/components/ArgumentFields.svelte.d.ts.map +1 -0
  51. package/dist/svelte/components/InboxView.svelte +137 -17
  52. package/dist/svelte/components/InboxView.svelte.d.ts +17 -0
  53. package/dist/svelte/components/InboxView.svelte.d.ts.map +1 -1
  54. package/dist/svelte/components/IntakeInbox.svelte +26 -2
  55. package/dist/svelte/components/IntakeInbox.svelte.d.ts +10 -1
  56. package/dist/svelte/components/IntakeInbox.svelte.d.ts.map +1 -1
  57. package/dist/svelte/components/IntakeWorkspace.svelte +23 -1
  58. package/dist/svelte/components/IntakeWorkspace.svelte.d.ts +13 -1
  59. package/dist/svelte/components/IntakeWorkspace.svelte.d.ts.map +1 -1
  60. package/dist/svelte/components/ReviewView.svelte +88 -10
  61. package/dist/svelte/components/ReviewView.svelte.d.ts.map +1 -1
  62. package/dist/svelte/components/TriageView.svelte +43 -3
  63. package/dist/svelte/components/TriageView.svelte.d.ts +10 -1
  64. package/dist/svelte/components/TriageView.svelte.d.ts.map +1 -1
  65. package/dist/svelte/i18n.d.ts +33 -0
  66. package/dist/svelte/i18n.d.ts.map +1 -1
  67. package/dist/svelte/i18n.js +36 -0
  68. package/dist/svelte/index.d.ts +2 -1
  69. package/dist/svelte/index.d.ts.map +1 -1
  70. package/dist/svelte/index.js +1 -0
  71. package/dist/svelte/upload-refusal.d.ts +25 -0
  72. package/dist/svelte/upload-refusal.d.ts.map +1 -0
  73. package/dist/svelte/upload-refusal.js +40 -0
  74. package/dist/svelte/view-utils.d.ts +8 -0
  75. package/dist/svelte/view-utils.d.ts.map +1 -1
  76. package/dist/svelte/view-utils.js +36 -0
  77. package/package.json +13 -13
  78. package/dist/chunks/feedback-DHcSKgVU.js.map +0 -1
  79. package/dist/chunks/proposal-contracts-CPH3ckgH.js.map +0 -1
@@ -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.57.44",
6
+ "packageVersion": "0.57.46",
7
7
  "sourceManifestPath": "dist/manifest.json",
8
8
  "agentDocPath": "AGENTS.md",
9
9
  "sourceHashes": {
10
- "manifest": "28ac686c6789c9b2bbf0f96587ed5ae1d0373f78feece037dd8534c1f59f5a42",
11
- "packageJson": "f38fc589ea59c8eda3d3dfbccb48cf88c7d04ddb00eb787c1879c607f7bade7a",
10
+ "manifest": "f08ce467fed2ff9aa47386b99116b8f20980923dc5fcc19e0129df05d68e2354",
11
+ "packageJson": "6c3589d816506e898bc0fba4d07e0c031f63a775387fe0d69c9424be7406a366",
12
12
  "agents": "dea14442054ec1de798cba9be1fbdd955f44b0e4672639cbf3db8101d290c1fb",
13
- "moduleDoc:agents/execution.md": "3b223cb3c85312a29bb6157f22b153b4d643dca790b149f47c35396f981f2dc7",
13
+ "moduleDoc:agents/execution.md": "8a7c3384e90a41eb0c6f89e5bdafddd57db5e93f0c015849c764716b86ced97f",
14
14
  "moduleDoc:README.md": "d4dfdb4a4c1af3e1def6cf038e315e5bf66ab8d5942dee12a014527737a69748",
15
15
  "moduleDoc:EXTRACTION.md": "7aebb8ab51149e406938502935a46fe96174aa83975bbe5b913940f9b11053e9",
16
- "moduleDoc:PROPOSALS.md": "ac7ccecae2df7fb2e46c901a8c7b65bd0197f7583171fbb5e6a67824bb349839",
17
- "moduleDoc:FEEDBACK.md": "bf244222a1bc24843bdb7e94320dc3c0dfb7cb892001639d274786f4b667dacb",
18
- "moduleDoc:REVIEW.md": "eb2714386988a15f762bdc726b1fb3aa85a08e97e9363317f39234ebceddedb0",
16
+ "moduleDoc:PROPOSALS.md": "c20953df4742042e8988b19eec54f6757f50567bfee0502c8b0fe29a3a1ae204",
17
+ "moduleDoc:FEEDBACK.md": "121555edc7e88208a509aa1e983b22a5dfd01d22b600e1ff694799af2aa5ad90",
18
+ "moduleDoc:REVIEW.md": "07f34ce3208247cf8b58bdc2a288e7219b5c563feefe89d301a0a00f1b4db613",
19
19
  "agentSurface:src/test-support/execution.ts": "cc72288b2605fc687b820da558fa862da1bab799cebe4ee88b32be9e902618b8",
20
- "agentSurface:src/test-support/proposals.ts": "8f627821bc11a5f806c3091dc46f0045f8a36a285dfeb8860ae0651fcd8f3781"
20
+ "agentSurface:src/test-support/proposals.ts": "a5667e2b0dc52ab41bd202abdc70875594e4d9cc467d84dd54a11fe55ec14f23"
21
21
  },
22
22
  "exports": [
23
23
  ".",
@@ -1705,7 +1705,7 @@
1705
1705
  {
1706
1706
  "path": "agents/execution.md",
1707
1707
  "module": "execution",
1708
- "content": "# Review and execution integration\n\n`/execution` exports `IntakeExecutionService`, handler/host types, policy\nresolution, binding digests and `continueIntakeReview`. `IngestionService` exposes\nthese operations when its optional `execution` configuration is present. Its\nloader is lazy: importing `/server` alone does not import the principal stack.\n`/dto` exposes execution messages using type-only exports. No generated REST,\nCLI or MCP mutation endpoint is enabled; applications authenticate their own\nservice surface and create `IngestionScope` from the session.\n\n## Catalog and authority\n\nApplications supply a trusted `IntakeExecutionOptions.handlers` catalog.\n`OperationHandler` has qualified ID, immutable version, description, object JSON\nschemas for arguments/results, allowlisted `resultModels`, `validate`, `preview`,\na registered `{model, action, version}` operation and explicit effect/idempotency/\nopen-world capability declaration. Preview returns display, exact normalized\narguments and target revision preconditions. `normalizedArgs` must equal the\nsubmitted args exactly; default or normalize before submission, never in preview. There is no arbitrary tool execution\nor expression evaluation. Reviewer display wraps application fields under `preview`\nand symbolic metadata under `dependencies`; plan steps additionally wrap that\nobject under `step` alongside the plan preview. Application display keys cannot\noverwrite framework metadata or be silently overwritten by it. A version change\nrequires a new preview and approval.\n`PlanHandler` references a real registered playbook key and resolved definition\nhash; expansion contains only ordered operation handlers and typed earlier-step\nresult references. Discovery/proposal generation consumes this catalog rather\nthan creating another registry. Semantic model output is never host configuration.\n\nAuthenticated receipt context captures `capturedCeiling.execution` with principal\nID and permission/handler/operation ceilings. The execution host's `authorize`\nresolves current grants and application/tenant/source/(optional request) policy\non the supplied executor, checking the active requester and confidential scope.\nLists intersect, budgets minimize, review requirements OR, and disabled policy\nwins. Policy versions must change when policy semantics change. Normal operation\nrequires human review; machine authorization requires explicit evaluated opt-ins\nat all three authority layers and remains separate provenance from human review.\nThe reference handlers always require review; no evaluation claim is made here.\n\n`operation: 'review_own'` is the submitter-scoped decision gate (#4085). The\nservice accepts it only when the host's `authorize` result carries\n`submitter: true`, the resolved policy's `submitterReview` is enabled (the\napplication layer opts in; tenant/source layers may only set it `false`), and\nthe item's server-recorded `submitter_id` (the receiving service's authenticated\n`scope.actorId`) equals the current actor and the captured\n`execution.principalId`; apply rechecks that a `review_own` decision's reviewer\nis that submitter and principal. All other `review` checks apply\nunchanged; `correct` is refused. The decision row records `mode` and\n`selfDecision` (decider is the submitter, in either mode), and `feedbackEvent` copies them as `decisionMode`/`selfDecision`;\n`authorizeAutomatic` never reads human decisions, so a self-decision cannot\nbecome automation evidence. `listOwnProposals` reads with the ordinary `read`\noperation per handler after an item-level `read` check. Unreadable items are\nskipped before projection (1000 hidden rows per call, then `Own proposal scan\nlimit`) and the cursor names only emitted items with a confirmed readable\nsuccessor. On this surface every host `assertTarget` throw is mapped to the\nexported `IntakeAccessDeniedError` (message `Intake unavailable`, the type of\nevery execution denial), so the item becomes an `unavailable` entry and host\nerror text is not returned; hosts need no change. Other errors propagate,\nincluding a throwing grant store in `authorize`. The feedback anti-widening\ncheck also refuses a re-evaluation that turns `submitterReview` on.\nDeletion redaction blanks `submitter_id` and `owner_key` with the payloads and\ndrops `execution.principalId` unless an external action is still `executing`\nor `outcome_unknown`; `finish` and the reconcile state update release it once\nnone is left, and later deletion sweeps do the same.\nHosts whose `authorize` switches exhaustively on the operation fail closed for\nthe new value until they opt in.\n\n`mutationBoundary: 'serialized'` is an explicit host guarantee, not an inferred\nproperty of a permissions array: grant revocation must serialize with the supplied\ntransaction, or the owning mutation must revalidate under its own lock. The host\nmust implement that guarantee before enabling handlers. `assertTarget` similarly\nlocks current tenant/confidential ownership and revision against concurrent\nwriters using the supplied executor. The reference host demonstrates a scoped\nrow lock before public `Contents` reads. A current `PrincipalRun` intersects live\npermissions with the captured ceiling and checks the exact registered collection\noperation at every effect. No `runOnce` atomicity is assumed.\n\n## Reviewer-chosen actions and dispositions\n\n`startAction(StartActionInput)` lets an authenticated reviewer begin any\noperation handler the item's evidence media types offer, without a model\nsuggestion. It checks `review` access under that handler before any callback,\nrefuses plan handlers and resolved items, binds the current analysis revision's\ncompleted/partial attempt, inserts an action keyed `reviewer:<requestId>` with\n`data.origin = 'reviewer-selected'`, and reuses `buildBinding`/`publish`: schema\nvalidation, `validate`, `preview`, exact normalized arguments, target locks,\nevidence pins and the request ledger behave exactly as for `previewProposal`,\nincluding the typed `HandlerArgumentsInvalidError` (with value-free `issues`)\nfor an argument-schema or `validate` refusal of the reviewer's arguments;\nevery other refusal stays a plain `Error` (#4281). Replays re-preview against the original revision and return the same review.\nApproval, apply, retention, redaction and reconciliation are unchanged.\n`authorizeAutomatic` refuses `reviewer-selected` actions and resolved items;\nhuman routing is never machine authority.\n\n`resolveItem(ResolveItemInput)` appends one terminal `intake_dispositions` row\n(`disposition = 'resolved_no_action'`, reason/reviewer in redactable `data`)\nunder the item lock. Reviewer authority is taken from the first handler the\ncaptured ceiling and policy offer; no new grant exists. It refuses while any\naction is `authorized` with an unexpired approval for its current review\nversion, `executing`, `outcome_unknown` or `succeeded`; `failed` actions and\nlapsed approvals do not block it (neither can be rejected). Afterwards\n`submitDecision` refuses everything but `reject`, `publish` refuses any new\nrevision (correction, re-preview, plan preview), the apply gate (`approved`)\nrefuses any execution or retry, and `IngestionService.analyze`,\n`reviseLogicalSplit` and `createAction` refuse the item under its lock before\nany write. `createAction` (process authority) also refuses the reserved\n`reviewer:` key prefix and `reviewer-selected` origin, which only\n`startReviewerAction` mints; `previewProposal` on such an action requires\n`review` access and the current handler@version. `resolveItem` supersedes\nqueued/running analyses and completes dispatch intents under the item lock, and\n`claimAnalysis` returns `null` for a resolved item; `publishProposal` refuses\na resolved item and any reviewer-selected action. `[feedbackActionTransaction]`\ntakes `targetRevisions` (default true); routing lineage re-checks pass false. The feedback context's\n`settled` flag gates selection only; lineage re-checks ignore it (FEEDBACK.md). `intake_dispositions` is a new model: deploy\nits manifest migration (`pnpm ... db:migrate`) before upgrading hosts;\n`assertReady` checks it, and both privacy deletion and retention expiry\n(`redactExecution`) redact its payload with the other item-owned tables.\n`IntakeItemDTO.disposition` is `{ state: 'resolved', at }` (row `created_at`,\nnever redacted); `getItemDisposition` returns reviewer and reason under\n`reviewerAccess`. `resolveItem` captures an optional `reviewer_routing` feedback projection in the\nsame transaction; a reviewer-selected action is captured when its approval is\nrecorded (FEEDBACK.md).\n\n## Durable review and effects\n\nPreview appends a proposal bound to exact analysis attempt/evidence, handler,\narguments, policy and target preconditions. Decision requests use unique durable\nrequest IDs; reusing an ID with changed content is rejected. First valid review\nwins under the item lock. Corrections append a new revision; reject/defer remain\nnon-executable. Plan corrections use re-expansion. Human decisions expire and\nlive authority is checked again before each step. Raw foundation proposals cannot\nbypass execution's schema, preview, evidence and approval verification.\n\nDatabase handlers must use `context.db` for every domain effect and must perform\nno external I/O. Domain result and successful execution commit together. A domain savepoint rolls failed effects\nback while preserving the item lock and atomically consuming the retry attempt. Completed\nactions survive job cleanup and evidence retention; expired originals leave a\nminimal result digest tombstone, preventing a second effect. Active result reads\nrecheck host visibility and result target ownership.\n\nExternal handlers reserve a stable action idempotency key before submission.\nTimeout, process death or ambiguous outcome requires reconciliation; an expired\nlease never means permission to resend. `reconcile` must return authoritative\n`succeeded`, `not_applied` or `unknown`. `not_applied` is safe only when the provider\ncan exclude a late acceptance of the original send; uncertainty stays `unknown`.\nThe same key is reused after a conclusive non-application. Cancellation prevents\npending work but cannot retract a send already issued. Applications must arrange\nprovider reconciliation before privacy retention removes the binding; a redacted\nunknown action fails closed and cannot automatically execute again.\n\nEach plan step has a stable action identity. Completed steps are immutable and\nreturn their original result. Symbolic record IDs bind to exact earlier proposal\nrevision, successful result digest/model and target revision; they cannot point\nacross items or form cycles. Failed dependent steps never repeat predecessors.\nThe plan preview and target preconditions are part of its digest and visible in\neach step review; changed preview/preconditions require a fresh review.\nAbort/continue follows the pinned public playbook definition, with fresh authority\nat every step.\n\nHuman corrections are the logical split and the reviewer instruction. Both are\nminted only by their authenticated review API under reviewer authority, written\ninto a new immutable extraction configuration, and reach interpretation only as\na digest-verified copy. Neither grants handlers, candidates, permissions or\nautomation; `authorizeAutomatic` and preview/approval are unchanged for actions\nproduced under an instruction. Recording either supersedes current suggestions\nand queues the existing dispatch stages (a new extraction revision, then\ninterpretation — provider extraction budget is spent per correction because the\npredecessor pin is not reused); hosts wake their worker through\n`onSplit`/`onInstruct` and rely on dispatch repair otherwise. While a stage is\nqueued/running the item reports `processing` regardless of earlier actions; a\nfailed stage (extraction or interpretation) exposes its safe category through\n`getReinterpretationState`, and a retry anchored on the latest completed\ngeneration carries forward any newer split correction.\n\n`continueIntakeReview` uses the existing jobs continuation context. Applications\ncreate tasks with owner, tenant and exact `{recordId, revision, inputKey}` binding\nand configure `authorizeMcpTask` to revalidate it. A continuation answer only wakes\nthe task; the service reloads the authoritative decision. Waiting persists without\nan occupied worker and survives runner restart.\n\n## Deployment and evidence\n\nApply normal manifest migrations before runtime. Execution imports the public\nagents/users principal stack, which registers profiles including `ProfileAsset`;\nexecution-enabled hosts must migrate their dependency graph (including profile\nasset joins used by asset deletion). `/server` receipt-only imports register none\nof these additional models. Content is not a runtime dependency of ingestion.\n`reference/handlers.ts` is an application/test fixture, excluded from published\nentries and declarations; importing it deliberately adds Content and its asset\njoins, whose migrations the application then owns. No runtime DDL is performed.\n\nReal SQLite and PostgreSQL execution suites exercise the public Content draft and\nattachment APIs, transaction rollback, actor/context denials, simultaneous applies\nand reviewers, retention replay, external process death and actual TaskRunner\nrestart. See the issue 3674 test matrix for the complete release evidence mapping.\n\n## Layered retention and request automation\n\nEvery automation-bearing policy layer, including an optional request layer, must\nmatch the evaluated version. An absent request automation block adds no evaluator\nrestriction; it cannot replace the three required application/tenant/source opt-ins.\n\nAuthorized execution-policy access monotonically narrows the existing intake\nexpiry to `min(existing expires_at, item.created_at + resolved retentionMs)`.\nThe anchor is receipt creation, never review, retry or replay time. A longer later\npolicy never extends a recorded deadline. This hard maximum applies to the whole\nintake item: the existing `sweepRetention` protocol removes retained originals and\nderivatives, preserving replay identities. No second expiry column or hidden clock\nis introduced, and no blob I/O occurs in an execution transaction.\n\nAt an observed expired deadline, execution reads/completions erase proposal,\ndecision, execution, plan, action and feedback payloads under the item lock. Review\nreads return existing identity/hash fields with `state: 'expired'` and empty\n`display`; completed action replay returns its digest-only tombstone. Failed writes, including ordinary validation/CAS/policy rejection and domain\nsavepoint rollback, cannot roll back an already-authorized retention ceiling or\nredaction. Restoring a recorded authorized maximum needs no new content-read grant;\nlater revocation cannot undo it. Initial denied authorization records no intent.\nCompleted replay checks the deadline again after target authorization\ncallbacks before returning cached content. Proposal publication and automatic\nauthorization also recheck after preview/evaluator callbacks, before publishing\nretained proposal or decision payloads. Unknown\nexternal outcomes remain unknown/reconcile-only, never eligible for blind resend.\n"
1708
+ "content": "# Review and execution integration\n\n`/execution` exports `IntakeExecutionService`, handler/host types, policy\nresolution, binding digests and `continueIntakeReview`. `IngestionService` exposes\nthese operations when its optional `execution` configuration is present. Its\nloader is lazy: importing `/server` alone does not import the principal stack.\n`/dto` exposes execution messages using type-only exports. No generated REST,\nCLI or MCP mutation endpoint is enabled; applications authenticate their own\nservice surface and create `IngestionScope` from the session.\n\n## Catalog and authority\n\nApplications supply a trusted `IntakeExecutionOptions.handlers` catalog.\n`OperationHandler` has qualified ID, immutable version, description, optional\nreviewer-facing `label` (presentation only, carried on the reviewer catalog and\nnever on generation input or digests; REVIEW.md), object JSON\nschemas for arguments/results, allowlisted `resultModels`, `validate`, `preview`,\na registered `{model, action, version}` operation and explicit effect/idempotency/\nopen-world capability declaration. Preview returns display, exact normalized\narguments and target revision preconditions. `normalizedArgs` must equal the\nsubmitted args exactly; default or normalize before submission, never in preview. There is no arbitrary tool execution\nor expression evaluation. Reviewer display wraps application fields under `preview`\nand symbolic metadata under `dependencies`; plan steps additionally wrap that\nobject under `step` alongside the plan preview. Application display keys cannot\noverwrite framework metadata or be silently overwritten by it. A version change\nrequires a new preview and approval.\n`PlanHandler` references a real registered playbook key and resolved definition\nhash; expansion contains only ordered operation handlers and typed earlier-step\nresult references. Discovery/proposal generation consumes this catalog rather\nthan creating another registry. Semantic model output is never host configuration.\n\nAuthenticated receipt context captures `capturedCeiling.execution` with principal\nID and permission/handler/operation ceilings. The execution host's `authorize`\nresolves current grants and application/tenant/source/(optional request) policy\non the supplied executor, checking the active requester and confidential scope.\nLists intersect, budgets minimize, review requirements OR, and disabled policy\nwins. Policy versions must change when policy semantics change. Normal operation\nrequires human review; machine authorization requires explicit evaluated opt-ins\nat all three authority layers and remains separate provenance from human review.\nThe reference handlers always require review; no evaluation claim is made here.\n\n`operation: 'review_own'` is the submitter-scoped decision gate (#4085). The\nservice accepts it only when the host's `authorize` result carries\n`submitter: true`, the resolved policy's `submitterReview` is enabled (the\napplication layer opts in; tenant/source layers may only set it `false`), and\nthe item's server-recorded `submitter_id` (the receiving service's authenticated\n`scope.actorId`) equals the current actor and the captured\n`execution.principalId`; apply rechecks that a `review_own` decision's reviewer\nis that submitter and principal. All other `review` checks apply\nunchanged; `correct` is refused. The decision row records `mode` and\n`selfDecision` (decider is the submitter, in either mode), and `feedbackEvent` copies them as `decisionMode`/`selfDecision`;\n`authorizeAutomatic` never reads human decisions, so a self-decision cannot\nbecome automation evidence. `listOwnProposals` reads with the ordinary `read`\noperation per handler after an item-level `read` check. Unreadable items are\nskipped before projection (1000 hidden rows per call, then `Own proposal scan\nlimit`) and the cursor names only emitted items with a confirmed readable\nsuccessor. On this surface every host `assertTarget` throw is mapped to the\nexported `IntakeAccessDeniedError` (message `Intake unavailable`, the type of\nevery execution denial), so the item becomes an `unavailable` entry and host\nerror text is not returned; hosts need no change. Other errors propagate,\nincluding a throwing grant store in `authorize`. The feedback anti-widening\ncheck also refuses a re-evaluation that turns `submitterReview` on.\nDeletion redaction blanks `submitter_id` and `owner_key` with the payloads and\ndrops `execution.principalId` unless an external action is still `executing`\nor `outcome_unknown`; `finish` and the reconcile state update release it once\nnone is left, and later deletion sweeps do the same.\nHosts whose `authorize` switches exhaustively on the operation fail closed for\nthe new value until they opt in.\n\n`mutationBoundary: 'serialized'` is an explicit host guarantee, not an inferred\nproperty of a permissions array: grant revocation must serialize with the supplied\ntransaction, or the owning mutation must revalidate under its own lock. The host\nmust implement that guarantee before enabling handlers. `assertTarget` similarly\nlocks current tenant/confidential ownership and revision against concurrent\nwriters using the supplied executor. The reference host demonstrates a scoped\nrow lock before public `Contents` reads. A current `PrincipalRun` intersects live\npermissions with the captured ceiling and checks the exact registered collection\noperation at every effect. No `runOnce` atomicity is assumed.\n\n## Reviewer-chosen actions and dispositions\n\n`startAction(StartActionInput)` lets an authenticated reviewer begin any\noperation handler the item's evidence media types offer, without a model\nsuggestion. It checks `review` access under that handler before any callback,\nrefuses plan handlers and resolved items, binds the current analysis revision's\ncompleted/partial attempt, inserts an action keyed `reviewer:<requestId>` with\n`data.origin = 'reviewer-selected'`, and reuses `buildBinding`/`publish`: schema\nvalidation, `validate`, `preview`, exact normalized arguments, target locks,\nevidence pins and the request ledger behave exactly as for `previewProposal`,\nincluding the typed `HandlerArgumentsInvalidError` (with value-free `issues`)\nfor an argument-schema or `validate` refusal of the reviewer's arguments;\nevery other refusal stays a plain `Error` (#4281). Replays re-preview against the original revision and return the same review.\nApproval, apply, retention, redaction and reconciliation are unchanged.\n`authorizeAutomatic` refuses `reviewer-selected` actions and resolved items;\nhuman routing is never machine authority.\n\n`resolveItem(ResolveItemInput)` appends one terminal `intake_dispositions` row\n(`disposition = 'resolved_no_action'`, reason/reviewer in redactable `data`)\nunder the item lock. Reviewer authority is taken from the first handler the\ncaptured ceiling and policy offer; no new grant exists. It refuses while any\naction is `authorized` with an unexpired approval for its current review\nversion, `executing`, `outcome_unknown` or `succeeded`; `failed` actions and\nlapsed approvals do not block it (neither can be rejected). Afterwards\n`submitDecision` refuses everything but `reject`, `publish` refuses any new\nrevision (correction, re-preview, plan preview), the apply gate (`approved`)\nrefuses any execution or retry, and `IngestionService.analyze`,\n`reviseLogicalSplit` and `createAction` refuse the item under its lock before\nany write. `createAction` (process authority) also refuses the reserved\n`reviewer:` key prefix and `reviewer-selected` origin, which only\n`startReviewerAction` mints; `previewProposal` on such an action requires\n`review` access and the current handler@version. `resolveItem` supersedes\nqueued/running analyses and completes dispatch intents under the item lock, and\n`claimAnalysis` returns `null` for a resolved item; `publishProposal` refuses\na resolved item and any reviewer-selected action. `[feedbackActionTransaction]`\ntakes `targetRevisions` (default true); routing lineage re-checks pass false. The feedback context's\n`settled` flag gates selection only; lineage re-checks ignore it (FEEDBACK.md). `intake_dispositions` is a new model: deploy\nits manifest migration (`pnpm ... db:migrate`) before upgrading hosts;\n`assertReady` checks it, and both privacy deletion and retention expiry\n(`redactExecution`) redact its payload with the other item-owned tables.\n`IntakeItemDTO.disposition` is `{ state: 'resolved', at }` (row `created_at`,\nnever redacted); `getItemDisposition` returns reviewer and reason under\n`reviewerAccess`. `resolveItem` captures an optional `reviewer_routing` feedback projection in the\nsame transaction; a reviewer-selected action is captured when its approval is\nrecorded (FEEDBACK.md).\n\n## Durable review and effects\n\nPreview appends a proposal bound to exact analysis attempt/evidence, handler,\narguments, policy and target preconditions. Decision requests use unique durable\nrequest IDs; reusing an ID with changed content is rejected. First valid review\nwins under the item lock. Corrections append a new revision; reject/defer remain\nnon-executable. Plan corrections use re-expansion. Human decisions expire and\nlive authority is checked again before each step. Raw foundation proposals cannot\nbypass execution's schema, preview, evidence and approval verification.\n\nDatabase handlers must use `context.db` for every domain effect and must perform\nno external I/O. Domain result and successful execution commit together. A domain savepoint rolls failed effects\nback while preserving the item lock and atomically consuming the retry attempt. Completed\nactions survive job cleanup and evidence retention; expired originals leave a\nminimal result digest tombstone, preventing a second effect. Active result reads\nrecheck host visibility and result target ownership.\n\nExternal handlers reserve a stable action idempotency key before submission.\nTimeout, process death or ambiguous outcome requires reconciliation; an expired\nlease never means permission to resend. `reconcile` must return authoritative\n`succeeded`, `not_applied` or `unknown`. `not_applied` is safe only when the provider\ncan exclude a late acceptance of the original send; uncertainty stays `unknown`.\nThe same key is reused after a conclusive non-application. Cancellation prevents\npending work but cannot retract a send already issued. Applications must arrange\nprovider reconciliation before privacy retention removes the binding; a redacted\nunknown action fails closed and cannot automatically execute again.\n\nEach plan step has a stable action identity. Completed steps are immutable and\nreturn their original result. Symbolic record IDs bind to exact earlier proposal\nrevision, successful result digest/model and target revision; they cannot point\nacross items or form cycles. Failed dependent steps never repeat predecessors.\nThe plan preview and target preconditions are part of its digest and visible in\neach step review; changed preview/preconditions require a fresh review.\nAbort/continue follows the pinned public playbook definition, with fresh authority\nat every step.\n\nHuman corrections are the logical split and the reviewer instruction. Both are\nminted only by their authenticated review API under reviewer authority, written\ninto a new immutable extraction configuration, and reach interpretation only as\na digest-verified copy. Neither grants handlers, candidates, permissions or\nautomation; `authorizeAutomatic` and preview/approval are unchanged for actions\nproduced under an instruction. Recording either supersedes current suggestions\nand queues the existing dispatch stages (a new extraction revision, then\ninterpretation — provider extraction budget is spent per correction because the\npredecessor pin is not reused); hosts wake their worker through\n`onSplit`/`onInstruct` and rely on dispatch repair otherwise. While a stage is\nqueued/running the item reports `processing` regardless of earlier actions; a\nfailed stage (extraction or interpretation) exposes its safe category through\n`getReinterpretationState`, and a retry anchored on the latest completed\ngeneration carries forward any newer split correction.\n\n`continueIntakeReview` uses the existing jobs continuation context. Applications\ncreate tasks with owner, tenant and exact `{recordId, revision, inputKey}` binding\nand configure `authorizeMcpTask` to revalidate it. A continuation answer only wakes\nthe task; the service reloads the authoritative decision. Waiting persists without\nan occupied worker and survives runner restart.\n\n## Deployment and evidence\n\nApply normal manifest migrations before runtime. Execution imports the public\nagents/users principal stack, which registers profiles including `ProfileAsset`;\nexecution-enabled hosts must migrate their dependency graph (including profile\nasset joins used by asset deletion). `/server` receipt-only imports register none\nof these additional models. Content is not a runtime dependency of ingestion.\n`reference/handlers.ts` is an application/test fixture, excluded from published\nentries and declarations; importing it deliberately adds Content and its asset\njoins, whose migrations the application then owns. No runtime DDL is performed.\n\nReal SQLite and PostgreSQL execution suites exercise the public Content draft and\nattachment APIs, transaction rollback, actor/context denials, simultaneous applies\nand reviewers, retention replay, external process death and actual TaskRunner\nrestart. See the issue 3674 test matrix for the complete release evidence mapping.\n\n## Layered retention and request automation\n\nEvery automation-bearing policy layer, including an optional request layer, must\nmatch the evaluated version. An absent request automation block adds no evaluator\nrestriction; it cannot replace the three required application/tenant/source opt-ins.\n\nAuthorized execution-policy access monotonically narrows the existing intake\nexpiry to `min(existing expires_at, item.created_at + resolved retentionMs)`.\nThe anchor is receipt creation, never review, retry or replay time. A longer later\npolicy never extends a recorded deadline. This hard maximum applies to the whole\nintake item: the existing `sweepRetention` protocol removes retained originals and\nderivatives, preserving replay identities. No second expiry column or hidden clock\nis introduced, and no blob I/O occurs in an execution transaction.\n\nAt an observed expired deadline, execution reads/completions erase proposal,\ndecision, execution, plan, action and feedback payloads under the item lock. Review\nreads return existing identity/hash fields with `state: 'expired'` and empty\n`display`; completed action replay returns its digest-only tombstone. Failed writes, including ordinary validation/CAS/policy rejection and domain\nsavepoint rollback, cannot roll back an already-authorized retention ceiling or\nredaction. Restoring a recorded authorized maximum needs no new content-read grant;\nlater revocation cannot undo it. Initial denied authorization records no intent.\nCompleted replay checks the deadline again after target authorization\ncallbacks before returning cached content. Proposal publication and automatic\nauthorization also recheck after preview/evaluator callbacks, before publishing\nretained proposal or decision payloads. Unknown\nexternal outcomes remain unknown/reconcile-only, never eligible for blind resend.\n"
1709
1709
  },
1710
1710
  {
1711
1711
  "path": "README.md",
@@ -1720,17 +1720,17 @@
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### 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\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\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\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\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.\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",
1732
1732
  "module": "REVIEW",
1733
- "content": "# Authenticated review surfaces\n\n`@happyvertical/smrt-ingestion/svelte` exports `IntakeInbox`, `IntakeReview`,\n`IntakeWorkspace` and `EvidenceViewer`. The browser-safe DTO entry exports their `IntakeReviewHost`\ncallback contract. Import styling/theme configuration from smrt-ui in the host.\nComponents use smrt-ui primitives and the `ingestion.*` i18n catalog.\nExisting `IntakeInbox` hosts now keep the previous rows visible, with their\ncontrols disabled, while a refresh or filter change loads; any failed read\n(Load more included) still clears them.\n\nThe host authenticates every request, resolves tenant/actor/confidential scope\nfrom its session, enforces CSRF on mutations, and constructs `IngestionService`.\nNever accept scope, reviewer, permissions or a principal from callback JSON.\nOnly supply authorized evidence URLs and escaped text; original URLs are\nsame-origin authenticated handlers that recheck `readEvidence` on every read.\nCandidate discovery uses `findCandidates` with current grants. Presentation\nstate and disabled buttons provide no server authority.\n\n`listReviews(itemId, {cursor?,limit?})` reloads saved action identities and their\ncurrent plan membership without browser storage. It returns at most 50 actions,\nwith an opaque action-ID cursor. Every payload requires current item, handler,\nparent plan and target access under the owning transaction. Denied reads fail\nclosed. Target reads check current authorization separately from historical\nrevision freshness: unfinished drift returns state-only stale reviews without\nremoving unrelated entries; succeeded results remain readable after authorized\ntarget changes. Apply still enforces exact bound target revisions. Expired entries\ncontain only review identity/state. Stale entries never disclose old args or target\nlabels; an authorized parent plan additionally exposes `stalePlan` identity, key,\ncurrent plan revision and handler identity. Hosts must collect fresh explicit args\nfrom the reviewer/current authorized evidence and call `previewPlan` with that\nexact plan CAS and the current completed analysis attempt. Action revision is not\nplan revision. Re-expansion preserves action identity and requires fresh approval.\nSuccess results are rechecked through the durable result reader.\nPlan membership contains the exact parent args/version so edits call\n`previewPlan`, not per-step correction. An item may have more review pages; the\nhost must aggregate state across pages when projecting a production inbox state.\n\nA `needs_review` suggestion is completable, not only rejectable (#4208). That\nincludes a suggestion kept because its arguments missed only required fields\n(#4284); nested misses appear as JSON Pointers such as `/vendor/name`. The\ncomponent shows its `missingFields`, an editable `Suggested arguments (JSON)`\ndraft prefilled from the generated arguments, and the candidate picker for\ndeclared candidate fields; Prepare review stays disabled while required fields\nare still missing from an unchanged draft. An unchanged draft previews the\ngenerated snapshot as before; an edited draft is sent as `preview({..., args})`,\nwhich the published host publishes through the ordinary `previewProposal` /\n`previewPlan` with the same `ui:<index>` intention, never by rewriting the\ngeneration. The handler validates the human arguments again before a\n`waiting_review` action exists, approval remains a separate explicit decision,\n`ActionReview` lists top-level required arguments missing from the current\ndraft while editing (nested misses named by JSON Pointer in `missingFields` are\nnot re-checked in the browser; the server's revalidation refuses them and the\ncomponent shows that inline as `HandlerArgumentsInvalidError`), and no authority or automation eligibility is added: a failed attempt,\nan unoffered handler or a foreign stage is still refused by the host.\n`preview` throws on every failure, as before. When the handler's argument\nschema or `validate` refused the arguments being previewed (operation preview,\nwhich also carries corrections, a reviewer-started action, or plan preview),\nthe server throws `HandlerArgumentsInvalidError` (`name` set, messages\nunchanged). An argument-schema refusal also carries `issues`: a frozen list of\nat most `HANDLER_ARGUMENT_ISSUE_LIMIT` (20) `{ path, keyword? }` entries\n(`HandlerArgumentIssue`). `path` is built only from schema-declared property\nnames, `required` names and real array indexes and is cut at\n`HANDLER_ARGUMENT_PATH_LIMIT` (160)\ncharacters (never splitting a `~0`/`~1` escape). Segments are escaped per RFC\n6901 (`~` as `~0`, `/` as `~1`), with two departures: `/` is the whole\narguments object (never a key `\"\"`), and `?` stands for a data-named key. A\n`required` refusal appends the missing schema name to the parent's path. The\nformat relates to a suggestion's `missingFields` as follows: a root path\n`/name` is the bare `missingFields` entry `name` (unescaped), and a nested\nentry is the same escaped pointer in both (for example `/vendor/a~1b~0c`).\nThe bundled view shows a root issue without its leading `/`, so its refused\nfields read like the missing-information list. `ProposalValidationError`\nreasons share the schema-owned segment rule but stay unescaped.\n`keyword` is the failing schema keyword. Argument values, Ajv\n`params`/messages and handler messages are never included. A `validate`\nrefusal has no `issues` (the handler contract returns only `ok`). The size and\nshape preconditions checked before the schema runs (arguments over the policy\nbyte limit, or a handler schema that is not a closed `type: 'object'` with\n`additionalProperties: false`) stay a plain `Error`: they fail closed as a\ndenial, never as the inline refusal. Apply-time and\nexternal-send revalidation and result-schema checks keep a plain `Error`. The component shows an inline message and\nkeeps the view and draft when `preview` either rejects with an error whose\n`name` is `HandlerArgumentsInvalidError` or resolves `{ rejected: 'invalid' }`\n(`PreviewRejection`, optionally with the same `issues`). A transport that\ncrosses a process boundary preserves the inline UX by keeping that name and\n`issues` (for example re-throwing an `Error` with\n`name = 'HandlerArgumentsInvalidError'` in the browser callback) or by\nreturning `{ rejected: 'invalid', issues? }` for that case only, as the\nmaintained fixture's `previewForReview` and `startActionForReview` do. Since\n#4281 the fixture's rejection body also carries `issues` when the schema\nrefused; read `rejected === 'invalid'` rather than comparing the whole body\nwith strict equality. Without either, the refusal behaves like\nany other failure: the view is cleared exactly as before this change, and the\nreviewer's in-memory draft returns after an authorized refresh. Every other\nthrown preview or candidate-search failure (denied, revoked, unavailable or\nunknown) clears the view.\nUnsent drafts live only in component memory, keyed by attempt and suggestion\nindex. They survive Refresh, a failed callback, an action on another card and a\ntransient `unavailable`/`stale` reload; a `revoked` or `expired` result\ndiscards them, a successful preview clears that card's draft, and an available\nreload drops drafts for attempts or cards no longer offered.\n\nThe host's `load` callback supplies a current `ItemReviewView`, using\n`getCompletedAnalysis` with no historical fallback. Generated suggestions bind\nthe **current generation attempt**, not `generation.source.attemptId` (the prior\nextraction). `previewGeneratedProposals` publishes exact reviews and continues to reject stale\ngeneration candidate pins. When `listReviews` reports `generationStale`, the host\nomits obsolete generation output and renders authorized saved reviews/results.\nCompleted saved actions do not hide healthy unprepared suggestions. The saved-binding hint is not\nan authoritative generation-availability check: a fresh human preview can bind a\ncurrent target while the immutable generation still pins its former revision.\n`getCompletedAnalysis` remains strict and throws server-only\n`GenerationSnapshotStaleError` only after every current catalog/provider/candidate\nread is authorized and an immutable candidate revision differs. The maintained\nhost catches only that class, reacquires `listReviews` under current owning\nauthority, and returns that new page without generation output. It never reuses\nthe earlier page after an error. Denials and unknown failures propagate; healthy\ngeneration still exposes unprepared sibling suggestions. Stale entries expose handler\nand attempt identity only when that attempt is still the current completed/partial\nanalysis. An empty-args editor submits fresh explicit human arguments through\n`previewProposal` or `previewPlan` with the saved CAS; it never reuses old generated\narguments, rewrites the generation snapshot or transfers approval. Analysis-stale\nentries without an attempt require normal reprocessing. Approve,\nreject, defer and correct call `submitDecision`; corrected args create a new\nrevision which requires a separate human approval. After an approve/defer/reject\ndecision, optional `editAction` calls `previewProposal` with the current action\nrevision to publish a new review; completed/executing/unknown actions cannot be\nrevised. Local dirty args disable Apply but confer no authority. Plan edits re-expand through\n`previewPlan` with the current **plan** revision. `applyAction` accepts only an\naction ID. Unknown external outcomes require server reconciliation; the UI\nnever offers a blind resend. Stable result IDs survive reload and retry.\n\nReplace `contextKey` whenever authenticated tenant/session context changes.\nChanging it or itemId destroys the old view and fences late callback results.\nDenied refresh clears prior originals, candidates, arguments and results.\nMissing confidence is unavailable; page/time links exist only for observed\nlocations. Provider errors and unresolved/partial results remain review states.\nA host that enabled `proposals.failureCapture` may fetch a failed attempt's\nredacted model output with `getFailedAttemptCapture(itemId, attemptId?)`.\nRetaining text requires a configured host redaction hook; a missing or failed\nhook yields only `redaction_failed` metadata. The host owns that redaction policy.\nThe getter requires current reviewer authority for that item and fails closed\notherwise;\n`load`, inbox rows and review pages never include it, so a host shows it only\nbehind its own explicit diagnostic action (see\n[PROPOSALS.md](PROPOSALS.md#failed-attempt-capture-opt-in-4285)).\n\n## Submitter-scoped decisions\n\nFor trusted internal sources the person who submitted an item may confirm or\ndecline their own proposal without the reviewer inbox. `listOwnProposals`\nreturns only items whose server-recorded `submitter_id` equals the current\nauthenticated actor, each with its bounded saved review page reloaded under\ncurrent item, handler and target authority. An item the actor can no longer\nread (the host `authorize` returns false or throws `IntakeAccessDeniedError`)\nis skipped before projection: the page is filled from readable items only, in\n50-row batches, and `nextCursor` names the last emitted item and is present\nonly when a further readable item was actually found. Neither the entries, the\npage size nor the cursor reveal a hidden item. If one call has to skip 1000\nhidden submissions it fails with `Own proposal scan limit` rather than return a\nshort page or a cursor that stops inside the hidden run; this error is the only\nsignal, and it says only that such a run exists. Any other `authorize` error\npropagates instead of shrinking the list. An item that is still readable but\nwhose reviews are denied is returned as `{ item, reviews: null, unavailable:\ntrue }`: that covers ingestion's own denials and any throw from the host\n`assertTarget` (deleted or revoked targets), whose text is never returned.\nIntegrity, validation and database errors from ingestion itself propagate. The\nreviewer `listReviews` surface keeps propagating host target errors unchanged.\n`submitOwnDecision` takes the same `ReviewInput` CAS fields and request ID as\n`submitDecision` and accepts `approve`, `reject` and `defer` only; `correct`\nbelongs to the reviewer surface. It runs under the `review_own` execution\noperation: the host's `authorize` must return `submitter: true`, the resolved\npolicy must have `submitterReview` enabled, and the recorded submitter must be\nthe current actor and also the receipt's captured execution principal (the\nidentity the effect runs as), checked under the item lock and again at apply.\nA receipt captured for a bot or service principal is never self-approvable. Policy enablement, handler/operation allowlists, captured\nceiling, confidential access, retention and the first-valid-decision lock are\nunchanged. The decision is a human decision by that actor, recorded with\n`mode: 'review_own'`; reviewer decisions carry `mode: 'review'`. In both modes\n`selfDecision` is true exactly when the deciding actor is the item's\nsubmitter, so a reviewer approving their own submission is never independent\nreview. A self-decision is not a reviewer judgment: it never feeds\nautomation eligibility (machine authorization remains the separate evaluated\n`kind: 'machine'` path) and its feedback events carry the same marker. The\n`unavailable` entry discloses nothing about the denied handler or target.\n`applyAction` then runs once under the approver's live grants exactly as\nfor reviewer decisions. Hosts render this surface from their own authenticated\nsession; presentation state confers no authority, and a source payload cannot\nnominate a submitter.\n\n## Assignment and logical splits\n\nAssignment is explicitly host-owned, durable and versioned. `assign` receives\nan expected assignment version and request ID; the host must authorize the\nmanager, constrain eligible assignees, CAS the durable record and reject stale\nwrites. Assignment does not grant read, review or execution rights. The maintained\nfixture provisions its own SQLite assignment table before serving requests; no\nproduction ingestion table or migration is introduced for assignment.\n\n`reviseLogicalSplit` authorizes the current generation through the same-executor\ncatalog/candidate gate and the existing reviewer grant and policy reviewer list.\nProcess access alone cannot mint or replay a human correction; reviewer authority\nis checked before mutation and again before publication. A generation without a\nreviewable catalogue cannot be corrected through this reviewer API.\nIt requires all observed pages exactly once, an exact\ncurrent attempt/revision and a request ID. It records the authenticated actor\nand predecessor as a **human correction** in a new immutable extraction\nconfiguration, queues re-extraction and immediately makes previous suggestions\nand approvals stale. It never changes original bytes/evidence or labels a human\nedit as model output. The host processes the new extraction, then calls\n`prepareGeneration` and the normal fenced interpretation stage. The supported\nimmediate-predecessor extraction pin is unchanged. The generator receives a\nhuman correction only after its digest matches the authoritative source. Ordinary\n`analyze` calls cannot mint an extraction correction; the owning split API is the\nauthenticated origin, and forged interpretation corrections fail before provider\ndisclosure. If its proposed grouping differs from the correction, suggestions are withheld\nwith `human_split_not_respected`. New proposals require new explicit review.\nThe reference host runs these stages synchronously for browser determinism;\nproduction hosts dispatch the existing durable analysis jobs.\n\n## Reviewer instructions\n\n`recordReviewerInstruction({itemId, attemptId, expectedRevision, text,\nrequestId})` records a plain-text instruction for one item (\"This is a customer\nPO from Badger; file it, do not bill it\") as the second kind of **human\ncorrection**. It is authorized exactly like `reviseLogicalSplit`: the current\ngeneration must pass the same-executor catalog/candidate gate and the reviewer\ngrant plus policy reviewer list, and authority is checked before mutation and\nagain before publication. Process access, `analyze`, and a client payload cannot\nmint one: `analyze` rejects a `reviewerInstruction` key on an extraction\nconfiguration, and an interpretation copy that differs from the pinned\nextraction's record fails with `Generation evidence changed` before provider\ndisclosure. Text is required, trimmed-nonempty and at most 4,000 characters.\n\nThe record is immutable: `{id, text, actorId, recordedAt, supersedesId, digest}`\nplus the request binding, written into a new extraction configuration beside\nany existing split correction. Recording supersedes current suggestions and\napprovals, queues the normal fenced re-extraction and interpretation through the\nexisting dispatch path, and returns immediately; the reviewer keeps working\nwhile the item reports `processing`. `prepareGeneration` copies the instruction\ninto the interpretation configuration, the generator receives it only after its\ndigest matches the authoritative extraction record, and saved generation\nprovenance records `reviewerInstruction: {id, digest}`. A later instruction\nrecords `supersedesId` and replaces the earlier one for future interpretations;\n`listReviewerInstructions(itemId)` returns the full history, newest first, and\nhistory is never deleted. The instruction steers the model only: it cannot add\nhandlers, candidates, schemas, permissions or automation eligibility, replies\nare validated as usual, and suggestions still require explicit preview and\napproval. A replay with the same request ID returns the same revision; a changed\ntext under the same request ID conflicts.\n\n**Cost.** Each recorded instruction appends a new extraction revision, so the\nitem is extracted again before it is interpreted again: cheap for embedded-text\nPDFs and plain text, but OCR/speech hosts spend provider budget per instruction,\nexactly as they do per split correction. The pinned extraction is not reused\nbecause the interpretation contract requires its source to be the immediately\npreceding revision and `getCompletedAnalysis(itemId, attemptId)` serves only\nthe current revision (PROPOSALS.md, \"Durable stages\"); reusing it would mean\nweakening that predecessor pin, which protects every generation from an\nintervening reprocess, so this feature follows the split path instead.\n\n**State and failure.** An in-flight stage (queued/running) reports the item as\n`processing` even when earlier, now-stale actions exist. If the re-extraction or\ninterpretation fails, `getReinterpretationState(itemId)` returns the latest\nattempt's safe failure category and the latest completed generation attempt;\nthe host projects them as `instruction.failure` and `instruction.binding`, and\n`recordReviewerInstruction` accepts that historical attempt as its anchor when\n`expectedRevision` is the item's current (failed) revision and no later\n**interpretation** completed and nothing is queued or running, so the reviewer\ncan retry or change the instruction after either stage fails. A completed\nextraction whose own interpretation failed belongs to the failed attempt, not a\nnewer result; a completed extraction whose interpretation has **not been\nappended yet** is in flight (the host is between stages) and is refused with\n`ReviewerInstructionStaleError` (`Stale reviewer instruction`), so a second\nreviewer cannot pre-empt it. That gap expires: once the extraction attempt's\ncompletion plus the item's analysis lease duration (`limits.leaseMs`, the lease\n`claimAnalysis` grants) has passed with no interpretation appended,\n`getReinterpretationState` reports `failure: 'not_started'` with the retry\nbinding and the guard allows the retry. `not_started` means **the\ninterpretation did not start within the lease window**: the host crashed,\nthrew between `prepareGeneration` and `analyze`, or its queue is merely slow.\nPre-empting a slow but healthy host is safe because `analyze` refuses an\ninterpretation whose pinned extraction is no longer the item's latest, under\nthe item lock and before anything is superseded\n(`GenerationSourceStaleError`, nothing appended): the slow host's late append\ncannot clobber the retry. Missing or malformed timing (no attempt, no\n`completedAt`, non-finite `leaseMs`) counts as already expired rather than\nholding retries forever. The \"still being re-read\" note shown after a stale\nresult is cleared by the next reload that shows the item settled; the draft\nthen carries a persistent \"This item changed while you were writing; your\ninstruction was not recorded.\" note (any stale cause: another reinterpretation,\na split, or a host reprocess) until the reviewer edits or resubmits it. The guard and\n`getReinterpretationState` share one predicate, and the latter's\n`reinterpreting` flag (projected as `instruction.reinterpreting`) is true in\nthe gap too, so the component keeps polling and keeps Re-read disabled there.\nThe published host maps two typed errors to `instruct` results:\n`ReviewerInstructionStaleError` → `{ stale: true }` (refresh-and-retry: reload\nwith a note, draft kept) and `ReviewerInstructionInvalidError` → `{ invalid:\ntrue }` (empty, whitespace-only or over 4,000 characters: shown inline, draft\nkept). Neither is a denial. Custom hosts should map them the same way; a host\nthat lets either propagate as a thrown error makes the component treat it like\nany other failed mutation, i.e. a whole-view deny with the \"view unavailable\"\nmessage, as before these results existed. The maintained fixture's\n`/api/instruct` now answers an invalid text with HTTP 200 `{ invalid: true }`\ninstead of 409. A retry from an older anchor builds on the **whole configuration**\nof the newest extraction after it (replacing only the instruction), because that\nis the item's current configuration: corrections chain forward through it and a\nhost reprocess replaces it. So a split followed by a failed stage is never\nsilently dropped, and a failed reprocess's changed configuration is neither\nreverted nor overlaid with a split it dropped. **Concurrency.** `recordReviewerInstruction` and `reviseLogicalSplit` each\nrun their whole decision in one transaction under the item row lock: the\nanchor snapshot read takes the lock first, the execution authorization of\nthat snapshot takes it again (`UPDATE intake_items` row lock), the guard step\nre-asserts it explicitly, and\nthe request-key replay check, the revision and later-work guards, the\ncarried-forward split, the history read that sets `supersedesId`, and the\nappend all run under it. On PostgreSQL a second reviewer at the same revision\nblocks on that lock and is then refused (`ReviewerInstructionStaleError` /\n`Stale logical split`), so the ledger cannot fork; an instruction racing a\nsplit (in either order) is refused rather than built from the pre-split\nconfiguration; and a double-click whose duplicate commits after the unlocked\nreplay check is answered as a replay of the committed request, not a conflict\nor a denial.\n\n**Host reprocess.** A host reprocess (a plain `analyze()` extraction the host\nconfigures itself) cannot carry human corrections — `analyze` rejects\n`humanCorrection`/`reviewerInstruction` on extraction configurations — so it\ndrops the split and the instruction alike, and neither is applied to its\ninterpretations. The instruction is then reported as `dropped`, not pending:\n`getReinterpretationState().instructionInEffect` names the instruction the\nnewest extraction carries (verified by digest) and is null after such a\nreprocess. History is unchanged; the reviewer can re-record the instruction,\nwhich supersedes the dropped one.\n\n`ItemReviewView.instruction` exposes `current` (the latest recorded instruction\nstill in effect, i.e. carried by the newest extraction), optional `dropped`\n(the latest recorded instruction a reprocess dropped), `applied` (the\ninstruction the displayed **generation** ran under; a completed extraction alone\napplies nothing), `stale` (the displayed suggestions predate the current\ninstruction), optional `failure` and optional `binding`. Feedback examples that carry instruction\ntext count it toward the feedback byte budget (FEEDBACK.md). The optional host callback\n`IntakeReviewHost.instruct` is implemented by the published adapter when the\nservice supports it, with an optional `onInstruct(itemId, revision)` wakeup\nmirroring `onSplit`. The review component renders \"Instructions for the\nassistant\" with \"Re-read with these instructions\", shows \"Reinterpreting…\" while\nthe item's stage is queued/running, repeats the existing authenticated `load`\non `pollMs` (default 2 s, backing off to 5×) and patches the view in place —\ndrafts, split edits, focus and the evidence viewer survive and no loading\nplaceholder is shown — stops when the stage is no longer in flight, and then\nshows the instruction that produced the current suggestions, marking a\nsuperseded one as stale. An explicit host denial on a poll tick fails closed at\nonce; a thrown tick is treated as transient (view and drafts kept, a\n\"Couldn't refresh; retrying.\" note, backoff continues), but because hosts may\nalso throw for revoked access, three consecutive thrown ticks fail closed.\n**Hosts must signal revocation by returning `availability: 'revoked'`** (or\nanother non-`available` state) from `load`, not by throwing: a returned denial\nclears the view on that tick, while a host that throws on revocation leaves the\nalready-displayed content visible until the third thrown tick (about 10 s at the\ndefault interval and backoff) before the view fails closed.\nSplit drafts survive a refresh only when the reviewer edited them. A failed stage shows its safe category with the form\nstill available. There is no\nstreaming channel; status is read through the existing item/analysis APIs. The\nmaintained fixture records the instruction durably and then runs the stages in\nthe background so the browser proof exercises the in-place update.\n\n`feedback` is an optional explicit correctness callback, separate from approval\nchoice and execution success. No learning, feedback storage or rule promotion is\nimplemented by these components; #3676 owns those services. Do not pass feedback\nor a feedback callback to readers without the relevant host grant.\n\n## Reviewer-chosen actions and \"handled, no action\"\n\nA reviewer is not limited to model suggestions. `ItemReviewView.catalog` carries\nthe handlers the item's catalog currently offers (`listHandlers`, discovery media\ntypes and live preview authority; it is presentation, never a grant). The optional\n`startAction` callback forwards `StartActionInput` (`itemId`, `handlerId@version`,\nexplicit `args`, `requestId`, optional `reason`) to `startReviewerAction`, which\nrequires the current reviewer grant under that handler, a completed or partial\nattempt on the current analysis revision, and an operation handler the item's\nevidence media types offer. Plan handlers go through `previewPlan`. The server\ncreates an action keyed `reviewer:<requestId>` with origin `reviewer-selected`\n(`createAction` refuses that key prefix and origin, so process authority cannot\nmint reviewer provenance; re-previewing such an action with `previewProposal`\nneeds the reviewer grant and keeps its handler fixed, so only its arguments can\nbe corrected),\nruns the handler's normal `validate`/`preview`, publishes a `waiting_review`\nrevision and requires the same explicit approval and apply as a generated\nproposal. The reviewer typed these arguments, so a handler argument-schema or\n`validate` refusal throws `HandlerArgumentsInvalidError` with the value-free\n`issues` described above, and the rolled-back transaction leaves no action row\n(#4281). Every other refusal (input shape, access, handler unavailable, item\nresolved, identity or request conflict, normalization mismatch) stays a plain\ndenial. `startAction` follows the `preview` contract: it throws, or a transport\nmay resolve `{ rejected: 'invalid', issues? }` for that one case. The component\nkeeps the start form, handler, arguments and reason, shows an inline refusal and\nlists any field paths; any other failure clears the view as before. Replays\nwith the same request return the same review; changed arguments or reason\nconflict. Such actions are never automation-eligible: `authorizeAutomatic`\nrefuses them regardless of policy opt-ins. The UI pre-fills arguments only from a\nsame-handler suggestion (for example a `needs_review` one) and a single original's\nevidence references, lists the required fields still missing, and submits exactly\nwhat the reviewer typed. An item whose current attempt failed outright must be\nreprocessed first; an interpretation that completed with `provider_error`,\n`unknown` or no suggestions can be acted on directly. `ReviewAction.origin`\nexposes the provenance so `ActionReview` can label human-started actions.\n\nThe optional `resolve` callback forwards `ResolveItemInput`\n(`disposition: 'resolve_no_action'`, `requestId`, optional `reason`) to\n`resolveItem`. It needs reviewer authority under any handler the item's captured\nceiling offers and refuses while an action is `authorized` with a live approval,\n`executing`, `outcome_unknown` or `succeeded`; waiting, deferred, rejected and\nfailed actions, and authorized ones whose approval expired, may remain (neither\nan exhausted failed action nor a lapsed approval can be rejected, so they must\nnot keep the queue open). Afterwards only reject remains: those actions can no\nlonger be approved, corrected, deferred, re-previewed, retried, applied or\nautomated. `submitDecision` refuses every decision but `reject`, no new revision\nis published for the item, `applyAction` rechecks the disposition before any\neffect, and `analyze`, `reviseLogicalSplit` and `createAction` refuse the item\nunder its lock before any write, so it is never reanalysed, re-split or given a\nnew action. `resolveItem` supersedes any queued or running analysis under the\nsame lock and `claimAnalysis` refuses a resolved item, so no provider is called\nafter a human closed it; the item's `processingState` keeps its last value (it\ndescribes analysis, not review), and the inbox state `resolved` is authoritative.\n`publishProposal` (process authority) refuses a resolved item and any\nreviewer-selected action. The UI hides Approve, Defer, Apply, every edit control, suggestion\npreview and split controls on a resolved item.\nResolved items hide the instruction editor and stop reinterpretation polling, even if an older processing projection is still queued. Recording an instruction cannot append a new revision after resolution.\n\nPaged lists project the resolved state and disposition time in the same bounded, scope-filtered query, so state filters and row controls agree with a full item reload.\n\nThe append-only `intake_dispositions` record is terminal: replaying the same\nrequest returns the same disposition, any other request conflicts, and\n`startReviewerAction` refuses the item. `IntakeItemDTO.disposition` projects only\n`{ state: 'resolved', at }` to any item reader (`listItems` reads it in the same\nstatement as the page); the reviewer and reason are returned only by\n`getItemDisposition`, which requires reviewer authority, and the review hosts put\nthem on `ItemReviewView.disposition` (omitted when that read is denied, so the\nview shows only \"Handled, no action\"). `loadReviewSummary` reports inbox state `resolved` unless an action\nactually succeeded. Privacy deletion and retention expiry redact the reason and\nreviewer (`intake_dispositions.data`) and keep only the kind. The disposition is\ndistinct from `reject`, which still means the proposal was wrong. Closing an item\nrecords `reviewer_routing` feedback immediately; a started action records it only\nwhen the reviewer approves it (see FEEDBACK.md). Capture is an optional projection\nthat never vetoes the decision or disposition.\n\n`startReviewerAction` applies the handler's discovery media types and the live\nreviewer grant/policy for that handler. It intentionally does not apply the\nproposal catalog's provider-policy filter or `maxHandlers` slice: those bound what\na model may be offered, and a human choosing a handler sends nothing to a\nprovider. The UI picker shows the offered catalog, so a handler hidden from it is\nonly reachable by a reviewer who already holds `review` authority for it. The maintained\nbrowser fixture serves both operations behind CSRF and the same session scope.\n\n## Single-page triage workspace\n\n`IntakeWorkspace` (#4215) composes the existing pieces so a reviewer works the\nwhole queue on one page: the paged inbox as a list pane, the review view of the\nselected item beside it (the original above its action form), and the\nreviewer-instruction message box of the item pane. Props: `host`, `contextKey`\n(replace on session change, as for the other components), optional initial\n`itemId`, `pollMs`, `rowAside` and `onselect(itemId | undefined)`, which only\nreports the selection (to keep a URL in step) and never navigates. It adds **no\nhost callback and no server authority**: every read is the host's `list` and\n`load`, every action still goes through the handler preview and an explicit\napproval and apply under the approver's live grants, and the message steers the\nmodel only, exactly as in `IntakeReview`.\n\n- **Inline original.** In the item pane `EvidenceViewer` shows one part at a\n time (`layout=\"pager\"`), opening on the first part that renders inline (the\n uploaded file rather than its capture record), with previous/next original.\n A PDF with more than one *observed* page (extraction locations or proposed\n page groups; `pages` prop) gets previous/next page, which reloads the frame\n at the same-origin URL plus `#page=n`; only `evidenceUrl`-approved URLs ever\n reach a frame. `IntakeReview` gets the same page navigation over its\n unchanged stacked list of parts. The chosen part and page belong to the item\n view (bindable `chosen`/`page`), so they survive in-place reloads, Prepare\n review, Approve and Apply.\n- **Keyboard.** J/K and Alt+Down/Alt+Up move to the next/previous row (loading\n the next page at the end), ignored while focus is in a text field, select or\n editable region; \"Previous item\"/\"Next item\" buttons carry\n `aria-keyshortcuts`. The selected row is `aria-current`, and every selection\n moves focus to the item pane region, named by the row's label. A navigation\n that waited for the next page is dropped if the reviewer chose another item\n meanwhile.\n- **Unsent input.** The pane holds unsent input when it has instruction text,\n an edited suggestion draft or split draft, a chosen start handler or start\n reason, a no-action reason, or an action editor with edited arguments, a\n reason or a feedback comment. It is read from the drafts themselves, so it\n holds while a reload has cleared the view; while the view is denied nothing\n is shown and nothing counts (the drafts stay in memory and return with an\n authorized refresh, as before). A reviewer-initiated move (J/K, Alt+arrows,\n Next/Previous item, a row's Review button) then asks inline, in a group\n labelled by its note: \"Stay on this item\" takes focus and returns it to the\n field the reviewer last used; \"Discard and open the other item\" proceeds.\n When an item is closed without action (here or by another session), input a\n closed item cannot take\n (instruction, suggestion and split drafts, a started action, a no-action\n reason) is discarded.\n- **Live state.** A row's status follows the item: \"Interpreting…\", \"Ready to\n review\", \"Needs review\" with missing argument names or the generation\n outcome, \"Awaiting approval\", \"Approved, not yet applied\", \"Failed\" with a\n safe category, \"Handled, no action\", or the listed inbox state. Rows the\n reviewer has not opened show the listed state only; reasons come from a\n loaded view, never from server exception text. The open item's own polling\n (`ReviewView`, unchanged backoff and three-failure fail-closed) reports each\n displayed view and the workspace patches that row in place\n (`InboxView.patch`, keeping the listed label and preview, and the row's\n assignment unless the patch carries a newer assignment version, so a view\n read before an assignment never rolls the row or the next expected version\n back), so the row follows each newer read of the form and the list is\n **not** re-listed per tick. An item the\n reviewer leaves while its stage is in flight, or before the pane showed the\n result of its last operation (an instruction just recorded), keeps\n following: the workspace re-reads followed items with the same `load` (first\n review page) on the pane's backoff, at most **5** reads per tick, one after\n another, least recently read first (so every followed row is reached), with\n only one tick running at a time. At most **20** items are followed; beyond\n that the longest-followed one (the earliest started, whatever the read\n rotation) stops. An item left while its pane was mid-operation (an Apply not\n yet answered) keeps following while a read still shows an action authorized\n or executing: exactly **3** more reads when it never answers, the fourth\n ending the follow. That debt belongs to the operation, so it survives\n reopening and leaving the item again until a view shows the operation\n answered or the reads run out; leaving mid-operation again starts a full\n debt for the new operation. Each follow has a\n generation: an answer from an earlier follow of the same item (one asked\n before the reviewer reopened or left it again) is dropped, and its failure\n does not count toward the new follow's three. An item stops being followed\n when it settles, its view is denied, three reads in a row throw, its row\n leaves the displayed list (a filter or a refreshed page removed it), the\n list fails closed, or the cap drops it; a denial, the failure stop or the\n cap drops its cached status and restores its entry exactly as its page read\n returned it (never a patched entry). Opening an item drops its cached\n status until the pane shows a view; a denial in the open pane (a failed\n action, the pane's own fail-closed poll, or a first load that failed) does\n the same as a follow denial, clears the announcement, and the item is not\n followed when left. A settled stage that was seen running is announced in a\n polite status region (\"badger-po.pdf: Ready to review\"), only while its row\n is displayed; a refreshed page or a failed list clears it.\n Other rows update on Refresh, a filter change or when opened; there is no\n streaming. While a refresh or \"Load more\" is pending, the displayed rows stay\n (controls disabled) and keep taking patches. Every read (a page, a pane\n view, including an unchanged poll, and a follow read) is numbered when its\n request starts, and each row shows the entry of its newest read, whatever\n the source: a page read before a pane or follow read never regresses the\n row, and a page read after them replaces what they showed. The same rule\n governs a follow: a follow read older than the row's newest read changes\n no status, does not stop the follow and announces nothing (a newer read\n settles it), so the announcement never contradicts the row. Cached status reasons follow the same ordering, even when entries have identical\n fingerprints. \"Load more\" continues the\n filter the rows were listed under, not filter inputs edited since, and does\n not repeat a row already shown. A failed \"Load more\" fails closed like any\n failed read (the host cannot tell a transient failure from a revoked\n grant): the rows clear and the list shows its error.\n- **Approve and advance.** After an approve, apply or \"Handled, no action\" whose\n reload left nothing for the reviewer (closed without action, or an action\n succeeded and none is waiting for approval, waiting to be applied, executing,\n unknown or failed; stale, rejected and deferred actions do not hold it), the\n item's row is patched and leaves the list when it no longer matches the\n listed state/assignee filter, and the next row that is not closed or\n completed opens and takes focus, with no navigation and no re-listing. An\n approval that leaves an apply step keeps the item open with Apply in place.\n Unloaded saved-review pages and an active background stage also prevent\n settlement. Advancing skips completed inbox pages until a reviewable row\n appears; a page that makes no progress stops the walk.\n It never advances over unsent input on the same item: the item stays open,\n the input stays, and a note says it is finished but has unsent input; the\n reviewer moves on explicitly, through the confirmation; input typed while\n the next page loads counts too. When no open row is displayed, the advance\n appends pages of finished rows until one has an open row or no page\n remains, at most **5** appends. After each append, the advance (like\n J/K at the end of the list) finds its place again by id: just after the\n item it left, or, if that row has gone, at the first row that followed it\n and is still listed, or at the first new row, so a row that left the list\n meanwhile never shifts it onto the wrong item. Its notes (and \"nothing else\n needs review\") are written into one persistent polite status region. The queue is never reported empty when\n that is unknown: past the bound, or when an append cannot start (a refresh\n is pending) or is superseded, the item stays open with a note to try Next\n item again, which still works; when an append fails, the list has failed\n closed (no rows, Next disabled), so the item stays open with a note to\n refresh the list to continue. The open item stays listed while the\n reviewer works on it even if its state stops matching the filter; it\n leaves once they move on.\n When nothing is left the pane says so. The per-row \"Handled, no action\"\n control is hidden in the workspace (`resolveInRow={false}`) so closing always\n goes through the item pane and advances.\n\n\n## Maintained browser proof\n\n`pnpm test:components` runs real Svelte component tests; `pnpm test:e2e` runs the\npackage-local authenticated Vite application under Chromium. The fixture uses\nHttpOnly same-site sessions, CSRF, real SQLite/assets/ingestion/content APIs,\nproduction unpdf child extraction and a deterministic proposal generator. Its\nhardcoded test login is fixture-only and is never a production auth provider.\nImage/audio originals remain inspectable when no OCR/speech provider is\nconfigured; the suite makes no recognition-quality claim and spends no provider\nbudget. `reference/review-host.ts` is a maintained development fixture, not a\npublished server entry. Browser tests show actual approved args and persisted\nContentDocument results, stale tabs, reload, retries and negative access.\n\nRun full package `test`, `test:postgres`, `test:providers`, `build`, `typecheck`,\n`test:components`, `test:e2e`; use the root Node/pnpm versions. Set a short\n`CI_TEST_TMPDIR`/`TMPDIR`, and optionally\n`PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH` to the supported installed Chromium.\n`pnpm test:evaluation` checks repository evaluation tooling contracts; measured\nheld-out quality remains a separate frozen-protocol, budget-gated #3677 run.\n\nThe existing CI browser job includes ingestion changes and shared UI primitive\nchanges in affected mode, and runs the ingestion browser suite in full mode. Its\nnormal dependency build precedes the suite and failed runs upload browser evidence.\n\nThe maintained host derives inbox state by traversing bounded public review pages,\nauthorizing every action/parent/target before classification. It retains only\nscalar totals and the requested page; an off-page denial denies the whole view.\nThe component's Load more and subsequent refresh/mutation reload every displayed\npage using fresh cursors, then publish the combined authorized set together. Old\npage payloads are cleared while loading; any unavailable page clears all payloads.\nThis keeps plan controls and earlier steps visible across page boundaries without\nreusing a prior authorization decision.\n\n## Published server adapter\n\nImport `createIntakeReviewHost` and `IntakeReviewHostOptions` from\n`@happyvertical/smrt-ingestion/server`. Call `createIntakeReviewHost(service,\noptions)` with a service constructed from the current authenticated session.\nThe returned `IntakeReviewHost` implements inbox state projection across saved\nreview pages, current generation loading, stable `ui:<index>` intention keys,\naction/plan preview CAS lookup, decisions, apply, corrections, candidates, split,\nfeedback, the offered `catalog`, `startAction` and `resolve`. Any catalog\nfailure (not configured, bound exceeded, denied) omits `catalog`, so the picker\ndisappears while existing reviews stay reviewable; item, review and evidence\ndenials still propagate as before; the reference host (`reference/review-host.ts`)\ndegrades the same way. Repeated\npreparation of an unchanged authorized suggestion retains\nits current review instead of creating a new revision. Changed arguments still\nrequire explicit re-preview and a fresh human decision.\n`list({ state?, assigneeId?, cursor?, limit? })` returns one page newest receipt\nfirst (`intake_items.created_at`, id tiebreak) through `service.listItemsPage`.\n`limit` defaults to 20 and is capped at 100; the cursor is an opaque\n(received-at, id) continuation, never a bare id. Tenant, confidential scope,\nretention and the `state` filter run inside the page query, so a page is full\nand `nextCursor` is present only when more rows follow.\n\nAuthority is rechecked at the same two levels `load` applies, but per page\nrather than per row: the host authorize callback once per distinct captured\nceiling in a batch, and the execution read gate (policy, ceiling, handler and\noperation allowlists, principal) once per distinct (item, handler) bound by\nthe page's saved actions. The list gate is read-only: it evaluates the same\nchecks as `listReviews` without the retention write, so an item that the item\nview would narrow past its deadline is simply not listed. The list gate also\nresolves each bound handler and rejects version drift against the saved\nbinding and omits a cancelled item, as `listReviews` does; it does not\nevaluate per-action target,\nevidence or plan gates, so an item whose target became unreadable still lists\nand its item view refuses. An item whose bound\nhandler the actor cannot currently read is not listed at all, rather than\nlisted with a state derived from actions the actor may not see; actions\nwithout a proposal bind no handler and are not gated, as in `listReviews`.\nHandler bindings (handler id and version, projected in SQL, distinct per\nitem) are read once per fetched batch for the rows that passed the item-level\ngate. Note the host cost plainly: the execution `authorize` callback runs once\nper distinct (item, handler) bound by a scanned row that passed the item-level\ngate. Each item is its own authorization subject, so nothing is deduplicated\nacross items; the count is bounded by rows scanned (at most\n`ITEM_SCAN_CEILING`) and runs in host code rather than as N+1 database reads. Either host callback, the item-level `authorize` or the execution\n`authorize` behind the handler gate, follows the same rule: a refusal (false,\nor an access check that fails) hides the rows it covers, and a callback that\nthrows rejects the whole page (and `listItems()`) with its error, as `load`\ndoes, so a transient failure never lets paging move past readable rows.\nDenied or unreadable rows are skipped without\ndisclosure and the page refills from the next rows; refills grow from the page\nsize to 100 rows per query, so a fully denied scope costs about a dozen page\nreads and as many binding reads per call. One service call examines at most\n`ITEM_SCAN_CEILING` (1000) rows, or the caller's smaller `scanLimit`, and\nreports the count as `scanned`; when a mostly-denied scope reaches the ceiling\nthe page comes back short with a `nextCursor`. Rows are authorized first and\nthe `state` filter is then applied to the fetched batch, so it is bounded by\nthe same scan limit: a rare state yields short pages with a cursor rather than\nan unbounded walk inside one query. A row the actor can read whose state does\nnot match discloses nothing and may anchor the cursor, so a filter with no\nmatch among the next 1000 rows returns an empty page with a cursor and still\npages to the end. The host `list` passes its remaining budget as `scanLimit`, so the\nrows scanned across the service calls of one host call never exceed 1000: a\nshort service page with a cursor, or an exhausted budget while filtering by\nassignee, ends the host call with the same cursor and the caller continues.\nOnly rows the service wrote are supported: cursors carry the canonical\nmillisecond ISO receipt time the service stores. A row whose stored receipt\ntime is not that form (on SQLite anything but `YYYY-MM-DDTHH:MM:SS.mmmZ`,\nincluding a parseable value without milliseconds or with an offset; on\nPostgreSQL a value with a sub-millisecond part) is never listed, whatever the\nactor's access, and counts toward the scan, as does a row whose id is not a\nUUID. On SQLite a non-text stored value (an integer, say) and a receipt value\nor id longer than 64 characters or containing a NUL character are excluded by\nthe page query itself: the first sorts after every text value so the scan\ncould never move past it, the second could not be carried by any cursor, and\nthe third is returned truncated at the NUL, so it would look canonical and\nsort above a legitimate row at the truncated value. Within a call the scan moves\npast a service-foreign row by its exact stored value, and an unsealed cursor\nnames the last row before it that the actor can read. A call that finds no readable row within its scan limit (at\nmost 1000) fails closed with `IntakeScanLimitError` unless a `cursorKey` is\nconfigured, as below. The host\n`list` returns what earlier service calls collected, with their cursor, when\na later call fails that way.\n\n`listItems()` is deprecated and kept only for callers of the array-returning\nAPI. It walks every page, so its cost grows with the scope, including one\nexecution authorization per (item, handler) across the whole scope. It follows\nthe internal scan position, which never leaves the service, so runs of rows\nthe actor cannot read never stop it and it returns `[]` where nothing is\nreadable. Items are newest-first and gated exactly as on a page.\n\nThe page's inbox state is the durable projection of the saved action journal\nand processing state, computed once per scanned row inside the page query;\n`load` remains the authoritative, live-gated projection for one item (it still\nprojects individual stale actions, which the list does not). Cost is\nproportional to the page for unfiltered pages and common states, and to the\nnumber of items scanned until enough matches are found for rare states: the\nstate is not persisted, because the action journal is append-only and\nprojecting it into an indexed column would need a maintained denormalisation\nin the execution service plus a migration, which this change does not take.\nListing does not load original bytes.\n\nCursors never disclose an unreadable row. Without a `cursorKey` in the\nservice options, every cursor (each row's and `nextCursor`) names a row the\nactor can read (the last one when a page stops early); a page that spends its scan limit before filling hands back\nthe last such row, and one that found none fails closed with\n`IntakeScanLimitError` (`Intake scan limit`, no id or time). A run of rows the\nactor cannot read (refused by the captured ceiling or the execution gate, or\nstored with a non-canonical receipt time) at least as long as the scan limit\ntherefore stops an unkeyed walk there; readable rows that the `state` filter\nexcludes never count toward such a run. With a `cursorKey` (a server secret of at least 32 bytes), every\ncursor is sealed with AES-256-GCM, bound to the tenant, confidential scope and\nactor, and a budget-stopped page returns a sealed position past what it\nskipped, so the walk always progresses. Sealed cursors have a fixed length\n(the plaintext is padded to 1024 bytes) and a fresh nonce per seal, so neither\ntheir length nor their bytes reveal anything about the stop row. `scanned` is for trusted host\naccounting and must not be sent to clients; a short page with a cursor tells\na caller only that unlisted rows exist, never which.\n\nNewest-first paging relies on `intake_items_received_idx`\n(`tenant_id, confidential_scope_id, created_at, id`), the full ordering key, so\nan unfiltered page is a backward index scan that stops at the page boundary;\nthe foundation suite asserts that plan on both engines (SQLite\n`EXPLAIN QUERY PLAN`, PostgreSQL `EXPLAIN`), with the per-row state counters\nserved by `intake_actions_item_idx`. On SQLite the page query pins the index with `INDEXED BY` (except under an\nid restriction, where direct id lookups are cheaper), because without planner\nstatistics SQLite otherwise picks `intake_items_expiry_idx` plus a sort; the\nSQLite plan check runs without `ANALYZE`. A deployment must have applied the\nmanifest migration, or the page query fails with a missing-index error. This package ships no\nmigration files: indexes are declared on the model, the build emits them into\n`dist/manifest.json`, and `smrt db:migrate` / the public migration API create\nthem, which is how `intake_items_receipt_idx` shipped. Deploy the manifest\nmigration before upgrading hosts; `db:status --parity` reports the index as\nmissing until then.\n\nSupply four application adapters: `upload(files, requestId)` (authenticated\nreceipt plus first extraction request), `assignment(itemId)` (durable read),\n`assign(input)` (manager authorization, eligible assignees, durable CAS and request\nreplay protection), and `evidence(part)` (safe label/text or authenticated\nsame-origin URL), which `load` calls for every part and `list` never calls;\n`load` sets no row preview on its entry.\n\nRow previews are opt-in through an optional fifth adapter,\n`rowEvidence(rows)`. When it is supplied, `list` reads the page's durable\nevidence metadata with one `service.listEvidence(itemIds)` query (at most 100\nids; items the scope cannot read, and expired or inactive items, are omitted\nwithout disclosure; the host `authorize` runs once per distinct captured\nceiling through the same gate as `listItemsPage`, so a refusal or a\nmalformed captured ceiling hides the item and a failing `authorize` rejects\nthe page; an item whose stored data does not parse is skipped by both\n`listItemsPage` and `listEvidence`, never fatal). It then calls `rowEvidence`\nonce with each row's primary part (`{ itemId, evidence }`) and publishes the\nreturned `{ label, viewUrl?, thumbnailUrl? }` as `InboxEntry.evidence`\n(`{ evidence, label, viewUrl?, thumbnailUrl? }`, never text). Build those URLs\nfrom metadata without reading bytes; if `rowEvidence` throws or returns a\nmalformed answer, the page still lists without previews, and a row without\ndurable parts never gets one. When it is omitted, rows show no original link.\nEither way `list` reads the page's evidence metadata once, in that same query,\nso the row label can use the original filename; it never reads original bytes\nand never calls `evidence(part)`. The primary part is chosen by role, not media\ntype: the shallowest child part when any part has a parent (an upload's file\nunder its capture record, an email's first attachment under the message, even\nwhen that child is JSON), else the first root part (a watched-folder file);\npart ids sort numerically. `IntakeInbox`/`InboxView` accept an\noptional `rowAside` snippet receiving the `InboxEntry`; without it a row renders\nthe host's \"Open original\" link (new tab) and thumbnail when the URLs are\nsame-origin; each link's accessible name is \"Open original: <row label>\", and\na row shows no wrapper when neither URL is usable. The slot is a plain `div`,\nnot an `aside` landmark, so a page does not add one landmark per row. Optional\n`label(item, evidence)` changes presentation; `evidence` is the item's durable\nparts with the primary part first, and the default label is the primary part's\nown original `filename`, else `Intake <8 hex>`. Optional\n`assignments(itemIds)` reads one page's assignments in one batch (otherwise\n`assignment` runs per row), and optional `assignedItemIds(assigneeId)` lets\n`list` push the assignee filter into the page query (junk ids are dropped, not\nfatal); without it an assignee filter scans further pages and filters by\n`assignment`, which stays correct but costs more rows. The page's continuation\nis always the last row actually returned, so an assignment that changes\nbetween the page read and the assignment read costs at most one extra scan and\nnever skips or repeats a row. Optional\n`enableFeedback: true` exposes the optional feedback callback when the service\nhas feedback configured. Optional `onSplit(itemId, revision)` wakes the host worker after the durable extraction\nrequest; repair dispatches if wakeup fails. The factory creates no assignment\nschema and grants no permissions. Create it per session, authenticate every HTTP\ncall and enforce CSRF before dispatching a mutation.\n\n`GenerationAnalysisOutput` is exported by `/dto` and describes the interpretation\nwrapper `{ proposals: GenerationOutput }` under `analysis.result.output`.\nThe factory unwraps this into `ItemReviewView.generation`. Stale generation is\nomitted while authorized saved reviews remain available; access denials propagate.\nThe reference application still owns its fixture provisioning and HTTP transport.\n\n## Explicit upload retries\n\nThe inbox retains selected original files and the receive request identity when\nupload fails or acknowledgment is lost. Retry Upload explicitly with the same\nselection; Refresh does not replace that identity. Selecting files again starts a\nnew receipt identity, even when names match. Successful upload clears the selection\nand identity. Replacing the authenticated host/context or destroying the component\ndiscards both and fences late completion from the prior context. No automatic\nupload retry or authorization bypass occurs.\n\nThe inbox clears only its native file-input value when opening the picker, so\nchoosing the same local file explicitly starts a new upload identity. Opening\nthen dismissing the chooser preserves the separately retained originals and\nrequest identity for retry; it does not clear the shared FilePicker's native-form\nbehavior. Successful upload and host/context disposal still discard retry state.\n\nWorkspace ordering also protects an open item during an awaited automatic page walk:\nthe selected row remains until navigation succeeds, except that a failed list read\nclears the inbox. Applying an action is disabled\nwhile that action card holds unsent arguments, reason, or feedback comment. A list\nrefresh retires earlier follow snapshots; only follow reads started after that\npage request may override its rows, so a newer refresh cannot be regressed by an\nalready settled or older in-flight follow read.\n"
1733
+ "content": "# Authenticated review surfaces\n\n`@happyvertical/smrt-ingestion/svelte` exports `IntakeInbox`, `IntakeReview`,\n`IntakeWorkspace` and `EvidenceViewer`. The browser-safe DTO entry exports their `IntakeReviewHost`\ncallback contract. Import styling/theme configuration from smrt-ui in the host.\nComponents use smrt-ui primitives and the `ingestion.*` i18n catalog.\nExisting `IntakeInbox` hosts now keep the previous rows visible, with their\ncontrols disabled, while a refresh or filter change loads; any failed read\n(Load more included) still clears them.\n\nThe host authenticates every request, resolves tenant/actor/confidential scope\nfrom its session, enforces CSRF on mutations, and constructs `IngestionService`.\nNever accept scope, reviewer, permissions or a principal from callback JSON.\nOnly supply authorized evidence URLs and escaped text; original URLs are\nsame-origin authenticated handlers that recheck `readEvidence` on every read.\nCandidate discovery uses `findCandidates` with current grants. Presentation\nstate and disabled buttons provide no server authority.\n\n`listReviews(itemId, {cursor?,limit?})` reloads saved action identities and their\ncurrent plan membership without browser storage. It returns at most 50 actions,\nwith an opaque action-ID cursor. Every payload requires current item, handler,\nparent plan and target access under the owning transaction. Denied reads fail\nclosed. Target reads check current authorization separately from historical\nrevision freshness: unfinished drift returns state-only stale reviews without\nremoving unrelated entries; succeeded results remain readable after authorized\ntarget changes. Apply still enforces exact bound target revisions. Expired entries\ncontain only review identity/state. Stale entries never disclose old args or target\nlabels; an authorized parent plan additionally exposes `stalePlan` identity, key,\ncurrent plan revision and handler identity. Hosts must collect fresh explicit args\nfrom the reviewer/current authorized evidence and call `previewPlan` with that\nexact plan CAS and the current completed analysis attempt. Action revision is not\nplan revision. Re-expansion preserves action identity and requires fresh approval.\nSuccess results are rechecked through the durable result reader.\nPlan membership contains the exact parent args/version so edits call\n`previewPlan`, not per-step correction. An item may have more review pages; the\nhost must aggregate state across pages when projecting a production inbox state.\n\nA `needs_review` suggestion is completable, not only rejectable (#4208). That\nincludes a suggestion kept because its arguments missed only required fields\n(#4284); nested misses appear as JSON Pointers such as `/vendor/name`. The\ncomponent shows its `missingFields`, an editable `Suggested arguments (JSON)`\ndraft prefilled from the generated arguments, and the candidate picker for\ndeclared candidate fields; Prepare review stays disabled while required fields\nare still missing from an unchanged draft. An unchanged draft previews the\ngenerated snapshot as before; an edited draft is sent as `preview({..., args})`,\nwhich the published host publishes through the ordinary `previewProposal` /\n`previewPlan` with the same `ui:<index>` intention, never by rewriting the\ngeneration. The handler validates the human arguments again before a\n`waiting_review` action exists, approval remains a separate explicit decision,\n`ActionReview` lists top-level required arguments missing from the current\ndraft while editing (nested misses named by JSON Pointer in `missingFields` are\nnot re-checked in the browser; the server's revalidation refuses them and the\ncomponent shows that inline as `HandlerArgumentsInvalidError`), and no authority or automation eligibility is added: a failed attempt,\nan unoffered handler or a foreign stage is still refused by the host.\n`preview` throws on every failure, as before. When the handler's argument\nschema or `validate` refused the arguments being previewed (operation preview,\nwhich also carries corrections, a reviewer-started action, or plan preview),\nthe server throws `HandlerArgumentsInvalidError` (`name` set, messages\nunchanged). An argument-schema refusal also carries `issues`: a frozen list of\nat most `HANDLER_ARGUMENT_ISSUE_LIMIT` (20) `{ path, keyword? }` entries\n(`HandlerArgumentIssue`). `path` is built only from schema-declared property\nnames, `required` names and real array indexes and is cut at\n`HANDLER_ARGUMENT_PATH_LIMIT` (160)\ncharacters (never splitting a `~0`/`~1` escape). Segments are escaped per RFC\n6901 (`~` as `~0`, `/` as `~1`), with two departures: `/` is the whole\narguments object (never a key `\"\"`), and `?` stands for a data-named key. A\n`required` refusal appends the missing schema name to the parent's path. The\nformat relates to a suggestion's `missingFields` as follows: a root path\n`/name` is the bare `missingFields` entry `name` (unescaped), and a nested\nentry is the same escaped pointer in both (for example `/vendor/a~1b~0c`).\nThe bundled view shows a root issue without its leading `/`, so its refused\nfields read like the missing-information list. `ProposalValidationError`\nreasons share the schema-owned segment rule but stay unescaped.\n`keyword` is the failing schema keyword. Argument values, Ajv\n`params`/messages and handler messages are never included. A `validate`\nrefusal has no `issues` (the handler contract returns only `ok`). The size and\nshape preconditions checked before the schema runs (arguments over the policy\nbyte limit, or a handler schema that is not a closed `type: 'object'` with\n`additionalProperties: false`) stay a plain `Error`: they fail closed as a\ndenial, never as the inline refusal. Apply-time and\nexternal-send revalidation and result-schema checks keep a plain `Error`. The component shows an inline message and\nkeeps the view and draft when `preview` either rejects with an error whose\n`name` is `HandlerArgumentsInvalidError` or resolves `{ rejected: 'invalid' }`\n(`PreviewRejection`, optionally with the same `issues`). A transport that\ncrosses a process boundary preserves the inline UX by keeping that name and\n`issues` (for example re-throwing an `Error` with\n`name = 'HandlerArgumentsInvalidError'` in the browser callback) or by\nreturning `{ rejected: 'invalid', issues? }` for that case only, as the\nmaintained fixture's `previewForReview` and `startActionForReview` do. Since\n#4281 the fixture's rejection body also carries `issues` when the schema\nrefused; read `rejected === 'invalid'` rather than comparing the whole body\nwith strict equality. Without either, the refusal behaves like\nany other failure: the view is cleared exactly as before this change, and the\nreviewer's in-memory draft returns after an authorized refresh. Every other\nthrown preview or candidate-search failure (denied, revoked, unavailable or\nunknown) clears the view.\nUnsent drafts live only in component memory, keyed by attempt and suggestion\nindex. They survive Refresh, a failed callback, an action on another card and a\ntransient `unavailable`/`stale` reload; a `revoked` or `expired` result\ndiscards them, a successful preview clears that card's draft, and an available\nreload drops drafts for attempts or cards no longer offered.\n\nThe host's `load` callback supplies a current `ItemReviewView`, using\n`getCompletedAnalysis` with no historical fallback. Generated suggestions bind\nthe **current generation attempt**, not `generation.source.attemptId` (the prior\nextraction). `previewGeneratedProposals` publishes exact reviews and continues to reject stale\ngeneration candidate pins. When `listReviews` reports `generationStale`, the host\nomits obsolete generation output and renders authorized saved reviews/results.\nCompleted saved actions do not hide healthy unprepared suggestions. The saved-binding hint is not\nan authoritative generation-availability check: a fresh human preview can bind a\ncurrent target while the immutable generation still pins its former revision.\n`getCompletedAnalysis` remains strict and throws server-only\n`GenerationSnapshotStaleError` only after every current catalog/provider/candidate\nread is authorized and an immutable candidate revision differs. The maintained\nhost catches only that class, reacquires `listReviews` under current owning\nauthority, and returns that new page without generation output. It never reuses\nthe earlier page after an error. Denials and unknown failures propagate; healthy\ngeneration still exposes unprepared sibling suggestions. Stale entries expose handler\nand attempt identity only when that attempt is still the current completed/partial\nanalysis. An empty-args editor submits fresh explicit human arguments through\n`previewProposal` or `previewPlan` with the saved CAS; it never reuses old generated\narguments, rewrites the generation snapshot or transfers approval. Analysis-stale\nentries without an attempt require normal reprocessing. Approve,\nreject, defer and correct call `submitDecision`; corrected args create a new\nrevision which requires a separate human approval. After an approve/defer/reject\ndecision, optional `editAction` calls `previewProposal` with the current action\nrevision to publish a new review; completed/executing/unknown actions cannot be\nrevised. Local dirty args disable Apply but confer no authority. Plan edits re-expand through\n`previewPlan` with the current **plan** revision. `applyAction` accepts only an\naction ID. Unknown external outcomes require server reconciliation; the UI\nnever offers a blind resend. Stable result IDs survive reload and retry.\n\nReplace `contextKey` whenever authenticated tenant/session context changes.\nChanging it or itemId destroys the old view and fences late callback results.\nDenied refresh clears prior originals, candidates, arguments and results.\nMissing confidence is unavailable; page/time links exist only for observed\nlocations. Provider errors and unresolved/partial results remain review states.\nA host that enabled `proposals.failureCapture` may fetch a failed attempt's\nredacted model output with `getFailedAttemptCapture(itemId, attemptId?)`.\nRetaining text requires a configured host redaction hook; a missing or failed\nhook yields only `redaction_failed` metadata. The host owns that redaction policy.\nThe getter requires current reviewer authority for that item and fails closed\notherwise;\n`load`, inbox rows and review pages never include it, so a host shows it only\nbehind its own explicit diagnostic action (see\n[PROPOSALS.md](PROPOSALS.md#failed-attempt-capture-opt-in-4285)).\n\n## Submitter-scoped decisions\n\nFor trusted internal sources the person who submitted an item may confirm or\ndecline their own proposal without the reviewer inbox. `listOwnProposals`\nreturns only items whose server-recorded `submitter_id` equals the current\nauthenticated actor, each with its bounded saved review page reloaded under\ncurrent item, handler and target authority. An item the actor can no longer\nread (the host `authorize` returns false or throws `IntakeAccessDeniedError`)\nis skipped before projection: the page is filled from readable items only, in\n50-row batches, and `nextCursor` names the last emitted item and is present\nonly when a further readable item was actually found. Neither the entries, the\npage size nor the cursor reveal a hidden item. If one call has to skip 1000\nhidden submissions it fails with `Own proposal scan limit` rather than return a\nshort page or a cursor that stops inside the hidden run; this error is the only\nsignal, and it says only that such a run exists. Any other `authorize` error\npropagates instead of shrinking the list. An item that is still readable but\nwhose reviews are denied is returned as `{ item, reviews: null, unavailable:\ntrue }`: that covers ingestion's own denials and any throw from the host\n`assertTarget` (deleted or revoked targets), whose text is never returned.\nIntegrity, validation and database errors from ingestion itself propagate. The\nreviewer `listReviews` surface keeps propagating host target errors unchanged.\n`submitOwnDecision` takes the same `ReviewInput` CAS fields and request ID as\n`submitDecision` and accepts `approve`, `reject` and `defer` only; `correct`\nbelongs to the reviewer surface. It runs under the `review_own` execution\noperation: the host's `authorize` must return `submitter: true`, the resolved\npolicy must have `submitterReview` enabled, and the recorded submitter must be\nthe current actor and also the receipt's captured execution principal (the\nidentity the effect runs as), checked under the item lock and again at apply.\nA receipt captured for a bot or service principal is never self-approvable. Policy enablement, handler/operation allowlists, captured\nceiling, confidential access, retention and the first-valid-decision lock are\nunchanged. The decision is a human decision by that actor, recorded with\n`mode: 'review_own'`; reviewer decisions carry `mode: 'review'`. In both modes\n`selfDecision` is true exactly when the deciding actor is the item's\nsubmitter, so a reviewer approving their own submission is never independent\nreview. A self-decision is not a reviewer judgment: it never feeds\nautomation eligibility (machine authorization remains the separate evaluated\n`kind: 'machine'` path) and its feedback events carry the same marker. The\n`unavailable` entry discloses nothing about the denied handler or target.\n`applyAction` then runs once under the approver's live grants exactly as\nfor reviewer decisions. Hosts render this surface from their own authenticated\nsession; presentation state confers no authority, and a source payload cannot\nnominate a submitter.\n\n## Assignment and logical splits\n\nAssignment is explicitly host-owned, durable and versioned. `assign` receives\nan expected assignment version and request ID; the host must authorize the\nmanager, constrain eligible assignees, CAS the durable record and reject stale\nwrites. Assignment does not grant read, review or execution rights. The maintained\nfixture provisions its own SQLite assignment table before serving requests; no\nproduction ingestion table or migration is introduced for assignment.\n\n`reviseLogicalSplit` authorizes the current generation through the same-executor\ncatalog/candidate gate and the existing reviewer grant and policy reviewer list.\nProcess access alone cannot mint or replay a human correction; reviewer authority\nis checked before mutation and again before publication. A generation without a\nreviewable catalogue cannot be corrected through this reviewer API.\nIt requires all observed pages exactly once, an exact\ncurrent attempt/revision and a request ID. It records the authenticated actor\nand predecessor as a **human correction** in a new immutable extraction\nconfiguration, queues re-extraction and immediately makes previous suggestions\nand approvals stale. It never changes original bytes/evidence or labels a human\nedit as model output. The host processes the new extraction, then calls\n`prepareGeneration` and the normal fenced interpretation stage. The supported\nimmediate-predecessor extraction pin is unchanged. The generator receives a\nhuman correction only after its digest matches the authoritative source. Ordinary\n`analyze` calls cannot mint an extraction correction; the owning split API is the\nauthenticated origin, and forged interpretation corrections fail before provider\ndisclosure. If its proposed grouping differs from the correction, suggestions are withheld\nwith `human_split_not_respected`. New proposals require new explicit review.\nThe reference host runs these stages synchronously for browser determinism;\nproduction hosts dispatch the existing durable analysis jobs.\n\n## Reviewer instructions\n\n`recordReviewerInstruction({itemId, attemptId, expectedRevision, text,\nrequestId})` records a plain-text instruction for one item (\"This is a customer\nPO from Badger; file it, do not bill it\") as the second kind of **human\ncorrection**. It is authorized exactly like `reviseLogicalSplit`: the current\ngeneration must pass the same-executor catalog/candidate gate and the reviewer\ngrant plus policy reviewer list, and authority is checked before mutation and\nagain before publication. Process access, `analyze`, and a client payload cannot\nmint one: `analyze` rejects a `reviewerInstruction` key on an extraction\nconfiguration, and an interpretation copy that differs from the pinned\nextraction's record fails with `Generation evidence changed` before provider\ndisclosure. Text is required, trimmed-nonempty and at most 4,000 characters.\n\nThe record is immutable: `{id, text, actorId, recordedAt, supersedesId, digest}`\nplus the request binding, written into a new extraction configuration beside\nany existing split correction. Recording supersedes current suggestions and\napprovals, queues the normal fenced re-extraction and interpretation through the\nexisting dispatch path, and returns immediately; the reviewer keeps working\nwhile the item reports `processing`. `prepareGeneration` copies the instruction\ninto the interpretation configuration, the generator receives it only after its\ndigest matches the authoritative extraction record, and saved generation\nprovenance records `reviewerInstruction: {id, digest}`. A later instruction\nrecords `supersedesId` and replaces the earlier one for future interpretations;\n`listReviewerInstructions(itemId)` returns the full history, newest first, and\nhistory is never deleted. The instruction steers the model only: it cannot add\nhandlers, candidates, schemas, permissions or automation eligibility, replies\nare validated as usual, and suggestions still require explicit preview and\napproval. A replay with the same request ID returns the same revision; a changed\ntext under the same request ID conflicts.\n\n**Cost.** Each recorded instruction appends a new extraction revision, so the\nitem is extracted again before it is interpreted again: cheap for embedded-text\nPDFs and plain text, but OCR/speech hosts spend provider budget per instruction,\nexactly as they do per split correction. The pinned extraction is not reused\nbecause the interpretation contract requires its source to be the immediately\npreceding revision and `getCompletedAnalysis(itemId, attemptId)` serves only\nthe current revision (PROPOSALS.md, \"Durable stages\"); reusing it would mean\nweakening that predecessor pin, which protects every generation from an\nintervening reprocess, so this feature follows the split path instead.\n\n**State and failure.** An in-flight stage (queued/running) reports the item as\n`processing` even when earlier, now-stale actions exist. If the re-extraction or\ninterpretation fails, `getReinterpretationState(itemId)` returns the latest\nattempt's safe failure category and the latest completed generation attempt;\nthe host projects them as `instruction.failure` and `instruction.binding`, and\n`recordReviewerInstruction` accepts that historical attempt as its anchor when\n`expectedRevision` is the item's current (failed) revision and no later\n**interpretation** completed and nothing is queued or running, so the reviewer\ncan retry or change the instruction after either stage fails. A completed\nextraction whose own interpretation failed belongs to the failed attempt, not a\nnewer result; a completed extraction whose interpretation has **not been\nappended yet** is in flight (the host is between stages) and is refused with\n`ReviewerInstructionStaleError` (`Stale reviewer instruction`), so a second\nreviewer cannot pre-empt it. That gap expires: once the extraction attempt's\ncompletion plus the item's analysis lease duration (`limits.leaseMs`, the lease\n`claimAnalysis` grants) has passed with no interpretation appended,\n`getReinterpretationState` reports `failure: 'not_started'` with the retry\nbinding and the guard allows the retry. `not_started` means **the\ninterpretation did not start within the lease window**: the host crashed,\nthrew between `prepareGeneration` and `analyze`, or its queue is merely slow.\nPre-empting a slow but healthy host is safe because `analyze` refuses an\ninterpretation whose pinned extraction is no longer the item's latest, under\nthe item lock and before anything is superseded\n(`GenerationSourceStaleError`, nothing appended): the slow host's late append\ncannot clobber the retry. Missing or malformed timing (no attempt, no\n`completedAt`, non-finite `leaseMs`) counts as already expired rather than\nholding retries forever. The \"still being re-read\" note shown after a stale\nresult is cleared by the next reload that shows the item settled; the draft\nthen carries a persistent \"This item changed while you were writing; your\ninstruction was not recorded.\" note (any stale cause: another reinterpretation,\na split, or a host reprocess) until the reviewer edits or resubmits it. The guard and\n`getReinterpretationState` share one predicate, and the latter's\n`reinterpreting` flag (projected as `instruction.reinterpreting`) is true in\nthe gap too, so the component keeps polling and keeps Re-read disabled there.\nThe published host maps two typed errors to `instruct` results:\n`ReviewerInstructionStaleError` → `{ stale: true }` (refresh-and-retry: reload\nwith a note, draft kept) and `ReviewerInstructionInvalidError` → `{ invalid:\ntrue }` (empty, whitespace-only or over 4,000 characters: shown inline, draft\nkept). Neither is a denial. Custom hosts should map them the same way; a host\nthat lets either propagate as a thrown error makes the component treat it like\nany other failed mutation, i.e. a whole-view deny with the \"view unavailable\"\nmessage, as before these results existed. The maintained fixture's\n`/api/instruct` now answers an invalid text with HTTP 200 `{ invalid: true }`\ninstead of 409. A retry from an older anchor builds on the **whole configuration**\nof the newest extraction after it (replacing only the instruction), because that\nis the item's current configuration: corrections chain forward through it and a\nhost reprocess replaces it. So a split followed by a failed stage is never\nsilently dropped, and a failed reprocess's changed configuration is neither\nreverted nor overlaid with a split it dropped. **Concurrency.** `recordReviewerInstruction` and `reviseLogicalSplit` each\nrun their whole decision in one transaction under the item row lock: the\nanchor snapshot read takes the lock first, the execution authorization of\nthat snapshot takes it again (`UPDATE intake_items` row lock), the guard step\nre-asserts it explicitly, and\nthe request-key replay check, the revision and later-work guards, the\ncarried-forward split, the history read that sets `supersedesId`, and the\nappend all run under it. On PostgreSQL a second reviewer at the same revision\nblocks on that lock and is then refused (`ReviewerInstructionStaleError` /\n`Stale logical split`), so the ledger cannot fork; an instruction racing a\nsplit (in either order) is refused rather than built from the pre-split\nconfiguration; and a double-click whose duplicate commits after the unlocked\nreplay check is answered as a replay of the committed request, not a conflict\nor a denial.\n\n**Host reprocess.** A host reprocess (a plain `analyze()` extraction the host\nconfigures itself) cannot carry human corrections — `analyze` rejects\n`humanCorrection`/`reviewerInstruction` on extraction configurations — so it\ndrops the split and the instruction alike, and neither is applied to its\ninterpretations. The instruction is then reported as `dropped`, not pending:\n`getReinterpretationState().instructionInEffect` names the instruction the\nnewest extraction carries (verified by digest) and is null after such a\nreprocess. History is unchanged; the reviewer can re-record the instruction,\nwhich supersedes the dropped one.\n\n`ItemReviewView.instruction` exposes `current` (the latest recorded instruction\nstill in effect, i.e. carried by the newest extraction), optional `dropped`\n(the latest recorded instruction a reprocess dropped), `applied` (the\ninstruction the displayed **generation** ran under; a completed extraction alone\napplies nothing), `stale` (the displayed suggestions predate the current\ninstruction), optional `failure` and optional `binding`. Feedback examples that carry instruction\ntext count it toward the feedback byte budget (FEEDBACK.md). The optional host callback\n`IntakeReviewHost.instruct` is implemented by the published adapter when the\nservice supports it, with an optional `onInstruct(itemId, revision)` wakeup\nmirroring `onSplit`. The review component renders \"Instructions for the\nassistant\" with \"Re-read with these instructions\", shows \"Reinterpreting…\" while\nthe item's stage is queued/running, repeats the existing authenticated `load`\non `pollMs` (default 2 s, backing off to 5×) and patches the view in place —\ndrafts, split edits, focus and the evidence viewer survive and no loading\nplaceholder is shown — stops when the stage is no longer in flight, and then\nshows the instruction that produced the current suggestions, marking a\nsuperseded one as stale. An explicit host denial on a poll tick fails closed at\nonce; a thrown tick is treated as transient (view and drafts kept, a\n\"Couldn't refresh; retrying.\" note, backoff continues), but because hosts may\nalso throw for revoked access, three consecutive thrown ticks fail closed.\n**Hosts must signal revocation by returning `availability: 'revoked'`** (or\nanother non-`available` state) from `load`, not by throwing: a returned denial\nclears the view on that tick, while a host that throws on revocation leaves the\nalready-displayed content visible until the third thrown tick (about 10 s at the\ndefault interval and backoff) before the view fails closed.\nSplit drafts survive a refresh only when the reviewer edited them. A failed stage shows its safe category with the form\nstill available. There is no\nstreaming channel; status is read through the existing item/analysis APIs. The\nmaintained fixture records the instruction durably and then runs the stages in\nthe background so the browser proof exercises the in-place update.\n\n**Try again (#4504).** `retryInterpretation({itemId, attemptId,\nexpectedRevision, requestId})` re-runs an item whose interpretation failed (the\ndisplayed generation is `provider_error`, or later work failed or never\nstarted) with no new instruction. It uses the same anchor, guards, `process`\nauthority and fresh extraction plus interpretation as an instruction, carries\nthe item's current configuration (an instruction or split already in effect\nincluded) unchanged, and records nothing in the instruction history. Superseded\nanchors, work in flight and items that did not fail throw\n`ReviewerInstructionStaleError`. A replay of the same intent (item, anchor,\nrevision, `requestId`, actor) returns the first append under current `process`\nauthority; the same `requestId` with another intent is a request conflict.\n`createIntakeReviewHost` exposes it as `IntakeReviewHost.retry` (stale resolves\n`{ stale: true }`) and wakes the worker through `onRetry`, else `onInstruct`.\n`ReviewView` draws a \"Try again\" button (`ingestion.tryAgain`) beside the\ninstruction box when `host.retry` exists, the item is open, nothing is in\nflight and the interpretation failed; it binds like the instruction\n(`instruction.binding`, else the displayed generation).\n\n`feedback` is an optional explicit correctness callback, separate from approval\nchoice and execution success. No learning, feedback storage or rule promotion is\nimplemented by these components; #3676 owns those services. Do not pass feedback\nor a feedback callback to readers without the relevant host grant.\n\n## Reviewer-chosen actions and \"handled, no action\"\n\nA reviewer is not limited to model suggestions. `ItemReviewView.catalog` carries\nthe handlers the item's catalog currently offers (`listHandlers`, discovery media\ntypes and live preview authority; it is presentation, never a grant). The optional\n`startAction` callback forwards `StartActionInput` (`itemId`, `handlerId@version`,\nexplicit `args`, `requestId`, optional `reason`) to `startReviewerAction`, which\nrequires the current reviewer grant under that handler, a completed or partial\nattempt on the current analysis revision, and an operation handler the item's\nevidence media types offer. Plan handlers go through `previewPlan`. The server\ncreates an action keyed `reviewer:<requestId>` with origin `reviewer-selected`\n(`createAction` refuses that key prefix and origin, so process authority cannot\nmint reviewer provenance; re-previewing such an action with `previewProposal`\nneeds the reviewer grant and keeps its handler fixed, so only its arguments can\nbe corrected),\nruns the handler's normal `validate`/`preview`, publishes a `waiting_review`\nrevision and requires the same explicit approval and apply as a generated\nproposal. The reviewer typed these arguments, so a handler argument-schema or\n`validate` refusal throws `HandlerArgumentsInvalidError` with the value-free\n`issues` described above, and the rolled-back transaction leaves no action row\n(#4281). Every other refusal (input shape, access, handler unavailable, item\nresolved, identity or request conflict, normalization mismatch) stays a plain\ndenial. `startAction` follows the `preview` contract: it throws, or a transport\nmay resolve `{ rejected: 'invalid', issues? }` for that one case. The component\nkeeps the start form, handler, arguments and reason, shows an inline refusal and\nlists any field paths; any other failure clears the view as before. Replays\nwith the same request return the same review; changed arguments or reason\nconflict. Such actions are never automation-eligible: `authorizeAutomatic`\nrefuses them regardless of policy opt-ins. The UI pre-fills arguments only from a\nsame-handler suggestion (for example a `needs_review` one) and a single original's\nevidence references, lists the required fields still missing, and submits exactly\nwhat the reviewer typed. An item whose current attempt failed outright must be\nreprocessed first; an interpretation that completed with `provider_error`,\n`unknown` or no suggestions can be acted on directly. `ReviewAction.origin`\nexposes the provenance so `ActionReview` can label human-started actions.\n\nThe optional `resolve` callback forwards `ResolveItemInput`\n(`disposition: 'resolve_no_action'`, `requestId`, optional `reason`) to\n`resolveItem`. It needs reviewer authority under any handler the item's captured\nceiling offers and refuses while an action is `authorized` with a live approval,\n`executing`, `outcome_unknown` or `succeeded`; waiting, deferred, rejected and\nfailed actions, and authorized ones whose approval expired, may remain (neither\nan exhausted failed action nor a lapsed approval can be rejected, so they must\nnot keep the queue open). Afterwards only reject remains: those actions can no\nlonger be approved, corrected, deferred, re-previewed, retried, applied or\nautomated. `submitDecision` refuses every decision but `reject`, no new revision\nis published for the item, `applyAction` rechecks the disposition before any\neffect, and `analyze`, `reviseLogicalSplit` and `createAction` refuse the item\nunder its lock before any write, so it is never reanalysed, re-split or given a\nnew action. `resolveItem` supersedes any queued or running analysis under the\nsame lock and `claimAnalysis` refuses a resolved item, so no provider is called\nafter a human closed it; the item's `processingState` keeps its last value (it\ndescribes analysis, not review), and the inbox state `resolved` is authoritative.\n`publishProposal` (process authority) refuses a resolved item and any\nreviewer-selected action. The UI hides Approve, Defer, Apply, every edit control, suggestion\npreview and split controls on a resolved item.\nResolved items hide the instruction editor and stop reinterpretation polling, even if an older processing projection is still queued. Recording an instruction cannot append a new revision after resolution.\n\nPaged lists project the resolved state and disposition time in the same bounded, scope-filtered query, so state filters and row controls agree with a full item reload.\n\nThe append-only `intake_dispositions` record is terminal: replaying the same\nrequest returns the same disposition, any other request conflicts, and\n`startReviewerAction` refuses the item. `IntakeItemDTO.disposition` projects only\n`{ state: 'resolved', at }` to any item reader (`listItems` reads it in the same\nstatement as the page); the reviewer and reason are returned only by\n`getItemDisposition`, which requires reviewer authority, and the review hosts put\nthem on `ItemReviewView.disposition` (omitted when that read is denied, so the\nview shows only \"Handled, no action\"). `loadReviewSummary` reports inbox state `resolved` unless an action\nactually succeeded. Privacy deletion and retention expiry redact the reason and\nreviewer (`intake_dispositions.data`) and keep only the kind. The disposition is\ndistinct from `reject`, which still means the proposal was wrong. Closing an item\nrecords `reviewer_routing` feedback immediately; a started action records it only\nwhen the reviewer approves it (see FEEDBACK.md). Capture is an optional projection\nthat never vetoes the decision or disposition.\n\n`startReviewerAction` applies the handler's discovery media types and the live\nreviewer grant/policy for that handler. It intentionally does not apply the\nproposal catalog's provider-policy filter or `maxHandlers` slice: those bound what\na model may be offered, and a human choosing a handler sends nothing to a\nprovider. The UI picker shows the offered catalog, so a handler hidden from it is\nonly reachable by a reviewer who already holds `review` authority for it. The maintained\nbrowser fixture serves both operations behind CSRF and the same session scope.\n\n## Review screen presentation (#4503)\n\nAll presentation only; no new authority.\n\n- **Handler labels.** A handler registration may declare `label`. It is carried\n on the reviewer catalog only (`listHandlers`, `ItemReviewView.catalog`), never\n on generation input, catalog digests or bindings, so adding one never stales\n existing work. The proposal heading, action heading and \"Start action as…\"\n select draw it, falling back to the handler id.\n- **State labels.** Review states draw `ingestion.reviewState.<state>` and\n generation outcomes `ingestion.outcome.<outcome>`; an unknown value is drawn\n as is.\n- **Arguments as fields.** Where a handler `argsSchema` declares top-level\n `string` (plain, `date`, `date-time`), `number`, `integer`, `boolean` or\n enum properties, or `references` declares a candidate/evidence field, the\n suggestion draft, the action's arguments and the start form draw those as\n fields (`title` as the label, `*` when required). A candidate reference is a\n search box over `host.candidates`, filtered to the reference's model, showing\n the candidate's label (the generation's offered candidates label the current\n value); an evidence reference picks among the item's originals. The JSON text\n stays the source of truth: fields rewrite it, and it remains editable under a\n collapsed \"Advanced\" disclosure for everything else (objects, arrays,\n unions). Without such properties the plain JSON textarea (and the\n destination picker) are drawn as before. Server validation is unchanged.\n- **Effects.** `action.review.display` is drawn as a `<dl>`: the handler's\n preview fields (`display.preview`, or `display.step.preview` for a plan step;\n a flat record as is), then non-empty `dependencies`/`plan` metadata as JSON,\n named `metadata.<key>` when a preview field already has that name\n (`displayEntries` in `view-utils`).\n- **Assignees.** An optional `IntakeReviewHost.assignees(query)` (adapter\n option `assignees`) answers `{ id, label }[]`; the inbox then draws a search\n picker for the filter and each row instead of the free-text \"Assignee ID\".\n `assign` still receives the id and still authorizes. A failed search offers\n nothing.\n- **Feedback state.** `ReviewAction.feedback` (see FEEDBACK.md) presses the\n current judgment; a further judgment supersedes it and\n `ingestion.feedbackSent` confirms it.\n- **Confidence.** Nothing is drawn when the provider reports no confidence.\n\n## Single-page triage workspace\n\n`IntakeWorkspace` (#4215) composes the existing pieces so a reviewer works the\nwhole queue on one page: the paged inbox as a list pane, the review view of the\nselected item beside it (the original above its action form), and the\nreviewer-instruction message box of the item pane. Props: `host`, `contextKey`\n(replace on session change, as for the other components), optional initial\n`itemId`, `pollMs`, `rowAside` and `onselect(itemId | undefined)`, which only\nreports the selection (to keep a URL in step) and never navigates. It adds **no\nhost callback and no server authority**: every read is the host's `list` and\n`load`, every action still goes through the handler preview and an explicit\napproval and apply under the approver's live grants, and the message steers the\nmodel only, exactly as in `IntakeReview`.\n\n- **Inline original.** In the item pane `EvidenceViewer` shows one part at a\n time (`layout=\"pager\"`), opening on the first part that renders inline (the\n uploaded file rather than its capture record), with previous/next original.\n A PDF with more than one *observed* page (extraction locations or proposed\n page groups; `pages` prop) gets previous/next page, which reloads the frame\n at the same-origin URL plus `#page=n`; only `evidenceUrl`-approved URLs ever\n reach a frame. `IntakeReview` gets the same page navigation over its\n unchanged stacked list of parts. The chosen part and page belong to the item\n view (bindable `chosen`/`page`), so they survive in-place reloads, Prepare\n review, Approve and Apply.\n- **Keyboard.** J/K and Alt+Down/Alt+Up move to the next/previous row (loading\n the next page at the end), ignored while focus is in a text field, select or\n editable region; \"Previous item\"/\"Next item\" buttons carry\n `aria-keyshortcuts`. The selected row is `aria-current`, and every selection\n moves focus to the item pane region, named by the row's label. A navigation\n that waited for the next page is dropped if the reviewer chose another item\n meanwhile.\n- **Unsent input.** The pane holds unsent input when it has instruction text,\n an edited suggestion draft or split draft, a chosen start handler or start\n reason, a no-action reason, or an action editor with edited arguments, a\n reason or a feedback comment. It is read from the drafts themselves, so it\n holds while a reload has cleared the view; while the view is denied nothing\n is shown and nothing counts (the drafts stay in memory and return with an\n authorized refresh, as before). A reviewer-initiated move (J/K, Alt+arrows,\n Next/Previous item, a row's Review button) then asks inline, in a group\n labelled by its note: \"Stay on this item\" takes focus and returns it to the\n field the reviewer last used; \"Discard and open the other item\" proceeds.\n When an item is closed without action (here or by another session), input a\n closed item cannot take\n (instruction, suggestion and split drafts, a started action, a no-action\n reason) is discarded.\n- **Live state.** A row's status follows the item: \"Interpreting…\", \"Ready to\n review\", \"Needs review\" with missing argument names or the generation\n outcome, \"Awaiting approval\", \"Approved, not yet applied\", \"Failed\" with a\n safe category, \"Handled, no action\", or the listed inbox state. Rows the\n reviewer has not opened show the listed state only; reasons come from a\n loaded view, never from server exception text. The open item's own polling\n (`ReviewView`, unchanged backoff and three-failure fail-closed) reports each\n displayed view and the workspace patches that row in place\n (`InboxView.patch`, keeping the listed label and preview, and the row's\n assignment unless the patch carries a newer assignment version, so a view\n read before an assignment never rolls the row or the next expected version\n back), so the row follows each newer read of the form and the list is\n **not** re-listed per tick. An item the\n reviewer leaves while its stage is in flight, or before the pane showed the\n result of its last operation (an instruction just recorded), keeps\n following: the workspace re-reads followed items with the same `load` (first\n review page) on the pane's backoff, at most **5** reads per tick, one after\n another, least recently read first (so every followed row is reached), with\n only one tick running at a time. At most **20** items are followed; beyond\n that the longest-followed one (the earliest started, whatever the read\n rotation) stops. An item left while its pane was mid-operation (an Apply not\n yet answered) keeps following while a read still shows an action authorized\n or executing: exactly **3** more reads when it never answers, the fourth\n ending the follow. That debt belongs to the operation, so it survives\n reopening and leaving the item again until a view shows the operation\n answered or the reads run out; leaving mid-operation again starts a full\n debt for the new operation. Each follow has a\n generation: an answer from an earlier follow of the same item (one asked\n before the reviewer reopened or left it again) is dropped, and its failure\n does not count toward the new follow's three. An item stops being followed\n when it settles, its view is denied, three reads in a row throw, its row\n leaves the displayed list (a filter or a refreshed page removed it), the\n list fails closed, or the cap drops it; a denial, the failure stop or the\n cap drops its cached status and restores its entry exactly as its page read\n returned it (never a patched entry). Opening an item drops its cached\n status until the pane shows a view; a denial in the open pane (a failed\n action, the pane's own fail-closed poll, or a first load that failed) does\n the same as a follow denial, clears the announcement, and the item is not\n followed when left. A settled stage that was seen running is announced in a\n polite status region (\"badger-po.pdf: Ready to review\"), only while its row\n is displayed; a refreshed page or a failed list clears it.\n Other rows update on Refresh, a filter change or when opened; there is no\n streaming. While a refresh or \"Load more\" is pending, the displayed rows stay\n (controls disabled) and keep taking patches. Every read (a page, a pane\n view, including an unchanged poll, and a follow read) is numbered when its\n request starts, and each row shows the entry of its newest read, whatever\n the source: a page read before a pane or follow read never regresses the\n row, and a page read after them replaces what they showed. The same rule\n governs a follow: a follow read older than the row's newest read changes\n no status, does not stop the follow and announces nothing (a newer read\n settles it), so the announcement never contradicts the row. Cached status reasons follow the same ordering, even when entries have identical\n fingerprints. \"Load more\" continues the\n filter the rows were listed under, not filter inputs edited since, and does\n not repeat a row already shown. A failed \"Load more\" fails closed like any\n failed read (the host cannot tell a transient failure from a revoked\n grant): the rows clear and the list shows its error.\n- **Approve and advance.** After an approve, apply or \"Handled, no action\" whose\n reload left nothing for the reviewer (closed without action, or an action\n succeeded and none is waiting for approval, waiting to be applied, executing,\n unknown or failed; stale, rejected and deferred actions do not hold it), the\n item's row is patched and leaves the list when it no longer matches the\n listed state/assignee filter, and the next row that is not closed or\n completed opens and takes focus, with no navigation and no re-listing. An\n approval that leaves an apply step keeps the item open with Apply in place.\n Unloaded saved-review pages and an active background stage also prevent\n settlement. Advancing skips completed inbox pages until a reviewable row\n appears; a page that makes no progress stops the walk.\n It never advances over unsent input on the same item: the item stays open,\n the input stays, and a note says it is finished but has unsent input; the\n reviewer moves on explicitly, through the confirmation; input typed while\n the next page loads counts too. When no open row is displayed, the advance\n appends pages of finished rows until one has an open row or no page\n remains, at most **5** appends. After each append, the advance (like\n J/K at the end of the list) finds its place again by id: just after the\n item it left, or, if that row has gone, at the first row that followed it\n and is still listed, or at the first new row, so a row that left the list\n meanwhile never shifts it onto the wrong item. Its notes (and \"nothing else\n needs review\") are written into one persistent polite status region. The queue is never reported empty when\n that is unknown: past the bound, or when an append cannot start (a refresh\n is pending) or is superseded, the item stays open with a note to try Next\n item again, which still works; when an append fails, the list has failed\n closed (no rows, Next disabled), so the item stays open with a note to\n refresh the list to continue. The open item stays listed while the\n reviewer works on it even if its state stops matching the filter; it\n leaves once they move on.\n When nothing is left the pane says so. The per-row \"Handled, no action\"\n control is hidden in the workspace (`resolveInRow={false}`) so closing always\n goes through the item pane and advances.\n\n\n**List following and refresh (#4504).** Every listed row (other than the open\nitem) whose entry shows a stage in flight is followed like an item left\nmid-stage, up to `WATCH_CAP` rows, `WATCH_LIMIT` reads per tick on the pane's\nbackoff, so rows no longer keep \"Interpreting…\" until Refresh. Opt-in\n`listPollMs` on `IntakeWorkspace`/`IntakeInbox` also re-reads the listed page\nunder its listed filter while any row is processing (skipped while a read or\noperation is pending or Load more appended pages). Both components export\n`refresh()` (`bind:this`), which re-reads the first page like the Refresh\nbutton and resolves `{ items, result: 'shown' | 'failed' | 'pending' }`.\n\n## Maintained browser proof\n\n`pnpm test:components` runs real Svelte component tests; `pnpm test:e2e` runs the\npackage-local authenticated Vite application under Chromium. The fixture uses\nHttpOnly same-site sessions, CSRF, real SQLite/assets/ingestion/content APIs,\nproduction unpdf child extraction and a deterministic proposal generator. Its\nhardcoded test login is fixture-only and is never a production auth provider.\nImage/audio originals remain inspectable when no OCR/speech provider is\nconfigured; the suite makes no recognition-quality claim and spends no provider\nbudget. `reference/review-host.ts` is a maintained development fixture, not a\npublished server entry. Browser tests show actual approved args and persisted\nContentDocument results, stale tabs, reload, retries and negative access.\n\nRun full package `test`, `test:postgres`, `test:providers`, `build`, `typecheck`,\n`test:components`, `test:e2e`; use the root Node/pnpm versions. Set a short\n`CI_TEST_TMPDIR`/`TMPDIR`, and optionally\n`PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH` to the supported installed Chromium.\n`pnpm test:evaluation` checks repository evaluation tooling contracts; measured\nheld-out quality remains a separate frozen-protocol, budget-gated #3677 run.\n\nThe existing CI browser job includes ingestion changes and shared UI primitive\nchanges in affected mode, and runs the ingestion browser suite in full mode. Its\nnormal dependency build precedes the suite and failed runs upload browser evidence.\n\nThe maintained host derives inbox state by traversing bounded public review pages,\nauthorizing every action/parent/target before classification. It retains only\nscalar totals and the requested page; an off-page denial denies the whole view.\nThe component's Load more and subsequent refresh/mutation reload every displayed\npage using fresh cursors, then publish the combined authorized set together. Old\npage payloads are cleared while loading; any unavailable page clears all payloads.\nThis keeps plan controls and earlier steps visible across page boundaries without\nreusing a prior authorization decision.\n\n## Published server adapter\n\nImport `createIntakeReviewHost` and `IntakeReviewHostOptions` from\n`@happyvertical/smrt-ingestion/server`. Call `createIntakeReviewHost(service,\noptions)` with a service constructed from the current authenticated session.\nThe returned `IntakeReviewHost` implements inbox state projection across saved\nreview pages, current generation loading, stable `ui:<index>` intention keys,\naction/plan preview CAS lookup, decisions, apply, corrections, candidates, split,\nfeedback, the offered `catalog`, `startAction` and `resolve`. Any catalog\nfailure (not configured, bound exceeded, denied) omits `catalog`, so the picker\ndisappears while existing reviews stay reviewable; item, review and evidence\ndenials still propagate as before; the reference host (`reference/review-host.ts`)\ndegrades the same way. Repeated\npreparation of an unchanged authorized suggestion retains\nits current review instead of creating a new revision. Changed arguments still\nrequire explicit re-preview and a fresh human decision.\n`list({ state?, assigneeId?, cursor?, limit? })` returns one page newest receipt\nfirst (`intake_items.created_at`, id tiebreak) through `service.listItemsPage`.\n`limit` defaults to 20 and is capped at 100; the cursor is an opaque\n(received-at, id) continuation, never a bare id. Tenant, confidential scope,\nretention and the `state` filter run inside the page query, so a page is full\nand `nextCursor` is present only when more rows follow.\n\nAuthority is rechecked at the same two levels `load` applies, but per page\nrather than per row: the host authorize callback once per distinct captured\nceiling in a batch, and the execution read gate (policy, ceiling, handler and\noperation allowlists, principal) once per distinct (item, handler) bound by\nthe page's saved actions. The list gate is read-only: it evaluates the same\nchecks as `listReviews` without the retention write, so an item that the item\nview would narrow past its deadline is simply not listed. The list gate also\nresolves each bound handler and rejects version drift against the saved\nbinding and omits a cancelled item, as `listReviews` does; it does not\nevaluate per-action target,\nevidence or plan gates, so an item whose target became unreadable still lists\nand its item view refuses. An item whose bound\nhandler the actor cannot currently read is not listed at all, rather than\nlisted with a state derived from actions the actor may not see; actions\nwithout a proposal bind no handler and are not gated, as in `listReviews`.\nHandler bindings (handler id and version, projected in SQL, distinct per\nitem) are read once per fetched batch for the rows that passed the item-level\ngate. Note the host cost plainly: the execution `authorize` callback runs once\nper distinct (item, handler) bound by a scanned row that passed the item-level\ngate. Each item is its own authorization subject, so nothing is deduplicated\nacross items; the count is bounded by rows scanned (at most\n`ITEM_SCAN_CEILING`) and runs in host code rather than as N+1 database reads. Either host callback, the item-level `authorize` or the execution\n`authorize` behind the handler gate, follows the same rule: a refusal (false,\nor an access check that fails) hides the rows it covers, and a callback that\nthrows rejects the whole page (and `listItems()`) with its error, as `load`\ndoes, so a transient failure never lets paging move past readable rows.\nDenied or unreadable rows are skipped without\ndisclosure and the page refills from the next rows; refills grow from the page\nsize to 100 rows per query, so a fully denied scope costs about a dozen page\nreads and as many binding reads per call. One service call examines at most\n`ITEM_SCAN_CEILING` (1000) rows, or the caller's smaller `scanLimit`, and\nreports the count as `scanned`; when a mostly-denied scope reaches the ceiling\nthe page comes back short with a `nextCursor`. Rows are authorized first and\nthe `state` filter is then applied to the fetched batch, so it is bounded by\nthe same scan limit: a rare state yields short pages with a cursor rather than\nan unbounded walk inside one query. A row the actor can read whose state does\nnot match discloses nothing and may anchor the cursor, so a filter with no\nmatch among the next 1000 rows returns an empty page with a cursor and still\npages to the end. The host `list` passes its remaining budget as `scanLimit`, so the\nrows scanned across the service calls of one host call never exceed 1000: a\nshort service page with a cursor, or an exhausted budget while filtering by\nassignee, ends the host call with the same cursor and the caller continues.\nOnly rows the service wrote are supported: cursors carry the canonical\nmillisecond ISO receipt time the service stores. A row whose stored receipt\ntime is not that form (on SQLite anything but `YYYY-MM-DDTHH:MM:SS.mmmZ`,\nincluding a parseable value without milliseconds or with an offset; on\nPostgreSQL a value with a sub-millisecond part) is never listed, whatever the\nactor's access, and counts toward the scan, as does a row whose id is not a\nUUID. On SQLite a non-text stored value (an integer, say) and a receipt value\nor id longer than 64 characters or containing a NUL character are excluded by\nthe page query itself: the first sorts after every text value so the scan\ncould never move past it, the second could not be carried by any cursor, and\nthe third is returned truncated at the NUL, so it would look canonical and\nsort above a legitimate row at the truncated value. Within a call the scan moves\npast a service-foreign row by its exact stored value, and an unsealed cursor\nnames the last row before it that the actor can read. A call that finds no readable row within its scan limit (at\nmost 1000) fails closed with `IntakeScanLimitError` unless a `cursorKey` is\nconfigured, as below. The host\n`list` returns what earlier service calls collected, with their cursor, when\na later call fails that way.\n\n`listItems()` is deprecated and kept only for callers of the array-returning\nAPI. It walks every page, so its cost grows with the scope, including one\nexecution authorization per (item, handler) across the whole scope. It follows\nthe internal scan position, which never leaves the service, so runs of rows\nthe actor cannot read never stop it and it returns `[]` where nothing is\nreadable. Items are newest-first and gated exactly as on a page.\n\nThe page's inbox state is the durable projection of the saved action journal\nand processing state, computed once per scanned row inside the page query;\n`load` remains the authoritative, live-gated projection for one item (it still\nprojects individual stale actions, which the list does not). Cost is\nproportional to the page for unfiltered pages and common states, and to the\nnumber of items scanned until enough matches are found for rare states: the\nstate is not persisted, because the action journal is append-only and\nprojecting it into an indexed column would need a maintained denormalisation\nin the execution service plus a migration, which this change does not take.\nListing does not load original bytes.\n\nCursors never disclose an unreadable row. Without a `cursorKey` in the\nservice options, every cursor (each row's and `nextCursor`) names a row the\nactor can read (the last one when a page stops early); a page that spends its scan limit before filling hands back\nthe last such row, and one that found none fails closed with\n`IntakeScanLimitError` (`Intake scan limit`, no id or time). A run of rows the\nactor cannot read (refused by the captured ceiling or the execution gate, or\nstored with a non-canonical receipt time) at least as long as the scan limit\ntherefore stops an unkeyed walk there; readable rows that the `state` filter\nexcludes never count toward such a run. With a `cursorKey` (a server secret of at least 32 bytes), every\ncursor is sealed with AES-256-GCM, bound to the tenant, confidential scope and\nactor, and a budget-stopped page returns a sealed position past what it\nskipped, so the walk always progresses. Sealed cursors have a fixed length\n(the plaintext is padded to 1024 bytes) and a fresh nonce per seal, so neither\ntheir length nor their bytes reveal anything about the stop row. `scanned` is for trusted host\naccounting and must not be sent to clients; a short page with a cursor tells\na caller only that unlisted rows exist, never which.\n\nNewest-first paging relies on `intake_items_received_idx`\n(`tenant_id, confidential_scope_id, created_at, id`), the full ordering key, so\nan unfiltered page is a backward index scan that stops at the page boundary;\nthe foundation suite asserts that plan on both engines (SQLite\n`EXPLAIN QUERY PLAN`, PostgreSQL `EXPLAIN`), with the per-row state counters\nserved by `intake_actions_item_idx`. On SQLite the page query pins the index with `INDEXED BY` (except under an\nid restriction, where direct id lookups are cheaper), because without planner\nstatistics SQLite otherwise picks `intake_items_expiry_idx` plus a sort; the\nSQLite plan check runs without `ANALYZE`. A deployment must have applied the\nmanifest migration, or the page query fails with a missing-index error. This package ships no\nmigration files: indexes are declared on the model, the build emits them into\n`dist/manifest.json`, and `smrt db:migrate` / the public migration API create\nthem, which is how `intake_items_receipt_idx` shipped. Deploy the manifest\nmigration before upgrading hosts; `db:status --parity` reports the index as\nmissing until then.\n\nSupply four application adapters: `upload(files, requestId)` (authenticated\nreceipt plus first extraction request), `assignment(itemId)` (durable read),\n`assign(input)` (manager authorization, eligible assignees, durable CAS and request\nreplay protection), and `evidence(part)` (safe label/text or authenticated\nsame-origin URL), which `load` calls for every part and `list` never calls;\n`load` sets no row preview on its entry.\n\nRow previews are opt-in through an optional fifth adapter,\n`rowEvidence(rows)`. When it is supplied, `list` reads the page's durable\nevidence metadata with one `service.listEvidence(itemIds)` query (at most 100\nids; items the scope cannot read, and expired or inactive items, are omitted\nwithout disclosure; the host `authorize` runs once per distinct captured\nceiling through the same gate as `listItemsPage`, so a refusal or a\nmalformed captured ceiling hides the item and a failing `authorize` rejects\nthe page; an item whose stored data does not parse is skipped by both\n`listItemsPage` and `listEvidence`, never fatal). It then calls `rowEvidence`\nonce with each row's primary part (`{ itemId, evidence }`) and publishes the\nreturned `{ label, viewUrl?, thumbnailUrl? }` as `InboxEntry.evidence`\n(`{ evidence, label, viewUrl?, thumbnailUrl? }`, never text). Build those URLs\nfrom metadata without reading bytes; if `rowEvidence` throws or returns a\nmalformed answer, the page still lists without previews, and a row without\ndurable parts never gets one. When it is omitted, rows show no original link.\nEither way `list` reads the page's evidence metadata once, in that same query,\nso the row label can use the original filename; it never reads original bytes\nand never calls `evidence(part)`. The primary part is chosen by role, not media\ntype: the shallowest child part when any part has a parent (an upload's file\nunder its capture record, an email's first attachment under the message, even\nwhen that child is JSON), else the first root part (a watched-folder file);\npart ids sort numerically. `IntakeInbox`/`InboxView` accept an\noptional `rowAside` snippet receiving the `InboxEntry`; without it a row renders\nthe host's \"Open original\" link (new tab) and thumbnail when the URLs are\nsame-origin; each link's accessible name is \"Open original: <row label>\", and\na row shows no wrapper when neither URL is usable. The slot is a plain `div`,\nnot an `aside` landmark, so a page does not add one landmark per row. Optional\n`label(item, evidence)` changes presentation; `evidence` is the item's durable\nparts with the primary part first, and the default label is the primary part's\nown original `filename`, else `Intake <8 hex>`. Optional\n`assignments(itemIds)` reads one page's assignments in one batch (otherwise\n`assignment` runs per row), and optional `assignedItemIds(assigneeId)` lets\n`list` push the assignee filter into the page query (junk ids are dropped, not\nfatal); without it an assignee filter scans further pages and filters by\n`assignment`, which stays correct but costs more rows. The page's continuation\nis always the last row actually returned, so an assignment that changes\nbetween the page read and the assignment read costs at most one extra scan and\nnever skips or repeats a row. Optional\n`enableFeedback: true` exposes the optional feedback callback when the service\nhas feedback configured. Optional `onSplit(itemId, revision)` wakes the host worker after the durable extraction\nrequest; repair dispatches if wakeup fails. The factory creates no assignment\nschema and grants no permissions. Create it per session, authenticate every HTTP\ncall and enforce CSRF before dispatching a mutation.\n\n`GenerationAnalysisOutput` is exported by `/dto` and describes the interpretation\nwrapper `{ proposals: GenerationOutput }` under `analysis.result.output`.\nThe factory unwraps this into `ItemReviewView.generation`. Stale generation is\nomitted while authorized saved reviews remain available; access denials propagate.\nThe reference application still owns its fixture provisioning and HTTP transport.\n\n## Upload refusals and accepted types (#4502)\n\n`IntakeWorkspace`/`IntakeInbox` take `accept` (an `<input accept>` value)\nfor their file picker, defaulting to `IntakeReviewHost.uploadAccept` (adapter\noption `uploadAccept`); it is a hint only, `upload` still enforces the host's\nallowlist. When `upload` throws `IntakeUploadRefusedError` (from `/svelte`) or\nany error with a string `userMessage` (or an error named\n`IntakeUploadRefusedError` / with `code: 'INTAKE_UPLOAD_REFUSED'`, whose\n`message` is then shown), the inbox shows that reason (trimmed, at most 500\ncharacters) and keeps its rows; `uploadRefusalMessage(error)` applies the same\nrule. Any other error still fails the list closed with `ingestion.error`.\n\n## Explicit upload retries\n\nThe inbox retains selected original files and the receive request identity when\nupload fails or acknowledgment is lost. Retry Upload explicitly with the same\nselection; Refresh does not replace that identity. Selecting files again starts a\nnew receipt identity, even when names match. Successful upload clears the selection\nand identity. Replacing the authenticated host/context or destroying the component\ndiscards both and fences late completion from the prior context. No automatic\nupload retry or authorization bypass occurs.\n\nThe inbox clears only its native file-input value when opening the picker, so\nchoosing the same local file explicitly starts a new upload identity. Opening\nthen dismissing the chooser preserves the separately retained originals and\nrequest identity for retry; it does not clear the shared FilePicker's native-form\nbehavior. Successful upload and host/context disposal still discard retry state.\n\nWorkspace ordering also protects an open item during an awaited automatic page walk:\nthe selected row remains until navigation succeeds, except that a failed list read\nclears the inbox. Applying an action is disabled\nwhile that action card holds unsent arguments, reason, or feedback comment. A list\nrefresh retires earlier follow snapshots; only follow reads started after that\npage request may override its rows, so a newer refresh cannot be regressed by an\nalready settled or older in-flight follow read.\n"
1734
1734
  }
1735
1735
  ],
1736
1736
  "agentSurface": {
@@ -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": 2429,
1768
+ "line": 2524,
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": 3001,
1776
+ "line": 3309,
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": 8846,
1784
+ "line": 9267,
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": 9478,
1792
+ "line": 9899,
1793
1793
  "column": 7,
1794
1794
  "sourceFile": "src/test-support/proposals.ts"
1795
1795
  }