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
6 changes: 6 additions & 0 deletions .changeset/attachment-reads-delivery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@schlessera/brain-ui-sdk": minor
"@schlessera/brain-ui-server": minor
"@schlessera/brain-ui-react": patch
---
Deliver recorded attachment reads to the browser so sent files can show what the agent read (#3589). A host with composer files advertises `server_hello.capabilities.attachmentReads`, answers `GET /api/sessions/:id/attachment-reads` with the recorded `read_attachment` calls of the originals a session's messages name (`{ fileId, turnId, outcome, scope, at }`, never text), and sends one `attachment_read` frame per read recorded during a live turn to connections that declared the flag. Nothing of either reaches a provider. The SDK adds `ATTACHMENT_READS_CAPABILITY`, `AttachmentReadEntry`, `SessionAttachmentReadsResponse`, `ServerAttachmentRead` and their schemas; the React client accepts the new frame without declaring the flag.
12 changes: 12 additions & 0 deletions .changeset/composer-generic-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@schlessera/brain-ui-react": minor
---

**Generic composer files (#3155, first slice).** When the host advertises `capabilities.composerFiles`, the composer offers an unrestricted **Files** source with no format allowlist. Desktop shows one Files… action and paste-or-drop guidance, without Photo library or Camera. Phones keep Photo library and Camera beside Files. Picked, pasted and dropped files that are not images upload unfiltered to `POST /api/drafts/:draftId/files`, and the host decides what each one is. Images keep their existing processing.

- **Chips say what is known.** A chip shows waiting, uploading, waiting for connection, `checking upload…` (no answer yet), upload failed, or the host's refusal (too large, no space). A stored PDF or text file reads `not read yet`. A file without a reader reads `no reader here` and can still be sent. A rejected track reads `not a usable track`.
- **Lost answers.** A lost answer is uploaded again with the same idempotency key, once automatically on reconnect or with **Upload again**. It never stores a second copy and is never reported as not stored.
- **Saving and sending.** A stored original becomes part of the draft. It is saved as a `fileIds` binding and reads as saved only once the host acknowledges that revision. Send holds while uploads or that save are pending, then sends `attachmentRefs` with the acknowledged `draftRef`.
- **Sent messages.** A sent message lists its originals by name, kind and size, with no claim about which contents were read.
- **Older hosts.** A host without `composerFiles` keeps the previous menu and the tab-only track queue.
- **API.** `ChatMessage.attachmentFiles?` is additive.
5 changes: 5 additions & 0 deletions .changeset/outgoing-snapshot-list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-ui-sdk": minor
"@schlessera/brain-ui-server": minor
---
Keep up to ten outgoing snapshots per chat instead of one (#3588). `Draft.snapshots` and `DraftSaveRequest.snapshots` carry each held, returned or unconfirmed send as `{ snapshotId, requestId, text, fileIds, state, createdAt }`. The save that creates one counts every live snapshot of the chat across its drafts, tabs and devices in the same transaction and refuses the eleventh with `409 DRAFT_OUTGOING_FULL`, before anything is sent; Cancel, an upload failure, dispatch and a recovery read edit a snapshot in place and never need a free slot. Accepting a message releases only its own snapshot, and only a returned snapshot can be deleted, which starts its files' seven-day clock. `SessionDraftLimits` advertises `maxOutgoingSnapshots`, a delete that would drop a held or unconfirmed snapshot is `409 DRAFT_OUTGOING_PENDING`, and the save body bound rises to 4,390,912 bytes. `Draft.outgoing` and the single-slot write keep working, and a slot saved earlier becomes the first snapshot.
1 change: 1 addition & 0 deletions api-report/ui-react.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ signatures (every public export and the types it is made of)
askUserExchanges?: AskUserExchange[];
attachments?: MessageAttachment[];
files?: SharedFileMeta[];
attachmentFiles?: AttachmentFile[];
attachmentCount?: number;
blocks?: MessageBlock[];
journal?: TurnJournalSummary;
Expand Down
172 changes: 170 additions & 2 deletions api-report/ui-sdk.txt

Large diffs are not rendered by default.

101 changes: 96 additions & 5 deletions docs/decisions/chat-attachments.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ linked in each section below. The
schemas, bounds and proof briefs; its six §13 recommendations were approved
at review on 2026-11-02. Admission, storage, ownership and cleanup are built
([what #3153 built](#what-3153-built)), and so is reading contents
([what #3154 built](#what-3154-built)); the composer is open work in epic
#3150.
([what #3154 built](#what-3154-built)). The composer's first slice is built
([what #3155 built so far](#what-3155-built-so-far)); the rest is open work in
epic #3150.

## Sources and one pipeline

Expand Down Expand Up @@ -115,8 +116,10 @@ The server side of admission, storage, ownership and cleanup, as the design's
operational database beside the drafts, and every mutation runs on the
draft store's write channel. A save, an acceptance and a sweep mark
therefore see one serialized state. Reference owners are `draft` and
`outgoing` (both keyed by the draft id; a draft has at most one outgoing
snapshot) and `message` (keyed by the session id). The design's compound
`outgoing` (both keyed by the draft id) and `message` (keyed by the session
id). #3153 shipped one outgoing slot per draft; #3588 replaced it with the
list described below, and the `outgoing` owner now covers every file of the
draft's snapshots. The design's compound
owner ids were simplified this way because a draft id may itself contain
`:`, and one reference per session protects a file as well as one per turn.
- **References on the wire.** A message names its originals in a new optional
Expand Down Expand Up @@ -149,6 +152,39 @@ The server side of admission, storage, ownership and cleanup, as the design's
- **Kept as before.** `/share`, `/track-upload`, staged-track references,
inline images and D52's tab-only legacy track path behave as they did.

## What #3588 built

The G1 A snapshot list
([ruling](https://github.com/schlessera/brain-kit/issues/3155#issuecomment-6591807939)),
replacing #3153's single slot:

- **A column, not a table.** The list is one JSON column on the draft row
(`outgoing_snapshots`, migration 079), so a save checks and writes it in the
draft's own immediate transaction. Migration 079 turns a saved slot into the
first snapshot, with its request id as its `snapshotId`. The ruling rejected
a send-intent table.
- **A chat is its session.** The capacity count sums the snapshots of every
live draft bound to the same `sessionId`, which is what one chat's tabs and
devices share; a draft with no session is a chat of its own. Only a save
that adds a `snapshotId` is counted against the ten.
- **The whole list on every save.** `snapshots` replaces the draft's list
under `If-Match`, as `PUT` replaces the rest of the draft. The host refuses
any change but an allowed state move or a held snapshot's files, and refuses
to drop anything but a `returned` snapshot. The save body bound rose to
4,390,912 bytes so ten snapshot texts fit at JSON's worst escapes.
- **Additive compatibility.** Retyping `outgoing` would break readers, so it
stays: `Draft.outgoing` shows the newest held or unconfirmed snapshot in the
old shape, and the old write creates or dispatches the snapshot of its
request, or removes the one it shows.
- **Nothing evicted by a send or a delete.** An acceptance that consumes a
draft still holding other snapshots keeps the row at the next revision with
an empty composer instead of a tombstone. A `DELETE` that would drop a held
or unconfirmed snapshot is `409 DRAFT_OUTGOING_PENDING`.
- **The composer keeps its envelope.** An upload's per-draft count now covers
the current revision and unbound uploads only. A snapshot's files are
checked against the per-message envelope when a save lists it, and stay in
the draft sub-limit and the pool.

## What #3154 built

The shared reader of the design's §7, with these concrete choices:
Expand Down Expand Up @@ -201,6 +237,16 @@ The shared reader of the design's §7, with these concrete choices:
provider. Session release and the sweep's forget remove a session's or a
file's rows. There is no derived cache, so nothing new is charged to the
pool.
- **Delivering reads (#3589).** The records reach the browser two ways. A
route, `GET /api/sessions/:id/attachment-reads`, returns a session's reads
when its view opens. A capability-gated `attachment_read` frame carries a
read recorded during a live turn. The frame is sent with `sendToCapable`,
which bypasses the dialogue recorder, so it never joins a transcript or a
replay. Both return only reads of files that a `message` reference of the
same session still names. They use the history replay's authorization,
which is a usable principal of this host's shared namespace; the route adds
no ownership rule that a replay does not have. A replay field was not used:
the native transcript, not the host, owns a replayed message.
- **Adding a reader.** A reader is concrete code, not a registry: add a rule
to `detectKind` (`packages/ui-server/src/attachments/detect.ts`) and a
`reader` value to `AttachmentReader` and migration 077's check; route it in
Expand All @@ -210,7 +256,52 @@ The shared reader of the design's §7, with these concrete choices:
parsing; then add an Odysseus fixture and its outcome tests. The composer's
Files picker has no `accept` filter, so it does not change.

## Rejected alternatives
## What #3155 built so far

The composer's Files source, its upload queue and the draft binding of
originals, on a host that advertises `composerFiles`:

- **Menus as ruled.** Desktop shows Files… and paste-or-drop guidance, and no
Photo library or Camera. A phone keeps both beside Files. The Files input
has no `accept`, and paste and drop feed the same pipeline. A host without
`composerFiles` keeps the old menu and D52's tab-only track queue.
- **One route for everything but images.** Every file that is not an image
goes to `POST /api/drafts/:draftId/files` as its raw bytes. The client
never routes by MIME type or extension; detection is the host's. Images
keep their existing frame processing. They do not upload an original yet,
so the image half of "a real file for every attachment" is still open.
- **A queue item keeps one key for its whole life.** The idempotency key is
minted once per item. A lost answer becomes `unknown`, never "not stored".
It is uploaded again with the same key once on reconnect, or through
**Upload again**. A `503` waits and retries with that key. Only a received
`4xx` says *not stored*. `fetch` reports no upload progress, so the chip
says `uploading…` rather than invent a percentage.
- **Stored originals are draft content.** A stored original joins
`ComposerDraft.files`, together with the draft id it was uploaded to (its
lineage). It is saved as `fileIds`, and it reads as saved only when an
acknowledged revision lists it. A file carried to another draft id, by a
rotation or a kept copy, cannot be bound there. It shows *not attached*,
blocks Send and is never listed in that id's save. The device copy of a
draft (#1014) keeps the references, so a restore cannot unbind them.
- **Send waits for the binding.** Send holds while an upload or the save
that binds the originals is pending, and then sends `attachmentRefs` with
the acknowledged `draftRef`. A refused or failed upload, or a detached
file, blocks Send with a reason. Unread contents, and kinds with no
reader, never block it. The hold uses the composer's existing tab-local
hold. The durable held snapshot, recovery bubbles and queue-full notice of
design brief rev 5 wait for the snapshot list (#3588).
- **Tracks follow the host.** On a host with `composerFiles` a picked track
is a generic original: the host detects it, the draft binds it and a reload
restores it, so it is not a tab-only staged track and the #1150 leave guard
no longer applies once its binding is acknowledged. D52's tab-only path
remains for a host without `composerFiles`. The mounted-app suites that
prove it (#1112, #1150, #1018) remove that capability from the real host's
hello so they keep proving it. The drop-and-reconnect suite (#1013) runs
the generic path against the real host.
- **Sent rows claim no read.** A sent message lists its originals by name,
kind and size. The read records are not delivered to clients yet (#3589),
so a row shows neither *read* nor *not read yet*.


The rejected options were offered in the rulings above:

Expand Down
4 changes: 3 additions & 1 deletion docs/http-api-coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fake backends and injected transports keep the checks keyless.

Each ordinary row runs the named `mounted supported handler: METHOD PATH` test
in [http-supported-mounts.test.ts](../packages/ui-server/tests/http-supported-mounts.test.ts)
(`checkHandler`, `packages/ui-server/tests/http-supported-mounts.test.ts:180-199`).
(`checkHandler`, `packages/ui-server/tests/http-supported-mounts.test.ts:181-200`).
The explicit [lifetime audit](../packages/ui-server/tests/helpers/http-mount-lifetimes.ts)
permits a bounded group of immutable readers to share startup, with a new owner
per case. Principal enumeration, activity ownership, CLI dispatch, caches,
Expand Down Expand Up @@ -125,6 +125,7 @@ row's real mounting check. They do not establish mounting by themselves.
| `GET /api/sessions/:sessionId/turns/:turnId/journal/:sequence/:side` | `mounted supported handler: GET /api/sessions/:sessionId/turns/:turnId/journal/:sequence/:side` | J |
| `GET /api/journal/configuration-coverage` | `mounted supported handler: GET /api/journal/configuration-coverage` | J |
| `GET /api/sessions/:id/safety` | `mounted supported handler: GET /api/sessions/:id/safety` | S |
| `GET /api/sessions/:id/attachment-reads` | `mounted supported handler: GET /api/sessions/:id/attachment-reads` | X |
| `GET /api/sessions/:id/recovery` | `mounted supported handler: GET /api/sessions/:id/recovery` | S |
| `POST /api/queue` | `mounted supported handler: POST /api/queue` | Q |
| `GET /api/schedules` | `mounted supported handler: GET /api/schedules` | K |
Expand Down Expand Up @@ -343,6 +344,7 @@ checks both nonempty priced and mixed-knownness fixtures
- `an upload retried after its bytes were swept stores them again under a usable id` ([source](../packages/ui-server/tests/drafts-store.test.ts)), (`an upload retried after its bytes were swept stores them again under a usable id`, `packages/ui-server/tests/drafts-store.test.ts:87-95`)
- `acceptance consumes only a matching, current, same-session revision` ([source](../packages/ui-server/tests/drafts-store.test.ts)), (`acceptance consumes only a matching, current, same-session revision`, `packages/ui-server/tests/drafts-store.test.ts:97-109`)
- `a revoked sender's acceptance consumes nothing` ([source](../packages/ui-server/tests/drafts-store.test.ts)), (`a revoked sender's acceptance consumes nothing`, `packages/ui-server/tests/drafts-store.test.ts:111-117`)
- `a client viewing a session gets that session's recorded reads, live and on request, and nothing else` ([source](../packages/ui-server/tests/attachment-reads-delivery.test.ts)), (`a client viewing a session gets that session's recorded reads, live and on request, and nothing else`, `packages/ui-server/tests/attachment-reads-delivery.test.ts:86-159`)

**J — Confirmed share intake.**

Expand Down
Loading
Loading