Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a9bf56c
feat(ui-server): review a sync's incoming governance policy change in…
schlessera Nov 20, 2026
de628cb
feat(ui-server, ui-react): review a sync's incoming policy change; do…
schlessera Nov 20, 2026
2a991ee
fix(ui-server): keep the owner review helpers module-private (#4256)
schlessera Nov 20, 2026
6956cf5
fix(ui-server): drop an unused Apify settings import (#4256)
schlessera Nov 20, 2026
426177a
chore(ui-sdk): record ProtectedMaintenanceOutputError in the API repo…
schlessera Nov 20, 2026
f3320cf
fix(ui-server): review only an upstream policy blob, a first policy t…
schlessera Nov 20, 2026
9807cf4
test(ui-react): register the slide-panel DOM again on a repeated run …
schlessera Nov 20, 2026
16ebb52
fix(ui-sdk): the plain output publisher refuses tier A changes with t…
schlessera Nov 20, 2026
551f333
test(ui-server): read the journal from its own database; accept an un…
schlessera Nov 20, 2026
02d9447
fix(ui-server): read the upstream policy blob before the worker runs,…
schlessera Nov 20, 2026
34ecb7e
test(ui-server): MUTATION, reverted next commit: the boundary drops o…
schlessera Nov 20, 2026
bb3d16c
test(ui-server): restore the boundary's onPolicyChange forwarding (#4…
schlessera Nov 20, 2026
d751b95
fix(ui-server, ui-react): a paused sync shows as waiting; newer sync …
schlessera Nov 20, 2026
f92b99d
fix(ui-server): a scheduled sync verifies the upstream policy blob be…
schlessera Nov 20, 2026
c425cd8
fix(ui-server, ui-react): bound the upstream policy read; show the re…
schlessera Nov 20, 2026
d197e33
fix(ui-server): name the right next step for every refusal (review of…
schlessera Nov 20, 2026
cbf4821
fix(ui-server): truthful sync review rationale and reports; relay ref…
schlessera Nov 20, 2026
0f091ba
fix(ui-server): name the right refusals and launch class (review of #…
schlessera Nov 20, 2026
bf77441
fix(ui-server): record the real cause of a refused sync review; every…
schlessera Nov 20, 2026
8f3bbd6
fix(ui-server): record a sync policy read failure by its cause; nativ…
schlessera Nov 20, 2026
c1eebc4
test(ui-server): the edit-path fixture takes the upstream note before…
schlessera Nov 20, 2026
7c5eda5
Merge remote-tracking branch 'origin/main' into feat/4256-sync-policy…
schlessera Nov 20, 2026
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/4256-sync-policy-review.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@schlessera/brain-ui-server": minor
"@schlessera/brain-ui-react": minor
"@schlessera/brain-ui-sdk": patch
---

A hosted sync whose pull changes `context/policies/governance.md` no longer fails every time until the upstream commit is reverted (#4256). It publishes nothing and opens a review of the incoming policy, which the owner approves or declines in the sync panel. Approving writes exactly the incoming bytes through the existing policy writer, and the next sync completes. Declining writes nothing. `POST /api/brain/sync` sends a new `policy_review` frame and ends with `reason: "policy_review"`, and `POST /api/brain/sync/policy/:turnId/:requestId` takes the owner's `{ approve }`. A scheduled sync opens no review and names the waiting change. Any other refused tier A change keeps its refusal, and the message now says to revert the upstream commit, or, for a policy file, to change the policy in chat.
1 change: 1 addition & 0 deletions api-report/ui-sdk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,7 @@ export "./internal" (./src/internal.ts)
PROVIDER_RELAY_KEYS_NAME
PROVIDER_RELAY_SOCKET_NAME
type PreparedWorkerOutput
ProtectedMaintenanceOutputError
type ProviderRelay
type ProviderRelayOptions
type ProviderRelayReceipt
Expand Down
25 changes: 25 additions & 0 deletions docs/decisions/governed-writable-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,31 @@ Publication also refuses deletion of a tier A ancestor directory, including an
empty `context` or `.git` whose protected descendants are currently absent.
This host-side check applies before any changed output is installed; worker
namespace mount points alone do not constrain the host publisher.

> **2026-11-20 — An incoming policy change from a sync is reviewed by the owner
> ([#4256](https://github.com/schlessera/brain-kit/issues/4256), maintainer ruling option 1).**
> The policy file is versioned host input, so a pull is where a policy change
> arrives. The refusal above still holds: a hosted sync's worker output never
> publishes a tier A change. When the only refused paths are
> `context/policies/governance.md` and the `context/policies` directory a first
> policy creates with it, on a sync with a remote, the host compares the stage's
> bytes with the upstream commit's own policy blob. The host transport reads that
> blob after the integrity check and the fetch, before the sync's worker runs,
> with replace objects disabled. Only equal bytes are reviewable, so worker output
> is never a policy source. The host then publishes nothing and opens a host-owned
> review through the existing policy proposals, the only policy writer, as
> Settings › Apify does (`createOwnerPolicyReviews`,
> `packages/ui-server/src/brain/owner-policy-reviews.ts`). A newer sync's review
> replaces the owner's unanswered one. Only the owner whose UI sync opened it can
> answer, and only an approval writes, in a `user` journal window. The next sync
> then merges the identical change cleanly. A scheduled sync opens no review and
> names the waiting change. Any other tier A change, a merged policy that differs
> from upstream's, or a sync without a remote keeps the refusal, with next-step
> text. No agent runtime, worker or autonomous turn proposes or answers these
> reviews, and the rationale shown is fixed host text. A Settings control for
> `outward.github.repositories` was not taken: chat's `propose_policy_change`
> already edits it.

Within one server process, maintenance clients serialize preparation through
publication per canonical brain. Even readers produce SQLite projections or
Git attribute objects in their private outputs; concurrent copies of that
Expand Down
39 changes: 30 additions & 9 deletions docs/http-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ compatibility guarantee. Authentication requirements are a separate property.
A public liveness probe can be supported; an authenticated settings route can
be internal.

The inventory includes the additive Queue intake, poke, scheduled-task, session-draft, composer-file, session-recovery, attachment-read, interactive HTML preview, saved-audio transcription, human-started hygiene-review, governance-event, roadblock-report, reference-grant, Apify-state, Apify-policy, retained-journal/user-revert, untrusted-mark, chat-deletion, individual safety-review, safety-recording recovery, GitHub detail-page, live-persona and markup-upload and human trust Settings routes (whose `/api/settings/voice` also carries the live-service default) mounted by `createApp`: 195 unique declared
The inventory includes the additive Queue intake, poke, scheduled-task, session-draft, composer-file, session-recovery, attachment-read, interactive HTML preview, saved-audio transcription, human-started hygiene-review, governance-event, roadblock-report, reference-grant, Apify-state, Apify-policy, retained-journal/user-revert, untrusted-mark, chat-deletion, individual safety-review, safety-recording recovery, GitHub detail-page, live-persona and markup-upload, human trust Settings and sync policy-review routes (whose `/api/settings/voice` also carries the live-service default) mounted by `createApp`: 196 unique declared
method/path pairs, plus the conditional SPA fallback. It describes the current
implementation, including limitations, rather than a proposed redesign.
Unknown response fields must be tolerated. There is no HTTP API revision
Expand Down Expand Up @@ -219,6 +219,7 @@ client code has a gap. Source owners are listed after the table.
| POST | `/api/apify/account` | I | Confirm the token's changed Apify account | Settings UI (#3159); live human owners only. Starts a new authority generation; accepts no token. |
| POST | `/api/apify/policy` | I | Propose one Apify setting through the policy-change review | Settings UI (#3163); live human owners only. `{ change, base_hash }` names exactly one of `enabled`, `discovery`, `actors` or `remove_grant` and the policy version it changes. Returns `{ turn_id, request_id, review }` with a pending `PolicyChangeReview` of the complete proposed `governance.md`; writes nothing. 409 when the policy changed since it was read; 422 when the file cannot be rewritten exactly. |
| POST | `/api/apify/policy/:turnId/:requestId` | I | Answer that exact review | Settings UI (#3163); only the proposing owner. `{ approve }`; an approval lets the existing policy writer publish it inside a user journal window. A repeated or late answer returns the recorded receipt and never writes again; a lost answer is reconciled through `GET /api/policy-proposals/:turnId/:requestId`. |
| POST | `/api/brain/sync/policy/:turnId/:requestId` | I | Answer a sync's incoming policy review | Sync panel (#4256); only the owner whose sync opened it. `{ approve }`; an approval lets the existing policy writer publish the incoming bytes inside a user journal window, and the owner syncs again. A repeated or late answer returns the recorded receipt and never writes again; a review of another family is never read here. |
| POST | `/share-target` | S | Explain missing service worker without reading body | SDK share-target and custom PWA shells; preserve ShareIntakeResult and body-unread fallback. |
| GET | `/ws` | S | Authenticate and admit WebSocket upgrade | SDK BrainUiClient; supported HTTP upgrade boundary, followed by the existing wire contract. |
| GET | `/*` (conditional) | I | Serve configured SPA deep links | Custom shell with `staticRoot`; deployment asset transport, not an independent JSON API. |
Expand All @@ -228,7 +229,7 @@ Authentication factories live in [auth.ts](../packages/ui-server/src/middleware/
[passkeys.ts](../packages/ui-server/src/middleware/passkeys.ts) and
[principals.ts](../packages/ui-server/src/middleware/principals.ts).
[app.ts](../packages/ui-server/src/app.ts) owns prefixing and middleware order.
All 195 declared endpoints are mounted regardless of backend, renderer or
All 196 declared endpoints are mounted regardless of backend, renderer or
speech-provider availability: unavailable capabilities return the responses
below rather than removing their handlers. Only static serving is conditional.

Expand Down Expand Up @@ -627,7 +628,12 @@ concurrent attempts get 409 `{ error, heldMs }` before SSE starts, where
the error text names it in seconds. The route invokes
`brain sync --human`. Disconnecting the reader stops delivery but **does not
cancel sync or release its reservation**; output continues draining until the
child exits.
child exits. Successful sync attempts voice keyterm rebuild; a rebuild failure
is progress text and does not turn successful sync into failure. A degraded
rebuild (no usable core peer, or an index core cannot read) is reported as
progress text and not cached. A canonical
root-resolution failure before admission can use the common 500. No idempotency
key or SSE resumption promise exists.

**Bounded start (additive, #4257).** Everything between admission and the
sync's first worker starting (the CLI version probe, the writer gate, the
Expand All @@ -642,12 +648,27 @@ kind and origin `cron`, `jobName: "ui-sync"`, attributed to the requesting
principal) whose terminal outcome carries the exit status and the last
non-empty output lines, with the combined output tail as its `job_output`
event, so a result survives a disconnected reader. A failure also logs
`ui sync failed` with the same text on the `brain` logger. Successful sync attempts voice keyterm rebuild; a rebuild failure
is progress text and does not turn successful sync into failure. A degraded
rebuild (no usable core peer, or an index core cannot read) is reported as
progress text and not cached. A canonical
root-resolution failure before admission can use the common 500. No idempotency
key or SSE resumption promise exists.
`ui sync failed` with the same text on the `brain` logger.

**Incoming policy change (additive, #4256).** On a hosted install, a pull
whose only tier A change is `context/policies/governance.md` publishes
nothing. When the requesting principal is a current owner, the stream sends
`{ type: "policy_review", turn_id, request_id, review }`, where `review` is the
same `PolicyChangeReview` a chat policy card shows (base hash, frontmatter
diff, changed sections, body diff, and a fixed host rationale saying the
brain's remote has this version at the named upstream commit), and ends with `{ type: "done", success: false, reason:
"policy_review", text }`. The owner answers it through
`POST /api/brain/sync/policy/:turnId/:requestId`. Approval writes exactly the
incoming bytes through the existing policy writer (journal actor `user`, class
`policy`, a `policy_change` governance event); the next admitted turn reads
it, and the next sync completes. Decline writes nothing, and the next sync
opens the review again. An incoming policy that is not UTF-8, exceeds 1 MiB or does not validate
opens no review: the sync fails, and its text names the next step. A scheduled sync opens no review; it fails naming the waiting change.
Any other refused tier A change keeps its refusal, and its text says what to do
next: revert the upstream commit, or remove a change the brain itself made
(and, under `context/policies/`, change the policy in chat with
`propose_policy_change`). A refused sync's human report is replaced by that
reason, since nothing was published or pushed.

## Sessions and execution records

Expand Down
16 changes: 16 additions & 0 deletions docs/integration-contract/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,22 @@ Three additions ([HTTP reference](../http-api.md#corpus-queries-capture-and-sync
terminal outcome carries the exit status and last output lines, and its
`job_output` event carries the output tail.

<a id="sync-incoming-policy-review-additive-4256"></a>

### A sync's incoming policy change is reviewed, not failed (additive, #4256)

`POST /api/brain/sync` may send one new frame,
`{ type: "policy_review", turn_id, request_id, review: PolicyChangeReview }`,
followed by `{ type: "done", success: false, reason: "policy_review", text }`,
when a hosted pull's only tier A change is `context/policies/governance.md`
([HTTP reference](../http-api.md#corpus-queries-capture-and-sync)). Nothing is
published. The internal `POST /api/brain/sync/policy/:turnId/:requestId`
takes `{ approve }` from the owner whose sync opened the review and returns the
recorded `PolicyChangeReview`; only an approval writes, through the existing
policy writer. `brainSync()` keeps mapping the terminal frame to
`{ success: false, message }`, and clients that ignore unknown frame types are
unaffected. No agent runtime proposes or answers these reviews.

<a id="typed-status-software-identity-additive-598"></a>

### Typed status software identity (additive, #598)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useState, useEffect, useRef } from "react";
import { SlidePanel } from "../layout/slide-panel.js";
import { linkifyPaths } from "../chat/brain-markdown.js";
import { StreamingOutput, type StreamState } from "./streaming-output.js";
import { isSyncPolicyReviewFrame, SyncPolicyReview, type SyncPolicyReviewFrame } from "./sync-policy-review.js";

/**
* The container (S6) for a streamed backend job: the request, the SSE reader
Expand All @@ -26,6 +27,8 @@ export function StreamingPanel({
const root = useBrainUiRoot();
const [state, setState] = useState<StreamState>("idle");
const [lines, setLines] = useState<string[]>([]);
/** A sync's incoming policy review (#4256), shown below the log once the stream offers one. */
const [policyReview, setPolicyReview] = useState<SyncPolicyReviewFrame | null>(null);
const scrollRef = useRef<HTMLDivElement>(null);
const controllerRef = useRef<AbortController | null>(null);

Expand All @@ -34,6 +37,7 @@ export function StreamingPanel({

setState("running");
setLines([]);
setPolicyReview(null);

let disposed = false;
let reader: ReadableStreamDefaultReader<Uint8Array> | undefined;
Expand Down Expand Up @@ -85,12 +89,16 @@ export function StreamingPanel({

try {
const data = JSON.parse(dataLine.slice(6));
if (isSyncPolicyReviewFrame(data)) {
setPolicyReview({ turn_id: data.turn_id, request_id: data.request_id, review: data.review });
continue;
}
if (data.text !== undefined) {
setLines((l) => [...l, data.text]);
}
if (data.type === "done") {
finished = true;
setState(data.success ? "success" : "error");
setState(data.success ? "success" : data.reason === "policy_review" ? "waiting" : "error");
}
} catch {}
}
Expand Down Expand Up @@ -149,6 +157,7 @@ export function StreamingPanel({
setLines((lines) => [...lines, "Cancelled."]);
}}
onClose={onClose}
after={policyReview && <SyncPolicyReview key={`${policyReview.turn_id}:${policyReview.request_id}`} frame={policyReview} />}
/>
</SlidePanel>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ import type { Tone } from "@schlessera/brain-ui-kit";
* failure or a cancellation — and the row is a polite live region so a
* screen reader hears "Complete" once, not every line.
*/
export type StreamState = "idle" | "running" | "success" | "error" | "cancelled";
/** `waiting`: the job paused for an owner answer (a sync's incoming policy review, #4256), not a failure. */
export type StreamState = "idle" | "running" | "success" | "error" | "cancelled" | "waiting";

const STATUS: Record<StreamState, { tone: Tone; pulse: boolean; text: string }> = {
idle: { tone: "neutral", pulse: false, text: "Ready" },
running: { tone: "amber", pulse: true, text: "Running..." },
success: { tone: "teal", pulse: false, text: "Complete" },
error: { tone: "red", pulse: false, text: "Failed" },
cancelled: { tone: "red", pulse: false, text: "Cancelled" },
waiting: { tone: "amber", pulse: false, text: "Waiting for your policy review" },
};

interface StreamingOutputProps {
Expand All @@ -33,6 +35,8 @@ interface StreamingOutputProps {
onClose: () => void;
/** Wire to the scroll anchor the container keeps in view. */
anchor?: ReactNode;
/** Shown after the log, inside the same scrolling area, above the footer (a sync's policy review, #4256). */
after?: ReactNode;
}

export function StreamingOutput(p: StreamingOutputProps) {
Expand All @@ -52,6 +56,7 @@ export function StreamingOutput(p: StreamingOutputProps) {
</div>
))}
{running && p.lines.length === 0 && <div className="text-muted-foreground/50">Starting...</div>}
{p.after && <div className="font-[family-name:var(--font-sans)] text-sm">{p.after}</div>}
{p.anchor}
</div>

Expand Down
Loading
Loading