Skip to content

fix(queue): bind agent ID at enqueue time to prevent cross-agent deli…#5371

Merged
zhijianma merged 5 commits into
agentscope-ai:mainfrom
zhaozhuang521:feat/queue-agent-binding
Jun 22, 2026
Merged

fix(queue): bind agent ID at enqueue time to prevent cross-agent deli…#5371
zhijianma merged 5 commits into
agentscope-ai:mainfrom
zhaozhuang521:feat/queue-agent-binding

Conversation

@zhaozhuang521

@zhaozhuang521 zhaozhuang521 commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator
  • Add agentId field to QueueItem, captured from storage at enqueue time
  • Override X-Agent-Id header in background sender with item.agentId
  • Fix waitForChatIdle to use correct agent ID for status polling, preventing spurious idle detection after agent switch
  • Handle AbortError correctly in waitForChatIdle fetch

Closes #5354

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactoring

Component(s) Affected

  • Core / Backend (app, agents, config, providers, utils, local_models)
  • Console (frontend web UI)
  • Channels (DingTalk, Feishu, QQ, Discord, iMessage, etc.)
  • Skills
  • CLI
  • Documentation (website)
  • Tests
  • CI/CD
  • Scripts / Deploy

Checklist

  • I ran pre-commit run --all-files locally and it passes
  • If pre-commit auto-fixed files, I committed those changes and reran checks
  • I ran tests locally (pytest or as relevant) and they pass
  • Documentation updated (if needed)
  • Ready for review

For Channel Changes (DingTalk, Feishu, QQ, Console, etc.)

  • I ran ./scripts/check-channels.sh (or ./scripts/check-channels.sh --changed) and it passes
  • Contract test exists in tests/contract/channels/test_<channel>_contract.py (REQUIRED)
  • Contract test implements create_instance() with proper channel initialization
  • All 19 contract verification points pass (see tests/contract/channels/__init__.py)
  • Optional: Unit tests in tests/unit/channels/test_<channel>.py for complex internal logic

Testing

[How to test these changes]

Local Verification Evidence

pre-commit run --all-files
# paste summary result

pytest
# paste summary result

Additional Notes

[Optional: any other context]

…very

- Add agentId field to QueueItem, captured from storage at enqueue time
- Override X-Agent-Id header in background sender with item.agentId
- Fix waitForChatIdle to use correct agent ID for status polling,
  preventing spurious idle detection after agent switch
- Handle AbortError correctly in waitForChatIdle fetch

Closes agentscope-ai#5354
@github-actions

Copy link
Copy Markdown

Welcome to QwenPaw! 🐾

Hi @zhaozhuang521, this is your 154th Pull Request.

📋 About PR Template

To help maintainers review your PR faster, please make sure to include:

  • Description - What this PR does and why
  • Type of Change - Bug fix / Feature / Breaking change / Documentation / Refactoring
  • Component(s) Affected - Core / Console / Channels / Skills / CLI / Documentation / Tests / CI/CD / Scripts
  • Checklist:
    • Run and pass pre-commit run --all-files
    • Run and pass relevant tests (pytest or as applicable)
    • Update documentation if needed
  • Testing - How to test these changes
  • Local Verification Evidence:
    pre-commit run --all-files
    # paste summary result
    
    pytest
    # paste summary result

Complete PR information helps speed up the review process. You can edit the PR description to add these details.

🙌 Join Developer Community

Thanks so much for your contribution! We'd love to invite you to join the official QwenPaw developer group! You can find the Discord and DingTalk group links under the "Developer Community" section on our docs page:
https://qwenpaw.agentscope.io/docs/community

We truly appreciate your enthusiasm—and look forward to your future contributions! 😊

We'll review your PR soon.

…ion drift

After an agent switch the session list is replaced with the new agent's
sessions, causing getBackendSessionId() to fail for the original chat.
The background sender then posts to an incorrect session_id, creating a
new conversation for the remaining queued items.

- Add backendSessionId field to QueueItem, captured from
  window.currentSessionId at enqueue time
- startAllBackgroundQueues prefers the item's snapshot over the live
  sessionApi lookup (which may be stale after agent switch)
- startBackgroundQueue POST body uses item.backendSessionId as primary
  source, falling back to the resolved parameter
zhaozhuang added 3 commits June 22, 2026 13:59
Two related fixes for cross-agent / queue interaction issues:

1. Foreground sender uses wrong session after agent switch
   - Removing ctrl.signal from background fetch keeps the HTTP connection
     alive when the queue loop is aborted, so the server completes and
     persists the turn (no message loss, no duplicates)
   - scheduleNextSend now force-sets window.currentSessionId from the
     queue item's backendSessionId snapshot before SDK submit, so
     customFetch always uses the correct session even if the global was
     overwritten by a recent agent switch
   - Agent switch effect sets chatLoading=true immediately as defense
     in depth against the reload race window

2. Slash commands swallowed by queue when busy
   - handleEnterEnqueue (capture-phase Enter listener) now skips strings
     starting with '/' so the slash-command system handles them
   - handleBeforeSubmit non-owner-tab branch returns true for slash
     commands instead of routing them through the queue
@zhijianma zhijianma merged commit 4cd1b75 into agentscope-ai:main Jun 22, 2026
9 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in QwenPaw Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: 消息发送队列容易串台;切换对话时切不回去

2 participants