Skip to content

cli: Add explicit daemon lifecycle commands#376

Open
timflannagan wants to merge 3 commits intoagentregistry-dev:mainfrom
timflannagan:refactor/explicit-daemon-lifecycle
Open

cli: Add explicit daemon lifecycle commands#376
timflannagan wants to merge 3 commits intoagentregistry-dev:mainfrom
timflannagan:refactor/explicit-daemon-lifecycle

Conversation

@timflannagan
Copy link
Collaborator

@timflannagan timflannagan commented Mar 18, 2026

Description

The root command's PersistentPreRunE hook previously auto-started
Docker containers (postgres + registry server) whenever the
registry URL targeted localhost:12121. This was a footgun for
users with existing registries, e.g. port-forwarding a Kubernetes
registry to localhost:12121 would risk silently spinning up a
separate local instance if the port-forward dropped.

We now follow the Docker CLI/daemon model where the CLI never
auto-starts infrastructure and fails fast if the registry is
unreachable. Daemon lifecycle is managed explicitly through
arctl daemon start, stop, and status subcommands. The stop
command accepts a --purge flag to also remove data volumes.

The client connectivity check is also simplified from 3 retries
with exponential backoff to a single ping, since the retries
only existed to compensate for the race between auto-starting
containers and the client connecting.

Fixes #307.

Change Type

/kind fix

Changelog

NONE

Additional Notes

The root command's PersistentPreRunE hook previously auto-started
Docker containers (postgres + registry server) whenever the
registry URL targeted localhost:12121. This was a footgun for
users with existing registries, e.g. port-forwarding a Kubernetes
registry to localhost:12121 would risk silently spinning up a
separate local instance if the port-forward dropped.

We now follow the Docker CLI/daemon model where the CLI never
auto-starts infrastructure and fails fast if the registry is
unreachable. Daemon lifecycle is managed explicitly through
arctl daemon start, stop, and status subcommands. The stop
command accepts a --purge flag to also remove data volumes.

The client connectivity check is also simplified from 3 retries
with exponential backoff to a single ping, since the retries
only existed to compensate for the race between auto-starting
containers and the client connecting.
Follows Go naming conventions where the package name already
provides context, so daemon.New reads better than
daemon.NewDaemonCmd.
Extract a composeCmd helper in the docker compose manager to
eliminate duplicated exec.Cmd construction across Start, down,
and isContainerRunning. This also fixes a subtle inconsistency
where down and isContainerRunning were using the raw ComposeYAML
instead of the patched output from getComposeYAML.

Remove the IsRunning guards from the start and stop subcommands
since docker compose up and down are idempotent operations. The
guards introduced a TOCTOU race without adding value.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the CLI’s implicit “auto-start local docker-compose daemon when targeting localhost” behavior and replaces it with explicit daemon lifecycle commands (arctl daemon start|stop|status), so the CLI fails fast when the registry is unreachable rather than silently spinning up local infrastructure.

Changes:

  • Add explicit daemon command group with start, stop (with --purge), and status.
  • Extend the docker-compose daemon manager with Stop() / Purge() and refactor compose command construction.
  • Simplify client connectivity verification from retry/backoff to a single Ping().

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/types/types.go Extends DaemonManager interface with stop/purge lifecycle methods.
pkg/daemon/dockercompose/manager.go Implements Stop()/Purge() via docker compose down, refactors command construction.
pkg/cli/root.go Removes daemon auto-start logic; adds daemon command to root; simplifies client creation and error message.
pkg/cli/root_test.go Updates tests to reflect new pre-run behavior and error messaging.
pkg/cli/commands_test.go Updates command tree expectations to include daemon.
internal/client/client.go Removes retry-based ping logic; uses single Ping() for connectivity check.
internal/cli/daemon/daemon.go Introduces daemon command tree wiring to the daemon manager.
internal/cli/daemon/daemon_test.go Adds unit tests for daemon start/stop/status commands.
Comments suppressed due to low confidence (1)

pkg/cli/root.go:41

  • Removing CLIOptions.DaemonManager is a compile-time breaking change for any external code configuring the CLI via cli.Configure(). If pkg/cli is intended to be used as a library, consider keeping the field (even if unused by default) or introducing a new options struct/versioned API to avoid breaking downstream builds.
// CLIOptions configures the CLI behavior.
// Can be extended for more options (e.g. client factory).
type CLIOptions struct {
	// AuthnProviderFactory provides CLI-specific authentication.
	AuthnProviderFactory types.CLIAuthnProviderFactory

	// OnTokenResolved is called when a token is resolved.
	// This allows extensions to perform additional actions when a token is resolved (e.g. storing locally).
	OnTokenResolved func(token string) error

	// ClientFactory creates the API client. If nil, uses client.NewClientWithConfig (requires network).
	ClientFactory ClientFactory
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@timflannagan timflannagan added the work in progress This pr is still being worked on label Mar 18, 2026
@timflannagan
Copy link
Collaborator Author

Need to figure out the e2e failures a bit. We were relying on the implicit behavior before. Have a couple of options here, but need to explore a bit more locally the right approach here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve daemon lifecycle management

2 participants