Skip to content

Commit c3c964e

Browse files
committed
fix: cover Telegram current session status
1 parent abe204f commit c3c964e

8 files changed

Lines changed: 107 additions & 10 deletions

File tree

‎.github/workflows/openclaw-release-checks.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ jobs:
462462
published_upgrade_survivor_baselines: all-since-2026.4.23
463463
published_upgrade_survivor_scenarios: reported-issues
464464
telegram_mode: mock-openai
465-
telegram_scenarios: telegram-help-command,telegram-commands-command,telegram-tools-compact-command,telegram-whoami-command,telegram-context-command,telegram-mention-gating
465+
telegram_scenarios: telegram-help-command,telegram-commands-command,telegram-tools-compact-command,telegram-whoami-command,telegram-context-command,telegram-current-session-status-tool,telegram-mention-gating
466466
secrets:
467467
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
468468
OPENAI_BASE_URL: ${{ secrets.OPENAI_BASE_URL }}

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Docs: https://docs.openclaw.ai
134134
- Channels/streaming: expose `streaming.progress.label`, `labels`, `maxLines`, and `toolProgress` in bundled channel config metadata so progress draft settings appear in config, docs, and control surfaces. Thanks @vincentkoc.
135135
- Channels/streaming: normalize whitespace and case for `streaming.progress.label: "auto"` so progress draft labels keep using the built-in label pool instead of rendering a literal `auto` title. Thanks @vincentkoc.
136136
- Plugins/Codex: preserve Codex-native OAuth routing for `/codex bind` app-server turns so bound sessions keep the selected Codex auth profile instead of falling back to public OpenAI credentials. (#76714) Thanks @keshavbotagent.
137-
- Fix `session_status` with `sessionKey: "current"` resolving to stale Telegram direct session instead of live run session (#76708). Thanks @amknight.
137+
- Telegram: keep status checks pointed at the active chat so asking for the current session no longer reports an old direct-message conversation. (#76708) Thanks @amknight.
138138
- Gateway/install: prefer supported system Node over nvm/fnm/volta/asdf/mise when regenerating managed gateway services, so `gateway install --force` no longer recreates service definitions that doctor immediately flags as version-manager-backed. Fixes #76339. Thanks @brokemac79.
139139
- Cron/status: render explicit `delivery.mode: "none"` jobs as no-delivery previews and label cron session history distinctly instead of showing fallback delivery or direct-session rows. Fixes #76945.
140140
- Gateway/usage: serve `usage.cost` and `sessions.usage` from a durable transcript aggregate cache with lock-safe background refreshes and localized stale-cache status, so large usage views avoid repeated full scans. (#76650) Thanks @Marvinthebored.

‎extensions/qa-lab/src/live-transports/telegram/telegram-live.runtime.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ describe("telegram live qa runtime", () => {
331331
"telegram-tools-compact-command",
332332
"telegram-whoami-command",
333333
"telegram-context-command",
334+
"telegram-current-session-status-tool",
334335
"telegram-mentioned-message-reply",
335336
"telegram-mention-gating",
336337
]);
@@ -340,9 +341,15 @@ describe("telegram live qa runtime", () => {
340341
"telegram-tools-compact-command",
341342
"telegram-whoami-command",
342343
"telegram-context-command",
344+
"telegram-current-session-status-tool",
343345
"telegram-mentioned-message-reply",
344346
"telegram-mention-gating",
345347
]);
348+
expect(
349+
scenarios
350+
.find((scenario) => scenario.id === "telegram-current-session-status-tool")
351+
?.buildRun("sut_bot").expectedTextIncludes,
352+
).toEqual(["QA-TELEGRAM-CURRENT-SESSION-OK", ":telegram:group:"]);
346353
expect(
347354
scenarios
348355
.find((scenario) => scenario.id === "telegram-mentioned-message-reply")

‎extensions/qa-lab/src/live-transports/telegram/telegram-live.runtime.ts‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type TelegramQaScenarioId =
4747
| "telegram-tools-compact-command"
4848
| "telegram-whoami-command"
4949
| "telegram-context-command"
50+
| "telegram-current-session-status-tool"
5051
| "telegram-mentioned-message-reply"
5152
| "telegram-mention-gating";
5253

@@ -208,6 +209,7 @@ type TelegramMessage = {
208209

209210
type TelegramUpdate = {
210211
update_id: number;
212+
edited_message?: TelegramMessage;
211213
message?: TelegramMessage;
212214
};
213215

@@ -270,6 +272,17 @@ const TELEGRAM_QA_SCENARIOS: TelegramQaScenarioDefinition[] = [
270272
expectedTextIncludes: ["/context list", "Inline shortcut"],
271273
}),
272274
},
275+
{
276+
id: "telegram-current-session-status-tool",
277+
title: "Telegram current session_status tool call",
278+
defaultEnabled: false,
279+
timeoutMs: 60_000,
280+
buildRun: (sutUsername) => ({
281+
expectReply: true,
282+
input: `@${sutUsername} Telegram current session_status QA check. Call session_status with sessionKey set to current, then reply with the exact QA marker and resolved session key.`,
283+
expectedTextIncludes: ["QA-TELEGRAM-CURRENT-SESSION-OK", ":telegram:group:"],
284+
}),
285+
},
273286
{
274287
id: "telegram-mentioned-message-reply",
275288
title: "Telegram mentioned message gets a reply",
@@ -471,7 +484,7 @@ function detectMediaKinds(message: TelegramMessage) {
471484
}
472485

473486
function normalizeTelegramObservedMessage(update: TelegramUpdate): TelegramObservedMessage | null {
474-
const message = update.message;
487+
const message = update.message ?? update.edited_message;
475488
if (!message?.from?.id) {
476489
return null;
477490
}
@@ -608,7 +621,7 @@ async function flushTelegramUpdates(token: string) {
608621
{
609622
offset,
610623
timeout: 0,
611-
allowed_updates: ["message"],
624+
allowed_updates: ["message", "edited_message"],
612625
},
613626
15_000,
614627
);
@@ -653,10 +666,12 @@ async function waitForObservedMessage(params: {
653666
observedMessages: TelegramObservedMessage[];
654667
observationScenarioId: string;
655668
observationScenarioTitle: string;
669+
expectedTextIncludes?: string[];
656670
}) {
657671
const startedAt = Date.now();
658672
let offset = params.initialOffset;
659673
let lastPollingError: unknown;
674+
let lastExpectedMismatch: Error | undefined;
660675
while (Date.now() - startedAt < params.timeoutMs) {
661676
const remainingMs = Math.max(
662677
1_000,
@@ -671,7 +686,7 @@ async function waitForObservedMessage(params: {
671686
{
672687
offset,
673688
timeout: timeoutSeconds,
674-
allowed_updates: ["message"],
689+
allowed_updates: ["message", "edited_message"],
675690
},
676691
timeoutSeconds * 1000 + 5_000,
677692
);
@@ -703,10 +718,23 @@ async function waitForObservedMessage(params: {
703718
};
704719
params.observedMessages.push(observedMessage);
705720
if (matchedScenario) {
721+
try {
722+
assertTelegramScenarioReply({
723+
expectedTextIncludes: params.expectedTextIncludes,
724+
message: observedMessage,
725+
});
726+
} catch (error) {
727+
lastExpectedMismatch =
728+
error instanceof Error ? error : new Error(formatErrorMessage(error));
729+
continue;
730+
}
706731
return { message: observedMessage, nextOffset: offset, observedAtMs: batchObservedAtMs };
707732
}
708733
}
709734
}
735+
if (lastExpectedMismatch) {
736+
throw lastExpectedMismatch;
737+
}
710738
const timeoutMessage = `timed out after ${params.timeoutMs}ms waiting for Telegram message`;
711739
if (lastPollingError) {
712740
throw new Error(
@@ -1332,6 +1360,9 @@ export async function runTelegramQaLive(params: {
13321360
observedMessages,
13331361
observationScenarioId: scenario.id,
13341362
observationScenarioTitle: scenario.title,
1363+
expectedTextIncludes: scenarioRun.expectReply
1364+
? scenarioRun.expectedTextIncludes
1365+
: undefined,
13351366
predicate: (message) =>
13361367
matchesTelegramScenarioReply({
13371368
allowAnySutReply: scenarioRun.allowAnySutReply,

‎extensions/qa-lab/src/providers/mock-openai/server.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ const QA_TOOL_PROGRESS_PROMPT_RE = /tool progress qa check/i;
152152
const QA_GROUP_VISIBLE_REPLY_TOOL_PROMPT_RE = /qa group visible reply tool check/i;
153153
const QA_GROUP_MESSAGE_UNAVAILABLE_FALLBACK_PROMPT_RE =
154154
/qa group message unavailable fallback check/i;
155+
const QA_TELEGRAM_CURRENT_SESSION_STATUS_PROMPT_RE = /telegram current session_status qa check/i;
155156
const QA_SUBAGENT_DIRECT_FALLBACK_PROMPT_RE = /subagent direct fallback qa check/i;
156157
const QA_SUBAGENT_DIRECT_FALLBACK_WORKER_RE = /subagent direct fallback worker/i;
157158
const QA_SUBAGENT_DIRECT_FALLBACK_MARKER = "QA-SUBAGENT-DIRECT-FALLBACK-OK";
@@ -673,6 +674,28 @@ function hasToolErrorOutput(toolJson: Record<string, unknown> | null, toolOutput
673674
return /\b(?:error|failed|failure|not found|no such file|enoent)\b/i.test(toolOutput);
674675
}
675676

677+
function extractSessionStatusSessionKey(
678+
toolJson: Record<string, unknown> | null,
679+
toolOutput: string,
680+
) {
681+
const details = toolJson?.details;
682+
if (details && typeof details === "object") {
683+
const sessionKey = (details as { sessionKey?: unknown }).sessionKey;
684+
if (typeof sessionKey === "string" && sessionKey.trim()) {
685+
return sessionKey.trim();
686+
}
687+
}
688+
const topLevelSessionKey = toolJson?.sessionKey;
689+
if (typeof topLevelSessionKey === "string" && topLevelSessionKey.trim()) {
690+
return topLevelSessionKey.trim();
691+
}
692+
const statusLineSessionKey = /(?:^|\n)[^\n]*Session:\s*([^\s•\n]+)/u.exec(toolOutput)?.[1];
693+
if (statusLineSessionKey?.trim()) {
694+
return statusLineSessionKey.trim();
695+
}
696+
return /"sessionKey"\s*:\s*"([^"]+)"/.exec(toolOutput)?.[1]?.trim() ?? "";
697+
}
698+
676699
function isHeartbeatPrompt(text: string) {
677700
const trimmed = text.trim();
678701
if (!trimmed || /remember this fact/i.test(trimmed)) {
@@ -1349,6 +1372,17 @@ async function buildResponsesPayload(
13491372
exactMarkerDirective ?? exactReplyDirective ?? "QA-GROUP-FALLBACK-OK",
13501373
);
13511374
}
1375+
if (QA_TELEGRAM_CURRENT_SESSION_STATUS_PROMPT_RE.test(allInputText)) {
1376+
if (!toolOutput && hasDeclaredTool(body, "session_status")) {
1377+
return buildToolCallEventsWithArgs("session_status", { sessionKey: "current" });
1378+
}
1379+
const sessionKey = extractSessionStatusSessionKey(toolJson, toolOutput);
1380+
return buildAssistantEvents(
1381+
sessionKey.includes(":telegram:group:")
1382+
? `QA-TELEGRAM-CURRENT-SESSION-OK ${sessionKey}`
1383+
: `QA-TELEGRAM-CURRENT-SESSION-BAD ${sessionKey || "missing-session-key"}`,
1384+
);
1385+
}
13521386
if (/\bmarker\b/i.test(allInputText) && exactReplyDirective) {
13531387
return buildAssistantEvents(exactReplyDirective);
13541388
}

‎src/agents/openclaw-tools.session-status.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,29 @@ describe("session_status tool", () => {
645645
expect(details.statusText).toContain("🧠 Model:");
646646
});
647647

648+
it("resolves sandboxed sessionKey=current to the requester when no run session override exists", async () => {
649+
resetSessionStore({});
650+
651+
const tool = getSessionStatusTool("agent:main:telegram:group:-5096326138", {
652+
sandboxed: true,
653+
});
654+
655+
const result = await tool.execute("call-current-sandboxed-channel", {
656+
sessionKey: "current",
657+
});
658+
const details = result.details as { ok?: boolean; sessionKey?: string; statusText?: string };
659+
expect(details.ok).toBe(true);
660+
expect(details.sessionKey).toBe("agent:main:telegram:group:-5096326138");
661+
expect(details.statusText).toContain("OpenClaw");
662+
expect(details.statusText).toContain("🧠 Model:");
663+
expect(callGatewayMock).not.toHaveBeenCalledWith(
664+
expect.objectContaining({
665+
method: "sessions.resolve",
666+
params: expect.objectContaining({ key: "current" }),
667+
}),
668+
);
669+
});
670+
648671
it("resolves the default session_status lookup for a channel-plugin requester via implicit fallback", async () => {
649672
resetSessionStore({});
650673

‎src/agents/tools/session-status-tool.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,11 @@ export function createSessionStatusTool(opts?: {
364364
}),
365365
);
366366

367-
// Resolve "current" to the live run session key for lookup purposes (#76708).
368-
if (requestedKeyRaw === "current" && opts?.runSessionKey) {
369-
requestedKeyRaw = opts.runSessionKey;
367+
// Resolve semantic "current" to the live run session key for lookup purposes (#76708).
368+
// In sandboxed channel runs there may be no separate runSessionKey because the sandbox
369+
// key already is the live requester; avoid probing literal "current" through the gateway.
370+
if (requestedKeyRaw === "current" && (opts?.runSessionKey || opts?.sandboxed === true)) {
371+
requestedKeyRaw = opts.runSessionKey ?? effectiveRequesterKey;
370372
}
371373

372374
const currentSessionAlias = resolveCurrentSessionClientAlias({
@@ -508,7 +510,7 @@ export function createSessionStatusTool(opts?: {
508510

509511
if (!resolved) {
510512
const fallback = resolveImplicitCurrentSessionFallback({
511-
allowFallback: requestedKeyRaw === "current" || requestedKeyParam === undefined,
513+
allowFallback: isSemanticCurrentRequest || requestedKeyParam === undefined,
512514
storeScopedRequesterKey,
513515
});
514516
if (fallback) {

‎test/scripts/package-acceptance-workflow.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ describe("package artifact reuse", () => {
522522
expect(workflow).toContain("published_upgrade_survivor_scenarios: reported-issues");
523523
expect(workflow).toContain("telegram_mode: mock-openai");
524524
expect(workflow).toContain(
525-
"telegram_scenarios: telegram-help-command,telegram-commands-command,telegram-tools-compact-command,telegram-whoami-command,telegram-context-command,telegram-mention-gating",
525+
"telegram_scenarios: telegram-help-command,telegram-commands-command,telegram-tools-compact-command,telegram-whoami-command,telegram-context-command,telegram-current-session-status-tool,telegram-mention-gating",
526526
);
527527
expect(workflow).toContain("ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}");
528528
expect(workflow).toContain("ANTHROPIC_API_TOKEN: ${{ secrets.ANTHROPIC_API_TOKEN }}");

0 commit comments

Comments
 (0)