Skip to content

fix(polecat): release pool slot on submit (worktree+branch cleanup)#9

Open
eric-jones wants to merge 1 commit into
mainfrom
topic/polecat-release-pool-slot
Open

fix(polecat): release pool slot on submit (worktree+branch cleanup)#9
eric-jones wants to merge 1 commit into
mainfrom
topic/polecat-release-pool-slot

Conversation

@eric-jones
Copy link
Copy Markdown
Owner

Fork-PR for review. Upstream: gastownhall#1925 WITHDRAWN 2026-05-20 (Q3 lifecycle-hook). Retained on fork.

@eric-jones eric-jones force-pushed the topic/polecat-release-pool-slot branch from 95d2e69 to 8099cd3 Compare May 20, 2026 16:07
…emove worktree

Polecat slots are bounded; a stale per-polecat branch and worktree
pinned to a dead bead is counted as "occupied" by the reconciler.
Under fan-out the next sling either reuses a stale workspace
(subtle) or never spawns a polecat at all (visible — the stuck
"3rd fan-out child unassigned" symptom). The polecat formula's
submit-and-exit step had a `git checkout --detach && git branch -D`
fragment that deleted the local branch but left the worktree on
detached HEAD; nothing removed the worktree. Worse, the agent
prompt template's FINAL REMINDER done sequence (which is what the
agent actually follows — agents in a session don't re-pour the
formula) had no cleanup at all. Result: every polecat session
across L4 / L5a / L5b / L5c left its worktree behind, and the
reconciler counted those slots as in-use.

`examples/gastown/packs/gastown/agents/polecat/prompt.template.md`
— FINAL REMINDER done sequence now captures `WORKTREE_PATH=$(pwd)`
and `BRANCH=$(git branch --show-current)`, `cd "$GC_RIG_ROOT"`, then
`git branch -D "$BRANCH"` and `git worktree remove --force
"$WORKTREE_PATH"` BEFORE `gc runtime drain-ack`. The cd is
load-bearing: `git worktree remove` refuses to delete the cwd, and
`$GC_RIG_ROOT` is the canonical rig checkout (the only worktree
guaranteed to exist after this cleanup). Subsequent `gc bd` and
`gc runtime` calls are path-agnostic.

`examples/gastown/packs/gastown/formulas/mol-polecat-work.toml` —
submit-and-exit step renumbered: old step 3 ("Clean up local
branch") removed in favor of new step 5 ("Release the pool slot")
that does branch-D + worktree-remove together, after the
reassign-to-refinery step. Description spells out the "cd before
remove" gotcha and the consequence of skipping the step.

`examples/gastown/gastown_test.go` — new
TestPolecatReleasesPoolSlotOnSubmit asserts the chained shape in
both files (prompt template's done sequence and formula's
submit-and-exit step), and explicitly rejects the prior `git
checkout --detach` shape so reverting half the fix fails the test.

Surface: polecat agent prompt template + mol-polecat-work formula
step prompt; not gascity Go code.

A runtime-level worktree janitor (gc reconciler that prunes
worktrees of closed beads as defense-in-depth) — would be a Go
behavior change, larger surface. Prompt-only fix closes the
observed regression.

- [x] `make build` — clean
- [x] `make check` — full suite passes (only failure is documented EXPECT-FAIL `TestDoctorScriptIgnoresDocumentedSystemSchemasForBackupFreshness`, unrelated to this PR)
- [x] `go test ./examples/gastown/ -run TestPolecatReleasesPoolSlotOnSubmit -count=1 -v` — passes
- [ ] `make check-docs` — not run (no docs files touched)
- [ ] `make test-integration` — not run (per CONTRIBUTING; prompt-only formula edit, no runtime/controller behavior touched)

- [x] Linked an issue, or explained why one is not needed: prompt-only fix surfaced from internal L5 fan-out testing; no public issue.
- [x] Added or updated tests for behavior changes: `TestPolecatReleasesPoolSlotOnSubmit` covers both files in sync.
- [x] Updated docs for user-facing changes: formula prompt + agent prompt updated directly; the new shape and the rationale prose are the user-visible change.
- [x] Called out breaking changes or migration notes: none — the prompt is what the LLM agent reads each cycle; no runtime contract change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Upstream-PR: gastownhall#1925
@eric-jones eric-jones force-pushed the topic/polecat-release-pool-slot branch from 8099cd3 to 10c596d Compare May 20, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant