Repository navigation
fix(codex): emit app-server final chat events - #71293
Conversation
🔒 Aisle Security AnalysisWe found 4 potential security issue(s) in this PR:
1. 🟠 Global agent event emission may broadcast Codex run events without session scoping (cross-session information disclosure)
Description
Key points:
Vulnerable code (emits global event with optional sessionKey): emitGlobalAgentEvent({
runId: params.runId,
stream: event.stream,
data: event.data,
...(params.sessionKey ? { sessionKey: params.sessionKey } : {}),
});RecommendationEnsure global agent events are always scoped to an authorized session (or never broadcast to the gateway when scoping is unknown). Recommended fixes (pick one, depending on desired behavior):
if (params.sessionKey) {
emitGlobalAgentEvent({
runId: params.runId,
sessionKey: params.sessionKey,
stream: event.stream,
data: event.data,
});
}
registerAgentRunContext(params.runId, { sessionKey: params.sessionKey });
emitGlobalAgentEvent({ runId: params.runId, stream: event.stream, data: event.data });
Any approach should guarantee that events cannot be delivered cross-session when 2. 🟠 Untrusted plugins can spoof/broadcast agent events via exported emitAgentEvent
Description
Because
Vulnerable code paths:
Vulnerable code: export { emitAgentEvent } from "../infra/agent-events.js";
export function emitAgentEvent(event: Omit<AgentEventPayload, "seq" | "ts">) {
// ...
notifyListeners(state.listeners, enriched);
}RecommendationDo not expose low-level global event emitters to plugins, or enforce strict authorization at the emission boundary. Recommended fixes (choose one):
Example (capability-based handle): // when starting a run
const emitter = createAgentEventEmitter({ runId, sessionKey });
// plugin only receives emitter, not global emitAgentEvent
emitter.emit({ stream: "assistant", data: { text: "..." } });
// implementation
export function createAgentEventEmitter(bound: { runId: string; sessionKey?: string }) {
return {
emit(evt: { stream: AgentEventStream; data: Record<string, unknown> }) {
emitAgentEvent({ runId: bound.runId, sessionKey: bound.sessionKey, ...evt });
},
};
}Additionally, consider rejecting caller-supplied 3. 🟡 Unsanitized terminal assistant text emitted to clients bypassing transcript hooks
Description
This introduces a sensitive-data/content exposure risk because:
Vulnerable code: const terminalAssistantText = collectTerminalAssistantText(result);
if (terminalAssistantText && !finalAborted && !finalPromptError) {
emitCodexAppServerEvent(params, {
stream: "assistant",
data: { text: terminalAssistantText },
});
}Impact depends on deployments/plugins, but in systems relying on RecommendationApply the same sanitization/redaction policy to emitted terminal assistant text that you apply before persistence. Options:
import { runAgentHarnessBeforeMessageWriteHook } from "openclaw/plugin-sdk/agent-harness-runtime";
const terminalAssistantText = collectTerminalAssistantText(result);
if (terminalAssistantText && !finalAborted && !finalPromptError) {
const sanitized = runAgentHarnessBeforeMessageWriteHook({
message: { role: "assistant", content: terminalAssistantText, timestamp: Date.now() },
agentId: sessionAgentId,
sessionKey: sandboxSessionKey,
});
if (sanitized && typeof sanitized.content === "string" && sanitized.content.trim()) {
emitCodexAppServerEvent(params, { stream: "assistant", data: { text: sanitized.content } });
}
}
Also consider clearly separating UI-safe text from internal/debug streams to prevent accidental client display. 4. 🟡 Potential sensitive information disclosure via logging raw Error objects in debug logs
Description
Because
Affected code paths were introduced/expanded in this change:
Vulnerable code (examples): embeddedAgentLog.debug("codex app-server agent event handler rejected", { error });
embeddedAgentLog.debug("codex app-server agent event handler threw", { error });RecommendationAvoid logging raw error objects from untrusted/extension callbacks. Log a sanitized string instead (and optionally a truncated stack) with redaction. Example fix: import { formatErrorMessage } from "openclaw/plugin-sdk/agent-harness-runtime";
import { redactSensitiveText } from "../../../src/logging/redact"; // or expose a helper
} catch (err) {
const msg = redactSensitiveText(formatErrorMessage(err));
embeddedAgentLog.debug("codex app-server agent event handler threw", { error: msg });
}Additionally, consider updating the logger transport to redact sensitive strings in structured metadata (including Analyzed PR: #71293 at commit Last updated on: 2026-04-25T00:12:02Z |
PR SummaryMedium Risk Overview Projected Codex app-server item/plan/compaction/etc events are also forwarded onto the global agent-event bus (with guarded error handling so consumer failures don’t break projection), and tests were updated to reset/verify global event state and ensure the gateway no longer relies on a message-less Reviewed by Cursor Bugbot for commit 9e39e28. Bugbot is set up for automated code reviews on this repo. Configure here. |
Greptile SummaryThis PR fixes Codex app-server runs so they emit the same native agent-event lifecycle/assistant events the gateway chat stream already understands, letting the Control UI/WebChat spinner resolve without needing a transcript-reload fallback. The implementation is well-structured: Confidence Score: 5/5Safe to merge — no P0/P1 issues; logic is correct and test coverage is thorough. All findings are P2 or lower. The emitLifecycleTerminal/lifecycleStarted guard logic is correct, the dual-try-catch pattern in both run-attempt.ts and event-projector.ts is defensive, and the finally safety net properly uses the idempotency guard to avoid double-emission. No files require special attention. Reviews (1): Last reviewed commit: "fix(codex): emit app-server final chat e..." | Re-trigger Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 07e138312a
ℹ️ 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".
| emitGlobalAgentEvent({ | ||
| runId: params.runId, | ||
| stream: event.stream, | ||
| data: event.data, | ||
| ...(params.sessionKey ? { sessionKey: params.sessionKey } : {}), |
There was a problem hiding this comment.
Stop double-emitting codex_app_server events
emitCodexAppServerEvent now publishes every event to the global bus, but the upstream onAgentEvent callbacks in src/auto-reply/reply/agent-runner-execution.ts:1142, src/auto-reply/reply/followup-runner.ts:338, and src/agents/agent-command.ts:921 still re-emit codex_app_server.* events. For Codex runs, each codex_app_server lifecycle/tool/item/hook event is therefore broadcast twice (with different seq values), which can duplicate operator/UI updates and inflate event-driven counters.
Useful? React with 👍 / 👎.
07e1383 to
b31beb5
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b31beb5f4e145faecf292423d52317ab2083ea9d. Configure here.
b31beb5 to
a34b935
Compare
…ut terminal lifecycle Some harnesses (e.g. native Codex app-server path for codex/gpt-5.x) record the final assistant answer and update the transcript, but do not emit a terminal assistant event + lifecycle:end onto the gateway chat event bus. chat.send then waits forever for a finalization path that never arrives, leaving the TUI spinning on 'hobnobbing...' until the user exits and reopens (at which point the already-stored answer is visible). This adds a conservative fallback in chat.send: after the user transcript update for an agent run, emit a message-less chat.final broadcast as a UI resync point. The transcript already contains the assistant message; the client reloads history and goes idle instead of spinning. Regression coverage: chat.directive-tags.test.ts now asserts the message-less final event fires on the agent-run path. Authored primarily by OpenAI Codex CLI (gpt-5.5) during a live debugging session with Parker. Verified end-to-end: Lēsa now streams cleanly on codex/gpt-5.5 in the TUI. Co-Authored-By: Parker Todd Brooks <[email protected]> Co-Authored-By: Lēsa <[email protected]> Co-Authored-By: OpenAI Codex CLI (GPT-5.5) <[email protected]> Co-Authored-By: Claude Opus 4.7 <[email protected]>
Co-authored-by: Lēsa <[email protected]>
d17d2a9 to
9e39e28
Compare
Fix live webchat finalization for Codex app-server runs by emitting standard assistant and lifecycle completion events on the global agent event bus, instead of relying on a message-less chat.final fallback. Replaces openclaw#70815. Closes openclaw#71183. Co-authored-by: Lēsa <[email protected]>
Fix live webchat finalization for Codex app-server runs by emitting standard assistant and lifecycle completion events on the global agent event bus, instead of relying on a message-less chat.final fallback. Replaces openclaw#70815. Closes openclaw#71183. Co-authored-by: Lēsa <[email protected]>
Fix live webchat finalization for Codex app-server runs by emitting standard assistant and lifecycle completion events on the global agent event bus, instead of relying on a message-less chat.final fallback. Replaces openclaw#70815. Closes openclaw#71183. Co-authored-by: Lēsa <[email protected]>
Fix live webchat finalization for Codex app-server runs by emitting standard assistant and lifecycle completion events on the global agent event bus, instead of relying on a message-less chat.final fallback. Replaces openclaw#70815. Closes openclaw#71183. Co-authored-by: Lēsa <[email protected]>
Fix live webchat finalization for Codex app-server runs by emitting standard assistant and lifecycle completion events on the global agent event bus, instead of relying on a message-less chat.final fallback. Replaces openclaw#70815. Closes openclaw#71183. Co-authored-by: Lēsa <[email protected]>
Fix live webchat finalization for Codex app-server runs by emitting standard assistant and lifecycle completion events on the global agent event bus, instead of relying on a message-less chat.final fallback. Replaces openclaw#70815. Closes openclaw#71183. Co-authored-by: Lēsa <[email protected]>
Fix live webchat finalization for Codex app-server runs by emitting standard assistant and lifecycle completion events on the global agent event bus, instead of relying on a message-less chat.final fallback. Replaces openclaw#70815. Closes openclaw#71183. Co-authored-by: Lēsa <[email protected]>
Fix live webchat finalization for Codex app-server runs by emitting standard assistant and lifecycle completion events on the global agent event bus, instead of relying on a message-less chat.final fallback. Replaces openclaw#70815. Closes openclaw#71183. Co-authored-by: Lēsa <[email protected]>

Summary
Replaces #70815 with the root fix instead of a message-less
chat.finalfallback.Codex app-server runs now emit the same terminal agent-event shape the gateway chat stream already understands:
startafter the Codex turn is acceptedassistanttext after transcript mirroringendorerrorexactly onceThis lets Control UI/WebChat receive the normal final signal and leave the spinner without relying on a transcript reload fallback.
Closes #71183.
Validation
pnpm test extensions/codex/src/app-server/run-attempt.test.tspnpm test extensions/codex/src/app-server/event-projector.test.tspnpm test src/gateway/server-methods/chat.directive-tags.test.tspnpm exec oxfmt --check --threads=1 CHANGELOG.md extensions/codex/src/app-server/event-projector.test.ts extensions/codex/src/app-server/event-projector.ts extensions/codex/src/app-server/run-attempt.test.ts extensions/codex/src/app-server/run-attempt.ts src/gateway/server-methods/chat.directive-tags.test.ts src/gateway/server-methods/chat.ts src/plugin-sdk/agent-harness-runtime.tspnpm check:changedpasses typecheck/lint/changed tests; fails only in unrelated Slack shardextensions/slack/src/monitor.tool-result.test.tswith existingapp.use is not a function/Slack message handler not registeredfailures.pnpm test extensions/slack/src/monitor.tool-result.test.ts; same unrelated Slack failure.Co-authored-by: Lēsa [email protected]