Skip to content

Commit 5ec2bb1

Browse files
steipeteml12580
andcommitted
fix(tui): show startup initialization activity
Co-authored-by: ml12580 <[email protected]>
1 parent bf04d04 commit 5ec2bb1

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/tui/tui-pty-harness.e2e.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ async function writeTuiPtyFixtureScript(dir: string) {
8383
8484
const actionLogPath = process.env.OPENCLAW_TUI_PTY_LOG_PATH;
8585
const gatewayStatus = process.env.OPENCLAW_TUI_PTY_GATEWAY_STATUS ?? "fixture gateway ok";
86+
const startupDelayMs = Number(process.env.OPENCLAW_TUI_PTY_STARTUP_DELAY_MS ?? 0);
8687
const xaiLimitError = '403 {"code":"The caller does not have permission to execute the specified operation","error":"Your team team-redacted has either used all available credits or reached its monthly spending limit. To continue making API requests, please purchase more credits or raise your spending limit."}';
8788
let currentModel = "fixture-provider/fixture-model";
8889
let fastMode = process.env.OPENCLAW_TUI_PTY_FAST_MODE === "true";
@@ -271,6 +272,9 @@ async function writeTuiPtyFixtureScript(dir: string) {
271272
272273
async loadHistory() {
273274
record("loadHistory");
275+
if (startupDelayMs > 0) {
276+
await new Promise((resolve) => setTimeout(resolve, startupDelayMs));
277+
}
274278
return { messages: [], fastMode };
275279
}
276280
@@ -445,6 +449,22 @@ describe.sequential("TUI PTY harness", () => {
445449
expect(fixture.run.output()).not.toContain("host local");
446450
});
447451

452+
it(
453+
"shows startup activity while post-connect initialization is pending",
454+
async () => {
455+
const slow = await startTuiFixture({
456+
env: { OPENCLAW_TUI_PTY_STARTUP_DELAY_MS: "400" },
457+
});
458+
try {
459+
await slow.run.waitForOutput("starting up", STARTUP_TIMEOUT_MS);
460+
await slow.run.waitForOutput("local ready | idle", STARTUP_TIMEOUT_MS);
461+
} finally {
462+
await slow.cleanup();
463+
}
464+
},
465+
STARTUP_TEST_TIMEOUT_MS,
466+
);
467+
448468
it("refreshes pending approvals before loading history", async () => {
449469
await fixture.waitForLogEntry((entry) => entry.method === "listPluginApprovals");
450470
await fixture.waitForLogEntry((entry) => entry.method === "loadHistory");

src/tui/tui.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ describe("isTuiBusyActivityStatus", () => {
188188
it("treats finishing context as a visible busy status", () => {
189189
expect(isTuiBusyActivityStatus("finishing context")).toBe(true);
190190
});
191+
192+
it("treats post-connect initialization as a visible busy status", () => {
193+
expect(isTuiBusyActivityStatus("starting up")).toBe(true);
194+
});
191195
});
192196

193197
describe("resolveTuiToolsToggleActivityStatus", () => {

src/tui/tui.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ const TUI_BUSY_ACTIVITY_STATUSES = new Set([
425425
"streaming",
426426
"running",
427427
"finishing context",
428+
"starting up",
428429
]);
429430

430431
export function isTuiBusyActivityStatus(status: string): boolean {
@@ -1573,6 +1574,11 @@ export async function runTui(opts: RunTuiOptions): Promise<TuiResult> {
15731574
reconnectStreamingWatchdog();
15741575
}
15751576
setConnectionStatus(isLocalMode ? "local ready" : "connected");
1577+
// A reconnect may already have restored a live run's busy status. Only
1578+
// claim the status line when startup owns it, then release that exact state.
1579+
if (!isTuiBusyActivityStatus(activityStatus)) {
1580+
setActivityStatus("starting up");
1581+
}
15761582
void (async () => {
15771583
try {
15781584
await client.subscribeSessionEvents?.();
@@ -1589,6 +1595,9 @@ export async function runTui(opts: RunTuiOptions): Promise<TuiResult> {
15891595
chatLog.addSystem(`plugin approval refresh failed: ${String(err)}`);
15901596
}
15911597
await loadHistory();
1598+
if (activityStatus === "starting up") {
1599+
setActivityStatus("idle");
1600+
}
15921601
setConnectionStatus(
15931602
isLocalMode ? "local ready" : reconnected ? "gateway reconnected" : "gateway connected",
15941603
4000,
@@ -1604,6 +1613,9 @@ export async function runTui(opts: RunTuiOptions): Promise<TuiResult> {
16041613
tui.requestRender();
16051614
})().catch((err: unknown) => {
16061615
chatLog.addSystem(`startup failed: ${String(err)}`);
1616+
if (activityStatus === "starting up") {
1617+
setActivityStatus("idle");
1618+
}
16071619
setConnectionStatus("startup failed", 5000);
16081620
tui.requestRender();
16091621
});

0 commit comments

Comments
 (0)