Repository navigation
Conversation
Greptile SummaryThis PR adopts phase-aware assistant text extraction across three surfaces (
Confidence Score: 3/5Not safe to merge as-is: the unbounded SSE fast path still leaks commentary/NO_REPLY messages, which is the core problem this PR aims to fix. Three of the four targeted surfaces are correctly fixed and well-tested. The remaining SSE fast-path gap is a genuine logic bug that leaves the PR's stated goal incomplete for the most common streaming consumer. The fix is small and mechanical but should include a regression test. src/gateway/sessions-history-http.ts (lines 269–282) and src/agents/tools/chat-history-text.ts (line 1)
|
There was a problem hiding this comment.
Pull request overview
This PR follows up on prior phase-separation fixes by updating remaining “phase-blind” assistant text extraction surfaces so user-visible output prefers final_answer over commentary, and by aligning the direct REST session history endpoint with the gateway’s chat.history sanitization behavior.
Changes:
- Make assistant text extraction phase-aware in sessions helper text extraction (
extractAssistantText) and the TUI formatter path. - Apply gateway
chat.historysanitization to the direct REST session history endpoint. - Add regression tests for mixed
commentary+final_answerhandling across sessions helper extraction, TUI extraction, and REST history.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/agents/tools/chat-history-text.ts | Switches sessions helper assistant text extraction to use phase-aware visible-text extraction. |
| src/agents/tools/sessions.test.ts | Adds regression coverage ensuring final_answer is preferred over commentary in helper extraction. |
| src/tui/tui-formatters.ts | Updates TUI message content extraction to prefer phase-aware assistant visible text. |
| src/tui/tui-formatters.test.ts | Adds regression test ensuring TUI prefers final_answer over commentary. |
| src/gateway/sessions-history-http.ts | Reuses chat.history sanitization logic for REST session history responses. |
| src/gateway/sessions-history-http.test.ts | Adds REST history regression test for sanitization and mixed-phase content. |
| src/gateway/server-methods/chat.ts | Exports sanitizeChatHistoryMessages() for reuse by REST history. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 422c5d0c72
ℹ️ 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".
|
Follow-up on review feedback:
CI note: the current red checks are still the pre-existing base/main failures we were already tracking ( Cross-references added to the PR body: #61474 #61475 #61476 #61477 #61478 and parent links to #59643 / #59150. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/gateway/sessions-history-http.ts:292
- In SSE mode, only the repaginated
historyrefresh path is sanitized here. The unbounded fast-path that emits a singlemessageevent whenlimit/cursorare undefined still sendsupdate.messagewithout passing throughsanitizeChatHistoryMessages(or envelope stripping), soNO_REPLY/commentary-only rows can still leak mid-stream. If the intention is to sanitize incremental updates too, apply the same sanitization before emittingevent: messagein that branch.
sentHistory = paginateSessionMessages(
sanitizeChatHistoryMessages(
readSessionMessages(entry.sessionId, target.storePath, entry.sessionFile),
effectiveMaxChars,
),
limit,
cursor,
);
sseWrite(res, "history", {
|
Review feedback status: Greptile + Copilot: dead Copilot: concatenation semantics change → Acknowledged. Copilot: paginateSessionMessages seq assumption → Fixed in commit Copilot: stripEnvelopeFromMessages not shared → Good catch. The current PR shares Codex P1: SSE fast-path unsanitized → Fixed in commit Codex P1: missing imports → Verified present on this branch. Imports exist at line 1 ( CI failures are pre-existing base/main issues — same as documented in #59643. |
|
Final review response — all items addressed:
No code changes needed on this pass — all items are either already addressed in existing commits or correctly scoped as follow-up. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eeefc0469b
ℹ️ 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".
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/infra/heartbeat-runner.ts:55
- This PR is scoped/title’d around phase-aware assistant text extraction and history sanitization, but this hunk changes heartbeat session routing (new
isSubagentSessionKeyguards) in an unrelated subsystem. This increases review/rollback risk and makes the PR behaviorally broader than described. Consider moving the heartbeat routing change into its own PR (or explicitly documenting it in the PR description if it must stay here).
import {
isSubagentSessionKey,
normalizeAgentId,
parseAgentSessionKey,
resolveAgentIdFromSessionKey,
toAgentStoreSessionKey,
} from "../routing/session-key.js";
import { defaultRuntime, type RuntimeEnv } from "../runtime.js";
import { escapeRegExp } from "../utils.js";
import { formatErrorMessage, hasErrnoCode } from "./errors.js";
import { isWithinActiveHours } from "./heartbeat-active-hours.js";
import {
- Pagination now searches by message seq value instead of using cursorSeq-1 as array index. After sanitization drops rows, seqs become sparse and positional indexing breaks cursor traversal. - SSE unbounded fast path now sanitizes incremental messages through sanitizeChatHistoryMessages before emitting, so NO_REPLY and directive messages are suppressed consistently with initial history.
|
Landed via temp rebase onto
Thanks @100yenadmin! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8e27b48596
ℹ️ 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 (typeof content === "string") { | ||
| return sanitizeRenderableText(content).trim(); | ||
| } |
There was a problem hiding this comment.
Route assistant string content through phase filter
extractContentFromMessage still returns assistant content strings directly, so records shaped like { role: "assistant", phase: "commentary", content: "..." } bypass phase-aware filtering and render commentary text. This helper is consumed by TuiStreamAssembler for streamed/final display, so any provider path that emits message-level phase metadata on string content will still leak hidden commentary in the TUI despite this patch.
Useful? React with 👍 / 👎.
What this fixes (plain English)
Several places in the codebase that display assistant text were not aware of the phase system (commentary vs. final answer). This meant internal "thinking out loud" commentary could leak into user-visible surfaces like the TUI and HTTP/SSE session history endpoints. This PR makes those surfaces phase-aware, and hardens heartbeat session resolution against subagent key leaks.
Technical details
Follow-up to #59643 and #59150, which fixed phase separation in the core WS path. Post-merge audit found adjacent surfaces still using phase-blind extraction.
Surfaces fixed:
src/tui/tui-formatters.ts— assistant text extraction now usesextractAssistantVisibleText()to preferfinal_answerovercommentaryphase blockssrc/infra/heartbeat-runner.ts— heartbeat session resolution now rejects subagent session keys, falling back to the main session key instead of leaking into subagent scopessrc/gateway/sessions-history-http.test.ts— regression test: REST history applieschat.historysanitization (strips NO_REPLY messages, preserves phase blocks)src/tui/tui-formatters.test.ts— regression test: mixed commentary + final_answer blocks extract only the visible final answerExplicitly deferred:
extractAssistantTextForSilentCheckand buffered delta/final rendering — lower-confidence, more behaviorally sensitive.Related
Test plan