Skip to content

🤖 fix: harden /btw side-question retry state#3324

Merged
ammario merged 1 commit into
mainfrom
btw-cleanup
May 19, 2026
Merged

🤖 fix: harden /btw side-question retry state#3324
ammario merged 1 commit into
mainfrom
btw-cleanup

Conversation

@ammar-agent
Copy link
Copy Markdown
Collaborator

@ammar-agent ammar-agent commented May 18, 2026

Summary

Small follow-up on the /btw side-question feature merged in #3293. This keeps the implementation easier to maintain and fixes an idle-chat UI flash where sending /btw could momentarily show the main-agent Stream interrupted retry banner.

Background

#3293 landed /btw across the backend side-question service, frontend streaming aggregator, transcript rendering, and tests. A focused post-merge cleanup found a few low-risk maintainability wins. While validating the idle /btw path, we also found that retry eligibility treated a trailing /btw user row like a normal main-agent send with no response yet, which briefly mounted RetryBarrier before the side-answer placeholder arrived.

Implementation

  • Inline the dead WorkspaceStore.processStreamEventdispatchProcessStreamEvent wrapper.
  • Drop tautological prompt-copy assertions in sideQuestionService.test.ts; keep behavioral assertions and rely on the streamText test for the tools-denied contract.
  • Name SIDE_QUESTION_MIN_FALLBACK_ATTEMPTS instead of a bare 3 in the candidate-attempt loop.
  • Narrow /btw's AI dependency to SideQuestionAIService = Pick<AIService, "createModel" | "getStreamInfo">, removing the test fake's as unknown as AIService cast.
  • Centralize the "/btw" literal as SIDE_QUESTION_COMMAND for frontend draft restoration and backend persisted command metadata.
  • Realign stale lifecycle comments in sideQuestionService.ts with the actual side-answer-aware aggregator/store lookups.
  • Keep /btw transcript extraction tolerant of persisted history: malformed parts are skipped, current dynamic-tool parts are summarized, and legacy AI SDK tool-<name> rows from older chat.jsonl histories are preserved as [tool name] context.
  • Add getLastMainRetryCandidateMessage() so retry eligibility, ChatPane suppression, and RetryBarrier copy all skip /btw rows consistently while still evaluating any earlier main-agent interruption or stream error.

Validation

  • make static-check
  • bun test src/node/services/sideQuestionService.test.ts
  • bun test src/common/utils/messages/retryEligibility.test.ts
  • bun test src/browser/features/Messages/ChatBarrier/RetryBarrier.test.tsx
  • bun run typecheck

Risks

Low. The retry behavior change is constrained to retry-barrier eligibility. /btw rows are a read-only side branch, not resumable main-agent turns, so they should be skipped when selecting the main retry candidate. The tests cover both sides: idle /btw no longer shows retry UI, and an earlier interrupted main response or context-exceeded stream error remains classified through the previous main-agent row even if /btw rows appear after it.


Generated with mux • Model: openai:gpt-5.5 • Thinking: xhigh • Cost: $307.29

@ammar-agent
Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

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

@ammar-agent
Copy link
Copy Markdown
Collaborator Author

@codex review

Amended to also realign two stale comments in sideQuestionService.ts (around the placeholder-before-stream-start emit and the stream-end-before-delete ordering). The old comments referenced a "WorkspaceStore main-agent buffering layer" that doesn't exist; replaced with accurate descriptions of what the side-answer-aware lookups actually guard.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

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

@ammar-agent ammar-agent changed the title 🤖 refactor: tighten /btw follow-up cleanups 🤖 fix: harden /btw side-question retry state May 19, 2026
@ammar-agent
Copy link
Copy Markdown
Collaborator Author

@codex review

Updated the PR with a small /btw retry-state fix: trailing side-question user rows and side-answer rows are now excluded from main-agent retry eligibility, preventing an idle-chat Stream interrupted flash when /btw starts. Local make static-check is green.

Copy link
Copy Markdown

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

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: 7435c56161

ℹ️ 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/common/utils/messages/retryEligibility.ts Outdated
@ammar-agent
Copy link
Copy Markdown
Collaborator Author

@codex review

Addressed the retry-candidate issue: retry eligibility now skips trailing /btw rows and continues evaluating the previous main-agent row, so idle /btw stays quiet while an earlier interrupted main stream remains retryable. Added tests for both cases; make static-check is green.

Copy link
Copy Markdown

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

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: c68df6d9ff

ℹ️ 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/common/utils/messages/retryEligibility.ts
@ammar-agent
Copy link
Copy Markdown
Collaborator Author

@codex review

Addressed the context-error suppression issue by exporting getLastMainRetryCandidateMessage() and using it consistently in retry eligibility, ChatPane suppression, and RetryBarrier copy. Validation is green locally (make static-check, targeted retry tests, targeted RetryBarrier tests, typecheck).

Copy link
Copy Markdown

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

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: bd41b4f022

ℹ️ 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/node/services/sideQuestionService.ts Outdated
@ammar-agent
Copy link
Copy Markdown
Collaborator Author

@codex review

Addressed the legacy tool-part concern by preserving tool-<name> transcript summaries alongside current dynamic-tool parts, with a sideQuestionService regression test. Also cleaned up the remaining stale side-question placeholder comment. Local make static-check is green.

Copy link
Copy Markdown

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

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: baf8422975

ℹ️ 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/node/services/sideQuestionService.ts Outdated
Small post-merge hardening for the /btw side-question feature (#3293):

- Inline dead processStreamEvent/dispatchProcessStreamEvent indirection.
- Drop tautological prompt-copy assertions; keep behavioral ones.
- Name SIDE_QUESTION_MIN_FALLBACK_ATTEMPTS instead of bare 3.
- Type summarizeToolPart against MuxMessage parts union; remove unknown casts.
- Narrow aiService dep to SideQuestionAIService = Pick<AIService, 'createModel' | 'getStreamInfo'>; drop the as-unknown-as-AIService test cast.
- Export SIDE_QUESTION_COMMAND so the /btw literal lives in one place.
- Ignore /btw side-question rows when evaluating main-agent retry state so idle /btw does not flash the Stream interrupted banner, while earlier interrupted main streams remain retryable.

Validation:
- make static-check
- bun test src/common/utils/messages/retryEligibility.test.ts
- bun run typecheck

---

Generated with mux • Model: openai:gpt-5.5 • Thinking: xhigh • Cost: $307.29
@ammar-agent
Copy link
Copy Markdown
Collaborator Author

@codex review

Addressed the tolerance concern: /btw transcript extraction now guards malformed parts in both text extraction and tool summarization, while preserving legacy tool-<name> summaries. Added regression coverage with null/malformed parts plus a legacy tool row. Local make static-check is green.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

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

@ammario ammario merged commit 8a6468a into main May 19, 2026
24 checks passed
@ammario ammario deleted the btw-cleanup branch May 19, 2026 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants