Skip to content

fix(app): prevent composer history update loops - #1669

Draft
Flame119052 wants to merge 1 commit into
get-bb:mainfrom
Flame119052:agent/fix-composer-history-update-loop
Draft

fix(app): prevent composer history update loops#1669
Flame119052 wants to merge 1 commit into
get-bb:mainfrom
Flame119052:agent/fix-composer-history-update-loop

Conversation

@Flame119052

Copy link
Copy Markdown

Summary

  • deduplicate composer history resets before React state dispatch
  • mark history sessions active before recall updates and inactive before reset updates
  • add a mixed-priority regression test for recreated empty history

Problem

Opening a bb thread could fail with React error #185 (Maximum update depth exceeded). The production stack pointed to PromptBoxInternal's history reset effect and resetHistorySession.

Root cause

Callers may recreate an empty history object while React is processing overlapping transition and synchronous updates. Each effect pass unconditionally dispatched three null state updates. With another update lane already pending, React could not always take its eager same-value bailout, so the redundant passive-effect commit could feed another render and eventually hit the nested update limit.

The reset now uses a ref as the accepted session-transition marker. History recall marks the session active before state dispatch. Reset marks it inactive before dispatching its three clears, so re-entrant effects cannot enqueue the same reset twice.

User impact

Thread composers no longer risk blanking the route with React #185 when empty history props are recreated during concurrent rendering. Normal history recall and reset behavior is preserved.

Regression coverage

The regression combines startTransition with flushSync while recreating an empty history object. It fails on the original implementation with six commits and passes with the bounded five-commit sequence after the fix.

Validation

  • pnpm --dir apps/app exec vitest run --config vitest.config.ts src/components/promptbox/PromptBoxInternal.test.tsx — 98 passed
  • pnpm exec prettier --check apps/app/src/components/promptbox/PromptBoxInternal.tsx apps/app/src/components/promptbox/PromptBoxInternal.test.tsx — passed
  • pnpm exec eslint apps/app/src/components/promptbox/PromptBoxInternal.tsx apps/app/src/components/promptbox/PromptBoxInternal.test.tsx — passed
  • pnpm exec turbo run typecheck --filter=@bb/app --force — passed
  • pnpm exec turbo run build --filter=@bb/app --force — passed

AGENT GENERATED: by GPT-5.6

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.

1 participant