Repository navigation
Description
Summary
On 2026.5.26 (10ad3aa), /usage tokens / /usage full can be persisted for a Telegram session and model usage is recorded, but Telegram replies sent through the message tool path do not show the usage footer.
This appears to happen because Telegram message_tool_only source replies bypass the normal internal source-reply/final-payload path where responseUsage is appended. The same path is only used for webchat today.
Environment
- OpenClaw:
2026.5.26 (10ad3aa) - Install: npm global under
~/.local/lib/node_modules/openclaw - Runtime: gateway systemd user service
- Channel: Telegram DM
- Session key:
agent:main:telegram:direct:<telegram-user-id> - Session setting observed:
responseUsage: "tokens" - Recent session usage observed: nonzero
inputTokens/outputTokens
Expected behavior
After running /usage tokens or /usage full, Telegram agent replies should include the usage footer, e.g.
Usage: 404 in / 8 out
or the full footer with session information when full is selected.
Actual behavior
Telegram visible replies are delivered, but no usage footer is appended. The session store shows that the usage setting is saved and usage metadata exists, so this is not a command persistence issue.
Source-level findings
1. Telegram source replies do not use the internal source-reply sink
In the built package, message-action-runner-kdd1czMt.js has:
function shouldUseInternalSourceReplySink(input, params) {
return input.action === "send" &&
input.sourceReplyDeliveryMode === "message_tool_only" &&
normalizeOptionalLowercaseString(input.toolContext?.currentChannelProvider) === "webchat" &&
Boolean(input.sessionKey?.trim()) &&
!hasExplicitRouteParam(params);
}Because this is gated to webchat, Telegram current-source replies in message_tool_only mode fall through to the normal channel message action instead of becoming an internal source reply payload.
Local dry-run probe:
import { n as runMessageAction } from './dist/message-action-runner-kdd1czMt.js';
await runMessageAction({
cfg: { tools: { message: { actions: { send: true } } } },
action: 'send',
params: { message: 'OK', dryRun: true },
toolContext: { currentChannelProvider: 'webchat', currentChannelId: 'source-chat' },
sourceReplyDeliveryMode: 'message_tool_only',
sessionKey: 'agent:main:telegram:direct:8223071058',
agentId: 'main',
dryRun: true
});
// => handledBy: internal-source
await runMessageAction({
cfg: { tools: { message: { actions: { send: true } } } },
action: 'send',
params: { message: 'OK', dryRun: true },
toolContext: { currentChannelProvider: 'telegram', currentChannelId: 'source-chat' },
sourceReplyDeliveryMode: 'message_tool_only',
sessionKey: 'agent:main:telegram:direct:8223071058',
agentId: 'main',
dryRun: true
});
// => falls through into Telegram target resolution instead of internal-sourceThe second call failed locally with Unknown target "source-chat" for Telegram, which is useful evidence that Telegram did not take the internal source-reply sink path. In a real Telegram turn, the current channel id is resolvable, so the reply can still be sent, but it is sent before the normal reply decorator can append usage.
2. The usage footer is appended only in the normal final payload path
In agent-runner.runtime-BWGj8NfM.js:
const responseUsageMode = resolveResponseUsageMode(
activeSessionEntry?.responseUsage ??
(sessionKey ? activeSessionStore?.[sessionKey]?.responseUsage : void 0)
);
if (responseUsageMode !== "off" && hasNonzeroUsage(usage) && !preserveUserFacingSessionState) {
// builds responseUsageLine
}
...
if (responseUsageLine) finalPayloads = appendUsageLine(finalPayloads, responseUsageLine);So if the visible Telegram reply is delivered directly by message(action=send), the footer is not appended to that already-sent visible message.
3. Potential secondary issue: footer append replaces payload object
appendUsageLine currently creates a replacement object:
const next = {
...existing,
text: `${existingText}${separator}${line}`
};If the source reply has WeakMap metadata such as deliverDespiteSourceReplySuppression or sourceReplyTranscriptMirror, replacing the object without copying metadata can drop the metadata needed by message_tool_only delivery. This may matter if Telegram source replies are routed back through the internal sink.
Suggested fix direction
For message_tool_only turns, default current-source replies from any channel with current source context should probably use the internal source-reply sink, not only webchat, while preserving explicit-target sends as direct channel sends.
A narrow shape would be:
- In
shouldUseInternalSourceReplySink, replace thecurrentChannelProvider === "webchat"condition with a check for current source context (currentChannelProvider,currentChannelId,currentThreadTs, orcurrentMessageId). - Keep
!hasExplicitRouteParam(params)so explicittarget/to/channelsends still go through normal message delivery. - In
appendUsageLine, preserve reply payload metadata when replacing the payload object, e.g. viacopyReplyPayloadMetadata(existing, next).
Impact
/usage appears to work from the command reply and session state, but users on Telegram do not see the configured usage footer for Codex/OpenClaw bridge replies. This makes the command misleading and removes the intended per-reply token/cost visibility.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
WarrenJones commentedon May 27, 2026
clawsweeper commentedon May 27, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed May 27, 2026, 3:46 PM ET / 19:46 UTC.
Summary
Keep open: current main and the latest release still have the webchat-only internal source-reply gate, while the documented
/usagebehavior promises a per-response footer. The report is narrow, source-backed, and not superseded by the related issues in the provided context.Reproducibility: yes. Source inspection gives a high-confidence path: a Telegram
message_tool_onlysend with no explicit route does not satisfy the webchat-only internal sink condition, so it can be delivered beforeappendUsageLinedecorates final payloads; I did not run a live Telegram probe in this read-only pass.Next step
The bug is narrow and source-reproducible with clear implementation and test files; the provided context has a contributor offer to investigate but no linked fix PR.
Review details
Best possible solution:
Route implicit current-source
message_tool_onlysends for Telegram and other channels through the internal source-reply payload path, preserve explicit target sends as normal outbound delivery, copy reply payload metadata when appending usage, and cover Telegram DM/topic plus explicit-route exceptions in tests.Do we have a high-confidence way to reproduce the issue?
Yes. Source inspection gives a high-confidence path: a Telegram
message_tool_onlysend with no explicit route does not satisfy the webchat-only internal sink condition, so it can be delivered beforeappendUsageLinedecorates final payloads; I did not run a live Telegram probe in this read-only pass.Is this the best way to solve the issue?
Yes. The narrow maintainable direction is to generalize the implicit current-source sink beyond webchat, keep explicit-route sends on the outbound path, and preserve reply payload metadata when appending the usage footer.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
message.sendtargets and Telegram topic routing, because maintainer notes treat wrong-surface Telegram delivery as worse than a loud failure.Codex review notes: model gpt-5.5, reasoning high; reviewed against b789e71e57d9.
Label changes
Label changes:
P2: This is a confirmed, limited-blast-radius Telegram reply formatting bug in an existing documented/usagefeature.impact:message-loss: The visible Telegram reply is delivered without the configured usage footer, so part of the expected user-visible message content is suppressed.impact:session-state: The issue is specifically about persisted per-sessionresponseUsagestate not affecting the Telegram message-tool delivery path.issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.clawsweeper:source-repro: Current issue advisory state selects this label.clawsweeper:queueable-fix: Current issue advisory state selects this label.clawsweeper:fix-shape-clear: Current issue advisory state selects this label.Label justifications:
P2: This is a confirmed, limited-blast-radius Telegram reply formatting bug in an existing documented/usagefeature.impact:message-loss: The visible Telegram reply is delivered without the configured usage footer, so part of the expected user-visible message content is suppressed.impact:session-state: The issue is specifically about persisted per-sessionresponseUsagestate not affecting the Telegram message-tool delivery path.Evidence reviewed
Acceptance criteria:
What I checked:
shouldUseInternalSourceReplySinkrequirescurrentChannelProviderto normalize to the internal webchat channel, so Telegrammessage_tool_onlysends with no explicit route do not usehandledBy: internal-source. (src/infra/outbound/message-action-runner.ts:546, b789e71e57d9)runReplyAgentresolvesresponseUsagefrom session state and appends the formatted usage line tofinalPayloads, which does not affect a visible message already sent directly through the normal message tool channel path. (src/auto-reply/reply/agent-runner.ts:1883, b789e71e57d9)appendUsageLinereplaces the selected payload object with a spread copy and updated text, but it does not callcopyReplyPayloadMetadata, so source-reply metadata can be lost when this path starts handling message-tool source replies. (src/auto-reply/reply/agent-runner-usage-line.ts:54, b789e71e57d9)/usagebehavior: The token-use docs say/usage off|tokens|fullappends a per-response usage footer to every reply and persists per session asresponseUsage. Public docs:docs/reference/token-use.md. (docs/reference/token-use.md:76, b789e71e57d9)v2026.5.26tag points at10ad3aa16068baa84a1bd9ac4f7d42ae725cedb7, and the taggedmessage-action-runner.tskeeps the same webchat-only source-reply condition. (src/infra/outbound/message-action-runner.ts:546, 10ad3aa16068)11dfef201f81a0cdbcf5688962036a704e1c0615; usage reporting itself traces through151523f47b9b0ef9e2d63cbcdcc6621d91b60dfcand the helper split through3392558b42ab48cc219e9ae47bdb24b4d8fc11ac. (src/infra/outbound/message-action-runner.ts:546, 11dfef201f81)Likely related people:
shouldUseInternalSourceReplySink,responseUsageresolution, andappendUsageLinein this checkout points to commit11dfef201f81a0cdbcf5688962036a704e1c0615, and3392558b42ab48cc219e9ae47bdb24b4d8fc11acsplit the usage-line helper. (role: recent area contributor; confidence: high; commits: 11dfef201f81, 3392558b42ab; files:src/infra/outbound/message-action-runner.ts,src/auto-reply/reply/agent-runner.ts,src/auto-reply/reply/agent-runner-usage-line.ts)git log -S appendUsageLinetraces usage cost reporting to151523f47b9b0ef9e2d63cbcdcc6621d91b60dfc, andbb46b79d3c1479f194a90afcf3dd69a1858a7898recently refactored the OpenClaw agent runtime surface. (role: feature-history contributor; confidence: medium; commits: 151523f47b9b, bb46b79d3c14; files:src/auto-reply/reply/agent-runner.ts,src/auto-reply/reply/agent-runner-usage-line.ts)4360a59c6d3f705ae86aebf6fefa19d3de595b20changed/usagesession-entry behavior and tests, which is adjacent to the persistedresponseUsageside of this bug. (role: related usage-session contributor; confidence: medium; commits: 4360a59c6d3f; files:src/auto-reply/reply/commands-session.ts,src/auto-reply/reply/commands-session-usage.test.ts)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.steipete commentedon May 31, 2026
Fixed on
mainby8f941ea0acb.The fix routes implicit non-webchat
message_tool_onlycurrent-source sends through the internal source-reply sink, so Telegram tool-only replies stay on the final source-reply payload path where/usagedecoration runs. It also preserves reply payload metadata while appending usage text, so the transcript mirror stores the footer-bearing reply.Proof:
git diff --checkpassedUsage:footerClosing as fixed.