Repository navigation
feat(codex-cli): prefer output-last-message artifacts - #66081
Rohan5commit wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the direct codex-cli runner to prefer Codex’s dedicated --output-last-message artifact as the source of truth for the final assistant reply, while keeping existing stdout parsing as a fallback for telemetry and compatibility.
Changes:
- Add temp
--output-last-messageartifact wiring forcodex-cliruns and prefer artifact text when present. - Extend JSONL parsing to extract Codex message text from
contentrecords. - Add unit tests covering artifact-vs-stdout precedence and stdout fallback.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/agents/cli-runner/execute.ts | Create/read/cleanup Codex last-message artifact and prefer it over parsed stdout text. |
| src/agents/cli-runner.spawn.test.ts | Add tests asserting artifact precedence and stdout fallback, plus artifact cleanup. |
| src/agents/cli-output.ts | Teach parseCliJsonl to extract Codex message text from content/message-like fields. |
| src/agents/cli-output.test.ts | Add coverage for Codex JSONL content-record text extraction. |
| const codexLastMessageArtifact = isCodexCliBackend(context) | ||
| ? await prepareCodexLastMessageArtifact({ | ||
| runId: params.runId, | ||
| }) | ||
| : undefined; | ||
| if (codexLastMessageArtifact) { | ||
| args.push("--output-last-message", codexLastMessageArtifact.filePath); | ||
| } |
Greptile SummaryThis PR adds Codex-specific One concern worth resolving before merge: the new text-extraction fallback added to Confidence Score: 4/5Safe to merge after addressing the unguarded parseCliJsonl fallback; the artifact flow itself is well-implemented. One P1 finding: the new fallback text extraction in parseCliJsonl is not scoped to codex-cli, contradicting the PR's stated scope boundary and creating a latent correctness risk for other JSONL backends. The artifact management in execute.ts is clean and well-tested. src/agents/cli-output.ts — the new fallback block needs a providerId === "codex-cli" guard Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/agents/cli-output.ts
Line: 486-493
Comment:
**New fallback text extraction applies to all JSONL backends, not just `codex-cli`**
The PR description explicitly states "other CLI backends still use their existing stdout/json/jsonl parsing paths," but this new fallback block runs for every provider whose output mode is `jsonl`. Any JSONL-configured backend that emits records with top-level `result`, `response`, `content`, or `message` fields for non-final-text purposes (e.g. structured diagnostics, tool results, operational metadata) will have those values incorrectly appended to the reply text.
`parseClaudeCliJsonlResult` provides an early return for Claude CLI's `{ type: "result" }` records, so the most common existing backend is safe. But this is fragile going forward — a future JSONL backend that emits `{ type: "tool-result", result: "..." }` or `{ type: "status", message: "Session started" }` would have those strings silently folded into the final reply.
Guard the new block with the `providerId` that is already in scope:
```suggestion
if (providerId === "codex-cli") {
const messageText =
collectCliText(parsed.message) ||
collectCliText(parsed.content) ||
collectCliText(parsed.result) ||
collectCliText(parsed.response);
if (messageText.trim()) {
texts.push(messageText.trim());
}
}
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/agents/cli-runner/execute.ts
Line: 272-279
Comment:
**`--output-last-message` path is not masked in verbose log output**
`buildCliLogArgs` masks known sensitive args (`systemPromptArg`, `sessionArg`, `modelArg`, `imageArg`) but has no handler for `--output-last-message`. The temp file path will appear in verbose CLI arg logs (`cli argv: codex --output-last-message /tmp/openclaw-codex-last-message-xxx/run-xxx.txt ...`). The path itself is not sensitive, but it exposes the temp dir structure and naming convention. Adding a masking case (or at least truncating the path) would be consistent with the existing pattern for other injected paths.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "feat(codex-cli): prefer output-last-mess..." | Re-trigger Greptile |
| const messageText = | ||
| collectCliText(parsed.message) || | ||
| collectCliText(parsed.content) || | ||
| collectCliText(parsed.result) || | ||
| collectCliText(parsed.response); | ||
| if (messageText.trim()) { | ||
| texts.push(messageText.trim()); | ||
| } |
There was a problem hiding this comment.
New fallback text extraction applies to all JSONL backends, not just
codex-cli
The PR description explicitly states "other CLI backends still use their existing stdout/json/jsonl parsing paths," but this new fallback block runs for every provider whose output mode is jsonl. Any JSONL-configured backend that emits records with top-level result, response, content, or message fields for non-final-text purposes (e.g. structured diagnostics, tool results, operational metadata) will have those values incorrectly appended to the reply text.
parseClaudeCliJsonlResult provides an early return for Claude CLI's { type: "result" } records, so the most common existing backend is safe. But this is fragile going forward — a future JSONL backend that emits { type: "tool-result", result: "..." } or { type: "status", message: "Session started" } would have those strings silently folded into the final reply.
Guard the new block with the providerId that is already in scope:
| const messageText = | |
| collectCliText(parsed.message) || | |
| collectCliText(parsed.content) || | |
| collectCliText(parsed.result) || | |
| collectCliText(parsed.response); | |
| if (messageText.trim()) { | |
| texts.push(messageText.trim()); | |
| } | |
| if (providerId === "codex-cli") { | |
| const messageText = | |
| collectCliText(parsed.message) || | |
| collectCliText(parsed.content) || | |
| collectCliText(parsed.result) || | |
| collectCliText(parsed.response); | |
| if (messageText.trim()) { | |
| texts.push(messageText.trim()); | |
| } | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/cli-output.ts
Line: 486-493
Comment:
**New fallback text extraction applies to all JSONL backends, not just `codex-cli`**
The PR description explicitly states "other CLI backends still use their existing stdout/json/jsonl parsing paths," but this new fallback block runs for every provider whose output mode is `jsonl`. Any JSONL-configured backend that emits records with top-level `result`, `response`, `content`, or `message` fields for non-final-text purposes (e.g. structured diagnostics, tool results, operational metadata) will have those values incorrectly appended to the reply text.
`parseClaudeCliJsonlResult` provides an early return for Claude CLI's `{ type: "result" }` records, so the most common existing backend is safe. But this is fragile going forward — a future JSONL backend that emits `{ type: "tool-result", result: "..." }` or `{ type: "status", message: "Session started" }` would have those strings silently folded into the final reply.
Guard the new block with the `providerId` that is already in scope:
```suggestion
if (providerId === "codex-cli") {
const messageText =
collectCliText(parsed.message) ||
collectCliText(parsed.content) ||
collectCliText(parsed.result) ||
collectCliText(parsed.response);
if (messageText.trim()) {
texts.push(messageText.trim());
}
}
```
How can I resolve this? If you propose a fix, please make it concise.| const codexLastMessageArtifact = isCodexCliBackend(context) | ||
| ? await prepareCodexLastMessageArtifact({ | ||
| runId: params.runId, | ||
| }) | ||
| : undefined; | ||
| if (codexLastMessageArtifact) { | ||
| args.push("--output-last-message", codexLastMessageArtifact.filePath); | ||
| } |
There was a problem hiding this comment.
--output-last-message path is not masked in verbose log output
buildCliLogArgs masks known sensitive args (systemPromptArg, sessionArg, modelArg, imageArg) but has no handler for --output-last-message. The temp file path will appear in verbose CLI arg logs (cli argv: codex --output-last-message /tmp/openclaw-codex-last-message-xxx/run-xxx.txt ...). The path itself is not sensitive, but it exposes the temp dir structure and naming convention. Adding a masking case (or at least truncating the path) would be consistent with the existing pattern for other injected paths.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/cli-runner/execute.ts
Line: 272-279
Comment:
**`--output-last-message` path is not masked in verbose log output**
`buildCliLogArgs` masks known sensitive args (`systemPromptArg`, `sessionArg`, `modelArg`, `imageArg`) but has no handler for `--output-last-message`. The temp file path will appear in verbose CLI arg logs (`cli argv: codex --output-last-message /tmp/openclaw-codex-last-message-xxx/run-xxx.txt ...`). The path itself is not sensitive, but it exposes the temp dir structure and naming convention. Adding a masking case (or at least truncating the path) would be consistent with the existing pattern for other injected paths.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9aea402bc3
ℹ️ 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".
| const codexLastMessageArtifact = isCodexCliBackend(context) | ||
| ? await prepareCodexLastMessageArtifact({ | ||
| runId: params.runId, | ||
| }) |
There was a problem hiding this comment.
Create Codex artifact inside the guarded cleanup block
In executePreparedCliRun, prepareCodexLastMessageArtifact is awaited before the outer try/finally begins, so an fs.mkdtemp failure (for example ENOSPC or temp-dir permission issues) aborts the function before cleanup runs for already-created resources like systemPromptFile, prompt images, and the Claude skills plugin handle. This is a regression from the previous flow because it introduces a new pre-try I/O failure point that can leave temp files behind (including system-prompt artifacts) on error paths.
Useful? React with 👍 / 👎.
|
Thanks for the context here. I did a careful shell check against current This stale PR should close because current main and the latest release moved the supported Codex path away from the bundled direct So I’m closing this older PR as already covered on Review detailsBest possible solution: Keep the shipped Codex app-server/plugin-owned implementation and close this stale core special-case branch; handle any remaining explicit custom CLI backend need as a new plugin-owned proposal with current-main config proof. Do we have a high-confidence way to reproduce the issue? Not applicable as a feature PR. Current-main and release source inspection is enough to verify the supported Codex path no longer uses a bundled direct codex-cli backend, and the remaining Codex CLI resume helper already reads the last-message artifact. Is this the best way to solve the issue? No. The PR was a plausible fix for the old direct codex-cli runner, but current main’s Codex app-server/plugin-owned route is the better owner boundary; any custom backend artifact mode should be proposed against that current design. Security review: Security review cleared: The diff adds temp-file handling and command arguments but no new dependency, workflow, permission, secret, network, or package-publishing surface; the remaining concern is compatibility, not a concrete security defect. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against c78f9376d929; fix evidence: release v2026.6.6, commit a0f35574d047. |
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
|
This pull request has been automatically marked as stale due to inactivity. |
|
ClawSweeper applied the proposed close for this PR.
|
Summary
codex-cliruns still finalize the user-visible reply from stdout even though Codex can write a dedicated final-message artifact--output-last-messageoutputcodex-cliruns now allocate a temp--output-last-messagefile, prefer that artifact when it contains text, and keep stdout parsing as the fallback pathChange Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause (if applicable)
codex-clirunner only treated stdout parsing as the final reply source even though Codex already exposes a more stable final-message artifact contract--output-last-message, but OpenClaw was not wiring that contract into thecodex-clibackend pathRegression Test Plan (if applicable)
src/agents/cli-runner.spawn.test.ts,src/agents/cli-output.test.ts--output-last-messagefile, OpenClaw should prefer the artifact when it is non-empty and fall back to parsed stdout when the artifact is emptyUser-visible / Behavior Changes
codex-clireplies now finalize from Codex's explicit final-message artifact when available, which makes delegated Codex runs less dependent on stdout formatting details.Diagram (if applicable)
Security Impact (required)
No)No)No)Yes)No)Yes, explain risk + mitigation:--output-last-messageflag plus a temp file under OpenClaw's preferred temp dir. The file is per-run, read back locally, and deleted in cleanup even when parsing falls back to stdout.Repro + Verification
Environment
codex-cli/gpt-5.4codex-clibackend with--jsonSteps
codex-cliexecution through the CLI runner.Expected
Actual
Evidence
Human Verification (required)
src/agents/cli-output.test.ts,src/agents/cli-runner.spawn.test.ts, andsrc/agents/cli-runner.reliability.test.tspnpm check/pnpm testlanes and a live end-to-end Codex CLI run against the actual binary in this branchReview Conversations
Compatibility / Migration
Yes)No)No)Risks and Mitigations
finally, and the unit test asserts the artifact path is removed after successparseCliJsonlnow extracts text from Codex message content records, and the fallback path is covered by a dedicated unit testAI-assisted: Yes (Codex). Testing: targeted vitest coverage listed above. I attempted
codex review --base origin/main, but the local Codex CLI is currently rate-limited.