Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/2869-intake-hold-aware-writes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-ui-server": patch
---

A conversation turn's `inbox_add` no longer refuses a still-valid turn when a journal observation or a scope pause begins while it stages its arrival (#2869). Before, the arrival's staging writes ran unchecked through such a hold, and the final check then refused with "Inbox principal or turn is no longer authorized" and removed the staged files during the hold. Now every intake write (staging, publication, the receipt commit and cleanup) waits for the hold, bounded by the existing 60-second wait shared across the whole intake, and is checked again in the tick it runs. The turn, its principal and the provider masks over the staging directory are checked again after the wait, and one item is accepted once the hold ends. Revocation, turn replacement and cancellation still refuse at once, and a hold past the bound refuses with nothing accepted. Cleanup of an abandoned arrival never runs during a hold: when it cannot run in time, its receipt stays queued for reconciliation.
29 changes: 24 additions & 5 deletions docs/decisions/governed-writable-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ the same places, where links lead included. Inbox staging is judged at each dire
it publishes, and before every compensation removes anything: its own
partial or published arrival, and an earlier arrival that the call
reconciles (`conversation: (input`,
`packages/ui-server/src/inbox/intake.ts:137-140`). A call refused before
`packages/ui-server/src/inbox/intake.ts:212-216`). A call refused before
staging leaves no receipt and no item. Links are read at each change, so a
link a governed worker swaps in between two changes stops the next one; one
swapped in between a check and its own system call is not covered, because
Expand Down Expand Up @@ -1223,6 +1223,25 @@ since a long hold is not revocation. A principal that really lost authority
refuses `authority_revoked` at once, waiting or not (`export async function retryHeld`,
`packages/ui-server/src/brain/authority-hold.ts:92-102`).

**Conversation intake waits out a hold at every write (#2869, maintainer,
2026-10-25).** A turn's `inbox_add` stages its arrival, publishes it, commits
its receipt and compensates what it abandoned, and each of those writes is
coordinated with the same hold rather than checked once at entry. Each change
runs through one write gate: it waits for a hold outside any transaction or
lock, sharing one 60-second deadline across the whole intake, then makes its
final check and its change in the same tick, so a hold that begins after that
check cannot overlap it. Staging writes are synchronous under the gate for that
reason. The final check renews the turn, the principal, the origin thread and
the turn's provider masks over the staging directory, and the receipt
transaction still refuses a receipt that reconciliation took meanwhile.
Revocation, turn replacement and cancellation refuse at once; a hold past the
bound refuses; none of them leaves a queue claim. Compensation is the host's
own effect: it waits for a hold on brain writes whatever the turn's authority,
and when it cannot run within the bound or after cancellation it removes
nothing and leaves its `cleanup` receipt for reconciliation. A committed
receipt is never compensated (`function writeBoundary`,
`packages/ui-server/src/inbox/intake.ts:113-127`).

**A pause the policy observation raises is a no-publication outcome (#2870,
maintainer, 2026-10-25).** Policy publication runs inside its own journal
observation, and that observation can itself reach a scope cap. Waiting there
Expand Down Expand Up @@ -3081,7 +3100,7 @@ every turn without a proven recipient:
roadblock signatures (`scope=roadblocks`). `running` and `rollups`
return labels and counts that may also name documents.
- `inbox_list` and `inbox_get` (`inboxList`,
`packages/ui-server/src/inbox/bridge-tools.ts:62-83`): each item's stored
`packages/ui-server/src/inbox/bridge-tools.ts:78-99`): each item's stored
payload, titles, details and option labels, and its thread.

None of these fields records which documents its text came from. A run from
Expand All @@ -3100,7 +3119,7 @@ every turn without a proven recipient:
#2741 option C).** #2698 left autonomous turns out. Their bridge still
serves `inbox_list` and `inbox_get` when the exact roster allows them,
scoped to the turn's origin thread (`inboxList: async`,
`packages/ui-server/src/inbox/bridge-tools.ts:62-83`), and the dispatcher
`packages/ui-server/src/inbox/bridge-tools.ts:78-99`), and the dispatcher
embeds the thread's text in the first message (`async function context`,
`packages/ui-server/src/inbox/dispatcher.ts:163-185`). Source inspection
finds these retained thread inputs:
Expand All @@ -3121,14 +3140,14 @@ every turn without a proven recipient:
context is built afterwards, from the admission's arrival read and in the
transaction that revalidates it, and both reads revalidate in their own
transaction before building any payload (`function authorizeRead`,
`packages/ui-server/src/inbox/bridge-tools.ts:52-56`). Host code records
`packages/ui-server/src/inbox/bridge-tools.ts:68-72`). Host code records
the evidence in `inbox_provenance`, in the transaction that writes the item
or checkpoint, bound to a digest of its text (`export function
recordInboxProvenance`, `packages/ui-server/src/inbox/provenance.ts:93-117`).
Compatible evidence is exactly: a person's arrival through the
authenticated share or queue route, outside any turn, also bound to a
digest of the staged bytes intake read (`const evidence = author`,
`packages/ui-server/src/inbox/intake.ts:105`); text the server composed
`packages/ui-server/src/inbox/intake.ts:178`); text the server composed
from no brain content or model output (schedule instructions, cleanup and
lifecycle notices); text an autonomous run wrote (escalations, yields)
whose admitted masks hid every folder now masked; and, since #2816, an
Expand Down
2 changes: 1 addition & 1 deletion docs/plans/async-collaboration-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Stated before the requirements because five of them derive from it.
that arrived from outside, including every v1 share). It is never present in any
model-authored payload schema, and no model output can change it. The share manifest
has its source selected server-side
(`const result = await stageShareAt(`, `packages/ui-server/src/inbox/intake.ts:101`); this generalizes that.
(`const result = await stageShareAt(`, `packages/ui-server/src/inbox/intake.ts:174`); this generalizes that.
- **T2. Model output is data, never authority.** `state_md`, T1 classifications, and
follow-up payloads are authored by a model that has read attacker-controllable text. They
may describe, request, and summarize. They may not select a tool profile, widen a
Expand Down
4 changes: 2 additions & 2 deletions docs/plans/async-collaboration.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ system gate. It is not a prerequisite to rebuild or a new independent package.
(`function createIntent(input: {`, `packages/ui-server/src/activity/notify.ts:102-154`) and
(`async deliverPending(notifier) {`, `packages/ui-server/src/activity/push-sender.ts:218-286`) are run-bound and do not
maintain an Actions aggregate count.
- **Share provenance/limits:** (`const result = await stageShareAt(`, `packages/ui-server/src/inbox/intake.ts:101`) assigns the source in server code.
- **Share provenance/limits:** (`const result = await stageShareAt(`, `packages/ui-server/src/inbox/intake.ts:174`) assigns the source in server code.
(`export const SHARE_MAX_TEXT_BYTES =`, `packages/ui-sdk/src/protocol.ts:2701`) bounds text, not binary uploads;
extracted T1 context needs its own byte/token bound.
- **Interactive locks:** (`const cap = host.maxConcurrentSessions();`, `packages/ui-server/src/ws/run-session.ts:1346-1358`) gates WS starts;
Expand Down Expand Up @@ -751,7 +751,7 @@ recovered tick after killing the interval

**Approach:**
- One arrival → one thread (trust class from the source record, hardcoded server-side per the
(`const result = await stageShareAt(`, `packages/ui-server/src/inbox/intake.ts:101`) precedent) + one `triage` Queue item; bytes stay in the staging
(`const result = await stageShareAt(`, `packages/ui-server/src/inbox/intake.ts:174`) precedent) + one `triage` Queue item; bytes stay in the staging
directory
- `dedup_key` from a content hash for shares; from an explicit key for authenticated CLI adds
- Trust class is written by the server and is not a parameter of any request body
Expand Down
6 changes: 3 additions & 3 deletions docs/plans/chat-attachments.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ operational inbox intake for `/share`. `/track-upload` calls `stageShare` with

**Staging.** `stageShareAt` writes generic bytes under a server-minted ID in
`.brain-ui/inbox/<id>/`, sanitizes names and publishes them with an atomic
rename (`stageShareAt`, `packages/ui-server/src/share/staging.ts:298-463`). It
rename (`stageShareAt`, `packages/ui-server/src/share/staging.ts:312-516`). It
tries the shared track parser on every file
(`let imported`, `packages/ui-server/src/share/staging.ts:379-381`). The
(`let imported`, `packages/ui-server/src/share/staging.ts:416-418`). The
MIME-to-extension table lists PDF
(`EXTENSION_BY_TYPE`, `packages/ui-server/src/share/staging.ts:91-114`), which
(`EXTENSION_BY_TYPE`, `packages/ui-server/src/share/staging.ts:96-119`), which
only names the stored file and reads nothing. Staged shares are pruned after
seven days (`SHARE_STAGING_TTL_MS`, `packages/ui-sdk/src/protocol.ts:2614`).

Expand Down
24 changes: 20 additions & 4 deletions packages/ui-server/src/inbox/bridge-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type { BackendBridge } from "@schlessera/brain-ui-sdk/server";
import { INBOX_ADD_INPUT_SCHEMA, INBOX_GET_INPUT_SCHEMA, INBOX_LIST_INPUT_SCHEMA, RESOLVE_ACTION_INPUT_SCHEMA } from "@schlessera/brain-ui-sdk/tool-contracts";
import type { V1ResolutionEffect } from "@schlessera/brain-ui-sdk/protocol";
import { isUsablePrincipal, resolvePrincipal } from "../db/principals.js";
import type { InboxIntake } from "./intake.js";
import type { InboxIntake, IntakeHolds } from "./intake.js";
import { AuthorityHeld } from "../brain/authority-hold.js";
import { createInboxStore } from "./store.js";
import { createInteractiveShares } from "./interactive-share.js";
import type { createInboxResolver } from "./resolve.js";
Expand All @@ -29,6 +30,16 @@ export interface InboxBridgeContext {
* compensation refuse a protected target, as the turn's application does.
*/
protectedPaths?: readonly string[];
/**
* The turn's write boundary (#2869): a journal observation or a scope pause
* that begins during an `inbox_add` holds its writes rather than revoking it.
*/
holds?: IntakeHolds;
/**
* Checks again, before each `inbox_add` write, what the turn admitted the
* call under, such as its provider masks; throws to refuse.
*/
requalify?: () => void;
/** Server-held exact approval only. V1 never creates a discuss binding. */
approvedAction?: { sessionId: string; itemId: string; optionId: string; expectedVersion: number; effect: V1ResolutionEffect };
}
Expand All @@ -42,10 +53,15 @@ export function createInboxBridgeTools(db: Database, intake: InboxIntake, resolv
const threadId = context.origin === "interactive" ? undefined : context.origin.threadId;
// A caller cannot mutate an approved effect after this bridge is constructed.
const approved = context.approvedAction ? structuredClone(context.approvedAction) : undefined;
function authorize() {
/** `write` marks an `inbox_add` write's check: a hold, not revocation, reports `AuthorityHeld` so intake waits it out. */
function authorize(write = false) {
const principal = resolvePrincipal(db, principalId);
if (!isCurrent() || !principal || !isUsablePrincipal(principal, Date.now())) throw new Error("Inbox principal or turn is no longer authorized");
if (!isCurrent() || !principal || !isUsablePrincipal(principal, Date.now())) {
if (write && principal && isUsablePrincipal(principal, Date.now()) && context.holds?.hold.active()) throw new AuthorityHeld();
throw new Error("Inbox principal or turn is no longer authorized");
}
if (threadId && store.getThread(threadId)?.status !== "open") throw new Error("Inbox origin thread is unavailable");
if (write) context.requalify?.();
return principal;
}
const reads = [...(context.allowedReads ?? [])];
Expand Down Expand Up @@ -88,7 +104,7 @@ export function createInboxBridgeTools(db: Database, intake: InboxIntake, resolv
// Reuse compensated, principal-checked intake; never accept a model
// source/trust field. The turn is this bridge's own: its host lineage
// alone decides what the item can qualify for (#2816).
const result = await intake.conversation({ text: parsed.text, files: [] }, `bridge:${principalId}:${turnId}:${parsed.idempotencyKey}`, principal, turnId, () => { authorize(); return true; }, context.protectedPaths);
const result = await intake.conversation({ text: parsed.text, files: [] }, `bridge:${principalId}:${turnId}:${parsed.idempotencyKey}`, principal, turnId, () => { authorize(true); return true; }, context.protectedPaths, context.holds);
return { created: result.created, threadId: result.threadId, itemId: result.itemId };
},
resolveAction: async input => {
Expand Down
Loading
Loading