Skip to content

Commit a441431

Browse files
authored
fix(tui): restore remembered global sessions (#126135)
1 parent 7e69b1d commit a441431

3 files changed

Lines changed: 54 additions & 12 deletions

File tree

‎src/tui/tui-pty-harness-fixture-test-support.ts‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,7 @@ export async function writeTuiPtyFixtureScript(dir: string) {
212212
${TUI_PTY_SESSION_SUBSCRIPTION_FIXTURE_SCRIPT}
213213
214214
async sendChat(opts: Parameters<TuiBackend["sendChat"]>[0]) {
215-
record("sendChat", {
216-
sessionKey: opts.sessionKey,
217-
message: opts.message,
218-
deliver: opts.deliver,
219-
thinking: opts.thinking,
220-
});
215+
record("sendChat", opts);
221216
const runId = opts.runId ?? "run-pty-fixture";
222217
${TUI_PTY_RECONNECT_FIXTURE.sendChat}
223218
if (opts.message.startsWith("live reply dedupe proof: ")) {
@@ -510,8 +505,8 @@ export async function writeTuiPtyFixtureScript(dir: string) {
510505
async listSessions(opts?: Parameters<TuiBackend["listSessions"]>[0]) {
511506
${TUI_PTY_STARTUP_SESSION_FIXTURE.listSessionsSetup}
512507
record("listSessions", {
508+
...opts,
513509
purpose: opts?.includeDerivedTitles ? "picker" : "refresh",
514-
search: opts?.search,
515510
});
516511
${TUI_PTY_STARTUP_SESSION_FIXTURE.listSessionsDelay}
517512
const sessions = enablePickerFixture
@@ -524,11 +519,14 @@ export async function writeTuiPtyFixtureScript(dir: string) {
524519
},
525520
]
526521
: [];
522+
const visibleSessions = sessions.filter(
523+
(session) => session.key !== "global" || opts?.includeGlobal === true,
524+
);
527525
return {
528526
ts: Date.now(),
529527
path: "",
530-
count: sessions.length,
531-
sessions,
528+
count: visibleSessions.length,
529+
sessions: visibleSessions,
532530
defaults: {
533531
model: currentModel,
534532
modelProvider: "fixture-provider",

‎src/tui/tui-session-identity-pty.e2e.test.ts‎

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ const STARTUP_TIMEOUT_MS = 60_000;
1515
const REMEMBERED_SESSION_KEY = "agent:main:picker-target";
1616
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
1717

18-
async function seedRememberedSession(stateDir: string) {
18+
async function seedRememberedSession(
19+
stateDir: string,
20+
sessionKey: string = REMEMBERED_SESSION_KEY,
21+
) {
1922
await writeTuiLastSessionKey({
2023
scopeKey: buildTuiLastSessionScopeKey({
2124
connectionUrl: "pty-fixture://local",
2225
agentId: "main",
2326
sessionScope: "per-sender",
2427
}),
25-
sessionKey: REMEMBERED_SESSION_KEY,
28+
sessionKey,
2629
stateDir,
2730
});
2831
}
@@ -106,6 +109,47 @@ it("hides a stale approval when startup restores the remembered session", async
106109
}
107110
}, 65_000);
108111

112+
it("restores a remembered global session before startup admits the first send", async () => {
113+
const stateDir = tempDirs.make("openclaw-tui-global-session-");
114+
const marker = "global startup session proof";
115+
await seedRememberedSession(stateDir, "global");
116+
const fixture = await startTuiFixture({
117+
env: {
118+
OPENCLAW_STATE_DIR: stateDir,
119+
OPENCLAW_TUI_PTY_PICKER_FIXTURE: "1",
120+
OPENCLAW_TUI_PTY_PICKER_SESSION_KEY: "global",
121+
},
122+
});
123+
124+
try {
125+
const lookup = await fixture.waitForLogEntry(
126+
(entry) => entry.method === "listSessions" && objectFieldEquals(entry, "search", "global"),
127+
STARTUP_TIMEOUT_MS,
128+
);
129+
expect(lookup.payload).toMatchObject({
130+
search: "global",
131+
includeGlobal: true,
132+
includeUnknown: false,
133+
agentId: "main",
134+
});
135+
136+
await fixture.run.waitForOutput("local ready", STARTUP_TIMEOUT_MS);
137+
await fixture.run.write(`${marker}\r`, { delay: false });
138+
await fixture.waitForLogEntry(
139+
(entry) => entry.method === "sendChat" && objectFieldEquals(entry, "message", marker),
140+
STARTUP_TIMEOUT_MS,
141+
);
142+
143+
const sends = (await readFixtureLog(fixture.logPath)).filter(
144+
(entry) => entry.method === "sendChat",
145+
);
146+
expect(sends).toHaveLength(1);
147+
expect(sends[0]?.payload).toMatchObject({ sessionKey: "global", agentId: "main" });
148+
} finally {
149+
await fixture.cleanup();
150+
}
151+
}, 65_000);
152+
109153
it("keeps startup input editable until the remembered session and history are stable", async () => {
110154
const stateDir = tempDirs.make("openclaw-tui-startup-session-");
111155
const marker = "startup remembered session proof";

‎src/tui/tui.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ async function runTuiUnlocked(opts: RunTuiOptions): Promise<TuiResult> {
10911091
.listSessions({
10921092
limit: TUI_SESSION_LOOKUP_LIMIT,
10931093
search: rememberedKey,
1094-
includeGlobal: false,
1094+
includeGlobal: rememberedKey === "global",
10951095
includeUnknown: false,
10961096
agentId: state.currentAgentId,
10971097
})

0 commit comments

Comments
 (0)