Skip to content

fix(harness): add explicit lifecycle management for spawned agents - #2917

Open
guslegend0510 wants to merge 2 commits into
agentscope-ai:mainfrom
guslegend0510:codex/fix-2915-agent-retention
Open

fix(harness): add explicit lifecycle management for spawned agents#2917
guslegend0510 wants to merge 2 commits into
agentscope-ai:mainfrom
guslegend0510:codex/fix-2915-agent-retention

Conversation

@guslegend0510

Copy link
Copy Markdown
Contributor

Summary

  • add an explicit agent_release tool for retained subagents
  • scope live subagent registries by (userId, parentSessionId)
  • manage spawned agents with ACTIVE, RELEASING, and RELEASED lifecycle states
  • track in-flight invocations across synchronous, asynchronous, cancelled, remote, and timeout-promoted executions
  • atomically remove live keys, labels, and persisted spawn registry entries during release
  • revoke exposed Gateway handles and close AutoCloseable child agents
  • prevent released agents from being restored from stale state
  • close factory-created candidates that lose concurrent label or persistent-key races
  • make agent_list runtime-context aware
  • preserve persistent session state when the parent HarnessAgent is closed
  • update the English and Chinese subagent documentation

Completed tasks are intentionally not released automatically. A retained subagent remains addressable for follow-up agent_send calls until agent_release is called.

agent_release returns busy while an invocation is still running. No TTL, LRU, force-release option, or automatic size limit is introduced.

Tests

  • added lifecycle regression coverage for 256 consecutive spawn/release cycles
  • covered send by key and label before and after release
  • covered cross-session isolation and state restoration
  • covered synchronous, asynchronous, cancellation, and timeout-promotion leases
  • covered concurrent duplicate labels and persistent keys
  • covered send/release and restore/release races
  • covered Gateway handle revocation and parent-agent cleanup
  • verified tests do not depend on Thread.sleep or System.gc

Validation completed:

  • focused AgentSpawnTool and middleware tests: 69 passed
  • mvn -pl agentscope-harness -am test
  • Spotless
  • git diff --check
  • jupyter-book build .

Fixes #2915

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]: AgentSpawnTool retains every non-persistent spawned Agent indefinitely

2 participants