Skip to content

feat(cmd): warn before clean-only return default - #221

Open
Dematom1 wants to merge 3 commits into
kunchenguid:mainfrom
Dematom1:fm/treehouse-220-default-clean
Open

Dematom1 wants to merge 3 commits into
kunchenguid:mainfrom
Dematom1:fm/treehouse-220-default-clean

Conversation

@Dematom1

@Dematom1 Dematom1 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Upstream issue accepted: when a maintainer labels one of our upstream issues ready-for-pr, start the PR immediately and raise it once green (standing preference, 2026-11-04). Posting the issue was approved as written on 2026-11-19.

Issue #220 (full text in data/treehouse-220-default-clean/issue.md) proposes making plain treehouse return use the clean-only behavior that --if-clean added in PR 217, staged: "First ship a documented warning period, with warnings on stderr and the old behavior and exit codes unchanged. Callers can opt into safety now with --if-clean." Then the default flips in the next major release, keeping --force as the explicit destructive escape, exit 4 plus a stdout blocker for default clean-only refusals, return --all covered with per-slot checks, and jj refused as unsupported until equivalent verification exists.

The maintainer labeled it ready-for-pr (triage in data/treehouse-220-default-clean/triage.md): contract-class new-default, so the PR is not auto-merged and goes to Kun for his own decision; the refusal must keep stdout data separate from stderr diagnostics and use exit status honestly; it needs realistic end-to-end and failure tests, including return --all and the jj unsupported path.

This PR is the first stage of that plan: the documented warning period.

Full text of issue #220, as approved and posted:

Could plain treehouse return default to the clean-only behavior added in #217?

Today, plain return can terminate processes and reset a clean worktree whose HEAD has not landed. A named branch survives, but a detached commit can become reachable only through the reflog. Dirty non-interactive returns already fail closed; clean unpushed work deserves the same protection. Requiring every automated caller to discover --if-clean leaves the less safe path as the easiest one.

This follows VISION's instruction to leave unverifiable work in place, and its allowance for safety-driven breaking changes with a clear migration path. I recognize that the merged change explicitly promised opt-in behavior; this would be a separate breaking change, not a correction to that implementation.

Proposed behavior and migration:

  • Make plain return use the existing locked clean-only checks, including changed seeded files and landedness on a remote-tracking ref or the parking base. Refuse without prompting or terminating processes, and keep the worktree and lease on a clean-only refusal. Keep --if-clean as an explicit, compatible spelling.
  • Announce the change for the next major release. First ship a documented warning period, with warnings on stderr and the old behavior and exit codes unchanged. Callers can opt into safety now with --if-clean.
  • Retain the existing --force as the explicit destructive escape for callers that intentionally discard work. Keep lease-identity conditions and existing ownership/lock protections. Do not silently retry a refused return with force.
  • Preserve exit 0 for a completed single return and exit 1 for operational or lease failures. Use the existing exit 4 and stdout blocker for default clean-only refusals; document that plain-return dirty aborts currently use exit 3. Scripts that handle only 3, pipe confirmation answers, or assume return kills workers need migration.
  • Cover return --all in the same migration: check each eligible slot safely, report retained slots, and document aggregate exit precedence. Keep forced bulk cleanup explicit. For jj, refuse as unsupported until equivalent verification exists; document the explicit-force migration rather than silently retaining unsafe defaults.

Maintainer triage of #220 (substance): VISION-aligned; contract-class new-default, so the implementing PR is not auto-merged and goes to Kun for his own decision; the refusal must keep stdout data separate from stderr diagnostics and use exit status honestly; core lifecycle and destructive-path change, so it needs realistic end-to-end and failure tests, including return --all and the jj unsupported path.

What Changed

  • Add a warning period for plain return and return --all: stderr warnings identify slots that clean-only checks would refuse, while existing behavior and exit statuses remain unchanged.
  • Reuse clean-only checks to report dirty, active-process, unpushed, unverifiable, and unsupported jj cases; document migration options using --if-clean and --force.
  • Add end-to-end coverage for warning behavior, unchanged return outcomes, bulk returns, explicit modes, and jj workspaces.

Risk Assessment

✅ Low: The change is a bounded advisory warning period that preserves plain-return behavior and reuses the clean-only checks for accurate warnings.

Testing

Ran the new end-to-end advisory-check failure case and targeted neighboring CLI scenarios for unlanded work, live workers, and return --all; all passed against disposable local Git repositories. Captured the new case's run log. No source changes were needed.

  • Live validation: ✅ go - 2 of 2 scenarios driven live against the product
Scenario Result Live Evidence
Plain return survives a failed clean-only advisory check ✅ pass live go test ./cmd -run '^TestPlainReturnWarnsWhenTheAdvisoryCheckFailsAndKeepsItsOutcome$' -count=1 -v; log: `~/.no-mistakes/evidence/01M7XFB4W3JE83BEDTH124HVX8/return-advisory-fail…
Warning period preserves legacy behavior for unlanded, active, and bulk returns ✅ pass live go test ./cmd -run 'TestPlainReturnWarnsAboutAnUnlandedHeadAndStillReturnsIt|TestPlainReturnWarnsAboutLiveProcessBeforeTerminatingIt|TestReturnAllWarnsPerSlotAndKeepsItsOutcome' -count=1 -v
Evidence: Advisory-check failure end-to-end test
=== RUN   TestPlainReturnWarnsWhenTheAdvisoryCheckFailsAndKeepsItsOutcome
--- PASS: TestPlainReturnWarnsWhenTheAdvisoryCheckFailsAndKeepsItsOutcome (1.27s)
PASS
ok  	github.com/kunchenguid/treehouse/v3/cmd	1.976s

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 2 of 2 scenarios driven live against the product
Scenario Result Live Evidence
Plain return survives a failed clean-only advisory check ✅ pass live go test ./cmd -run '^TestPlainReturnWarnsWhenTheAdvisoryCheckFailsAndKeepsItsOutcome$' -count=1 -v; log: `~/.no-mistakes/evidence/01M7XFB4W3JE83BEDTH124HVX8/return-advisory-fail…
Warning period preserves legacy behavior for unlanded, active, and bulk returns ✅ pass live go test ./cmd -run 'TestPlainReturnWarnsAboutAnUnlandedHeadAndStillReturnsIt|TestPlainReturnWarnsAboutLiveProcessBeforeTerminatingIt|TestReturnAllWarnsPerSlotAndKeepsItsOutcome' -count=1 -v
  • go test ./cmd -run '^TestPlainReturnWarnsWhenTheAdvisoryCheckFailsAndKeepsItsOutcome$' -count=1 -v
  • go test ./cmd -run 'TestPlainReturnWarnsAboutAnUnlandedHeadAndStillReturnsIt|TestPlainReturnWarnsAboutLiveProcessBeforeTerminatingIt|TestReturnAllWarnsPerSlotAndKeepsItsOutcome' -count=1 -v
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…lean-only default

Plain 'treehouse return' and 'return --all' now print one stderr warning for
each worktree that 'return --if-clean' would refuse, naming the blocker, or
for a jj workspace that it will be refused as unsupported. Behavior, stdout,
and exit statuses are unchanged. --if-clean and --force print no warning.

The warning reuses the --if-clean checks through pool.CheckReleaseClean,
which judges under the state lock and changes nothing. README documents the
planned default change and how to migrate.

First stage of kunchenguid#220.
@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no outstanding findings.

Reviews (3) · Last reviewed commit: "test(return): cover advisory-check failu..." · Reviewed by Greptile

Comment thread internal/pool/pool.go Resolved
Comment thread cmd/return_default_warning_e2e_test.go Resolved
…t merge check while sharing ref/HEAD resolution; updated design docs. Added live-worker warning-order/return coverage and a generic advisory-error warning test. Targeted cmd and clean-focused pool tests pass; broader internal pool suite timed out at 120s
Replace the direct call of the warning helper with an end-to-end case: a slot
parked on an explicit base branch that was deleted since makes the clean-only
snapshot fail, so the plain return prints the generic 'cannot verify' warning
while keeping its unchanged fallback, empty stdout, and exit 0.
@Dematom1 Dematom1 changed the title feat(cmd): warn before return's planned clean-only default feat(cmd): warn before clean-only return default Nov 20, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @Dematom1, this is a careful first stage of #220. I read the full diff against current main 38fcb38 (cmd/return_cmd.go, internal/pool/pool.go, internal/vcs/*, README, design doc, and the new e2e tests). I see no security risk. Every check is green on 963c0fd, including both no-mistakes checks and Windows. Greptile is at 5/5 on that head with nothing outstanding, and the PR is CLEAN.

Contract-class: new-default. Plain treehouse return and return --all, with no flags, now run the clean-only checks under the pool lock and print new stderr warnings. Stdout, prompts, exit statuses, and effects are unchanged, but the unconfigured run still does something it didn't before (always-on), and it starts the default migration #220 describes. As the #220 triage said, that is Kun's call, so I won't auto-merge it.

VISION per-rule (VISION.md on main 38fcb38):

  • Isolation and reuse: aligns. No change to acquisition or recycling. It only reports what --if-clean would refuse.
  • Safe lifecycle operations: aligns. This follows "when safety requires a breaking change, make the risk and migration path plain." The warning prints before any confirmation, termination, or reset, and the README states the migration (--if-clean / --force, exit 3→4, --all, jj).
  • Ownership and interface: aligns. Diagnostics go only to stderr and stdout is untouched. Exit status is unchanged, including when the advisory check itself fails (covered by TestPlainReturnWarnsWhenTheAdvisoryCheckFailsAndKeepsItsOutcome). The warnings use the 🌳 branding.
  • Scope and evaluation: aligns. This is a lifecycle change with e2e coverage of unlanded, live-worker, bulk, explicit-mode, jj, and check-failure paths, plus live evidence in the body.

This is a captain-decision hold, not something waiting on you. Nothing is needed from you right now. I'm taking it to Kun as ready for his decision.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants