Repository navigation
fix(agents): harden OpenAI phase-aware visible text — suppress commentary partials, prevent empty final_answer fallback leak - #61481
100yenadmin wants to merge 224 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Hardens the embedded agent delivery path to prevent commentary leaks by making visible-text extraction phase-aware even when final_answer sanitizes to empty, and by fully suppressing commentary-phase partial streaming output.
Changes:
- Prevents
extractAssistantVisibleText()from falling back to commentary/legacy text when an explicitfinal_answerblock exists but sanitizes to empty. - Suppresses all
commentarypartial streaming emissions inhandleMessageUpdate, regardless of extracted visible text. - Adds/updates regression tests to cover both leak paths.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/agents/pi-embedded-utils.ts | Adds phase-presence detection and tightens visible-text fallback rules to avoid commentary/legacy leaks when final_answer exists but is empty. |
| src/agents/pi-embedded-utils.test.ts | Adds regression coverage for “empty final_answer must not fall back to legacy/unphased text”. |
| src/agents/pi-embedded-subscribe.handlers.messages.ts | Suppresses all commentary-phase partial updates by returning early on deliveryPhase === "commentary". |
| src/agents/pi-embedded-subscribe.handlers.messages.test.ts | Updates/extends tests to assert commentary partials are suppressed even when they contain visible text. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e13d80997f
ℹ️ 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".
Greptile SummaryThis PR hardens phase-aware visible text extraction and commentary suppression against two P1 leaks introduced in #59643. The changes are well-targeted and the accompanying regression tests are thorough.
Confidence Score: 4/5Safe to merge — the two targeted bug fixes are correct and well-covered by regression tests; no behavioral changes outside the two described leak paths. Score of 4 reflects correct, well-tested fixes for two specific P1 leaks with no unintended side effects. A point is held back because the changes touch streaming-state machine logic where ordering of side effects (deltaBuffer, blockBuffer accumulation) is subtle, and the new commentary guard is placed after a redundant
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/agents/pi-embedded-subscribe.handlers.messages.ts
Line: 332-336
Comment:
**Unnecessary work before early return**
`extractAssistantVisibleText` (which runs the full phase-aware extraction pipeline) is called on line 332 before the `deliveryPhase === "commentary"` guard on line 334 discards its result. For a purely-commentary partial this always produces `""`, so no incorrect behavior results, but the extraction work is wasted on every commentary-phase delta event.
Consider hoisting the delivery-phase check above the `phaseAwareVisibleText` computation:
```suggestion
const deliveryPhase = resolveAssistantDeliveryPhase(partialAssistant);
if (deliveryPhase === "commentary") {
return;
}
const phaseAwareVisibleText = coerceText(extractAssistantVisibleText(partialAssistant)).trim();
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix: harden phase-aware assistant visibi..." | Re-trigger Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5551d898ef
ℹ️ 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".
| entry?.sessionId | ||
| ? readSessionMessages(entry.sessionId, target.storePath, entry.sessionFile) | ||
| : [], | ||
| sanitizeChatHistoryMessages( |
There was a problem hiding this comment.
Import chat history sanitizers before using them
handleSessionHistoryHttpRequest now calls sanitizeChatHistoryMessages(...) in both the initial history load and SSE update path, but this module never imports that symbol (or DEFAULT_CHAT_HISTORY_TEXT_MAX_CHARS). As written, the first /sessions/:key/history request will hit this call and throw a ReferenceError, which breaks both REST and SSE history responses at runtime.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This was stale review state. Neither sanitizeChatHistoryMessages nor DEFAULT_CHAT_HISTORY_TEXT_MAX_CHARS is referenced in sessions-history-http.ts in the current branch state — the code that used them was removed. Verified no ReferenceError risk.
There was a problem hiding this comment.
Resolved — these symbols are no longer referenced in sessions-history-http.ts in the current branch state. The code that used them was removed.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f1fd584757
ℹ️ 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 sanitized = sanitizeChatHistoryMessages([nextMessage], effectiveMaxChars); | ||
| if (sanitized.length === 0) { | ||
| return; |
There was a problem hiding this comment.
Sanitize bounded SSE history refreshes before emitting
This block sanitizes only the unbounded message fast path, but when limit or cursor is set the code falls through to paginateSessionMessages(readSessionMessages(...)) and emits that history payload without sanitizeChatHistoryMessages. As a result, /sessions/:key/history SSE clients using bounded windows can receive NO_REPLY or unsanitized transcript text in subsequent updates even though the initial history was sanitized, causing inconsistent and potentially user-visible leakage of filtered content.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed — bounded SSE history refreshes now apply sanitizeChatHistoryMessages before pagination, consistent with the unbounded path.
There was a problem hiding this comment.
Fixed — rawTranscriptSeq now initialized from raw transcript's last __openclaw.seq value. Bounded SSE paths now sanitized.
|
Addressed review feedback in commits Copilot: extractAssistantVisibleText double-scan → Fixed. Refactored Copilot + Greptile: unnecessary work before early return → Fixed. Codex: late phase metadata concern → Verified safe. The suppression only fires on Codex P1 on missing imports (sessions-history-http.ts, chat-history-text.ts) → These comments appear to be against stale diff state. The imports exist on both branches. CI failures ( |
|
Final review pass — all 9 items addressed:
All items either have code fixes or clear explanations. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8adeb3a532
ℹ️ 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".
|
Closing this PR because it looks dirty (too many unrelated or unexpected changes). This usually happens when a branch picks up unrelated commits or a merge went sideways. Please recreate the PR from a clean branch. |
|
Closing this PR because it looks dirty (too many unrelated or unexpected changes). This usually happens when a branch picks up unrelated commits or a merge went sideways. Please recreate the PR from a clean branch. |
|
Too many files changed for review. ( |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a585b59d92
ℹ️ 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".
| if (deliveryPhase === "commentary") { | ||
| return; |
There was a problem hiding this comment.
Do not drop final-answer deltas when phase metadata lags
This unconditional deliveryPhase === "commentary" return can suppress legitimate final-answer streaming text in mixed-phase OpenAI Responses output. Fresh evidence in this commit is that src/agents/openai-transport-stream.ts only assigns textSignature.phase on response.output_item.done (lines 457-460), so while a final block is still emitting text_delta it may be unsigned while a prior commentary block is already signed; resolveAssistantMessagePhase(...) then resolves the partial as commentary and this branch drops the update. The result is delayed or missing final text for users (e.g., if the run is interrupted before text_end).
Useful? React with 👍 / 👎.
Summary
final_answerblock never falls back to commentary or legacy unphased text when it sanitizes to emptyContext
This hardens the merged #59643 behavior against two P1 leaks:
Related issues / bug family
Parent / sibling PRs
Remaining follow-ups from the same adversarial review
Related open PRs
Testing