Skip to content

Commit 37623f8

Browse files
committed
feat(ui): unify system notices in chat with a minimal line family
Class A (model-facing system turns: restart recovery, gateway restarted, generic internal_system fallback) and class B (lifecycle facts: compaction) now share one hairline+icon+label rendering; known kinds show operator summaries instead of raw injected prompts. Core producers share one formatSystemTurnPrompt owner for the [System] prefix; subagent resume copy unified from "gateway reload" to "gateway restart". No protocol, channel, or marker changes.
1 parent 1ccd701 commit 37623f8

19 files changed

Lines changed: 298 additions & 79 deletions

‎src/agents/main-session-recovery/main-session-restart-dispatch.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import type { AgentRunRequest } from "../../gateway/server-methods/agent-request
1717
import { getAgentEventLifecycleGeneration } from "../../infra/agent-events.js";
1818
import { createSubsystemLogger } from "../../logging/subsystem.js";
1919
import { CommandLane } from "../../process/lanes.js";
20-
import { MAIN_SESSION_RESTART_RECOVERY_SOURCE_TOOL } from "../../sessions/input-provenance.js";
20+
import {
21+
formatSystemTurnPrompt,
22+
MAIN_SESSION_RESTART_RECOVERY_SOURCE_TOOL,
23+
} from "../../sessions/input-provenance.js";
2124
import { resolveSendPolicy } from "../../sessions/send-policy.js";
2225
import {
2326
deliveryContextFromSession,
@@ -41,10 +44,11 @@ import { commitMainSessionRecovery } from "./main-session-recovery-store.js";
4144
import { normalizeFiniteTimestamp } from "./main-session-restart-recovery-shared.js";
4245

4346
const log = createSubsystemLogger("main-session-restart-recovery");
44-
const RESTART_RECOVERY_RESUME_MESSAGE =
45-
"[System] Your previous turn was interrupted by a gateway restart while " +
46-
"OpenClaw was waiting on tool/model work. Continue from the existing " +
47-
"transcript and finish the interrupted response.";
47+
const RESTART_RECOVERY_RESUME_MESSAGE = formatSystemTurnPrompt(
48+
"Your previous turn was interrupted by a gateway restart while " +
49+
"OpenClaw was waiting on tool/model work. Continue from the existing " +
50+
"transcript and finish the interrupted response.",
51+
);
4852

4953
type RestartRecoveryTerminalStatus = "error" | "ok" | "timeout";
5054

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { describe, expect, it } from "vitest";
2+
import { buildRestartRecoveryResumeMessage } from "./subagent-registry-restart-recovery-helpers.js";
3+
4+
describe("buildRestartRecoveryResumeMessage", () => {
5+
it("uses the canonical system prefix and gateway restart wording", () => {
6+
expect(buildRestartRecoveryResumeMessage("Finish the report", "Use the latest figures")).toBe(
7+
"[System] Your previous turn was interrupted by a gateway restart. " +
8+
"Your original task was:\n\nFinish the report\n\n" +
9+
"The last message from the user before the interruption was:\n\n" +
10+
"Use the latest figures\n\nPlease continue where you left off.",
11+
);
12+
});
13+
});

‎src/agents/subagents/registry/subagent-registry-restart-recovery-helpers.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createHash } from "node:crypto";
22
import { loadSessionEntry } from "../../../config/sessions/session-accessor.js";
33
import * as agentEvents from "../../../infra/agent-events.js";
4+
import { formatSystemTurnPrompt } from "../../../sessions/input-provenance.js";
45
import { truncateUtf16Safe } from "../../../utils.js";
56
import type {
67
SubagentRestartRecoveryReceipt,
@@ -29,13 +30,13 @@ export function isRestartRecoveryLifecycleCurrent(
2930

3031
export function buildRestartRecoveryResumeMessage(task: string, lastHumanMessage?: string): string {
3132
const original = task.length > 2_000 ? `${truncateUtf16Safe(task, 2_000)}...` : task;
32-
return (
33-
`[System] Your previous turn was interrupted by a gateway reload. ` +
34-
`Your original task was:\n\n${original}\n\n` +
35-
(lastHumanMessage
36-
? `The last message from the user before the interruption was:\n\n${lastHumanMessage}\n\n`
37-
: "") +
38-
`Please continue where you left off.`
33+
return formatSystemTurnPrompt(
34+
`Your previous turn was interrupted by a gateway restart. ` +
35+
`Your original task was:\n\n${original}\n\n` +
36+
(lastHumanMessage
37+
? `The last message from the user before the interruption was:\n\n${lastHumanMessage}\n\n`
38+
: "") +
39+
`Please continue where you left off.`,
3940
);
4041
}
4142

‎src/auto-reply/reply/stranded-reply-recovery.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ describe("resolveStrandedReplyRecovery", () => {
8282
if (recovery.kind === "retry") {
8383
expect(recovery.run.strandedReplyRetry).toBe(true);
8484
expect(recovery.run.disableCollectBatching).toBe(true);
85+
expect(recovery.run.prompt).toBe(
86+
`[System] Your previous reply was not delivered to the conversation because ` +
87+
`you did not call message(action=send). Your reply text was:\n\n` +
88+
`"${substantiveFinal}"\n\n` +
89+
`Please deliver this reply now by calling message(action=send). ` +
90+
`Do not add any extra commentary; just deliver the original reply.`,
91+
);
8592
}
8693
});
8794

‎src/auto-reply/reply/stranded-reply-recovery.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { formatSystemTurnPrompt } from "../../sessions/input-provenance.js";
12
import type { SourceReplyDeliveryMode } from "../get-reply-options.types.js";
23
import { markReplyPayloadForSourceSuppressionDelivery } from "../reply-payload.js";
34
import type { ReplyPayload } from "../types.js";
@@ -58,12 +59,12 @@ export function resolveStrandedReplyRecovery(params: {
5859
}
5960

6061
function buildStrandedReplyRetryPrompt(finalText: string): string {
61-
return (
62-
`[System] Your previous reply was not delivered to the conversation because ` +
63-
`you did not call message(action=send). Your reply text was:\n\n` +
64-
`"${finalText}"\n\n` +
65-
`Please deliver this reply now by calling message(action=send). ` +
66-
`Do not add any extra commentary; just deliver the original reply.`
62+
return formatSystemTurnPrompt(
63+
`Your previous reply was not delivered to the conversation because ` +
64+
`you did not call message(action=send). Your reply text was:\n\n` +
65+
`"${finalText}"\n\n` +
66+
`Please deliver this reply now by calling message(action=send). ` +
67+
`Do not add any extra commentary; just deliver the original reply.`,
6768
);
6869
}
6970

‎src/sessions/input-provenance.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@
22
import { describe, expect, it } from "vitest";
33
import {
44
annotateInterSessionPromptText,
5+
formatSystemTurnPrompt,
56
isAgentMediatedCompletionSourceTool,
67
shouldPreserveUserFacingSessionStateForInputProvenance,
78
stripInterSessionPromptPrefixForDisplay,
89
} from "./input-provenance.js";
910

11+
describe("formatSystemTurnPrompt", () => {
12+
it.each([
13+
["resume the turn", "[System] resume the turn"],
14+
[" resume the turn ", "[System] resume the turn"],
15+
[" [System] resume the turn ", "[System] resume the turn"],
16+
])("formats %j without duplicating the system prefix", (body, expected) => {
17+
expect(formatSystemTurnPrompt(body)).toBe(expected);
18+
});
19+
});
20+
1021
describe("annotateInterSessionPromptText", () => {
1122
it("marks inter-session prompt text as non-user-authored", () => {
1223
const text = annotateInterSessionPromptText("do the thing", {

‎src/sessions/input-provenance.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type InputProvenance = {
1919

2020
export const MAIN_SESSION_RESTART_RECOVERY_SOURCE_TOOL = "main_session_restart_recovery" as const;
2121

22+
export const SYSTEM_TURN_PROMPT_PREFIX = "[System]";
2223
export const INTER_SESSION_PROMPT_PREFIX_BASE = "[Inter-session message]";
2324
const AGENT_MEDIATED_COMPLETION_SOURCE_TOOLS = [
2425
"agent_harness_task",
@@ -128,6 +129,13 @@ export function hasInterSessionUserProvenance(
128129
return isInterSessionInputProvenance(message.provenance);
129130
}
130131

132+
export function formatSystemTurnPrompt(body: string): string {
133+
const trimmedBody = body.trim();
134+
return trimmedBody.startsWith(SYSTEM_TURN_PROMPT_PREFIX)
135+
? trimmedBody
136+
: `${SYSTEM_TURN_PROMPT_PREFIX} ${trimmedBody}`;
137+
}
138+
131139
// Prefix text is model-facing safety context for inter-session handoffs. It
132140
// states source metadata and explicitly prevents treating the payload as direct
133141
// end-user instruction.

‎ui/src/components/icons-tools.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ export function strokeIcon(body: SVGTemplateResult): TemplateResult {
2222
}
2323

2424
export const toolIcons = {
25+
cpu: strokeIcon(svg` <rect width="16" height="16" x="4" y="4" rx="2" />
26+
<rect width="6" height="6" x="9" y="9" rx="1" />
27+
<path d="M15 2v2" />
28+
<path d="M15 20v2" />
29+
<path d="M2 15h2" />
30+
<path d="M2 9h2" />
31+
<path d="M20 15h2" />
32+
<path d="M20 9h2" />
33+
<path d="M9 2v2" />
34+
<path d="M9 20v2" />`),
35+
foldVertical: strokeIcon(svg` <path d="M12 22v-6" />
36+
<path d="M12 8V2" />
37+
<path d="M4 12H2" />
38+
<path d="M10 12H8" />
39+
<path d="M16 12h-2" />
40+
<path d="M22 12h-2" />
41+
<path d="m19 9-3 3 3 3" />
42+
<path d="m5 15 3-3-3-3" />`),
2543
wrench: strokeIcon(svg` <path
2644
d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"
2745
/>`),

‎ui/src/i18n/locales/en.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4753,10 +4753,19 @@ export const en: TranslationMap = {
47534753
compaction: {
47544754
label: "Compacted history",
47554755
savedTokens: "saved {count} tokens",
4756-
description:
4757-
"The compacted transcript is preserved as a checkpoint. Open session checkpoints to branch or restore from that compacted view.",
4756+
description: "The compacted transcript is preserved as a checkpoint.",
47584757
openCheckpoints: "Open checkpoints",
47594758
},
4759+
systemNotice: {
4760+
restartRecovery: {
4761+
label: "System · restart recovery",
4762+
summary:
4763+
"Turn interrupted by a gateway restart — asked the agent to resume and finish the response.",
4764+
},
4765+
gatewayRestarted: {
4766+
label: "System · gateway restarted",
4767+
},
4768+
},
47604769
progressLabels: {
47614770
shelling: "Shelling",
47624771
scuttling: "Scuttling",

‎ui/src/lib/chat/chat-types.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import type { MediaKind } from "@openclaw/media-core/constants";
6+
import type { toolIcons } from "../../components/icons-tools.ts";
67
import type { SenderIdentity } from "./sender-label.ts";
78

89
export type BrowserAnnotationAttachment = {
@@ -89,13 +90,15 @@ export type ChatItem =
8990
key: string;
9091
text: string;
9192
timestamp: number;
93+
icon?: keyof typeof toolIcons;
9294
label?: string;
9395
startsTurn?: true;
9496
}
9597
| {
9698
kind: "divider";
9799
key: string;
98100
label: string;
101+
icon?: keyof typeof toolIcons;
99102
metric?: string;
100103
description?: string;
101104
action?: { kind: "session-checkpoints"; label: string };

0 commit comments

Comments
 (0)