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
63 changes: 63 additions & 0 deletions apps/mobile/src/screens/session-execution-panel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,69 @@ test("renders active execution and mutable queued inbox work", () => {
expect(callbacks.onCancelInbox).toHaveBeenCalledWith("msg_queued");
});

test("agent-switch reminders do not become actionable steering cards", () => {
render(
<SessionExecutionPanel
active={false}
admissions={[]}
permissions={[]}
permissionReplyError={false}
projectedMessageIds={new Set()}
{...callbacks}
inbox={[
{
type: "synthetic",
id: "msg_mode",
sessionID: "ses_test",
time: { created: 1 },
delivery: "steer",
payload: { text: "<system-reminder>You are in Plan mode.</system-reminder>" },
},
]}
/>,
);
expect(screen.queryByText("STEERING")).toBeNull();
expect(screen.queryByRole("button", { name: "Queue next" })).toBeNull();
expect(screen.queryByRole("button", { name: "Cancel" })).toBeNull();
});

test("keeps a real steering prompt actionable alongside internal mode reminders", () => {
render(
<SessionExecutionPanel
active={false}
admissions={[]}
permissions={[]}
permissionReplyError={false}
projectedMessageIds={new Set()}
{...callbacks}
inbox={[
{
type: "synthetic",
id: "msg_mode",
sessionID: "ses_test",
time: { created: 1 },
delivery: "steer",
payload: { text: "Mode reminder" },
},
{
type: "user",
id: "msg_followup",
sessionID: "ses_test",
time: { created: 2 },
delivery: "steer",
payload: { text: "Please check the tests" },
},
]}
/>,
);
expect(screen.getAllByText("STEERING")).toHaveLength(1);
expect(screen.getByText("Please check the tests")).toBeOnTheScreen();
fireEvent.press(screen.getByRole("button", { name: "Queue next" }));
expect(callbacks.onQueueInbox).toHaveBeenLastCalledWith("msg_followup");
fireEvent.press(screen.getByRole("button", { name: "Cancel" }));
expect(callbacks.onCancelInbox).toHaveBeenLastCalledWith("msg_followup");
});

test("keeps unknown delivery visible until reconciliation finds the stable ID", () => {
const admission: PromptAdmission = {
durable: false,
Expand Down
7 changes: 5 additions & 2 deletions apps/mobile/src/screens/session-execution-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export function SessionExecutionPanel({
replyingPermissionId?: string | undefined;
}) {
const { height } = useWindowDimensions();
// Agent-mode reminders and other control inputs are server-owned inbox work,
// not user prompts that should offer steering or cancellation controls.
const promptInbox = inbox.filter((item) => item.type === "user");
const inboxIds = new Set(inbox.map((item) => item.id));
const localOverlays = admissions.filter(
(admission) =>
Expand All @@ -64,7 +67,7 @@ export function SessionExecutionPanel({
);
if (
!active &&
inbox.length === 0 &&
promptInbox.length === 0 &&
localOverlays.length === 0 &&
permissions.length === 0 &&
!formRequests
Expand Down Expand Up @@ -166,7 +169,7 @@ export function SessionExecutionPanel({
</View>
))}

{inbox.map((item) => (
{promptInbox.map((item) => (
<View key={item.id} style={styles.inboxCard}>
<View style={styles.inboxHeading}>
<Text dynamicTypeRamp={typeRamp.caption} style={styles.cardEyebrow}>
Expand Down
11 changes: 10 additions & 1 deletion apps/mobile/src/screens/session-transcript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,16 @@ export const SessionTranscriptRow = memo(function SessionTranscriptRow({
</View>
);
case "agent-switched":
return <Notice compact={!detailed} label="Agent changed" text={message.agent} />;
return (
<View style={styles.notice}>
<Text dynamicTypeRamp={typeRamp.control} style={styles.activitySummary}>
Agent changed to{" "}
<Text style={styles.activityLabel}>
{sanitizeTranscriptText(capitalize(message.agent), 256)}
</Text>
</Text>
</View>
);
case "model-switched":
return <Notice compact={!detailed} label="Model changed" text={message.model.id} />;
case "location-switched":
Expand Down
106 changes: 70 additions & 36 deletions apps/mobile/src/state/connection-event-query-bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,50 +340,84 @@ test("invalidates only the affected session inbox for inbox events", () => {
queryClient.clear();
});

test("projects permission requests immediately while scheduling REST reconciliation", () => {
const queryClient = new QueryClient();
const invalidate = jest.spyOn(queryClient, "invalidateQueries");
const bridge = new ConnectionEventQueryBridge(queryClient, "connection-1", (callback) =>
callback(),
);
const location = { directory: "/workspace" };
const key = openCodeQueryKeys.permissions("connection-1", location);
queryClient.setQueryData(key, { data: [], location });

bridge.apply({
created: 1,
data: {
action: "shell",
id: "per_test",
resources: ["redacted command"],
sessionID: "session-1",
},
id: "event-permission",
location,
type: "permission.asked",
});
test.each([true, false])(
"projects permission requests while scheduling REST reconciliation, existing cache: %s",
(cached) => {
const queryClient = new QueryClient();
const invalidate = jest.spyOn(queryClient, "invalidateQueries");
const bridge = new ConnectionEventQueryBridge(queryClient, "connection-1", (callback) =>
callback(),
);
const location = { directory: "/workspace" };
const key = openCodeQueryKeys.permissions("connection-1", location);
if (cached) queryClient.setQueryData(key, { data: [], location });

expect(queryClient.getQueryData(key)).toEqual({
data: [
{
bridge.apply({
created: 1,
data: {
action: "shell",
id: "per_test",
resources: ["redacted command"],
sessionID: "session-1",
},
],
location,
});
const query = queryClient.getQueryCache().find({ queryKey: key });
expect(query && invalidate.mock.calls[0]?.[0]?.predicate?.(query)).toBe(true);
id: "event-permission",
location,
type: "permission.asked",
});

expect(queryClient.getQueryData(key)).toEqual({
data: [
{
action: "shell",
id: "per_test",
resources: ["redacted command"],
sessionID: "session-1",
},
],
location,
});
const query = queryClient.getQueryCache().find({ queryKey: key });
expect(query && invalidate.mock.calls[0]?.[0]?.predicate?.(query)).toBe(true);

bridge.apply({
created: 2,
data: { reply: "once", requestID: "per_test", sessionID: "session-1" },
id: "event-permission-replied",
bridge.apply({
created: 2,
data: { reply: "once", requestID: "per_test", sessionID: "session-1" },
id: "event-permission-replied",
location,
type: "permission.replied",
});
expect(queryClient.getQueryData(key)).toEqual({ data: [], location });
queryClient.clear();
},
);

test("fresh form hints protect cold locations until authoritative reconciliation", () => {
const queryClient = new QueryClient();
const location = { directory: "/workspace/retired" };
const key = openCodeQueryKeys.forms("connection-1", location);
const bridge = new ConnectionEventQueryBridge(queryClient, "connection-1", (flush) => flush());
const event = {
type: "form.created",
id: "event-form",
created: 1,
location,
type: "permission.replied",
});
data: {
form: {
id: "form_test",
sessionID: "ses_test",
title: "Input",
fields: [{ key: "answer", type: "string" }],
},
},
} satisfies OpenCodeEvent;
bridge.apply(event);
bridge.apply(event);
expect(queryClient.getQueryData(key)).toEqual({ data: [event.data.form], location });
expect(queryClient.getQueryState(key)?.isInvalidated).toBe(true);
expect(
queryClient.getQueryData(openCodeQueryKeys.forms("connection-2", location)),
).toBeUndefined();
queryClient.setQueryData(key, { data: [], location });
expect(queryClient.getQueryData(key)).toEqual({ data: [], location });
queryClient.clear();
});
Expand Down
20 changes: 20 additions & 0 deletions apps/mobile/src/state/connection-event-query-bridge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
FormInfo,
LocationRef,
OpenCodeEvent,
PermissionRequest,
Expand Down Expand Up @@ -54,6 +55,17 @@ export class ConnectionEventQueryBridge {
const next = reduceActiveSessions(current, event);
if (next !== current) this.queryClient.setQueryData(activeKey, next);
reducePermissionQueries(this.queryClient, this.connectionId, event);
if (event.type === "form.created" && event.location) {
const form = event.data.form;
const location = event.location;
const key = openCodeQueryKeys.forms(this.connectionId, location);
this.queryClient.setQueryData<{ data: FormInfo[]; location: unknown }>(key, (current) => ({
location: current?.location ?? location,
data: current?.data.some((item) => item.id === form.id)
? current.data
: [...(current?.data ?? []), form],
}));
}

const root = eventInvalidationRoot(event);
if (root) {
Expand Down Expand Up @@ -217,6 +229,14 @@ function reducePermissionQueries(
) {
return;
}
if (event.type === "permission.asked") {
const key = openCodeQueryKeys.permissions(connectionId, event.location);
if (!queryClient.getQueryData(key)) {
// A fresh request protects an otherwise retired location until the exact
// location's authoritative REST snapshot replaces this volatile hint.
queryClient.setQueryData(key, { data: [event.data], location: event.location });
}
}
const queries = queryClient.getQueryCache().findAll({
predicate: (query) => matchesRoot(query, connectionId, "permissions", event.location),
});
Expand Down
9 changes: 8 additions & 1 deletion apps/mobile/src/state/connection-runtime-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ export function ConnectionRuntimeProvider({ children }: { children: ReactNode })
bridge.apply(event);
const eventLocation = event.location;
if (eventLocation) {
setEventLocations((current) => appendEventLocation(current, eventLocation));
setEventLocations((current) => {
const next = appendEventLocation(current, eventLocation);
// Reconsider retired locations when actual attention arrives,
// even if a generic event already introduced the location.
return event.type === "permission.asked" || event.type === "form.created"
? [...next]
: next;
});
}
diagnosticsRef.current = appendDiagnostic(diagnosticsRef.current, {
atMs: Date.now(),
Expand Down
Loading
Loading