3.4 KiB
3.4 KiB
id, title, status, wave, depends_on, plan, spec, decision
| id | title | status | wave | depends_on | plan | spec | decision | |
|---|---|---|---|---|---|---|---|---|
| 02-lifecycle-creation-barrier | Serialize task cleanup with creation | done | 2 |
|
plan.md | ../../specs/tasks/requirements/session-delete-resource-cleanup.md | ../../decisions/2026-08-08-task-owned-worktree-lifetime.md |
Task 02: Serialize Task Cleanup With Session and Worktree Creation
Acceptance
- Archive/delete preparation reserves a durable lifecycle barrier before capturing resource inventory.
- Session creation and canonical environment-repository persistence serialize against the owning task and cannot commit after cleanup preparation has begun.
- PostgreSQL row locking and SQLite writer serialization enforce the same contract without relying on an in-process mutex.
- The barrier transaction commits before filesystem, target-path, repository, or Git locks are acquired.
- A worktree physically created before a concurrent barrier rejection is safely compensated without touching pre-existing resources.
DeleteSessiondoes not reserve or activate a cleanup job and cannot invoke a physical worktree cleaner, including for the last session.- A new session created after an old session is deleted reuses the retained task environment when no task-lifecycle barrier exists.
TDD Sequence
- RED: add repository concurrency tests that pause archive/delete after barrier reservation and prove session/environment-repository insertion cannot cross the barrier.
- RED: exercise the inverse ordering and prove a committed session/worktree is included in the later task snapshot.
- RED: add a materialization test where the database barrier rejects the owner transaction after Git creation and assert bounded, target-specific rollback.
- RED: add
DeleteSessionregressions for the only session and one of two shared sessions, with a spy that fails on cleanup-job activation or physical cleanup. - GREEN: implement the prepared-job barrier and task-row serialization for both database engines.
- REFACTOR: make lock ordering explicit in comments/tests and keep Git locks outside the database transaction.
Verification
cd apps/backend && go test ./internal/task/repository/sqlite/... -run 'Cleanup|Barrier|Session'
cd apps/backend && go test ./internal/task/service/... -run 'Cleanup|Archive|Delete'
cd apps/backend && go test ./internal/orchestrator/... -run 'DeleteSession|Environment|Worktree'
Files likely touched
apps/backend/internal/task/service/resource_cleanup_jobs.goapps/backend/internal/task/repository/sqlite/resource_cleanup.goapps/backend/internal/task/repository/sqlite/session.goapps/backend/internal/worktree/store.goapps/backend/internal/orchestrator/task_operations.goapps/backend/internal/orchestrator/executor/task_environment.goapps/backend/internal/orchestrator/executor/executor_environment_reuse.go
Dependencies
- Task 01 supplies the canonical environment-repository transaction and compensation seam.
Inputs
- Existing task operation locks and worktree manager target-path/repository lock order.
- Existing prepared/activated
task_resource_cleanup_jobslifecycle.
Output contract
Report the exact serialization point for SQLite and PostgreSQL, both tested race orderings, the lock-order proof, materialization compensation result, and a call trace showing that session deletion performs no filesystem, Git, branch, or cleanup-job action.