Skip to content

Commit e03d1a4

Browse files
improve(ui): collapse limited access notice (#123735)
* improve(ui): collapse limited access notice * test(ui): follow limited access banner host * test(ui): await limited access guidance host * test(compaction): split context budget coverage --------- Co-authored-by: RoboClaw <[email protected]>
1 parent 19ace68 commit e03d1a4

11 files changed

Lines changed: 357 additions & 150 deletions

‎docs/gateway/operator-scopes.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ that asks for a broader role or broader scopes creates a new pending upgrade
155155
request.
156156

157157
A connected limited Control UI can file that same pending request through its
158-
**Request admin** banner without attempting a broader reconnect. The request is
158+
**Request admin** banner without attempting a broader reconnect. The banner can
159+
collapse into a persistent **Limited access** chip that reopens the action. The request is
159160
bound to the signed device identity on the live connection. Approval still
160161
comes from `device.pair.approve` and therefore requires `operator.pairing` plus
161162
authority for every requested scope. After approval rotates the operator token,

‎docs/web/control-ui.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ If the browser retries pairing with changed auth details (role/scopes/public key
8080

8181
Switching an already-paired browser from read access to write/admin access through ordinary stored or shared credentials is treated as an approval upgrade, not a silent reconnect: OpenClaw keeps the old approval active, blocks the broader reconnect, and asks you to approve the new scope set explicitly. The narrow exception is a fresh owner handoff issued on the Gateway host by `openclaw dashboard` or graphical onboarding; it can upgrade only the same signed browser that redeems that one-time handoff.
8282

83-
When the connected Control UI reports limited access, click **Request admin** in the access banner. The browser files the same pending device scope-upgrade request over its existing connection; approve it with `openclaw devices` on the Gateway host or from **Devices** in another admin-capable browser that also has `operator.pairing`. Keep the requesting tab connected while approval completes so it can receive and store the freshly rotated device token before reconnecting. **Retry** reattaches to the pending request. **Cancel** stops the local wait but does not reject the device request; if you cancel or disconnect before approval, use the normal pairing repair path on the next connection.
83+
When the connected Control UI reports limited access, click **Request admin** in the access banner. You can collapse the banner into a persistent **Limited access** chip and click the chip whenever you need the full explanation or request action again. The browser files the same pending device scope-upgrade request over its existing connection; approve it with `openclaw devices` on the Gateway host or from **Devices** in another admin-capable browser that also has `operator.pairing`. Keep the requesting tab connected while approval completes so it can receive and store the freshly rotated device token before reconnecting. **Retry** reattaches to the pending request. **Cancel** stops the local wait but does not reject the device request; if you cancel or disconnect before approval, use the normal pairing repair path on the next connection.
8484

8585
Once approved, the device is remembered and won't require re-approval unless you revoke it with `openclaw devices revoke --device <id> --role <role>`. See [Devices CLI](/cli/devices) for token rotation, revocation, and the Paperclip / `openclaw_gateway` first-run approval flow.
8686

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
// Tests compact command context-budget resolution separately from command lifecycle behavior.
2+
import { beforeEach, describe, expect, it, vi } from "vitest";
3+
import type { OpenClawConfig } from "../../config/config.js";
4+
import {
5+
resolveAgentDirMock,
6+
resolveSessionAgentIdMock,
7+
} from "./commands-agent-scope.test-support.js";
8+
import type { HandleCommandsParams } from "./commands-types.js";
9+
10+
vi.mock("./commands-compact.runtime.js", () => ({
11+
abortEmbeddedAgentRun: vi.fn(),
12+
compactEmbeddedAgentSession: vi.fn(),
13+
enqueueSystemEvent: vi.fn(),
14+
formatContextUsageShort: vi.fn(() => "Context 12.1k"),
15+
formatTokenCount: vi.fn((value: number) => `${value}`),
16+
incrementCompactionCount: vi.fn(),
17+
isCurrentSessionEntry: vi.fn(() => true),
18+
isEmbeddedAgentRunAbortableForCompaction: vi.fn().mockReturnValue(false),
19+
resolveFreshSessionTotalTokens: vi.fn(() => 12_345),
20+
resolveSessionFilePathOptions: vi.fn(() => ({})),
21+
waitForEmbeddedAgentRunEnd: vi.fn().mockResolvedValue(true),
22+
}));
23+
24+
const {
25+
compactEmbeddedAgentSession,
26+
formatContextUsageShort,
27+
incrementCompactionCount,
28+
isCurrentSessionEntry,
29+
} = await import("./commands-compact.runtime.js");
30+
const { handleCompactCommand } = await import("./commands-compact.js");
31+
32+
function buildCompactParams(cfg: OpenClawConfig): HandleCommandsParams {
33+
return {
34+
cfg,
35+
ctx: {
36+
Provider: "whatsapp",
37+
Surface: "whatsapp",
38+
CommandSource: "text",
39+
CommandBody: "/compact",
40+
commandText: "/compact",
41+
},
42+
command: {
43+
commandBodyNormalized: "/compact",
44+
isAuthorizedSender: true,
45+
senderIsOwner: false,
46+
senderId: "owner",
47+
channel: "whatsapp",
48+
ownerList: [],
49+
},
50+
sessionKey: "agent:main:main",
51+
sessionStore: {},
52+
resolveDefaultThinkingLevel: async () => "medium",
53+
} as unknown as HandleCommandsParams;
54+
}
55+
56+
function requireCompactEmbeddedAgentSessionCall() {
57+
const call = vi.mocked(compactEmbeddedAgentSession).mock.calls[0]?.[0];
58+
if (!call) {
59+
throw new Error("compactEmbeddedAgentSession call missing");
60+
}
61+
return call;
62+
}
63+
64+
describe("handleCompactCommand context budget", () => {
65+
beforeEach(() => {
66+
vi.clearAllMocks();
67+
vi.mocked(incrementCompactionCount).mockResolvedValue(1);
68+
vi.mocked(isCurrentSessionEntry).mockReturnValue(true);
69+
resolveAgentDirMock.mockImplementation(
70+
(_cfg: unknown, agentId: string) => `/tmp/workspace/.openclaw/agents/${agentId}/agent`,
71+
);
72+
resolveSessionAgentIdMock.mockReturnValue("main");
73+
});
74+
75+
it("resolves the active Codex runtime config instead of stale session metadata", async () => {
76+
vi.mocked(compactEmbeddedAgentSession).mockResolvedValueOnce({
77+
ok: true,
78+
compacted: true,
79+
result: {
80+
summary: "compacted",
81+
firstKeptEntryId: "first-kept",
82+
tokensBefore: 199_000,
83+
tokensAfter: 56_000,
84+
},
85+
});
86+
87+
await handleCompactCommand(
88+
{
89+
...buildCompactParams({
90+
agents: {
91+
defaults: {
92+
models: {
93+
"openai/gpt-5.5": {
94+
agentRuntime: { id: "codex" },
95+
},
96+
},
97+
},
98+
},
99+
commands: { text: true },
100+
channels: { whatsapp: { allowFrom: ["*"] } },
101+
models: {
102+
providers: {
103+
openai: {
104+
models: [{ id: "gpt-5.5", contextWindow: 258_000 }],
105+
},
106+
},
107+
},
108+
} as unknown as OpenClawConfig),
109+
provider: "openai",
110+
model: "openai/gpt-5.5",
111+
contextTokens: 0,
112+
sessionEntry: {
113+
sessionId: "live-session",
114+
updatedAt: Date.now(),
115+
contextTokens: 400_000,
116+
},
117+
} as HandleCommandsParams,
118+
true,
119+
);
120+
121+
expect(requireCompactEmbeddedAgentSessionCall().contextTokenBudget).toBe(258_000);
122+
expect(vi.mocked(formatContextUsageShort)).toHaveBeenLastCalledWith(56_000, 258_000);
123+
});
124+
125+
it.each([
126+
{ globalCap: undefined, agentCap: undefined, expectedBudget: 1_000_000 },
127+
{ globalCap: 372_000, agentCap: 120_000, expectedBudget: 120_000 },
128+
{ globalCap: 120_000, agentCap: 372_000, expectedBudget: 372_000 },
129+
])("respects the target agent context cap (#117470)", async (testCase) => {
130+
vi.mocked(compactEmbeddedAgentSession).mockResolvedValueOnce({
131+
ok: true,
132+
compacted: true,
133+
result: {
134+
summary: "compacted",
135+
firstKeptEntryId: "first-kept",
136+
tokensBefore: 134_930,
137+
tokensAfter: 56_000,
138+
},
139+
});
140+
141+
await handleCompactCommand(
142+
{
143+
...buildCompactParams({
144+
agents: {
145+
...(testCase.globalCap === undefined
146+
? {}
147+
: { defaults: { contextTokens: testCase.globalCap } }),
148+
...(testCase.agentCap === undefined
149+
? {}
150+
: { list: [{ id: "main", contextTokens: testCase.agentCap }] }),
151+
},
152+
commands: { text: true },
153+
channels: { whatsapp: { allowFrom: ["*"] } },
154+
} as OpenClawConfig),
155+
provider: "claude-cli",
156+
model: "claude-fable-5",
157+
contextTokens: testCase.globalCap ?? 0,
158+
sessionEntry: {
159+
sessionId: "fable-session",
160+
updatedAt: Date.now(),
161+
contextTokens: 1_000_000,
162+
},
163+
} as HandleCommandsParams,
164+
true,
165+
);
166+
167+
expect(requireCompactEmbeddedAgentSessionCall().contextTokenBudget).toBe(
168+
testCase.expectedBudget,
169+
);
170+
});
171+
172+
it("retains persisted context when an unknown custom model uses a legacy alias", async () => {
173+
vi.mocked(compactEmbeddedAgentSession).mockResolvedValueOnce({
174+
ok: true,
175+
compacted: false,
176+
reason: "already compacted",
177+
});
178+
179+
await handleCompactCommand(
180+
{
181+
...buildCompactParams({
182+
agents: {
183+
defaults: {
184+
models: { "custom/actual-model": { alias: "legacy-fast-model" } },
185+
},
186+
},
187+
commands: { text: true },
188+
channels: { whatsapp: { allowFrom: ["*"] } },
189+
} as OpenClawConfig),
190+
provider: "custom",
191+
model: "actual-model",
192+
contextTokens: 0,
193+
sessionEntry: {
194+
sessionId: "legacy-model-session",
195+
updatedAt: Date.now(),
196+
providerOverride: "custom",
197+
modelOverride: "legacy-fast-model",
198+
modelOverrideSource: "user",
199+
contextTokens: 777_777,
200+
},
201+
} as HandleCommandsParams,
202+
true,
203+
);
204+
205+
expect(requireCompactEmbeddedAgentSessionCall().contextTokenBudget).toBe(777_777);
206+
});
207+
});

‎src/auto-reply/reply/commands-compact.test.ts‎

Lines changed: 0 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,137 +1005,4 @@ describe("handleCompactCommand", () => {
10051005
expect(result?.reply?.text).toContain("Compaction finished (resulting context unknown) •");
10061006
expect(result?.reply?.text).not.toContain("undefined");
10071007
});
1008-
1009-
it("resolves /compact context budget from the active Codex runtime config instead of stale session metadata", async () => {
1010-
vi.mocked(compactEmbeddedAgentSession).mockResolvedValueOnce({
1011-
ok: true,
1012-
compacted: true,
1013-
result: {
1014-
summary: "compacted",
1015-
firstKeptEntryId: "first-kept",
1016-
tokensBefore: 199_000,
1017-
tokensAfter: 56_000,
1018-
},
1019-
});
1020-
1021-
await handleCompactCommand(
1022-
{
1023-
...buildCompactParams("/compact", {
1024-
agents: {
1025-
defaults: {
1026-
models: {
1027-
"openai/gpt-5.5": {
1028-
agentRuntime: { id: "codex" },
1029-
},
1030-
},
1031-
},
1032-
},
1033-
commands: { text: true },
1034-
channels: { whatsapp: { allowFrom: ["*"] } },
1035-
models: {
1036-
providers: {
1037-
openai: {
1038-
models: [{ id: "gpt-5.5", contextWindow: 258_000 }],
1039-
},
1040-
},
1041-
},
1042-
} as unknown as OpenClawConfig),
1043-
provider: "openai",
1044-
model: "openai/gpt-5.5",
1045-
contextTokens: 0,
1046-
sessionEntry: {
1047-
sessionId: "live-session",
1048-
updatedAt: Date.now(),
1049-
contextTokens: 400_000,
1050-
},
1051-
} as HandleCommandsParams,
1052-
true,
1053-
);
1054-
1055-
expect(requireCompactEmbeddedAgentSessionCall().contextTokenBudget).toBe(258_000);
1056-
expect(vi.mocked(formatContextUsageShort)).toHaveBeenLastCalledWith(56_000, 258_000);
1057-
});
1058-
1059-
it.each([
1060-
{ globalCap: undefined, agentCap: undefined, expectedBudget: 1_000_000 },
1061-
{ globalCap: 372_000, agentCap: 120_000, expectedBudget: 120_000 },
1062-
{ globalCap: 120_000, agentCap: 372_000, expectedBudget: 372_000 },
1063-
])("respects the target agent context cap for /compact (#117470)", async (testCase) => {
1064-
vi.mocked(compactEmbeddedAgentSession).mockResolvedValueOnce({
1065-
ok: true,
1066-
compacted: true,
1067-
result: {
1068-
summary: "compacted",
1069-
firstKeptEntryId: "first-kept",
1070-
tokensBefore: 134_930,
1071-
tokensAfter: 56_000,
1072-
},
1073-
});
1074-
1075-
await handleCompactCommand(
1076-
{
1077-
...buildCompactParams("/compact", {
1078-
agents: {
1079-
...(testCase.globalCap === undefined
1080-
? {}
1081-
: { defaults: { contextTokens: testCase.globalCap } }),
1082-
...(testCase.agentCap === undefined
1083-
? {}
1084-
: { list: [{ id: "main", contextTokens: testCase.agentCap }] }),
1085-
},
1086-
commands: { text: true },
1087-
channels: { whatsapp: { allowFrom: ["*"] } },
1088-
} as OpenClawConfig),
1089-
provider: "claude-cli",
1090-
model: "claude-fable-5",
1091-
contextTokens: testCase.globalCap ?? 0,
1092-
sessionEntry: {
1093-
sessionId: "fable-session",
1094-
updatedAt: Date.now(),
1095-
contextTokens: 1_000_000,
1096-
},
1097-
} as HandleCommandsParams,
1098-
true,
1099-
);
1100-
1101-
expect(requireCompactEmbeddedAgentSessionCall().contextTokenBudget).toBe(
1102-
testCase.expectedBudget,
1103-
);
1104-
});
1105-
1106-
it("retains persisted context when an unknown custom model is stored as a legacy alias", async () => {
1107-
vi.mocked(compactEmbeddedAgentSession).mockResolvedValueOnce({
1108-
ok: true,
1109-
compacted: false,
1110-
reason: "already compacted",
1111-
});
1112-
1113-
await handleCompactCommand(
1114-
{
1115-
...buildCompactParams("/compact", {
1116-
agents: {
1117-
defaults: {
1118-
models: { "custom/actual-model": { alias: "legacy-fast-model" } },
1119-
},
1120-
},
1121-
commands: { text: true },
1122-
channels: { whatsapp: { allowFrom: ["*"] } },
1123-
} as OpenClawConfig),
1124-
provider: "custom",
1125-
model: "actual-model",
1126-
contextTokens: 0,
1127-
sessionEntry: {
1128-
sessionId: "legacy-model-session",
1129-
updatedAt: Date.now(),
1130-
providerOverride: "custom",
1131-
modelOverride: "legacy-fast-model",
1132-
modelOverrideSource: "user",
1133-
contextTokens: 777_777,
1134-
},
1135-
} as HandleCommandsParams,
1136-
true,
1137-
);
1138-
1139-
expect(requireCompactEmbeddedAgentSessionCall().contextTokenBudget).toBe(777_777);
1140-
});
11411008
});

‎ui/src/app/app-shell-view.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,6 @@ function renderScopeUpgradeBanner(
6464
if (state.phase === "hidden") {
6565
return nothing;
6666
}
67-
if (state.phase === "guidance") {
68-
return html`<openclaw-update-banner
69-
.props=${{
70-
statusBanner: {
71-
tone: "warn",
72-
text: t("connection.scopeUpgrade.guidance"),
73-
},
74-
}}
75-
></openclaw-update-banner>`;
76-
}
7767
void ensureOptionalElementForHost(host, SCOPE_UPGRADE_BANNER_ELEMENT).catch(() => undefined);
7868
if (isOptionalElementDefined(SCOPE_UPGRADE_BANNER_ELEMENT)) {
7969
return html`<openclaw-device-scope-upgrade-banner

0 commit comments

Comments
 (0)