Skip to content

fix(ui): preserve question queue order when upserting duplicate requests#479

Open
JDis03 wants to merge 1 commit into
NeuralNomadsAI:devfrom
JDis03:fix/question-queue-ordering-448
Open

fix(ui): preserve question queue order when upserting duplicate requests#479
JDis03 wants to merge 1 commit into
NeuralNomadsAI:devfrom
JDis03:fix/question-queue-ordering-448

Conversation

@JDis03
Copy link
Copy Markdown

@JDis03 JDis03 commented May 18, 2026

Summary

Root Cause

upsertQuestion replaced the entire queue entry on duplicate request id, losing the original enqueuedAt value. If question-1 arrived at t=1000 (global), then question-2 at t=1500, and question-1 resolved to a tool part at t=2000, the newer enqueuedAt (2000) would place question-1 behind question-2 in the sorted queue, breaking active interruption ordering.

Fix

  • Add mergeQuestionEntry mirroring mergePermissionEntry behavior
  • Preserve original enqueuedAt using Math.min(existing, new)
  • Keep newer messageId/partId when resolving from global to tool part
  • Clean up stale byMessage entries for the same request id
  • Sort queue by enqueuedAt and recalculate active after each upsert

Validation

  • npm run typecheck --workspace @codenomad/ui
  • node --import tsx --test packages/ui/src/stores/message-v2/instance-store.test.ts
  • Added 3 regression tests covering duplicate resolution and ordering

Fixes NeuralNomadsAI#448 - Questions can deadlock with "Waiting for earlier responses"
when a question arrives first as a global entry and later resolves to a
tool part with a newer enqueuedAt timestamp.

Root cause:
- upsertQuestion replaced the entire queue entry on duplicate request id,
  losing the original enqueuedAt value.
- If question-1 arrived at t=1000 (global), then question-2 at t=1500,
  and question-1 resolved to a tool part at t=2000, the newer enqueuedAt
  (2000) would place question-1 behind question-2 in the sorted queue.
- This broke the active interruption ordering, leaving both questions
  showing "Waiting for earlier responses."

Fix:
- Add mergeQuestionEntry mirroring mergePermissionEntry behavior.
- Preserve original enqueuedAt using Math.min(existing, new).
- Keep newer messageId/partId when resolving from global to tool part.
- Clean up stale byMessage entries for the same request id.
- Sort queue by enqueuedAt and recalculate active after each upsert.

Validation:
- npm run typecheck --workspace @codenomad/ui
- node --import tsx --test packages/ui/src/stores/message-v2/instance-store.test.ts
- Added 3 regression tests covering duplicate resolution and ordering.
@JDis03 JDis03 force-pushed the fix/question-queue-ordering-448 branch from 6636745 to 4dc05d3 Compare May 18, 2026 13:06
@github-actions
Copy link
Copy Markdown

PR builds are available as GitHub Actions artifacts:

https://github.com/NeuralNomadsAI/CodeNomad/actions/runs/26034514624

Artifacts expire in 7 days.
Artifacts:

  • pr-479-66367454adf9ba9c7603ea45be110e1e0ed1fe92-tauri-macos
  • pr-479-66367454adf9ba9c7603ea45be110e1e0ed1fe92-electron-macos
  • pr-479-66367454adf9ba9c7603ea45be110e1e0ed1fe92-tauri-linux
  • pr-479-66367454adf9ba9c7603ea45be110e1e0ed1fe92-tauri-windows
  • pr-479-66367454adf9ba9c7603ea45be110e1e0ed1fe92-tauri-macos-arm64
  • pr-479-66367454adf9ba9c7603ea45be110e1e0ed1fe92-electron-windows
  • pr-479-66367454adf9ba9c7603ea45be110e1e0ed1fe92-electron-linux

@github-actions
Copy link
Copy Markdown

PR builds are available as GitHub Actions artifacts:

https://github.com/NeuralNomadsAI/CodeNomad/actions/runs/26035402900

Artifacts expire in 7 days.
Artifacts:

  • pr-479-4dc05d3773ea6e82137836637d00b9b89859471e-tauri-macos
  • pr-479-4dc05d3773ea6e82137836637d00b9b89859471e-tauri-linux
  • pr-479-4dc05d3773ea6e82137836637d00b9b89859471e-tauri-windows
  • pr-479-4dc05d3773ea6e82137836637d00b9b89859471e-electron-macos
  • pr-479-4dc05d3773ea6e82137836637d00b9b89859471e-tauri-macos-arm64
  • pr-479-4dc05d3773ea6e82137836637d00b9b89859471e-electron-windows
  • pr-479-4dc05d3773ea6e82137836637d00b9b89859471e-electron-linux

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.

[Bug]: questions do not open and garble leading to deadlock "Waiting for earlier responses"

1 participant