Skip to content

fix(agents): OpenAI WS replay — inherit message-level phase for untagged blocks when siblings have explicit textSignature - #61529

Merged
steipete merged 3 commits into
openclaw:mainfrom
electricsheephq:fix/61476-replay-phase-inheritance
Apr 6, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
electricsheephq:fix/61476-replay-phase-inheritance

Conversation

@100yenadmin

@100yenadmin 100yenadmin commented Apr 5, 2026 •

Copy link
Copy Markdown
Contributor

What this fixes (plain English)

When replaying chat history that mixes phase-tagged and untagged text blocks, untagged blocks lost their phase label — causing internal commentary to leak into visible conversation output. This fix ensures untagged blocks correctly inherit their parent message's phase.

Technical details

Root cause: The hasExplicitBlockPhase scan in openai-ws-message-conversion.ts was intended to separate legacy unphased content from new phased content, but it overcorrected — it forced undefined phase on untagged blocks whenever any sibling block had an explicit textSignature.phase.

Fix: Remove the hasExplicitBlockPhase scan entirely. Untagged blocks now always inherit assistantMessagePhase (from m.phase). Blocks with an explicit textSignature.phase still use their own value.

Files changed:

  • src/agents/openai-ws-message-conversion.ts — remove overcorrective phase scan
  • src/agents/openai-ws-stream.test.ts — regression test for mixed explicit/untagged blocks; corrected phase-buffering expectation for mid-stream deltas

Related

Test plan

  • 94/94 existing tests pass
  • Regression test added: mixed explicit/untagged blocks verify phase inheritance
  • Phase-buffering test corrected for mid-stream delta timing

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Apr 5, 2026
@100yenadmin
100yenadmin marked this pull request as ready for review April 5, 2026 22:20
Copilot AI review requested due to automatic review settings April 5, 2026 22:20
@greptile-apps

greptile-apps Bot commented Apr 5, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR removes the hasExplicitBlockPhase pre-scan from convertMessagesToInputItems and simplifies the phase resolution to parsedSignature?.phase ?? assistantMessagePhase. The old guard over-corrected by forcing untagged blocks to undefined phase whenever any sibling had an explicit textSignature.phase, which broke phase-aware suppression on replay for messages where untagged blocks should naturally inherit the message-level phase.

Confidence Score: 5/5

Safe to merge; logic change is minimal and correct, regression test added, 94/94 tests pass.

The only finding is a P2 stale test description — no logic, data integrity, or reliability issues remain. All P2 findings per scoring guidance keep confidence at 5.

No files require special attention beyond the stale test label at line 708.

Comments Outside Diff (1)

  1. src/agents/openai-ws-stream.test.ts, line 708 (link)

    P2 Stale test description after behavior inversion

    The it(...) label still says "splits legacy unphased text from later phased text during replay", but the expected output was changed to a single merged item ("Legacy. Done."). After this fix the untagged block inherits the same message-level phase as its sibling and they merge — the description now directly contradicts the assertion it guards.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/agents/openai-ws-stream.test.ts
    Line: 708
    
    Comment:
    **Stale test description after behavior inversion**
    
    The `it(...)` label still says "splits legacy unphased text from later phased text during replay", but the expected output was changed to a single merged item (`"Legacy. Done."`). After this fix the untagged block inherits the same message-level phase as its sibling and they merge — the description now directly contradicts the assertion it guards.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/openai-ws-stream.test.ts
Line: 708

Comment:
**Stale test description after behavior inversion**

The `it(...)` label still says "splits legacy unphased text from later phased text during replay", but the expected output was changed to a single merged item (`"Legacy. Done."`). After this fix the untagged block inherits the same message-level phase as its sibling and they merge — the description now directly contradicts the assertion it guards.

```suggestion
  it("untagged text inherits message-level phase and merges with siblings sharing the same phase", () => {
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(agents): inherit message-level phase..." | Re-trigger Greptile

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes OpenAI WS replay conversion so untagged assistant text blocks inherit the message-level phase even when sibling blocks have an explicit textSignature.phase, preventing phase loss and downstream phase-aware suppression issues.

Changes:

  • Update convertMessagesToInputItems() to always use m.phase as the fallback phase for untagged text blocks (removes the hasExplicitBlockPhase guard).
  • Update/extend unit tests to cover mixed explicit/untagged blocks and the updated replay behavior.
  • Add a new WS streaming regression test around late item-phase attribution (see comment).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/agents/openai-ws-message-conversion.ts Removes explicit-block scan and makes untagged blocks inherit message-level phase during replay conversion.
src/agents/openai-ws-stream.test.ts Updates replay expectations and adds regression tests for phase inheritance and late phase attribution.

Comment thread src/agents/openai-ws-stream.test.ts Resolved
Comment thread src/agents/openai-ws-stream.test.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@100yenadmin

Copy link
Copy Markdown
Contributor Author

Related issues: This PR also relates to #61734 (commentary-phase text leaks into user-visible output with openai-codex/gpt-5.4), #25592 (text between tool calls leaks to messaging channels), and #48709 (Gemini 2.5 Pro textSignature bloat + think tags + mixed text/tool causes session failures). These share the same root cause around phase/textSignature handling during history replay.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 974e0573fb

ℹ️ 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".

Comment thread src/agents/openai-ws-stream.test.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

…eplay splitting

Fixes #61476

Untagged text blocks in mixed assistant messages were forced to undefined
phase when any sibling had an explicit textSignature phase. Now they
correctly inherit the message-level assistantMessagePhase, preventing
commentary leaks during history replay.

Removes the hasExplicitBlockPhase scan — untagged blocks always inherit
m.phase. Blocks with explicit textSignature.phase still use their own.

94/94 tests pass. Regression test added for mixed explicit/untagged blocks.
@steipete
steipete merged commit 16d0f05 into openclaw:main Apr 6, 2026
9 checks passed
@steipete

steipete commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Landed via temp rebase onto main.

  • Gate: pnpm check; pnpm build; pnpm test src/agents/openai-ws-stream.test.ts; pnpm test src/agents/pi-embedded-utils.test.ts
  • Note: pnpm test on fresh main hit unrelated pre-existing failures in src/agents/model-auth.test.ts and src/agents/model-auth.profiles.test.ts
  • Land commit: e94e5dc
  • Merge commit: 16d0f05

Thanks @100yenadmin!

steipete added a commit to leoleedev/openclaw that referenced this pull request Apr 6, 2026
Mlightsnow pushed a commit to Mlightsnow/openclaw that referenced this pull request Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(agents): OpenAI WS replay drops message-level phase when block has explicit textSignature — commentary leaks on history replay

3 participants