Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .agents/skills/secondmate-provisioning/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ It refuses retirement while that cleanup is uncertain or unavailable, preserving
Raw deletion is unsupported because a blocking process-event child can outlive its home.

With `--force`, teardown is the explicit discard path.
The worktree-slot ownership contract in `bin/fm-teardown.sh` still applies: `--force` never authorizes returning a descendant pool slot that another task may own.
It kills child windows, discards child work and state inside the secondmate home, removes the route, releases the lease, and removes the retired secondmate home.
If forced teardown contends with a fresh task publication in any affected home, one command refuses without publishing or removing task state; treat that refusal as terminal and inspect the other operation before retrying.
Relaunch and non-forced teardown remain outside that serialization.
Expand Down
27 changes: 27 additions & 0 deletions bin/fm-spawn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@
# even when they select different backends. A fresh spawn first takes the
# per-home task-set lock and refuses rather than waits when forced teardown owns
# it; relaunch is exempt because the existing task's control lock covers it.
# A fresh Treehouse-backed spawn also takes the project-identity lock in the root
# Firstmate home's state directory before slot allocation and holds it through
# task metadata publication. Teardown holds that same lock while proving and
# returning a slot, so allocation cannot reuse a slot before its owner record
# is published;
# contention refuses rather than waits.
# With no harness arg, a crewmate/scout spawn resolves the CREW harness only when
# config/crew-dispatch.json is absent. When that file exists, crewmate/scout
# spawns require an explicit harness so firstmate cannot silently skip dispatch
Expand Down Expand Up @@ -808,6 +814,8 @@ SPAWN_META_PUBLISH_STARTED=0
SPAWN_FRESH_COMMIT_PENDING=0
SPAWN_TASK_SET_LOCK=
SPAWN_TASK_SET_LOCK_HELD=0
SPAWN_TREEHOUSE_PROJECT_LOCK=
SPAWN_TREEHOUSE_PROJECT_LOCK_HELD=0
RELAUNCH_REPLACEMENT_PENDING=0
RELAUNCH_REPLACEMENT_BUSY_GEN=
RELAUNCH_REPLACEMENT_HARNESS=
Expand Down Expand Up @@ -939,6 +947,10 @@ spawn_abort_cleanup() {
SPAWN_META_LOCK_HELD=0
fm_lock_release "$SPAWN_META_LOCK" || true
fi
if [ "$SPAWN_TREEHOUSE_PROJECT_LOCK_HELD" = 1 ]; then
SPAWN_TREEHOUSE_PROJECT_LOCK_HELD=0
fm_lock_release "$SPAWN_TREEHOUSE_PROJECT_LOCK" || true
fi
if [ "$SPAWN_TASK_SET_LOCK_HELD" = 1 ]; then
SPAWN_TASK_SET_LOCK_HELD=0
fm_lock_release "$SPAWN_TASK_SET_LOCK" || true
Expand Down Expand Up @@ -2020,6 +2032,17 @@ else
WT=""
BRIEF="$DATA/$ID/brief.md"
fi
if [ "$RELAUNCH" -eq 0 ] && [ "$KIND" != secondmate ] && [ "$BACKEND" != orca ]; then
SPAWN_TREEHOUSE_PROJECT_LOCK=$(fm_treehouse_project_lock_path "$PROJ_ABS") || {
echo "error: could not resolve the shared Treehouse project lock for $PROJ_ABS" >&2
exit 1
}
if ! fm_lock_try_acquire "$SPAWN_TREEHOUSE_PROJECT_LOCK"; then
echo "error: another Treehouse slot allocation or return is in progress for $PROJ_ABS; refusing to race it" >&2
exit 1
fi
SPAWN_TREEHOUSE_PROJECT_LOCK_HELD=1
fi
[ -f "$BRIEF" ] || { echo "error: task $ID has no brief at inaccessible data path $BRIEF" >&2; exit 1; }
if [ "$KIND" = ship ] || [ "$KIND" = scout ]; then
if fm_brief_task_placeholders_present "$BRIEF"; then
Expand Down Expand Up @@ -3392,6 +3415,10 @@ fi
# still being delivered, cannot observe or complete a fresh provisional record
# between its state check and `tasks-axi start`, and a delivery failure cannot
# follow a committed In-flight transition.
if [ "$SPAWN_TREEHOUSE_PROJECT_LOCK_HELD" = 1 ]; then
SPAWN_TREEHOUSE_PROJECT_LOCK_HELD=0
fm_lock_release "$SPAWN_TREEHOUSE_PROJECT_LOCK"
fi
if [ "$SPAWN_TASK_SET_LOCK_HELD" = 1 ]; then
# The record is published, so this task is now part of the set a teardown
# enumerates and locks per task. The set lock is only needed across that
Expand Down
Loading
Loading