Skip to content

fix(env): warn when a DISABLE_* flag is set to a falsy value - #48

Merged
miguelrisero merged 1 commit into
mainfrom
fix/env-disable-gate-warn
Jul 26, 2026
Merged

fix(env): warn when a DISABLE_* flag is set to a falsy value#48
miguelrisero merged 1 commit into
mainfrom
fix/env-disable-gate-warn

Conversation

@miguelrisero

Copy link
Copy Markdown
Owner

Problem

The four DISABLE_* opt-out gates use std::env::var(..).is_ok(), which is true for any value. So DISABLE_WORKTREE_CLEANUP=0 still disables cleanup — the opposite of what setting it to 0 suggests. Same for false, no, off, and the empty string.

Affected gates:

Location Flag
workspace_manager.rs:539 DISABLE_WORKTREE_CLEANUP
container.rs:281 DISABLE_WORKTREE_CLEANUP
container.rs:319 DISABLE_CLI_SESSION_REAP
loop_supervisor.rs:358 DISABLE_LOOP_AUTOMATION

Approach: warn, don't reinterpret

The obvious fix is to parse booleans properly. This PR deliberately does not do that.

Two of these gates guard cleanup_workspace(), which kills CLI tmux sessions, deletes worktrees, and marks them deleted in the DB. If DISABLE_WORKTREE_CLEANUP=0 started meaning "enabled", anyone currently relying on the permissive behaviour would have worktree deletion silently switched on by what looks like a routine bug fix. That is a bad thing to ship in a drive-by change.

So the semantics are unchanged — any value still disables — and a falsy-looking value now produces a warning telling you to unset the variable instead. The confusion is fixed without any behavioural risk.

If you'd rather have strict boolean parsing, that's a reasonable call, but it should be a deliberate breaking change with a release note rather than folded in here.

Changes

  • New utils::env::disable_flag_set(), following the existing normalize_path_override pattern in that module (pure inner fn for testability, tracing::warn! on the surprising case)
  • All four gates routed through it
  • 3 unit tests, including one asserting that 0, false, no, off, "" and " FALSE " all still disable

WSL_DISTRO_NAME / WSLENV in utils::is_wsl2 are left alone — those are genuine presence checks, not opt-out flags.

Verification

  • cargo test -p utils --lib env — 12 passed (9 existing + 3 new)
  • cargo check -p workspace-manager -p local-deployment — clean

Provenance

To be clear about authorship: this was written by Claude Code on the shared ded02 dev box at @dev1's request, while investigating a disk-space issue. The commit is attributed to Miguel Rasero because that is the git identity configured in that checkout and the only GitHub credential available on the box — not because Miguel wrote or reviewed it. Flagging so the history isn't misread.

It came out of noticing that DISABLE_WORKTREE_CLEANUP=1 was set on the dev servers. Worth saying plainly: this fix would not have prevented that disk issue. The space was in active, registered worktrees that no cleanup path touches; the orphaned dirs totalled ~6 MB.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UsimweKP7yPhJFvCSGswBa

The `std::env::var(..).is_ok()` gates treat any value as "disable", so
`DISABLE_WORKTREE_CLEANUP=0` still disables cleanup — the opposite of what
setting it to 0 suggests.

Route the four opt-out gates through a shared `utils::env::disable_flag_set`
helper that keeps the existing permissive semantics and logs a warning when the
value looks falsy (0/false/no/off/empty).

The semantics are deliberately left unchanged. Two of these gates guard
`cleanup_workspace()`, which kills CLI tmux sessions and deletes worktrees.
Reinterpreting `DISABLE_WORKTREE_CLEANUP=0` as "enabled" would silently switch
worktree deletion back on for anyone relying on the current behaviour, so the
surprising value is reported rather than reinterpreted.

`WSL_DISTRO_NAME`/`WSLENV` in utils::is_wsl2 are left alone: those are genuine
presence checks, not opt-out flags.
@miguelrisero
miguelrisero merged commit 8449971 into main Jul 26, 2026
7 checks passed
@miguelrisero
miguelrisero deleted the fix/env-disable-gate-warn branch July 26, 2026 18:13
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.

1 participant