feat(automations): continue the last session without pinning a workspace first
Summary
- The "running in a new session / continuing the last session" option is now always available in the automation editor, not only when a workspace is pinned.
- When an automation continues sessions and has no pinned workspace, the first run's workspace (local or cloud) becomes the pin. Later runs reuse it and continue the session that run left.
Why / Context
Until now, continuing a session required picking an existing workspace up front. An automation that creates its own workspace had to start a new workspace every run, with no way to say "keep using the one you made last time".
How It Works
planTargetno longer refusescontinueAgentSessionwithout a pin. The mode now survives pin, host and project changes: it describes how runs behave, not one particular workspace.- New
pinCreatedWorkspaceinrun.tswrites the created workspace as the pin. It only writes when the automation is still unpinned and still continuing, so a pin a person set in the meantime is not overwritten.- Local: called when
createFreshWorkspacecreates the workspace. This includes the gone-pin fallback, which clears the stale pin first, so a deleted pinned workspace is replaced instead of the automation going back to a new workspace each run. - Cloud: called after
startCloudWorkspacewhen there was no pin. A stale cloud pin still moves throughreplacePin.
- Local: called when
replacePinno longer forcescontinueAgentSessionto false. The first run in a new pin finds no earlier session there (previousRunSessionfilters by workspace), so it starts a fresh session either way.- Desktop: the session chip always renders, and changing device, project or workspace no longer resets it.
- CLI: removed the client-side
--session+--continue-sessionrefusal, and updated the flag help text andcli-reference.mdx.
Compatibility
The input schema is unchanged; the server only accepts a combination it used to refuse. Older desktop builds hide the chip when no workspace is pinned and send continueAgentSession: false when a workspace is cleared, which still behaves correctly. Released CLIs still refuse --session --continue-session locally, which is harmless. The continueNeedsPinnedWorkspace server-error message is no longer thrown; I left it in server-errors.ts to avoid catalog churn.
Manual QA Checklist
Not yet done in a running app:
- Local automation, no workspace picked: choose "continuing the last session" and save. Run 1 creates a workspace, which now shows in "using". Run 2 delivers into the same agent session.
- Cloud automation, environment only: same flow. Run 1 starts a cloud workspace, and run 2 continues in it.
- Delete the pinned local workspace, then run: a fresh workspace is created and becomes the new pin.
- "In a new session" with no pin: each run still creates its own workspace, and nothing is pinned.
Testing
bun test src/router/automationinpackages/trpc: 42 pass. TheplanTargettests were updated for the new rules, including a new "continues a session with no pin yet" case.bun run typecheckpasses inpackages/trpcandpackages/cli. Inapps/desktop, the only errors are TS1149 file-casing errors from this worktree's path, none in changed files.biome checkpasses on the changed files.pinCreatedWorkspacehas no unit test:packages/trpchas no database harness.
Summary by cubic
The "continue the last session" option in the automation editor now works without pinning a workspace first. Previously, continuing a session required selecting an existing workspace up front, so automations that create their own workspace had to start fresh every run. Now, when an unpinned automation continues sessions, the first run's workspace (local or cloud) becomes the pin, and later runs reuse that workspace and continue the session it left.
Key changes
planTargetno longer rejectscontinueAgentSessionwithout a pin, and keeps the mode through pin, host, and project changes.- New
pinCreatedWorkspacewrites the created workspace as the pin only when the automation is still unpinned and still continuing, so a pin set manually in the meantime is not overwritten. It also handles a deleted pinned workspace by replacing the stale pin. replacePinno longer forcescontinueAgentSessionto false, since the first run in a new pin finds no earlier session and starts fresh anyway.- In the desktop editor, the session chip always renders and is no longer reset when the device, project, or workspace changes.
- The CLI no longer refuses
--sessioncombined with--continue-session; help text andcli-reference.mdxwere updated.
The input schema is unchanged; the server only accepts a combination it used to refuse. Older desktop builds hide the chip when no workspace is pinned and send continueAgentSession: false when a workspace is cleared, which still behaves correctly.
Summary by CodeRabbit
- New Features
- Automations can now continue agent sessions without a pre-pinned workspace. The first run’s workspace is retained for later runs.
- The session-mode picker is available regardless of the selected workspace.
- Automation updates can combine session selection with session continuation.
- Bug Fixes
- Changing or clearing a host, project, or workspace no longer turns off session continuation.