diff --git a/apps/backend/internal/agent/lifecycle/agent_session_seeder.go b/apps/backend/internal/agent/lifecycle/agent_session_seeder.go index 28fdd9a1f2..ecc99e3ba3 100644 --- a/apps/backend/internal/agent/lifecycle/agent_session_seeder.go +++ b/apps/backend/internal/agent/lifecycle/agent_session_seeder.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "os" - "os/exec" "path/filepath" "runtime" "strings" @@ -75,10 +74,6 @@ func (localFileUploader) WriteFile(_ context.Context, path string, data []byte, return os.WriteFile(path, data, mode) } -func (localFileUploader) RunCommand(ctx context.Context, name string, args ...string) error { - return exec.CommandContext(ctx, name, args...).Run() -} - // SeedAgentSessionDir copies the agent's RemoteAuth.SourceFiles from the host // home into a per-container session dir, populating just the auth-relevant // files (typically auth.json + config.toml). Stale per-host state — codex's diff --git a/apps/backend/internal/agent/lifecycle/agent_session_seeder_test.go b/apps/backend/internal/agent/lifecycle/agent_session_seeder_test.go index 6a94fda430..6771fbf316 100644 --- a/apps/backend/internal/agent/lifecycle/agent_session_seeder_test.go +++ b/apps/backend/internal/agent/lifecycle/agent_session_seeder_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/kandev/kandev/internal/agent/agents" + "github.com/kandev/kandev/internal/common/config" "github.com/kandev/kandev/internal/common/logger" ) @@ -183,47 +184,61 @@ func TestCleanupAgentSessionDir_NoopOnEmptyPath(t *testing.T) { CleanupAgentSessionDir("", newSeederTestLogger(t)) } -// TestDockerStopInstance_PreservesSessionDirOnPlainStop mirrors the Sprites -// preserve-on-stop rule for Docker: a plain agent stop must leave the -// per-container agent session dir alone so resume can re-attach to the same -// state. Only destructive stops (task/session deleted/archived) clean up. +// TestDockerStopInstance_PreservesSessionDirOnPlainStop drives the real +// DockerExecutor.StopInstance for both preserve and destructive stop +// reasons and asserts on the on-disk session dir. We pass instances with +// ContainerID == "" so StopInstance returns before talking to the docker +// daemon — the cleanup branch under test is the kandev-side dir teardown. func TestDockerStopInstance_PreservesSessionDirOnPlainStop(t *testing.T) { hostHome := seedTestHostHome(t) writeFile(t, hostHome, ".codex/auth.json", []byte(`{"token":"a"}`)) - kandevHome := t.TempDir() - instanceID := "stop-test-instance" - root := InstanceSessionRoot(kandevHome, instanceID) - if err := SeedAgentSessionDir(context.Background(), agents.NewCodexACP(), root, newSeederTestLogger(t)); err != nil { - t.Fatalf("seed: %v", err) - } - if _, err := os.Stat(filepath.Join(root, ".codex/auth.json")); err != nil { - t.Fatalf("seed precondition: %v", err) + cases := []struct { + reason string + expectExists bool + }{ + {reason: "", expectExists: true}, + {reason: "stopped via API", expectExists: true}, + {reason: "agent crashed", expectExists: true}, + {reason: "user requested", expectExists: true}, + {reason: "task archived", expectExists: false}, + {reason: "task deleted", expectExists: false}, + {reason: "session archived", expectExists: false}, + {reason: "session deleted", expectExists: false}, } - // Plain stop reasons must NOT remove the dir. Only destructive reasons - // trigger CleanupAgentSessionDir from StopInstance, mirroring the - // shouldRunExecutorCleanup() rule used by Sprites. - preserveReasons := []string{"", "stopped via API", "agent crashed", "user requested"} - for _, reason := range preserveReasons { - if shouldRunExecutorCleanup(reason) { - t.Fatalf("preserve reason %q would unexpectedly trigger destructive cleanup", reason) - } - } - if _, err := os.Stat(root); err != nil { - t.Fatalf("session dir disappeared without a destructive reason: %v", err) - } + log := newSeederTestLogger(t) - // Destructive reasons trigger cleanup. - destructive := []string{"task archived", "task deleted", "session archived", "session deleted"} - for _, reason := range destructive { - if !shouldRunExecutorCleanup(reason) { - t.Fatalf("destructive reason %q must opt into cleanup", reason) - } - } + for _, tc := range cases { + t.Run(tc.reason, func(t *testing.T) { + kandevHome := t.TempDir() + instanceID := "stop-test-instance" + root := InstanceSessionRoot(kandevHome, instanceID) + if err := SeedAgentSessionDir(context.Background(), agents.NewCodexACP(), root, log); err != nil { + t.Fatalf("seed: %v", err) + } + if _, err := os.Stat(filepath.Join(root, ".codex/auth.json")); err != nil { + t.Fatalf("seed precondition: %v", err) + } - CleanupAgentSessionDir(root, newSeederTestLogger(t)) - if _, err := os.Stat(root); !os.IsNotExist(err) { - t.Fatalf("expected dir removed after destructive cleanup, got err=%v", err) + exec := NewDockerExecutor(config.DockerConfig{}, kandevHome, log) + instance := &ExecutorInstance{ + InstanceID: instanceID, + StopReason: tc.reason, + // ContainerID intentionally empty so StopInstance returns + // before invoking the docker daemon — we're testing the + // kandev-side cleanup branch only. + } + if err := exec.StopInstance(context.Background(), instance, false); err != nil { + t.Fatalf("StopInstance returned error for reason=%q: %v", tc.reason, err) + } + + _, statErr := os.Stat(root) + gotExists := statErr == nil + if gotExists != tc.expectExists { + t.Fatalf("session dir for reason=%q: exists=%v, want=%v (statErr=%v)", + tc.reason, gotExists, tc.expectExists, statErr) + } + }) } } diff --git a/apps/backend/internal/agent/lifecycle/container.go b/apps/backend/internal/agent/lifecycle/container.go index 43afcbd3f7..caf3f90736 100644 --- a/apps/backend/internal/agent/lifecycle/container.go +++ b/apps/backend/internal/agent/lifecycle/container.go @@ -7,7 +7,6 @@ import ( "crypto/rand" "encoding/hex" "fmt" - "os" "strings" "time" @@ -528,21 +527,14 @@ func (cm *ContainerManager) expandMounts(templates []agents.MountTemplate, works return mounts } -// expandMountSource expands template variables in mount source paths +// expandMountSource expands template variables in mount source paths. +// Only `{workspace}` is honoured here — agent session dirs that used to use +// `{home}/.` now route through the kandev-managed per-container +// session dir (see SessionDirHostPath), which keeps host state DBs out of +// the container. Production agents don't ship `{home}` in Mounts; codex_acp +// has a regression test asserting this. func (cm *ContainerManager) expandMountSource(source, workspacePath string) string { - result := source - result = strings.ReplaceAll(result, "{workspace}", workspacePath) - - // Expand {home} to user's home directory - if strings.Contains(result, "{home}") { - homeDir, err := os.UserHomeDir() - if err != nil { - homeDir = "/tmp" - } - result = strings.ReplaceAll(result, "{home}", homeDir) - } - - return result + return strings.ReplaceAll(source, "{workspace}", workspacePath) } // buildEnvVars builds environment variables for the container diff --git a/apps/backend/internal/agent/lifecycle/credential_uploader.go b/apps/backend/internal/agent/lifecycle/credential_uploader.go index 843bff7336..6ae8c2480a 100644 --- a/apps/backend/internal/agent/lifecycle/credential_uploader.go +++ b/apps/backend/internal/agent/lifecycle/credential_uploader.go @@ -15,10 +15,11 @@ import ( "github.com/kandev/kandev/internal/common/logger" ) -// FileUploader abstracts writing files and running commands on a remote environment. +// FileUploader abstracts writing files to a remote environment. Used by +// UploadCredentialFiles to seed agent auth files into the kandev-managed +// per-container session dir (local) or sprite (remote). type FileUploader interface { WriteFile(ctx context.Context, path string, data []byte, mode os.FileMode) error - RunCommand(ctx context.Context, name string, args ...string) error } // UploadCredentialFiles reads local credential files and uploads them to the remote environment. diff --git a/apps/backend/internal/agent/lifecycle/env_preparer_docker.go b/apps/backend/internal/agent/lifecycle/env_preparer_docker.go index e92761c7ec..0ffc5986f5 100644 --- a/apps/backend/internal/agent/lifecycle/env_preparer_docker.go +++ b/apps/backend/internal/agent/lifecycle/env_preparer_docker.go @@ -41,14 +41,10 @@ func (p *DockerPreparer) Prepare(ctx context.Context, req *EnvPrepareRequest, on Steps: steps, WorkspacePath: req.WorkspacePath, Duration: time.Since(start), - WorktreeBranch: dockerTaskBranch(req), + WorktreeBranch: nonWorktreeTaskBranch(req), }, nil } -func dockerTaskBranch(req *EnvPrepareRequest) string { - return nonWorktreeTaskBranch(req) -} - // nonWorktreeTaskBranch resolves the kandev-managed feature branch for executors // that don't go through the host-side worktree path (Docker, Sprites). On a // fresh launch it generates a deterministic branch name from the task title + diff --git a/apps/backend/internal/agent/lifecycle/executor_docker.go b/apps/backend/internal/agent/lifecycle/executor_docker.go index 254053daac..3354c57a07 100644 --- a/apps/backend/internal/agent/lifecycle/executor_docker.go +++ b/apps/backend/internal/agent/lifecycle/executor_docker.go @@ -34,20 +34,6 @@ func getMetadataString(metadata map[string]interface{}, key string) string { return "" } -func getMetadataBool(metadata map[string]interface{}, key string) bool { - if metadata == nil { - return false - } - switch raw := metadata[key].(type) { - case bool: - return raw - case string: - return strings.EqualFold(strings.TrimSpace(raw), boolStringTrue) - default: - return false - } -} - // DockerExecutor implements Runtime for Docker-based agent execution. // The Docker client is created lazily on first use (not at startup). type DockerExecutor struct { @@ -584,7 +570,7 @@ func (r *DockerExecutor) resolvePrepareScript(req *ExecutorCreateRequest) string req.Metadata, req.Env, getGitRemoteURL, - r.injectTokenIntoURL, + injectGitHubTokenIntoCloneURL, )). // Docker image has agents and agentctl pre-installed; // resolve these to empty so stored scripts with these placeholders don't break. @@ -623,27 +609,3 @@ func localPathFromCloneURL(raw string) string { } return path } - -// injectTokenIntoURL adds a GitHub token to clone URLs for authentication. -// Handles both HTTPS and SSH URLs (converting SSH to authenticated HTTPS). -func (r *DockerExecutor) injectTokenIntoURL(cloneURL string, env map[string]string) string { - token := env["GITHUB_TOKEN"] - if token == "" { - token = env["GH_TOKEN"] - } - if token == "" { - return cloneURL - } - - // Convert SSH URLs to HTTPS first - if strings.HasPrefix(cloneURL, "git@github.com:") { - path := strings.TrimPrefix(cloneURL, "git@github.com:") - cloneURL = "https://github.com/" + path - } - - // Convert https://github.com/... to https://x-access-token:TOKEN@github.com/... - if strings.HasPrefix(cloneURL, "https://github.com/") { - return strings.Replace(cloneURL, "https://github.com/", "https://x-access-token:"+token+"@github.com/", 1) - } - return cloneURL -} diff --git a/apps/backend/internal/agent/lifecycle/executor_docker_test.go b/apps/backend/internal/agent/lifecycle/executor_docker_test.go index 9617fdf836..69dec51ff4 100644 --- a/apps/backend/internal/agent/lifecycle/executor_docker_test.go +++ b/apps/backend/internal/agent/lifecycle/executor_docker_test.go @@ -347,9 +347,6 @@ func TestExecutorRegistry_CloseAll(t *testing.T) { } func TestInjectTokenIntoURL(t *testing.T) { - log := newTestDockerLogger() - exec := NewDockerExecutor(config.DockerConfig{}, "", log) - tests := []struct { name string url string @@ -408,7 +405,7 @@ func TestInjectTokenIntoURL(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := exec.injectTokenIntoURL(tt.url, tt.env) + got := injectGitHubTokenIntoCloneURL(tt.url, tt.env) if got != tt.expected { t.Errorf("injectTokenIntoURL(%q) = %q, want %q", tt.url, got, tt.expected) } diff --git a/apps/backend/internal/agent/lifecycle/executor_sprites.go b/apps/backend/internal/agent/lifecycle/executor_sprites.go index 8ae634bce8..285e658edb 100644 --- a/apps/backend/internal/agent/lifecycle/executor_sprites.go +++ b/apps/backend/internal/agent/lifecycle/executor_sprites.go @@ -38,11 +38,6 @@ func (u *spriteFileUploader) WriteFile(ctx context.Context, path string, data [] return u.runtime.writeFileWithRetry(ctx, u.sprite, path, data, mode) } -func (u *spriteFileUploader) RunCommand(ctx context.Context, name string, args ...string) error { - _, err := u.sprite.CommandContext(ctx, name, args...).Output() - return err -} - func (u *spriteFileUploader) RunCommandOutput(ctx context.Context, name string, args ...string) ([]byte, error) { return u.sprite.CommandContext(ctx, name, args...).Output() } diff --git a/apps/backend/internal/agent/lifecycle/executor_sprites_clone_auth_test.go b/apps/backend/internal/agent/lifecycle/executor_sprites_clone_auth_test.go index 6d3905a7d8..cf2acf50e1 100644 --- a/apps/backend/internal/agent/lifecycle/executor_sprites_clone_auth_test.go +++ b/apps/backend/internal/agent/lifecycle/executor_sprites_clone_auth_test.go @@ -38,10 +38,17 @@ func TestRewriteGitHubSSHToHTTPS(t *testing.T) { } func TestInjectTokenIntoURL_RewritesGitHubSSHWhenTokenExists(t *testing.T) { - exec := &SpritesExecutor{} env := map[string]string{"GITHUB_TOKEN": "test-token"} - got := exec.injectTokenIntoURL("git@github.com:kdlbs/agents-protocol-debug.git", env) - require.Equal(t, "https://test-token@github.com/kdlbs/agents-protocol-debug.git", got) + got := injectGitHubTokenIntoCloneURL("git@github.com:kdlbs/agents-protocol-debug.git", env) + require.Equal(t, "https://x-access-token:test-token@github.com/kdlbs/agents-protocol-debug.git", got) +} + +func TestInjectTokenIntoURL_HonoursGHTokenFallback(t *testing.T) { + // Sprites used to ignore GH_TOKEN; since unifying with Docker, both env + // var names are accepted (GITHUB_TOKEN wins when both are set). + env := map[string]string{"GH_TOKEN": "gh-token"} + got := injectGitHubTokenIntoCloneURL("https://github.com/org/repo.git", env) + require.Equal(t, "https://x-access-token:gh-token@github.com/org/repo.git", got) } func TestIsTransientUploadError(t *testing.T) { diff --git a/apps/backend/internal/agent/lifecycle/executor_sprites_helpers.go b/apps/backend/internal/agent/lifecycle/executor_sprites_helpers.go index 6f21b186e5..882daa6ed9 100644 --- a/apps/backend/internal/agent/lifecycle/executor_sprites_helpers.go +++ b/apps/backend/internal/agent/lifecycle/executor_sprites_helpers.go @@ -16,18 +16,32 @@ import ( var uploadHTTPStatusRE = regexp.MustCompile(`(?i)\b(?:http|status)\s*:?\s*(\d{3})\b`) -func (r *SpritesExecutor) injectTokenIntoURL(remoteURL string, env map[string]string) string { +// injectGitHubTokenIntoCloneURL injects a GitHub token into a clone URL so +// in-container `git clone` works without prompting. Honours both +// GITHUB_TOKEN and GH_TOKEN (gh CLI uses GH_TOKEN; Actions/most workflows +// use GITHUB_TOKEN — accepting either keeps callers from a 401 because they +// only set one). GITHUB_TOKEN wins when both are present, matching the +// original Docker behaviour. Uses the documented +// `https://x-access-token:T@github.com/` form, which works for both clone +// and gh CLI authentication. +// +// Used by both Docker and Sprites executors. SSH→HTTPS rewrite is delegated +// to rewriteGitHubSSHToHTTPS so the two surfaces never drift again. +func injectGitHubTokenIntoCloneURL(cloneURL string, env map[string]string) string { token := env["GITHUB_TOKEN"] if token == "" { - return remoteURL + token = env["GH_TOKEN"] } - if converted := rewriteGitHubSSHToHTTPS(remoteURL); converted != "" { - remoteURL = converted + if token == "" { + return cloneURL } - if strings.HasPrefix(remoteURL, "https://") { - return strings.Replace(remoteURL, "https://", "https://"+token+"@", 1) + if converted := rewriteGitHubSSHToHTTPS(cloneURL); converted != "" { + cloneURL = converted } - return remoteURL + if strings.HasPrefix(cloneURL, "https://github.com/") { + return strings.Replace(cloneURL, "https://github.com/", "https://x-access-token:"+token+"@github.com/", 1) + } + return cloneURL } func rewriteGitHubSSHToHTTPS(remoteURL string) string { diff --git a/apps/backend/internal/agent/lifecycle/executor_sprites_lifecycle.go b/apps/backend/internal/agent/lifecycle/executor_sprites_lifecycle.go index ecae14eb52..79816e1d6e 100644 --- a/apps/backend/internal/agent/lifecycle/executor_sprites_lifecycle.go +++ b/apps/backend/internal/agent/lifecycle/executor_sprites_lifecycle.go @@ -105,7 +105,7 @@ func (r *SpritesExecutor) runTerminalCleanupScript(ctx context.Context, sprite * instance.Metadata, nil, getGitRemoteURL, - r.injectTokenIntoURL, + injectGitHubTokenIntoCloneURL, )) resolved := resolver.Resolve(script) if strings.TrimSpace(resolved) == "" { diff --git a/apps/backend/internal/agent/lifecycle/executor_sprites_operations.go b/apps/backend/internal/agent/lifecycle/executor_sprites_operations.go index a10723192c..614d31bd77 100644 --- a/apps/backend/internal/agent/lifecycle/executor_sprites_operations.go +++ b/apps/backend/internal/agent/lifecycle/executor_sprites_operations.go @@ -169,7 +169,7 @@ func (r *SpritesExecutor) resolvePrepareScript(req *ExecutorCreateRequest) strin req.Metadata, req.Env, getGitRemoteURL, - r.injectTokenIntoURL, + injectGitHubTokenIntoCloneURL, )) return resolver.Resolve(script) diff --git a/apps/backend/internal/orchestrator/executor/executor_execute.go b/apps/backend/internal/orchestrator/executor/executor_execute.go index 57d944ba02..6c48a3d2e4 100644 --- a/apps/backend/internal/orchestrator/executor/executor_execute.go +++ b/apps/backend/internal/orchestrator/executor/executor_execute.go @@ -30,9 +30,11 @@ func isConfigModeSession(session *models.TaskSession) bool { return ok && cm } -// isContainerizedExecutor returns true for executor types that run in containers. -// These executors need GitHub token injection for git operations since they don't -// have access to the host's git credentials. +// isContainerizedExecutor returns true for executor types that run agents in +// containers or remote sandboxes (Docker variants + Sprites). These executors +// need GitHub token injection for git operations since they don't have access +// to the host's git credentials, and they're the same set that needs the +// kandev-managed feature branch propagated through env metadata. func isContainerizedExecutor(executorType string) bool { switch models.ExecutorType(executorType) { case models.ExecutorTypeLocalDocker, models.ExecutorTypeRemoteDocker, models.ExecutorTypeSprites: @@ -513,8 +515,7 @@ func (e *Executor) handleLaunchFailure(ctx context.Context, taskID, sessionID st // finalizeLaunch persists launch state and returns the resulting TaskExecution. func (e *Executor) finalizeLaunch(ctx context.Context, task *v1.Task, session *models.TaskSession, agentProfileID, sessionID string, repoInfo *repoInfo, resp *LaunchAgentResponse, startAgent bool, execCfg executorConfig) (*TaskExecution, error) { now := time.Now().UTC() - // On initial launch there is no existing ExecutorRunning record to carry forward. - e.persistLaunchState(ctx, task.ID, sessionID, session, resp, startAgent, now, execCfg, nil) + e.persistLaunchState(ctx, task.ID, sessionID, session, resp, startAgent, now) e.persistWorktreeAssociation(ctx, task.ID, session, repoInfo.RepositoryID, resp) sessionState := v1.TaskSessionStateCreated @@ -1131,21 +1132,12 @@ func (e *Executor) applyExistingEnvironment(req *LaunchAgentRequest, env *models // preparer is responsible for stamping env.WorktreeBranch in the first // place); the host-side worktree path uses req.WorktreeID instead and // doesn't need this metadata. - if env.WorktreeBranch != "" && isCloneBasedExecutorType(req.ExecutorType) { + if env.WorktreeBranch != "" && isContainerizedExecutor(req.ExecutorType) { metadata := ensureLaunchMetadata(req) metadata[lifecycle.MetadataKeyWorktreeBranch] = env.WorktreeBranch } } -func isCloneBasedExecutorType(executorType string) bool { - switch models.ExecutorType(executorType) { - case models.ExecutorTypeLocalDocker, models.ExecutorTypeRemoteDocker, models.ExecutorTypeSprites: - return true - default: - return false - } -} - func (e *Executor) applyExistingEnvironmentRuntimeMetadata(ctx context.Context, req *LaunchAgentRequest, env *models.TaskEnvironment) { if env == nil || env.ID == "" { return diff --git a/apps/backend/internal/orchestrator/executor/executor_interaction.go b/apps/backend/internal/orchestrator/executor/executor_interaction.go index 08620a86dd..a125e0e71a 100644 --- a/apps/backend/internal/orchestrator/executor/executor_interaction.go +++ b/apps/backend/internal/orchestrator/executor/executor_interaction.go @@ -262,7 +262,7 @@ func (e *Executor) launchModelSwitchAgent(ctx context.Context, taskID, sessionID return fmt.Errorf("failed to launch agent with new model: %w", err) } - e.persistModelSwitchState(ctx, taskID, sessionID, session, resp, newModel, existingRunning) + e.persistModelSwitchState(ctx, taskID, sessionID, session, newModel) if err := e.agentManager.StartAgentProcess(ctx, resp.AgentExecutionID); err != nil { e.logger.Error("failed to start agent process after model switch", @@ -368,10 +368,7 @@ func (e *Executor) applyWorktreeToSwitchRequest(req *LaunchAgentRequest, session // after a model switch launch. The executors_running row's agent_execution_id / // container_id / status are written by the lifecycle manager during the launch // itself (lifecycle.persistExecutorRunning) and not touched here. -func (e *Executor) persistModelSwitchState(ctx context.Context, taskID, sessionID string, session *models.TaskSession, resp *LaunchAgentResponse, newModel string, existingRunning *models.ExecutorRunning) { - _ = resp - _ = existingRunning - +func (e *Executor) persistModelSwitchState(ctx context.Context, taskID, sessionID string, session *models.TaskSession, newModel string) { session.State = models.TaskSessionStateStarting session.UpdatedAt = time.Now().UTC() diff --git a/apps/backend/internal/orchestrator/executor/executor_resume.go b/apps/backend/internal/orchestrator/executor/executor_resume.go index 158547f9a0..5a5b0bf522 100644 --- a/apps/backend/internal/orchestrator/executor/executor_resume.go +++ b/apps/backend/internal/orchestrator/executor/executor_resume.go @@ -173,19 +173,15 @@ func (e *Executor) ensureRepoCloned(ctx context.Context, repo *models.Repository // persistLaunchState updates the session record after a successful agent launch. // The executors_running row is now written by the lifecycle manager itself in // lockstep with executionStore.Add (see lifecycle.persistExecutorRunning) — this -// function no longer touches it. The lifecycle manager also owns the columns that -// used to live on task_sessions (agent_execution_id, container_id); the orchestrator -// stops writing them so the only remaining source of truth is executors_running. +// function no longer touches it. The lifecycle manager also owns the columns +// that used to live on task_sessions (agent_execution_id, container_id); the +// orchestrator stops writing them so the only remaining source of truth is +// executors_running. // -// What remains here: state transitions (e.g., STARTING) and prepare-result metadata -// merge, both of which are session-row concerns the lifecycle manager doesn't know -// about. The execCfg / existingRunning parameters are kept on the signature for -// historical call shape but are no longer used. -func (e *Executor) persistLaunchState(ctx context.Context, taskID, sessionID string, session *models.TaskSession, resp *LaunchAgentResponse, startAgent bool, now time.Time, execCfg executorConfig, existingRunning *models.ExecutorRunning) { - _ = resp // executors_running fields are written by lifecycle manager - _ = execCfg // ditto - _ = existingRunning // ditto - +// What remains here: state transitions (e.g., STARTING) and prepare-result +// metadata merge, both of which are session-row concerns the lifecycle manager +// doesn't know about. +func (e *Executor) persistLaunchState(ctx context.Context, taskID, sessionID string, session *models.TaskSession, resp *LaunchAgentResponse, startAgent bool, now time.Time) { if startAgent { session.State = models.TaskSessionStateStarting } @@ -283,7 +279,7 @@ func (e *Executor) ResumeSession(ctx context.Context, session *models.TaskSessio } defer unlock() - req, repositoryID, execCfg, existingRunning, err := e.buildResumeRequest(ctx, task, session, startAgent) + req, repositoryID, _, _, err := e.buildResumeRequest(ctx, task, session, startAgent) if err != nil { return nil, err } @@ -343,7 +339,7 @@ func (e *Executor) ResumeSession(ctx context.Context, session *models.TaskSessio return nil, err } - e.persistResumeState(ctx, task.ID, session, resp, startAgent, execCfg, existingRunning) + e.persistResumeState(ctx, task.ID, session, startAgent) e.persistWorktreeAssociation(ctx, task.ID, session, repositoryID, resp) worktreePath := resp.WorktreePath @@ -703,14 +699,10 @@ func (e *Executor) applyResumeRepoConfig(ctx context.Context, task *v1.Task, ses // persistResumeState updates the session row after a successful resume launch. // Like persistLaunchState, executors_running is owned by the lifecycle manager -// and not touched here — see lifecycle.persistExecutorRunning. The orchestrator's -// only remaining responsibility is the session-row state machine (STARTING / -// CompletedAt-clear). -func (e *Executor) persistResumeState(ctx context.Context, taskID string, session *models.TaskSession, resp *LaunchAgentResponse, startAgent bool, execCfg executorConfig, existingRunning *models.ExecutorRunning) { - _ = resp - _ = execCfg - _ = existingRunning - +// and not touched here — see lifecycle.persistExecutorRunning. The +// orchestrator's only remaining responsibility is the session-row state +// machine (STARTING / CompletedAt-clear). +func (e *Executor) persistResumeState(ctx context.Context, taskID string, session *models.TaskSession, startAgent bool) { session.ErrorMessage = "" if startAgent { session.State = models.TaskSessionStateStarting diff --git a/apps/backend/internal/orchestrator/executor/executor_test.go b/apps/backend/internal/orchestrator/executor/executor_test.go index 2fb5c98e87..3e6557a752 100644 --- a/apps/backend/internal/orchestrator/executor/executor_test.go +++ b/apps/backend/internal/orchestrator/executor/executor_test.go @@ -841,8 +841,7 @@ func TestPersistResumeState_SetsStartingState(t *testing.T) { } repo.sessions[session.ID] = session - resp := &LaunchAgentResponse{AgentExecutionID: "exec-1"} - executor.persistResumeState(context.Background(), "task-1", session, resp, true, executorConfig{}, nil) + executor.persistResumeState(context.Background(), "task-1", session, true) if session.State != models.TaskSessionStateStarting { t.Errorf("expected state STARTING, got %s", session.State) @@ -861,8 +860,7 @@ func TestPersistResumeState_SetsStartingState(t *testing.T) { } repo.sessions[session.ID] = session - resp := &LaunchAgentResponse{AgentExecutionID: "exec-2"} - executor.persistResumeState(context.Background(), "task-1", session, resp, false, executorConfig{}, nil) + executor.persistResumeState(context.Background(), "task-1", session, false) if session.State != models.TaskSessionStateWaitingForInput { t.Errorf("expected state WAITING_FOR_INPUT, got %s", session.State) diff --git a/apps/web/components/task/executor-settings-button.tsx b/apps/web/components/task/executor-settings-button.tsx index 2014fcd448..9c671e95ef 100644 --- a/apps/web/components/task/executor-settings-button.tsx +++ b/apps/web/components/task/executor-settings-button.tsx @@ -173,21 +173,23 @@ export function ExecutorSettingsButton({ <> - {/* Borderless info trigger: not a button — just an icon + status dot. - tabIndex makes it focusable so keyboard users can still surface - the popover via focus. */} - for free Enter/Space activation, focus rings and + disabled semantics. variant="ghost" removes the outline so the + trigger reads as info, not as a clickable action — but we keep + the click→toggle behaviour the underlying HoverCard offers. */} +