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
7 changes: 7 additions & 0 deletions .changeset/ended-question-recovery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@schlessera/brain-ui-sdk": minor
"@schlessera/brain-ui-server": minor
"@schlessera/brain-backend-claude": minor
"@schlessera/brain-ui-react": minor
---
A question whose turn ends before it is answered no longer loses what the user had entered, and a turn that hits the host's time limit now says so (#3356). The ended card keeps its draft and says the turn ended or timed out. Its Submit sends nothing to the ended request; it keeps the answer on the card as Not delivered. Send as message is the only way to send it, as one ordinary new chat message carrying the question and the answer, and it is offered once. The host's turn limit is unchanged: it is still a hard elapsed-time limit, and the time a question waits for the user counts against it. When it ends a turn, the cancelled `result` now carries `outcomeDetail: "host_timeout"` (`HOST_TIMEOUT_OUTCOME_DETAIL`) and the `status: cancelled` carries `detail: "Turn timed out"`, and the conversation shows a "Turn timed out" status. The Claude runtime's own stop notices, "No response requested." and "API Error: Request was aborted.", no longer replay as the agent's reply. They arrive as the new `SessionHistoryMessage.runtimeNotice` and are drawn as a short turn status. The same words written by the model or the user stay their text.
8 changes: 8 additions & 0 deletions api-report/ui-react.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ signatures (every public export and the types it is made of)
editable?: boolean;
mirror?: boolean;
focus?: boolean;
sentAsMessage?: boolean;
}
AnswerPayload (packages/ui-react/src/lib/answer-delivery/types.ts)
export type AnswerPayload = {
Expand Down Expand Up @@ -160,6 +161,7 @@ signatures (every public export and the types it is made of)
export interface AskUserExchange {
requestId: string;
terminal?: true;
endedBy?: "timeout";
turnId?: string;
questions: AskUserQuestion[];
list?: AskUserListSpec;
Expand Down Expand Up @@ -292,6 +294,8 @@ signatures (every public export and the types it is made of)
failure?: TurnFailure;
retryOfTurnId?: string;
failureLive?: boolean;
runtimeNotice?: TurnNotice;
runtimeNoticeLive?: boolean;
retry?: TurnRetry;
}
ChatPage (packages/ui-react/src/components/chat/chat-page.tsx)
Expand Down Expand Up @@ -889,6 +893,10 @@ signatures (every public export and the types it is made of)
view: TrackFileView;
props: TrackMapProps;
}
TurnNotice (packages/ui-react/src/stores/chat-state.ts)
export interface TurnNotice {
cause: "timeout" | "aborted" | "unspecified";
}
UIShellState (packages/ui-react/src/stores/shell-stores.ts)
export interface UIShellState {
readonly activeView: ActiveView;
Expand Down
30 changes: 30 additions & 0 deletions api-report/ui-sdk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export "." (./src/index.ts)
HANDOFF_MAX_CHARS
HANDOFF_MAX_REFERENCES
HANDOFF_REFERENCES_HEADING
HOST_TIMEOUT_OUTCOME_DETAIL
type HandoffRequest
type HygieneAction
type HygieneDiff
Expand Down Expand Up @@ -254,6 +255,7 @@ export "." (./src/index.ts)
type RenderFormat
type RenderRequest
type ResolutionEffect
type RuntimeNotice
SESSION_DRAFT_LIMITS
SESSION_NOT_FOUND
SESSION_RECOVERY_CAPABILITY
Expand Down Expand Up @@ -671,6 +673,7 @@ export "./client" (./src/client/index.ts)
HANDOFF_MAX_CHARS
HANDOFF_MAX_REFERENCES
HANDOFF_REFERENCES_HEADING
HOST_TIMEOUT_OUTCOME_DETAIL
type HandoffRequest
type HelloState
type HygieneAction
Expand Down Expand Up @@ -800,6 +803,7 @@ export "./client" (./src/client/index.ts)
type RequestImageMaskInput
type ResolutionEffect
type ResolveActionInput
type RuntimeNotice
SESSION_DRAFT_LIMITS
SESSION_NOT_FOUND
SESSION_RECOVERY_CAPABILITY
Expand Down Expand Up @@ -1508,6 +1512,7 @@ export "./protocol" (./src/protocol.ts)
HANDOFF_MAX_CHARS
HANDOFF_MAX_REFERENCES
HANDOFF_REFERENCES_HEADING
HOST_TIMEOUT_OUTCOME_DETAIL
type HandoffRequest
type HygieneAction
type HygieneDiff
Expand Down Expand Up @@ -1575,6 +1580,7 @@ export "./protocol" (./src/protocol.ts)
type RenderFormat
type RenderRequest
type ResolutionEffect
type RuntimeNotice
SESSION_DRAFT_LIMITS
SESSION_NOT_FOUND
SESSION_RECOVERY_CAPABILITY
Expand Down Expand Up @@ -2217,6 +2223,7 @@ export "./server" (./src/server/index.ts)
HANDOFF_MAX_CHARS
HANDOFF_MAX_REFERENCES
HANDOFF_REFERENCES_HEADING
HOST_TIMEOUT_OUTCOME_DETAIL
type HandoffRequest
type HistoricalItem
type HistoricalResultRef
Expand Down Expand Up @@ -2361,6 +2368,7 @@ export "./server" (./src/server/index.ts)
type ResolvedBackendModule
type ReverseGeocodeConfig
type ReverseGeocodeResult
type RuntimeNotice
SESSION_DRAFT_LIMITS
SESSION_NOT_FOUND
SESSION_RECOVERY_CAPABILITY
Expand Down Expand Up @@ -6994,6 +7002,8 @@ signatures (every public export and the types it is made of)
const HANDOFF_MAX_REFERENCES: 8;
HANDOFF_REFERENCES_HEADING (packages/ui-sdk/src/protocol.ts)
const HANDOFF_REFERENCES_HEADING: "References:";
HOST_TIMEOUT_OUTCOME_DETAIL (packages/ui-sdk/src/protocol.ts)
const HOST_TIMEOUT_OUTCOME_DETAIL: "host_timeout";
HandoffRequest (packages/ui-sdk/src/protocol.ts)
export interface HandoffRequest {
handoffId: string;
Expand Down Expand Up @@ -8431,6 +8441,11 @@ signatures (every public export and the types it is made of)
request: Request;
url: URL;
}
RuntimeNotice (packages/ui-sdk/src/protocol.ts)
export interface RuntimeNotice {
cause: "aborted" | "unspecified";
message: string;
}
SESSION_DRAFT_LIMITS (packages/ui-sdk/src/protocol.ts)
const SESSION_DRAFT_LIMITS: Readonly<SessionDraftLimits>;
SESSION_NOT_FOUND (packages/ui-sdk/src/protocol.ts)
Expand Down Expand Up @@ -10285,6 +10300,7 @@ signatures (every public export and the types it is made of)
effectiveThinkingLevel?: ThinkingLevel;
localAnswer?: LocalAnswer;
failure?: TurnFailure;
runtimeNotice?: RuntimeNotice;
retryOfTurnId?: string;
turnId?: string;
journal?: import("./turn-journal.js").TurnJournalSummary;
Expand Down Expand Up @@ -17543,6 +17559,13 @@ signatures (every public export and the types it is made of)
assistant: "assistant";
user: "user";
}>;
runtimeNotice: z.ZodCatch<z.ZodOptional<z.ZodObject<{
cause: z.ZodEnum<{
aborted: "aborted";
unspecified: "unspecified";
}>;
message: z.ZodString;
}, z.core.$loose>>>;
source: z.ZodCatch<z.ZodOptional<z.ZodEnum<{
"voice-context": "voice-context";
"voice-conversation": "voice-conversation";
Expand Down Expand Up @@ -19969,6 +19992,13 @@ signatures (every public export and the types it is made of)
assistant: "assistant";
user: "user";
}>;
runtimeNotice: z.ZodCatch<z.ZodOptional<z.ZodObject<{
cause: z.ZodEnum<{
aborted: "aborted";
unspecified: "unspecified";
}>;
message: z.ZodString;
}, z.core.$loose>>>;
source: z.ZodCatch<z.ZodOptional<z.ZodEnum<{
"voice-context": "voice-context";
"voice-conversation": "voice-conversation";
Expand Down
76 changes: 74 additions & 2 deletions docs/decisions/answer-delivery.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ manufacture an identity, and it was not needed.
## One card per request

The store updates a request it already holds and never appends it again
(`addExchange`, `packages/ui-react/src/stores/chat-state.ts:270-301`). A
(`addExchange`, `packages/ui-react/src/stores/chat-state.ts:289-320`). A
settled card stays settled, so a late or replayed frame cannot revive a
dismissed or answered question. A pending card keeps its payload and the
exchange object it is keyed by, so a draft in progress survives a re-send.
Expand Down Expand Up @@ -106,7 +106,7 @@ capability flag is what peers check, because a revision number alone was
ruled not to establish receipt support.

Outcomes are remembered in memory for 24 hours, at most 1,024 of them
(`ASK_OUTCOME_TTL_MS`, `packages/ui-server/src/ws/turns.ts:374`). That is the
(`ASK_OUTCOME_TTL_MS`, `packages/ui-server/src/ws/turns.ts:381`). That is the
client's maximum replay age, so any answer a client may still replay finds
its outcome. Persisting outcomes would not help after a restart: the
requests themselves are gone then, and an answer for them must stop, not
Expand Down Expand Up @@ -203,6 +203,78 @@ abandoned and retried through the normal backoff (`private abandon`,
`ws-client.ts:492`). This adds no new timeout to a question. The host's turn
deadline stays the only limit on an ask.

## A question whose turn ended (#3356)

The maintainer settled three choices on #3356 on 2026-11-02. This section
records how they were applied and does not reopen them.

**The turn limit stays a hard elapsed-time limit.** A pending question does
not pause, restart or extend the host's turn deadline, and the time a
question waits for the user counts against it. Configured values and every
other authorization, resource and worker guard are unchanged. The reason is
resource lifetime: a turn holds a worker, a concurrency slot and its relay
for as long as it runs, so a question that kept a turn alive would keep all
of that open for as long as the user stays away. A user who returns late
recovers through an explicit Send as message instead. The timer still
drains pending questions when it fires (`const timeoutHandle = setTimeout`,
`packages/ui-server/src/ws/run-session.ts:388-403`), and a later answer
still gets `closed`/`ended`.

**The timeout is said, not inferred.** The timer itself records the turn it
ended, and the bridge stamps that turn's own cancelled terminal frames
(`if (turn.timedOutTurnId === turnId`,
`packages/ui-server/src/ws/bridge.ts:219-222`): `detail: "Turn timed out"`
on `status: cancelled`, and `outcomeDetail: "host_timeout"` on the
cancelled `result`. A cancel, a revoked principal or a journal or egress
abort leaves no such mark, even though each also aborts the turn's signal.
The client draws a turn status from it, announced once when it arrives live.

**An ended card keeps its draft, and it leaves only by Send as message.**
Before this, the terminal frame replaced an unanswered card with a dismissed
stub, and its draft went with the controls. Now the card stays the editable
question under a prompt that says the turn ended or timed out
(`const [endedDismissed`,
`packages/ui-react/src/components/chat/message-bubble.tsx:608-626`). Its
Submit sends no frame to the ended request. It records the answer locally as
a `closed`/`ended` delivery, so the card shows the shipped Not delivered
footer with Copy answer and Send as message (R1). Send as message is the only
path that sends anything. It sends an ordinary new chat message, quoting the
question and the answer the way a reask does, through the composer's normal
admission for the session on screen. It is offered once: the action goes as
it is used, and focus stays on the card's outcome
(`case "sendAsMessage": {`,
`packages/ui-react/src/components/chat/answer-delivery-status.tsx:77-88`).
A local `closed` delivery also makes the queue ignore any later submit for
that request, so nothing can mark the old request accepted. An unsubmitted
draft lives only in the page, so a reload loses it, and nothing ever resends
one automatically. A submitted answer that was queued or unconfirmed when
the turn ended follows the existing receipts unchanged.

**Runtime stop notices are statuses.** When Claude Code resumes a session
whose turn was interrupted, it writes a reply of its own under its
`<synthetic>` model: `No response requested.`, or `API Error: Request was
aborted.` for an aborted request. These replayed as the agent's words. They
now replay as `SessionHistoryMessage.runtimeNotice` on the message they
ended, after any partial answer (`export function runtimeNotice`,
`packages/ui-backend-claude/src/history.ts:339-350`). Recognition needs
both the runtime's provenance and one of its two constant texts, read from
the installed CLI, so the same words from the model or the user stay theirs.
Only an aborted request names a cause, and neither notice says who stopped
the turn. A failure on the same message stays the one account of the stop.
Other synthetic texts, such as usage warnings, still replay as text.
`API Error: 499 Inference request cancelled` was already a classified
failure and is unchanged. Live, these messages arrive without text deltas,
so the stream never showed them.

Evidence: `packages/ui-server/tests/ws-ask-turn-timeout.test.ts` (the
original deadline with the wait counted, the drain, the closed late answer,
a cancel that is not a timeout, a timely answer and an answer that wins the
race, for every kind); `packages/ui-backend-claude/tests/history-api-failure.test.ts`;
`packages/ui-react/tests/render/ended-question.test.tsx`; and
`packages/ui-react/tests/ended-question-runtime.test.ts`, which runs real
Chrome against the real host for all four kinds, at 320px, at 200% text and
in both themes, using the keyboard.

## Rejected

- **Explicit Retry only (Recovery A).** It was rejected by ruling. It also
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/async-collaboration.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ permission and unwinds the turn. Already completed side effects are not undone
by an abort. Attempt staging and cleanup therefore need idempotent recovery,
with filesystem compensation outside SQLite transactions. Ordinary permission
parking still exists (`requestPermission: (req) => {`,
`packages/ui-server/src/ws/bridge.ts:362-455`); it is not a durable Action store.
`packages/ui-server/src/ws/bridge.ts:372-465`); it is not a durable Action store.

Resolution validates the stored effect again, checks current authority, records
one resolution and applies the guarded state transition in one transaction.
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/design-kit/follow-ups.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ does a replayed session show?
last call that parses is lifted to the answer's closing row, after the text
and the share menu. At its call position `groupParts` draws nothing
(`payload?.block.kind === "suggestions"`,
`packages/ui-react/src/components/chat/message-bubble.tsx:292`), and shares
`packages/ui-react/src/components/chat/message-bubble.tsx:293`), and shares
and prints leave it out. This also amends D37 §8's "chips while live,
`FeedbackRow` later": #41 closed as not planned, so the closing row is
suggestions or nothing.
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/design-kit/sessions-and-drafts.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ event deletes the whole set. Draft content never enters this record (§5).
null, no time is printed.
- **`lastActiveAt` and `lastTouched` are never read.** A newer
`lastActiveAt` can mean that a new turn started
(`export interface ChatSession`, `packages/ui-sdk/src/protocol.ts:1580-1610`),
(`export interface ChatSession`, `packages/ui-sdk/src/protocol.ts:1610-1640`),
and `lastTouched` is LRU bookkeeping for buffer eviction.

**Merging snapshots and live frames.**
Expand Down
6 changes: 3 additions & 3 deletions docs/decisions/governed-writable-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ still holds.
**Voice.** Ruling 1 makes voice `governed` too. Voice keeps its narrower
membership (`VOICE_ALLOWED_TOOLS`, `packages/ui-backend-claude/src/tool-policy.ts:120`):
no Bash, no raw `Write`/`Edit`, no archive, and approval returns false
(`const apply = createBrainApplication`, `packages/ui-server/src/ws/bridge.ts:666-671`).
(`const apply = createBrainApplication`, `packages/ui-server/src/ws/bridge.ts:676-681`).
A voice turn therefore writes only through curated capture and update, now
with a journal behind it. The writable mount gives voice no tool it lacked.
Pi still refuses voice turns.
Expand Down Expand Up @@ -1407,7 +1407,7 @@ from worker transcripts, and no extension of the observed-shell guarantee.

**Where the next request waited.** The bridge never awaits an observation: it
starts one per result and carries on
(`void host.journal?.toolEnded`, `packages/ui-server/src/ws/bridge.ts:226`).
(`void host.journal?.toolEnded`, `packages/ui-server/src/ws/bridge.ts:236`).
The wait is the observation's hold. `held` takes it synchronously, before it
queues the capture
(`function held<T>`, `packages/ui-server/src/brain/turn-journal.ts:232-253`),
Expand Down Expand Up @@ -1522,7 +1522,7 @@ unmet rather than relaxed.

**Why.** Every governed turn queues an automatic index refresh after it
(`host.governedTurns?.refresh(host.workerLock)`,
`packages/ui-server/src/ws/run-session.ts:939`). The refresh usually finishes
`packages/ui-server/src/ws/run-session.ts:940`). The refresh usually finishes
while the next turn runs, so that turn's finish observation found a rewritten
`brain.db` and copied a whole new version of it into retained objects, inside
the observation's worker hold. #2831 measured 36 versions of a ~120 MB index in
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/live-conversation.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ posture. A speech provider cannot reinterpret a visual grant, widen an
allowlist, or settle an approval because it generated an answer.

The host resolves pending exchanges when a turn ends
(`drainPendingForTurn`, `packages/ui-server/src/ws/turns.ts:704-738`). The
(`drainPendingForTurn`, `packages/ui-server/src/ws/turns.ts:711-745`). The
conversation integration must also reconcile client cards and audible claims;
that server method is not proof of a client receipt. Completion requires host
terminal state plus local playback drained or discarded. Provider generation
Expand Down
4 changes: 2 additions & 2 deletions docs/decisions/managed-worktrees.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ unknown; what happens next is in [hygiene and cleanup](#hygiene-and-cleanup).
Each governed or strict turn whose journal is recording opens one worker
generation, and every worker of that turn binds the generation's root-owned
directory whole at `/tmp/brain-worktrees`, inside the turn's own `/tmp`
(`// Managed worktrees (#2430): a journaled turn's workers bind one empty generation.`, `packages/ui-server/src/ws/run-session.ts:570-582`;
(`// Managed worktrees (#2430): a journaled turn's workers bind one empty generation.`, `packages/ui-server/src/ws/run-session.ts:571-583`;
`// Managed worktrees (#2430): the whole access generation`, `packages/ui-sdk/src/server/worker-launcher.ts:852-863`).
A granted worktree appears there as `/tmp/brain-worktrees/<worktree id>/` on the
worker's next path lookup; the worker cannot create entries beside it, and a
Expand Down Expand Up @@ -199,7 +199,7 @@ The host side is `createReferenceTools`
start, the host records its principal and what those workers bind: the public
view, the principal's private view and the turn's worker generation, if one
opened
(`// Reference tools (#2432): the turn's workers bind the principal's source`, `packages/ui-server/src/ws/run-session.ts:583-589`).
(`// Reference tools (#2432): the turn's workers bind the principal's source`, `packages/ui-server/src/ws/run-session.ts:584-590`).
A call carries only a repository, a revision or a worktree identity. The bridge
adds the turn's own principal, and a call for a turn the host did not prepare,
or under another principal, refuses
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/session-handoff.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ its distinct retry treatment. Nothing archives, purges or automatically sends.
The notice's presentation and actions are (`StateRoomNotice`,
`packages/ui-react/src/components/chat/state-room-notice.tsx:22-100`); the host
keeps the measurement and first quiet event (`if (msg.type === "result") {`,
`packages/ui-server/src/ws/bridge.ts:282-292`).
`packages/ui-server/src/ws/bridge.ts:292-302`).

### Historical state directories remain untouched

Expand Down
Loading
Loading