Repository navigation
fix(agents): persist cli transcript turns - #67490
Conversation
🔒 Aisle Security AnalysisWe found 3 potential security issue(s) in this PR:
1. 🟡 Unbounded CLI payload concatenation and transcript persistence can cause resource exhaustion (DoS)
Description
This is vulnerable to denial-of-service via oversized outputs:
Vulnerable code (unbounded concatenation): return (result.payloads ?? [])
.filter((payload) => !payload.isError && !payload.isReasoning)
.map((payload) => payload.text?.trim() ?? "")
.filter(Boolean)
.join("\n\n");Vulnerable code (unbounded persistence): sessionManager.appendMessage({
role: "assistant",
content: [{ type: "text", text: replyText }],
...
});RecommendationAdd hard limits before concatenation/persistence:
Example: const MAX_PAYLOADS = 50;
const MAX_REPLY_CHARS = 50_000;
function resolveCliTranscriptReplyText(result: EmbeddedPiRunResult): string {
const visibleText = result.meta.finalAssistantVisibleText?.trim();
if (visibleText) return visibleText.slice(0, MAX_REPLY_CHARS);
let out = "";
for (const payload of (result.payloads ?? [])) {
if (payload.isError || payload.isReasoning) continue;
const chunk = (payload.text ?? "").trim();
if (!chunk) continue;
if (out) out += "\n\n";
out += chunk;
if (out.length >= MAX_REPLY_CHARS) {
out = out.slice(0, MAX_REPLY_CHARS);
break;
}
}
return out;
}Also consider enforcing a maximum transcript file size or triggering compaction/rotation when exceeding a threshold. 2. 🟡 Untrusted CLI agent metadata persisted into transcripts (provider/model/usage spoofing)
Description
This creates a trust-boundary violation:
Vulnerable flow (new behavior):
const provider = params.result.meta.agentMeta?.provider?.trim() ?? "cli";
const model = params.result.meta.agentMeta?.model?.trim() ?? "default";
...
usage: params.result.meta.agentMeta?.usage,Additionally, numeric usage fields are not bounded here; very large values can cause extreme totals/costs in reports (integrity/DoS-on-reporting). RecommendationTreat CLI-returned metadata as untrusted and prevent it from becoming authoritative billing/audit data. Recommended fixes:
Example approach: function sanitizeTokenCount(v: unknown, max = 5_000_000): number | undefined {
if (typeof v !== "number" || !Number.isFinite(v)) return undefined;
const n = Math.floor(v);
if (n < 0) return 0;
if (n > max) return max;
return n;
}
const safeProvider = "cli"; // or derived from config/providerOverride
const safeModel = "default"; // or derived from modelOverride
const safeUsage = {
input: sanitizeTokenCount(meta?.usage?.input),
output: sanitizeTokenCount(meta?.usage?.output),
cacheRead: sanitizeTokenCount(meta?.usage?.cacheRead),
cacheWrite: sanitizeTokenCount(meta?.usage?.cacheWrite),
total: sanitizeTokenCount(meta?.usage?.total),
};
3. 🟡 CLI agent outputs and prompts persisted to session transcript without redaction (possible secret leakage)
DescriptionThe CLI-backed runner now persists both the user prompt ( This is risky because CLI providers commonly:
The persisted transcript is written to disk and an update event is emitted, which can make the full text available to other components (e.g., UI/session viewers). No explicit opt-in, allowlist, or secret redaction/scrubbing is applied to either the prompt or the reply text before persistence. Vulnerable flow:
Vulnerable code (persistence enabled for CLI runner): if (result.meta.executionTrace?.runner === "cli") {
sessionEntry = await attemptExecutionRuntime.persistCliTurnTranscript({
body,
result,
// ...
});
}Vulnerable code (no redaction before writing): if (promptText) {
sessionManager.appendMessage({ role: "user", content: promptText, timestamp: Date.now() });
}
if (replyText) {
sessionManager.appendMessage({
role: "assistant",
content: [{ type: "text", text: replyText }],
api: params.assistant.api,
provider: params.assistant.provider,
model: params.assistant.model,
usage: resolveTranscriptUsage(params.assistant.usage),
stopReason: "stop",
timestamp: Date.now(),
});
}Even though newly created session files are written with mode RecommendationAdd a safety gate and redaction before persisting CLI transcripts. Recommended mitigations (use both):
Example approach: function redactSecrets(text: string): string {
// Apply your existing secret redaction utilities or implement patterns for:
// - API keys/tokens
// - PEM blocks
// - AWS/GCP credentials
// - .env key=value lines
return scrubKnownSecrets(text);
}
if (cfg.persistCliTranscripts === true) {
const safePrompt = redactSecrets(body);
const safeReply = redactSecrets(resolveCliTranscriptReplyText(result));
await persistTextTurnTranscript({ ...params, body: safePrompt, finalText: safeReply, assistant: { ... } });
}Also consider:
Analyzed PR: #67490 at commit Last updated on: 2026-04-16T03:58:06Z |
Greptile SummaryThis PR adds persistence of successful CLI agent turn transcripts (user message + assistant reply) to the OpenClaw session file, and introduces a regression test covering the Confidence Score: 5/5Safe to merge; the only finding is a semantic inconsistency in the The core logic — persisting CLI transcript turns, the shared helper refactor, the try/catch guard, and the regression test — is all correct. The single P2 finding is a style/semantic issue on the src/agents/command/attempt-execution.ts — the Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/agents/command/attempt-execution.ts
Line: 207-213
Comment:
**`api` field set to provider name instead of wire-protocol format**
`api: provider` stores the CLI provider name (e.g. `"google-gemini-cli"`) in the `api` field of the transcript message. Every other transcript write in the codebase uses an API format string like `"openai-responses"` or `"anthropic-messages"`. `transport-message-transform.ts` uses `msg.api` for `isSameModel` checks, so a novel value here won't break anything functionally, but it is semantically inconsistent and may confuse tooling or UI code that interprets the field. Consider a constant like `"cli"` or mapping to the backing API format if known.
```suggestion
assistant: {
api: "cli",
provider,
model,
usage: params.result.meta.agentMeta?.usage,
},
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(agents): persist cli transcript turn..." | Re-trigger Greptile |
2d40d2f to
ee37797
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 68013eead4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
57cbcbb to
00d2af3
Compare
Persist successful CLI turns into the OpenClaw session transcript and add a regression test for google-gemini-cli.
Fixes #67469.