Skip to content

Session lifecycle and robustness#8

Merged
chanakyav merged 1 commit intomainfrom
session-lifecycle-robustness
Mar 16, 2026
Merged

Session lifecycle and robustness#8
chanakyav merged 1 commit intomainfrom
session-lifecycle-robustness

Conversation

@chanakyav
Copy link
Copy Markdown
Owner

Summary

This PR addresses three session lifecycle and robustness issues:

1. STOPPED state (Closes #6)

  • Problem: Stopping an autopilot session marked it as FAILED, making it indistinguishable from actual failures.
  • Fix: Add STOPPED as a distinct terminal state. cmd_stop now saves the task's current state in pre_stop_state before marking it STOPPED.
  • New command: autopilot restart <task_id> re-launches a stopped task from its pre-stop phase, mapping waiting/verification states back to their action states.

2. Existing autopilot branch detection (Closes #7)

  • Problem: Running autopilot start --prompt "..." on an existing autopilot/<task-id> branch created an entirely new branch instead of working on the current one.
  • Fix: cmd_start now checks the current git branch. If it matches autopilot/*, it reuses that branch and uses a tailored prompt (implement_on_existing_branch_prompt) that instructs the agent to stay on the current branch rather than creating a new one.

3. Check codespace idle timeout before setting (Closes #4)

  • Problem: set_idle_timeout() always issued a PATCH request, even when the codespace timeout was already >= the desired value.
  • Fix: Add get_idle_timeout() to read the current value first. Skip the PATCH if the timeout is already sufficient.

Schema Changes

  • Schema version bumped from 3 to 4
  • New columns: pre_stop_state TEXT, existing_branch INTEGER NOT NULL DEFAULT 0
  • Migration handles existing databases gracefully

Tests

  • 93 tests passing (7 new tests for STOPPED state, existing branch, and migration)

…ion, idle timeout check

- Add STOPPED as a distinct terminal state (not FAILED) when stopping a session (#6)
  - cmd_stop saves pre_stop_state before marking STOPPED
  - Add cmd_restart to re-launch stopped tasks from their pre-stop phase
  - Orchestrator treats STOPPED as terminal alongside COMPLETE/FAILED

- Detect existing autopilot branch in cmd_start (#7)
  - If current branch matches autopilot/*, reuse it instead of creating new
  - Use implement_on_existing_branch_prompt that tells agent to stay on branch
  - Persist existing_branch flag in task for orchestrator to pick up

- Check codespace idle timeout before setting (#4)
  - GET current timeout first, skip PATCH if already >= desired value
  - Add get_idle_timeout() helper

- Schema v4: add pre_stop_state and existing_branch columns with migration
- 93 tests passing
@chanakyav chanakyav merged commit 6bc974d into main Mar 16, 2026
0 of 3 checks passed
@chanakyav chanakyav deleted the session-lifecycle-robustness branch March 16, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant