Skip to content

Fix resume creating new agents instead of restarting stopped ones#271

Merged
ptone merged 3 commits into
GoogleCloudPlatform:mainfrom
ptone:scion/dev-issue-61
Jun 1, 2026
Merged

Fix resume creating new agents instead of restarting stopped ones#271
ptone merged 3 commits into
GoogleCloudPlatform:mainfrom
ptone:scion/dev-issue-61

Conversation

@ptone
Copy link
Copy Markdown
Member

@ptone ptone commented May 31, 2026

Summary

Fixes ptone#61scion resume was creating new agents instead of resuming stopped ones.

  • Root cause: The Hub server's CreateAgentRequest struct was missing the Resume field that the CLI client sends. All stopped agents were treated as "stale" and deleted+recreated, losing the agent ID, template association, and metadata.
  • Fix: Added the Resume field to the Hub's CreateAgentRequest and added a new handler path in handleExistingAgent that restarts stopped agents in-place when Resume=true, mirroring the existing suspended-agent path.
  • Preserved behavior: scion start on a stopped agent (without Resume) still deletes and recreates — only scion resume triggers the in-place restart.

Test plan

  • TestCreateAgent_ResumeFromStoppedStatus — verifies resume returns 200, preserves agent ID, calls DispatchAgentStart (not delete+create)
  • TestCreateAgent_StartFromStoppedStatus_NoResume — verifies start (no resume flag) still recreates with 201
  • TestCreateProjectAgent_ResumeFromStoppedStatus — same resume test through project-scoped endpoint
  • Existing TestCreateAgent_RecreateFromStoppedStatus still passes (no regression)
  • Full go test ./pkg/hub/... passes
  • go vet ./... and go build ./... pass

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes an issue where resuming a stopped agent created a new agent instead of resuming the existing one in-place. It introduces a Resume flag to the CreateAgentRequest and updates the agent-handling logic to preserve the agent record and restart the container when this flag is set. Comprehensive unit tests have been added to verify this behavior. The review feedback suggests defensively initializing existingAgent.AppliedConfig if it is nil to prevent potential issues when applying task and attach parameters.

Comment thread pkg/hub/handlers.go Outdated
Comment on lines +8854 to +8857
if req.Task != "" && existingAgent.AppliedConfig != nil {
existingAgent.AppliedConfig.Task = req.Task
existingAgent.AppliedConfig.Attach = req.Attach
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

If existingAgent.AppliedConfig is nil, the task and attach parameters will not be updated, and subsequent calls (such as dispatcher.DispatchAgentStart or database updates) may encounter nil pointer dereferences.

To prevent panics and ensure robust handling, defensively initialize existingAgent.AppliedConfig if it is nil before applying the request parameters.

		if existingAgent.AppliedConfig == nil {
			existingAgent.AppliedConfig = &store.AgentAppliedConfig{}
		}
		if req.Task != "" {
			existingAgent.AppliedConfig.Task = req.Task
			existingAgent.AppliedConfig.Attach = req.Attach
		}

ptone added 3 commits June 1, 2026 00:16
The Hub server's CreateAgentRequest struct was missing the Resume field
that the CLI client sends, causing all stopped agents to be treated as
stale and deleted+recreated rather than restarted in-place.

Add the Resume field to the Hub's CreateAgentRequest and handle the
stopped+resume case in handleExistingAgent: when Resume=true and the
agent is in PhaseStopped, restart it in-place (preserving agent ID,
metadata, and template association) rather than deleting and recreating.

When Resume is not set (i.e. scion start), the existing delete+recreate
behavior is preserved unchanged.
- Defensively initialize existingAgent.AppliedConfig when nil before
  applying task/attach params during resume, preventing potential nil
  pointer dereference (review feedback).
- Fix profile-telegram.ts TS6133 error: _linkedTelegramId was declared
  but never read, causing CI Build & Test failure.
@scion-gteam scion-gteam Bot force-pushed the scion/dev-issue-61 branch from 621a818 to e21c723 Compare June 1, 2026 00:17
@ptone ptone merged commit 39544ee into GoogleCloudPlatform:main Jun 1, 2026
5 checks passed
@scion-gteam scion-gteam Bot deleted the scion/dev-issue-61 branch June 1, 2026 12:22
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: scion resume creates new agents instead of resuming stopped ones

1 participant