Skip to content

fix(controlplane): let failed managed turns be cancelled to release the session - #4033

Merged
juruoO-o merged 1 commit into
agentscope-ai:mainfrom
Shay-Deng:fix/service-discard-failed-turn
Nov 11, 2026
Merged

juruoO-o merged 1 commit into
agentscope-ai:mainfrom
Shay-Deng:fix/service-discard-failed-turn

Conversation

@Shay-Deng

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT (main at 85fa9a60)

Description

A managed Turn that fails (model error, budget exceeded, max iterations) is terminal in the public Session API, but the dataplane still holds it ahead of later Turns until it is resumed or cancelled (SessionTurnCommandRepository.findDispatchable). The control plane gave no way to release it:

  • createServiceCommand rejected every command on a terminal invocation with 409 invocation has ended;
  • requestServiceCancellation returned early for terminal invocations, so cancel never reached the dataplane;
  • resume only accepts interrupted dataplane turns, and the projection stops refreshing terminal invocations.

As a result every later Turn in the Session stayed queued forever.

This PR adds an explicit discard path in the control plane. Neither state machine changes:

  • When the public Turn is failed and its dataplane turn is still failed, accept /cancel and forward it to the dataplane /turns/{id}/cancel. That endpoint already runs cancelPending and moves the turn to cancelled, which releases the Session queue.
  • The public Turn keeps its failed status. No terminal state is reopened and no tool call is replayed.
  • Turn /capabilities lists cancel in available_commands for such a Turn.
  • Other commands on such a Turn still return 409, now pointing to cancel instead of suggesting a new invocation.
  • The EN and ZH service/session-event-log pages describe the discard step.

Resuming a failed Turn would require reopening a terminal invocation and its projection, so it is out of scope here.

Validation

  • New TestPublicManagedSessionCancelDiscardsFailedTurn walks through the whole path with a fake dataplane: failure is projected, only cancel is offered, resume gets 409, cancel gets 202, the sweep forwards exactly one dataplane cancel, the command completes, the Turn stays failed, and a second cancel gets 409. It fails on main without this change.
  • go test -p 1 ./... and go vet ./... in service-controlplane pass against PostgreSQL 17 with CONTROL_PLANE_TEST_POSTGRES_DSN set, matching the service source check workflow. gofmt -l is clean.
  • The dataplane is unchanged; its existing cancel() handling of failed turns was read but not exercised end to end against a live deployment. Documentation checks (npm test, npm run validate) were not run locally.

Fixes #4011

Checklist

  • Code has been formatted (gofmt; no Java files changed, so mvn spotless:apply does not apply)
  • All tests are passing (go test -p 1 ./... in service-controlplane; mvn test not affected)
  • Javadoc comments are complete and follow project conventions (no Java changes)
  • Related documentation has been updated
  • Code is ready for review

AI assistance: developed with help from Claude Code. I reviewed the change, and the checks listed under Validation were run locally.

…he session

A managed turn that fails is terminal in the public API, but the dataplane
keeps it ahead of later turns until it is resumed or cancelled. The control
plane rejected every command on terminal invocations and never forwarded
cancellation, so later turns in the Session stayed queued forever.

Accept /cancel for a failed public Turn whose dataplane turn is still
failed, forward it to the dataplane, and list cancel in available_commands.
The public Turn keeps its failed status and no tool call is replayed.
Other commands on such a Turn now point to cancel instead of suggesting a
new invocation.

Fixes agentscope-ai#4011

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mintlify

mintlify Bot commented Nov 6, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit bd32eb8.

Approve preview

@jujn jujn added the P0 重要紧急 label Nov 7, 2026

@juruoO-o juruoO-o left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

已核对 failed Turn 的能力查询、命令接收、ScheduleInvocation 唤醒、后台 processServiceCommands 以及数据面 cancel 路径。仅允许丢弃仍在阻塞队列的 failed native turn,公共终态保持 failed,没有重开终态或重放工具。实现范围合理,未发现阻塞问题。本轮为调用链审查,未运行真实数据面端到端测试。

@juruoO-o
juruoO-o merged commit 53c0649 into agentscope-ai:main Nov 11, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P0 重要紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[service] failed turn 永久阻塞会话:resume/cancel 被控制面 terminal 检查拒绝,会话死锁

3 participants