Skip to content

agent: Treat empty spawn_agent session IDs as new sessions - #60902

Closed
haotian467 wants to merge 5 commits into
zed-industries:mainfrom
haotian467:main
Closed

agent: Treat empty spawn_agent session IDs as new sessions#60902
haotian467 wants to merge 5 commits into
zed-industries:mainfrom
haotian467:main

Conversation

@haotian467

Copy link
Copy Markdown

Objective

spawn_agent uses an optional session_id to distinguish between creating a new session and resuming an existing one:

  • None creates a new session.
  • A session ID resumes an existing session.

In some model tool-call paths, a JSON null session ID is serialized as an empty string. Because an empty string still deserializes as Some(SessionId("")), spawn_agent attempts to resume that session and fails with:

No subagent session found with id


## Solution

Normalize an empty `session_id` to `None` while deserializing `SpawnAgentToolInput`.

This defensively handles the coerced representation while preserving the existing behavior for non-empty session IDs.

## Testing

Added `empty_session_id_deserializes_as_none`.
- Confirmed the regression test fails without the fix with:
  - `left: Some(SessionId(""))`
  - `right: None`
- Confirmed the regression test passes with the fix.
- Verified the existing sub-agent create, resume, cancellation, and output tests pass:

```sh
cargo test \
  -p agent \
  -p gpui_platform \
  --features gpui_platform/runtime_shaders \
  test_subagent_tool \
  --lib
  • Ran cargo fmt --all -- --check.
  • Ran git diff --check.

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content adheres to Zed's UI standards (UX/UI and icon guidelines)
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Fixed spawn_agent failing to create a new sub-agent session when its session ID was serialized as an empty string.

@cla-bot

cla-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @haotian467 on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Jul 13, 2026
@haotian467

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jul 13, 2026
@cla-bot

cla-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@SomeoneToIgnore SomeoneToIgnore added the area:ai/agent thread Feedback for Zed's Agent Thread label Jul 16, 2026
@bennetbo

Copy link
Copy Markdown
Member

This was added in #60893

@bennetbo bennetbo closed this Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ai/agent thread Feedback for Zed's Agent Thread cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants