Skip to content
Python

Mode notice waits for the server-confirmed mode; Auto-approve copy pass

Devika Verma97eca9c8ba90
diff --git a/surfaces/gui/src/App.tsx b/surfaces/gui/src/App.tsx
index 46304fca..06f35b7d 100644
--- a/surfaces/gui/src/App.tsx
+++ b/surfaces/gui/src/App.tsx
@@ -59,7 +59,7 @@ import { Icon } from "./components/Icon";
import { Sidebar } from "./components/Sidebar";
import { ThinkingBlock, Transcript } from "./components/Transcript";
import { Composer } from "./components/Composer";
-import { modeNotice, type ModeMark } from "./modeNotice";
+import { modeNoticeStep, type ModeNoticeState } from "./modeNotice";
import { Markdown } from "./components/Markdown";
import { SearchModal } from "./components/SearchModal";
import { SessionIntro } from "./components/SessionIntro";
@@ -216,11 +216,16 @@ export function App() {
const [streaming, setStreamingState] = useState("");
// Ref mirror of `streaming`: the WS handler closure is built once per socket and can't read
// fresh state — the interrupted/error flush below needs the live buffer at event time.
- // Mode markers in the transcript: which session has already seen the full Auto-Approve
+ // Mode markers in the transcript: which session has already seen the full Auto-approve
// explanation, and what mode the transcript last recorded (so a switch can be told apart
- // from a re-render or a session change). See `modeNotice`.
- const autoApproveNoticeFor = useRef("");
- const lastModeMark = useRef<ModeMark>(null);
+ // from a re-render or a session change). See `modeNoticeStep`.
+ const modeNoticeState = useRef<ModeNoticeState>({ mark: null, bannerShownFor: "" });
+ // Which session the current `mode` value is CONFIRMED for. On a session switch, `mode`
+ // still holds the previous session's value until the server's `ready` event delivers the
+ // real one — announcing anything in that window posts the old session's banner into the
+ // new transcript (seen 2026-08-22: a fresh Ask-for-approval session opened with the
+ // Auto-approve banner, then a stray "Ask for approval is on." marker when `ready` landed).
+ const [modeConfirmedFor, setModeConfirmedFor] = useState("");
const streamingRef = useRef("");
const setStreaming = (value: string | ((s: string) => string)) => {
streamingRef.current = typeof value === "function" ? value(streamingRef.current) : value;
@@ -684,6 +689,9 @@ export function App() {
setConnected(true);
if (d.model) setModel(d.model);
if (d.mode) setMode(d.mode);
+ // Even when d.mode is absent (older servers), this is the best truth we'll get —
+ // unblock the mode-notice effect for this session either way.
+ setModeConfirmedFor(sessionId);
if (d.command_trust?.required) setWorkspaceTrustRequest(d.command_trust);
// Cowork: adopt the server-provisioned scratch dir (only when we don't already have one).
if (d.workspace) setWorkspace((cur) => cur || d.workspace);
@@ -1011,11 +1019,12 @@ export function App() {
}, [sessionId]);
useEffect(() => {
- const item = modeNotice(mode, sessionId, lastModeMark.current, autoApproveNoticeFor.current);
- lastModeMark.current = { session: sessionId, mode };
- if (mode === "auto-approve") autoApproveNoticeFor.current = sessionId;
+ // The step is a no-op while `mode` still belongs to the previous session (until `ready`
+ // confirms it) — see modeNoticeStep for why acting on the stale value misfires.
+ const { item, state } = modeNoticeStep(modeNoticeState.current, mode, sessionId, modeConfirmedFor);
+ modeNoticeState.current = state;
if (item) setItems((p) => [...p, item]);
- }, [mode, sessionId]);
+ }, [mode, sessionId, modeConfirmedFor]);
useEffect(() => {
if (atBottomRef.current) scrollToBottom();
}, [items, streaming]);
diff --git a/surfaces/gui/src/components/Composer.tsx b/surfaces/gui/src/components/Composer.tsx
index a8c0e225..5e5e166f 100644
--- a/surfaces/gui/src/components/Composer.tsx
+++ b/surfaces/gui/src/components/Composer.tsx
@@ -29,17 +29,18 @@ import {
type ModeOption = Option & { caution?: boolean; gated?: boolean };
// "auto" is the legacy wire value for Bypass approvals (server: Mode.BYPASS_APPROVALS).
-// Auto-Approve is `gated`: shown only when getSettings().auto_approve is true (the feature
-// flag, off by default). Copy (owner, 2026-08-12): two lines like every other entry —
-// "your session model" carries the who-judges fact inline; per-check cost surfaces in the
-// metering badge, not as picker text.
+// Auto-approve is `gated`: shown only when getSettings().auto_approve is true (the feature
+// flag, off by default). Copy (owner, 2026-08-22): imperative like the sibling entries;
+// "your session model" carries the who-judges fact inline; per-check cost is logged, not
+// picker text.
const PERMISSION_OPTIONS: ModeOption[] = [
{ value: "discuss", label: "Discuss", description: "Chat and explore — no edits or commands" },
{ value: "interactive", label: "Ask for approval", description: "Ask before edits and commands" },
{
value: "auto-approve",
- label: "Auto-Approve",
- description: "Your session model lets lower-risk actions through; anything it isn't sure about asks you",
+ label: "Auto-approve",
+ description:
+ "Let your session model classify actions and handle approvals, prompting you for anything it's unsure about",
gated: true,
},
{
@@ -50,7 +51,7 @@ const PERMISSION_OPTIONS: ModeOption[] = [
},
];
-/** The picker's label for a mode value ("auto-approve" -> "Auto-Approve"). Exported so the
+/** The picker's label for a mode value ("auto-approve" -> "Auto-approve"). Exported so the
* transcript's mode markers read the same names the user just chose from. */
export function modeLabel(value: string): string {
return PERMISSION_OPTIONS.find((o) => o.value === value)?.label || value;
@@ -107,8 +108,8 @@ interface Props {
// when" is one mental model. Absent handler = no toggle (e.g. Chat).
unattended?: boolean;
onUnattendedChange?: (on: boolean) => void;
- // Auto-Approve metering (§1.7): the "Auto-Approve · N checks" badge + mode-menu summary.
- // Absent/zero hides both; only the LIVE bucket surfaces here (shadow is a Settings concern).
+ // The pending-approval card rendered above the input (plan / work-items / team / tool /
+ // folder requests). Attended sessions only — Unattended parks the prompt in the Inbox.
approvalSlot?: ReactNode;
// Push text + attachments into the composer (e.g. a start-panel task card). The `nonce` makes
// repeated identical prefills re-apply; the user can still edit before sending.
diff --git a/surfaces/gui/src/components/SettingsView.tsx b/surfaces/gui/src/components/SettingsView.tsx
index b52d1a3e..a735e63f 100644
--- a/surfaces/gui/src/components/SettingsView.tsx
+++ b/surfaces/gui/src/components/SettingsView.tsx
@@ -869,7 +869,7 @@ function AutoApproveCard() {
if (on === null) return null;
return (
<div className={CARD + " p-4 mb-4"} data-testid="auto-approve-card">
- <div className={FIELD_LABEL}>Auto-Approve (experimental)</div>
+ <div className={FIELD_LABEL}>Auto-approve (experimental)</div>
<label className="flex items-start gap-3 py-2">
<input
type="checkbox"
@@ -879,9 +879,9 @@ function AutoApproveCard() {
onChange={(e) => saveOn(e.target.checked)}
/>
<span>
- <span className="block text-[13px] text-ink">Enable Auto-Approve mode</span>
+ <span className="block text-[13px] text-ink">Enable Auto-approve mode</span>
<span className="block text-[12px] text-muted">
- Adds an <em>Auto-Approve</em> option to the mode picker. In that mode, your session
+ Adds an <em>Auto-approve</em> option to the mode picker. In that mode, your session
model reviews each action that would normally need approval and clears the routine
ones; anything doubtful still asks you. It can never allow something the rules
block. One extra model call per check, billed to your usage.
diff --git a/surfaces/gui/src/components/Transcript.test.tsx b/surfaces/gui/src/components/Transcript.test.tsx
index c477de54..dae63b02 100644
--- a/surfaces/gui/src/components/Transcript.test.tsx
+++ b/surfaces/gui/src/components/Transcript.test.tsx
@@ -326,7 +326,7 @@ describe("mode notice", () => {
{
kind: "notice",
tone: "info",
- title: "Auto-Approve is on.",
+ title: "Auto-approve is on.",
text: "First paragraph about what it does.\n\nSecond paragraph about what it can't tell.",
},
];
@@ -334,7 +334,7 @@ describe("mode notice", () => {
it("renders the title and one paragraph per blank-line break", () => {
render(<Transcript items={BANNER} running={false} onApprove={() => {}} />);
const block = screen.getByTestId("mode-notice");
- expect(block.textContent).toContain("Auto-Approve is on.");
+ expect(block.textContent).toContain("Auto-approve is on.");
expect(block.querySelectorAll("p")).toHaveLength(2);
// Prose layout, not the centred one-liner used for "Context compacted".
expect(block.className).toContain("notice-block");
diff --git a/surfaces/gui/src/modeNotice.test.ts b/surfaces/gui/src/modeNotice.test.ts
index f0b72f31..a3cc2d31 100644
--- a/surfaces/gui/src/modeNotice.test.ts
+++ b/surfaces/gui/src/modeNotice.test.ts
@@ -1,5 +1,11 @@
import { describe, expect, it } from "vitest";
-import { AUTO_APPROVE_NOTICE, modeNotice, type ModeMark } from "./modeNotice";
+import {
+ AUTO_APPROVE_NOTICE,
+ modeNotice,
+ modeNoticeStep,
+ type ModeMark,
+ type ModeNoticeState,
+} from "./modeNotice";
// The transcript has to answer "which mode was this exchange under?" after the fact. The
// full explanation is a once-per-session thing; the markers are what make the log readable.
@@ -10,7 +16,7 @@ describe("modeNotice", () => {
it("explains Auto-Approve in full the first time a session is in it", () => {
const item = modeNotice("auto-approve", S, null, "");
expect(item).not.toBeNull();
- expect(item).toMatchObject({ kind: "notice", tone: "info", title: "Auto-Approve is on." });
+ expect(item).toMatchObject({ kind: "notice", tone: "info", title: "Auto-approve is on." });
// The prose, not just the heading — the block layout keys off `title`.
expect((item as { text: string }).text).toBe(AUTO_APPROVE_NOTICE);
});
@@ -24,7 +30,7 @@ describe("modeNotice", () => {
it("marks a switch BACK to Auto-Approve without repeating the explanation", () => {
// The reported behaviour: leaving and returning left no trace at all.
const item = modeNotice("auto-approve", S, mark(S, "discuss"), S);
- expect(item).toMatchObject({ text: "Auto-Approve is on." });
+ expect(item).toMatchObject({ text: "Auto-approve is on." });
expect(item).not.toHaveProperty("title");
});
@@ -56,7 +62,16 @@ describe("modeNotice", () => {
it("explains again in a new session, since the first banner scrolled away with the old one", () => {
const item = modeNotice("auto-approve", "session-2", mark(S, "auto-approve"), S);
- expect(item).toMatchObject({ title: "Auto-Approve is on." });
+ expect(item).toMatchObject({ title: "Auto-approve is on." });
+ });
+
+ it("stays silent while the mode is still the previous session's (unconfirmed)", () => {
+ // On a session switch the app's mode state is stale until the server's `ready` event.
+ // Acting on it posted the OLD session's banner into a fresh transcript.
+ const item = modeNotice("auto-approve", "session-2", mark(S, "auto-approve"), S);
+ // The pure function alone can't tell stale from restored — that's modeNoticeStep's job;
+ // this pins that the raw call WOULD banner here, so the step's gate is load-bearing.
+ expect(item).toMatchObject({ title: "Auto-approve is on." });
});
it("never claims to detect prompt injection", () => {
@@ -68,3 +83,52 @@ describe("modeNotice", () => {
expect(AUTO_APPROVE_NOTICE).toContain("a false allow executes unchecked");
});
});
+
+// The step function is what the app actually drives: it owns the ordering rules the pure
+// function can't see — chiefly that a (mode, session) pair means nothing until the server's
+// `ready` event has confirmed the mode belongs to that session.
+describe("modeNoticeStep", () => {
+ const fresh: ModeNoticeState = { mark: null, bannerShownFor: "" };
+
+ // The reported bug, replayed event for event: an Auto-approve session, then "New
+ // session" (defaulting to Ask for approval). The old code showed the banner from the
+ // stale mode, then a stray "Ask for approval is on." marker when `ready` landed.
+ it("a new non-auto session shows neither the banner nor a marker", () => {
+ // Session 1 is confirmed in auto-approve; the banner shows there.
+ let r = modeNoticeStep(fresh, "auto-approve", "s1", "s1");
+ expect(r.item).toMatchObject({ title: "Auto-approve is on." });
+ // New session: sessionId flips first, mode still stale, ready not yet in. Silence.
+ r = modeNoticeStep(r.state, "auto-approve", "s2", "s1");
+ expect(r.item).toBeNull();
+ // `ready` confirms s2 is in interactive. Still silence — nothing changed, s2-wise.
+ r = modeNoticeStep(r.state, "interactive", "s2", "s2");
+ expect(r.item).toBeNull();
+ });
+
+ it("an unconfirmed pair records nothing — no fake 'switch' when the truth lands", () => {
+ // If the stale (auto-approve, s2) pair were recorded as s2's mode, ready's
+ // "interactive" would read as a mode change and print a marker at the transcript top.
+ let r = modeNoticeStep(fresh, "auto-approve", "s2", "s1");
+ expect(r.state).toEqual(fresh);
+ // And the banner must not be marked as "already shown" for s2 either — a session
+ // genuinely restored into auto-approve still deserves its banner (next test).
+ expect(r.state.bannerShownFor).toBe("");
+ });
+
+ it("a session RESTORED into auto-approve still gets the banner once confirmed", () => {
+ // Switch from an auto-approve session to another auto-approve session: the mode
+ // VALUE never changes, only the confirmation. The banner must still re-fire.
+ let r = modeNoticeStep(fresh, "auto-approve", "s1", "s1");
+ r = modeNoticeStep(r.state, "auto-approve", "s3", "s1"); // stale window
+ expect(r.item).toBeNull();
+ r = modeNoticeStep(r.state, "auto-approve", "s3", "s3"); // ready confirms
+ expect(r.item).toMatchObject({ title: "Auto-approve is on." });
+ });
+
+ it("an in-session switch still gets its one-line marker", () => {
+ let r = modeNoticeStep(fresh, "auto-approve", "s1", "s1");
+ r = modeNoticeStep(r.state, "interactive", "s1", "s1");
+ expect(r.item).toMatchObject({ text: "Ask for approval is on." });
+ expect(r.item).not.toHaveProperty("title");
+ });
+});
diff --git a/surfaces/gui/src/modeNotice.ts b/surfaces/gui/src/modeNotice.ts
index 58045c0f..4bf7adb0 100644
--- a/surfaces/gui/src/modeNotice.ts
+++ b/surfaces/gui/src/modeNotice.ts
@@ -12,8 +12,9 @@ import type { Item } from "./types";
// unhedged — where it can be wrong. It reduces interruptions, not risk, and the closing
// line has to leave that clear.
export const AUTO_APPROVE_NOTICE = [
- "Your session model lets routine actions through without asking; anything it isn't sure " +
- "about still comes to you — whatever the rules settle outright, it never sees.",
+ "Your session model classifies each action and lets the routine ones through without " +
+ "asking; anything it isn't sure about still comes to you — whatever the rules settle " +
+ "outright, it never sees.",
"It reduces interruptions from lower-risk actions, not the risk from what it can't tell: " +
"what a script will do, or whether an instruction came from you or from a web page or " +
"email. Shell commands aren't sandboxed — they reach anything you can. These are model " +
@@ -41,7 +42,7 @@ export function modeNotice(
return {
kind: "notice",
tone: "info",
- title: "Auto-Approve is on.",
+ title: "Auto-approve is on.",
text: AUTO_APPROVE_NOTICE,
};
}
@@ -53,3 +54,34 @@ export function modeNotice(
}
return null;
}
+
+/** What the caller carries between mode changes: the last recorded mark and which session
+ * has already seen the full banner. */
+export type ModeNoticeState = { mark: ModeMark; bannerShownFor: string };
+
+/**
+ * One observed (mode, session) pair → the item to append (or null) plus the next state.
+ *
+ * `modeConfirmedFor` is the session the current `mode` value is KNOWN to belong to — on a
+ * session switch, the app's mode state still holds the previous session's value until the
+ * server's `ready` event delivers the real one. Acting in that window posts the old
+ * session's banner into the new transcript, then a stray marker when the truth lands
+ * (seen 2026-08-22). So an unconfirmed pair is a no-op: nothing said, nothing recorded —
+ * recording the stale mode would also fake a "switch" once the real mode arrives.
+ */
+export function modeNoticeStep(
+ state: ModeNoticeState,
+ mode: string,
+ sessionId: string,
+ modeConfirmedFor: string,
+): { item: Item | null; state: ModeNoticeState } {
+ if (modeConfirmedFor !== sessionId) return { item: null, state };
+ const item = modeNotice(mode, sessionId, state.mark, state.bannerShownFor);
+ return {
+ item,
+ state: {
+ mark: { session: sessionId, mode },
+ bannerShownFor: mode === "auto-approve" ? sessionId : state.bannerShownFor,
+ },
+ };
+}