Skip to content

fix(devtools): dispose a verification run's temp and daemon when it ends - #4333

Merged
Sinity merged 2 commits into
masterfrom
fix/dmypy-leak
Aug 27, 2026
Merged

Sinity merged 2 commits into
masterfrom
fix/dmypy-leak

Conversation

@Sinity

@Sinity Sinity commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Summary

A verification run left two things behind for an age sweep to collect days later. Both are now disposed when the run no longer needs them.

Problem

pytest temp. pytest keeps the last three numbered run directories under one temp root and deletes older ones. The session TMPDIR is per-shell, so every nix develop --command starts a fresh root and that pruning never fires. Measured: 17,707 shell directories holding 128 GB, 191 of them over 100 MB, several at 3.5 GB each.

dmypy. devtools verify starts mypy's persistent daemon, which is reparented to the user manager and outlives the run that started it. In the main checkout that is the point — successive runs reuse the type cache. A lane or batch worktree gates once and is then disposed, so its daemon is never reused and never exits. Measured: ten alive holding 9.2 GB, from gates finished up to three and a half hours earlier. Killing them took free memory from 3.5 GB to 11 GB.

This is what looked like a ceiling on concurrent verification. An active run is ~1.5 GB; the pressure was dead weight.

Solution

The run owns its basetemp and removes it on success. A failed run keeps its tree, since that is when the fixtures are worth reading.

A non-primary checkout uses plain mypy. The daemon stays where repeated runs amortise it.

Verification

A green devtools test leaves no .cache/verify/tmp; a failing one keeps it (2.6 MB observed).
_is_primary_checkout() returns False in /realm/worktrees/batch-14 and selects ['mypy']; True in the main checkout, selecting ['dmypy','run'].

Residual risk

Existing shell directories are not retroactively cleaned by this change; /realm/tmp/shell still ages out on the 7-day tmpfiles rule. Plain mypy is slower than a warm daemon on repeated runs in the same worktree, which ephemeral worktrees do not do.

🤖 Generated with Claude Code

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

Sinity and others added 2 commits August 27, 2026 12:11
`devtools verify` starts dmypy for incremental type checking. The daemon is
reparented to the user manager, so it outlives the run that started it and
exits only when killed. In the main checkout that is the point: successive
runs reuse the cache. A lane or batch worktree gates once and is then
disposed, so its daemon is never reused and simply accumulates.

Ten were alive holding 9.2 GB, from gates finished up to three and a half
hours earlier; killing them took free memory from 3.5 GB to 11 GB. What looked
like a ceiling on concurrent verification was this.

A non-primary checkout now uses plain mypy; the daemon stays where repeated
runs amortise it.

Verification: `_is_primary_checkout()` is False in /realm/worktrees/batch-14
and selects `['mypy']`; True in the main checkout, selecting `['dmypy','run']`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA
Two things a run created were left for an age sweep days later.

pytest's temp trees live under the session TMPDIR, which is per-shell, so its
own "keep the last three runs" pruning never fires: every shell starts a fresh
root and nothing is ever pruned. 17,707 shell directories held 128 GB, with
191 of them over 100 MB and several at 3.5 GB. The run now owns its basetemp
and removes it on success, keeping it when the run fails — that is when the
fixtures are worth reading.

`devtools verify` also starts dmypy, which is reparented to the user manager
and outlives the run. In the main checkout successive runs reuse the cache; a
lane or batch worktree gates once and is disposed, so its daemon accumulates.
Ten held 9.2 GB from gates finished up to three and a half hours earlier.
A non-primary checkout now uses plain mypy.

Verification: a green `devtools test` leaves no `.cache/verify/tmp`; a failing
one keeps it. `_is_primary_checkout()` is False in a worktree and selects
`['mypy']`, True in the main checkout and selects `['dmypy','run']`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA
@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 694fddb1-5153-48d9-bfd2-b7737d2efae5


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Sinity
Sinity merged commit 26fc443 into master Aug 27, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the fix/dmypy-leak branch August 27, 2026 10:24

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e6fa83344

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread devtools/run_tests.py Resolved
Comment thread devtools/run_tests.py Resolved
Comment thread devtools/verify.py Resolved
Sinity added a commit that referenced this pull request Aug 27, 2026
…#4334)

## Summary
Reverts the worktree exemption from #4333 and moves the daemon's
shutdown to the point where the workspace is actually gone.

## Problem
#4333 stopped using dmypy in non-primary checkouts to prevent the leak.
Measured afterwards in a batch worktree:

| | time |
|---|---|
| plain mypy | 50s |
| dmypy, cold start | 51s |
| dmypy, warm | **1s** |

A workspace is gated repeatedly while it is repaired, so only the first
run pays for the cache. The exemption bought memory that a lifecycle
hook releases anyway, at ~49s per re-gate.

mypy's own idle timeout does not solve it either: a daemon started with
`--timeout 10` was still running after twenty seconds idle, so that flag
cannot be relied on.

## Solution
sinnixd stops the daemon when it removes a worktree (sinnix `3f8fcea2`),
which releases the cache exactly when the workspace it describes
disappears. devtools uses the daemon everywhere again.

## Verification
`devtools verify --quick` green in the main checkout with the daemon in
use.
sinnix side: `nix build .#sinnixd` and `nix develop --command check`
green, with a test asserting removal invokes `dmypy stop` and tolerates
a workspace with no provisioned venv.

## Residual risk
A worktree removed outside `agentctl workspace` — by hand, or by `git
worktree remove` directly — still leaks its daemon. The basetemp
lifecycle from #4333 is unaffected and stays.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Aug 27, 2026
…nds (#4333)

## Summary
A verification run left two things behind for an age sweep to collect
days later. Both are now disposed when the run no longer needs them.

## Problem
**pytest temp.** pytest keeps the last three numbered run directories
under one temp root and deletes older ones. The session TMPDIR is
per-shell, so every `nix develop --command` starts a fresh root and that
pruning never fires. Measured: **17,707 shell directories holding 128
GB**, 191 of them over 100 MB, several at 3.5 GB each.

**dmypy.** `devtools verify` starts mypy's persistent daemon, which is
reparented to the user manager and outlives the run that started it. In
the main checkout that is the point — successive runs reuse the type
cache. A lane or batch worktree gates once and is then disposed, so its
daemon is never reused and never exits. Measured: **ten alive holding
9.2 GB**, from gates finished up to three and a half hours earlier.
Killing them took free memory from 3.5 GB to 11 GB.

This is what looked like a ceiling on concurrent verification. An active
run is ~1.5 GB; the pressure was dead weight.

## Solution
The run owns its basetemp and removes it on success. A failed run keeps
its tree, since that is when the fixtures are worth reading.

A non-primary checkout uses plain mypy. The daemon stays where repeated
runs amortise it.

## Verification
A green `devtools test` leaves no `.cache/verify/tmp`; a failing one
keeps it (2.6 MB observed).
`_is_primary_checkout()` returns False in `/realm/worktrees/batch-14`
and selects `['mypy']`; True in the main checkout, selecting
`['dmypy','run']`.

## Residual risk
Existing shell directories are not retroactively cleaned by this change;
`/realm/tmp/shell` still ages out on the 7-day tmpfiles rule. Plain mypy
is slower than a warm daemon on repeated runs in the same worktree,
which ephemeral worktrees do not do.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Aug 27, 2026
…g collected (#4343)

## Summary
Fixes a regression from #4333 plus the diagnosis gap that has repeatedly
misled integration.

## Problem
**Colliding basetemp.** #4333 pointed `--basetemp` at a fixed path.
pytest creates that directory itself and fails when it exists, so two
runs in one checkout collide:

```
INTERNALERROR> FileExistsError: [Errno 17] File exists: '.cache/verify/tmp'
```

Lanes, batches and the coordinator all run concurrently in the same
checkout here, so this fires routinely — and an INTERNALERROR mid-run is
a plausible source of the empty collections that were being written off
as flakes.

**Cleanup that silently failed.** Tests seal archive generations
read-only, so `rmtree(ignore_errors=True)` could not unlink them and
left the tree behind — exactly the accumulation #4333 set out to stop.

**Indistinguishable exit 5.** pytest exits 5 both when a selection
genuinely matches nothing and when a path in it does not exist. A
selection derived from `git diff --name-only` contains files the branch
deleted, so the run collects nothing and reads as "no work to do". That
has already produced false conclusions during integration, including a
report that multi-path selections were broken.

## Solution
The basetemp is unique per invocation. Cleanup clears permissions before
removing. On exit 5 the runner names the absent paths, or states that
every path existed so the caller looks at the `-k`/`-m` expression or
contention instead.

## Verification
`devtools verify --quick` → exit 0.
`devtools test tests/unit/devtools/test_run_tests.py` → exit 0.
A selection naming a deleted file prints `collected nothing because
these paths do not exist: tests/unit/gone.py`.
Repeated green runs leave no `.cache/verify/tmp-*` behind; a failed run
keeps its own for inspection.

## Residual risk
A failed collection still keeps an empty temp directory, which is litter
rather than a leak. Callers deriving selections from a diff should still
filter to files that exist — this makes the failure legible rather than
preventing it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Aug 27, 2026
…nds (#4333)

## Summary
A verification run left two things behind for an age sweep to collect
days later. Both are now disposed when the run no longer needs them.

## Problem
**pytest temp.** pytest keeps the last three numbered run directories
under one temp root and deletes older ones. The session TMPDIR is
per-shell, so every `nix develop --command` starts a fresh root and that
pruning never fires. Measured: **17,707 shell directories holding 128
GB**, 191 of them over 100 MB, several at 3.5 GB each.

**dmypy.** `devtools verify` starts mypy's persistent daemon, which is
reparented to the user manager and outlives the run that started it. In
the main checkout that is the point — successive runs reuse the type
cache. A lane or batch worktree gates once and is then disposed, so its
daemon is never reused and never exits. Measured: **ten alive holding
9.2 GB**, from gates finished up to three and a half hours earlier.
Killing them took free memory from 3.5 GB to 11 GB.

This is what looked like a ceiling on concurrent verification. An active
run is ~1.5 GB; the pressure was dead weight.

## Solution
The run owns its basetemp and removes it on success. A failed run keeps
its tree, since that is when the fixtures are worth reading.

A non-primary checkout uses plain mypy. The daemon stays where repeated
runs amortise it.

## Verification
A green `devtools test` leaves no `.cache/verify/tmp`; a failing one
keeps it (2.6 MB observed).
`_is_primary_checkout()` returns False in `/realm/worktrees/batch-14`
and selects `['mypy']`; True in the main checkout, selecting
`['dmypy','run']`.

## Residual risk
Existing shell directories are not retroactively cleaned by this change;
`/realm/tmp/shell` still ages out on the 7-day tmpfiles rule. Plain mypy
is slower than a warm daemon on repeated runs in the same worktree,
which ephemeral worktrees do not do.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Aug 27, 2026
…#4334)

## Summary
Reverts the worktree exemption from #4333 and moves the daemon's
shutdown to the point where the workspace is actually gone.

## Problem
#4333 stopped using dmypy in non-primary checkouts to prevent the leak.
Measured afterwards in a batch worktree:

| | time |
|---|---|
| plain mypy | 50s |
| dmypy, cold start | 51s |
| dmypy, warm | **1s** |

A workspace is gated repeatedly while it is repaired, so only the first
run pays for the cache. The exemption bought memory that a lifecycle
hook releases anyway, at ~49s per re-gate.

mypy's own idle timeout does not solve it either: a daemon started with
`--timeout 10` was still running after twenty seconds idle, so that flag
cannot be relied on.

## Solution
sinnixd stops the daemon when it removes a worktree (sinnix `3f8fcea2`),
which releases the cache exactly when the workspace it describes
disappears. devtools uses the daemon everywhere again.

## Verification
`devtools verify --quick` green in the main checkout with the daemon in
use.
sinnix side: `nix build .#sinnixd` and `nix develop --command check`
green, with a test asserting removal invokes `dmypy stop` and tolerates
a workspace with no provisioned venv.

## Residual risk
A worktree removed outside `agentctl workspace` — by hand, or by `git
worktree remove` directly — still leaks its daemon. The basetemp
lifecycle from #4333 is unaffected and stays.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Aug 27, 2026
…g collected (#4343)

## Summary
Fixes a regression from #4333 plus the diagnosis gap that has repeatedly
misled integration.

## Problem
**Colliding basetemp.** #4333 pointed `--basetemp` at a fixed path.
pytest creates that directory itself and fails when it exists, so two
runs in one checkout collide:

```
INTERNALERROR> FileExistsError: [Errno 17] File exists: '.cache/verify/tmp'
```

Lanes, batches and the coordinator all run concurrently in the same
checkout here, so this fires routinely — and an INTERNALERROR mid-run is
a plausible source of the empty collections that were being written off
as flakes.

**Cleanup that silently failed.** Tests seal archive generations
read-only, so `rmtree(ignore_errors=True)` could not unlink them and
left the tree behind — exactly the accumulation #4333 set out to stop.

**Indistinguishable exit 5.** pytest exits 5 both when a selection
genuinely matches nothing and when a path in it does not exist. A
selection derived from `git diff --name-only` contains files the branch
deleted, so the run collects nothing and reads as "no work to do". That
has already produced false conclusions during integration, including a
report that multi-path selections were broken.

## Solution
The basetemp is unique per invocation. Cleanup clears permissions before
removing. On exit 5 the runner names the absent paths, or states that
every path existed so the caller looks at the `-k`/`-m` expression or
contention instead.

## Verification
`devtools verify --quick` → exit 0.
`devtools test tests/unit/devtools/test_run_tests.py` → exit 0.
A selection naming a deleted file prints `collected nothing because
these paths do not exist: tests/unit/gone.py`.
Repeated green runs leave no `.cache/verify/tmp-*` behind; a failed run
keeps its own for inspection.

## Residual risk
A failed collection still keeps an empty temp directory, which is litter
rather than a leak. Callers deriving selections from a diff should still
filter to files that exist — this makes the failure legible rather than
preventing it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Aug 28, 2026
…nds (#4333)

## Summary
A verification run left two things behind for an age sweep to collect
days later. Both are now disposed when the run no longer needs them.

## Problem
**pytest temp.** pytest keeps the last three numbered run directories
under one temp root and deletes older ones. The session TMPDIR is
per-shell, so every `nix develop --command` starts a fresh root and that
pruning never fires. Measured: **17,707 shell directories holding 128
GB**, 191 of them over 100 MB, several at 3.5 GB each.

**dmypy.** `devtools verify` starts mypy's persistent daemon, which is
reparented to the user manager and outlives the run that started it. In
the main checkout that is the point — successive runs reuse the type
cache. A lane or batch worktree gates once and is then disposed, so its
daemon is never reused and never exits. Measured: **ten alive holding
9.2 GB**, from gates finished up to three and a half hours earlier.
Killing them took free memory from 3.5 GB to 11 GB.

This is what looked like a ceiling on concurrent verification. An active
run is ~1.5 GB; the pressure was dead weight.

## Solution
The run owns its basetemp and removes it on success. A failed run keeps
its tree, since that is when the fixtures are worth reading.

A non-primary checkout uses plain mypy. The daemon stays where repeated
runs amortise it.

## Verification
A green `devtools test` leaves no `.cache/verify/tmp`; a failing one
keeps it (2.6 MB observed).
`_is_primary_checkout()` returns False in `/realm/worktrees/batch-14`
and selects `['mypy']`; True in the main checkout, selecting
`['dmypy','run']`.

## Residual risk
Existing shell directories are not retroactively cleaned by this change;
`/realm/tmp/shell` still ages out on the 7-day tmpfiles rule. Plain mypy
is slower than a warm daemon on repeated runs in the same worktree,
which ephemeral worktrees do not do.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Aug 28, 2026
…#4334)

## Summary
Reverts the worktree exemption from #4333 and moves the daemon's
shutdown to the point where the workspace is actually gone.

## Problem
#4333 stopped using dmypy in non-primary checkouts to prevent the leak.
Measured afterwards in a batch worktree:

| | time |
|---|---|
| plain mypy | 50s |
| dmypy, cold start | 51s |
| dmypy, warm | **1s** |

A workspace is gated repeatedly while it is repaired, so only the first
run pays for the cache. The exemption bought memory that a lifecycle
hook releases anyway, at ~49s per re-gate.

mypy's own idle timeout does not solve it either: a daemon started with
`--timeout 10` was still running after twenty seconds idle, so that flag
cannot be relied on.

## Solution
sinnixd stops the daemon when it removes a worktree (sinnix `3f8fcea2`),
which releases the cache exactly when the workspace it describes
disappears. devtools uses the daemon everywhere again.

## Verification
`devtools verify --quick` green in the main checkout with the daemon in
use.
sinnix side: `nix build .#sinnixd` and `nix develop --command check`
green, with a test asserting removal invokes `dmypy stop` and tolerates
a workspace with no provisioned venv.

## Residual risk
A worktree removed outside `agentctl workspace` — by hand, or by `git
worktree remove` directly — still leaks its daemon. The basetemp
lifecycle from #4333 is unaffected and stays.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Aug 28, 2026
…g collected (#4343)

## Summary
Fixes a regression from #4333 plus the diagnosis gap that has repeatedly
misled integration.

## Problem
**Colliding basetemp.** #4333 pointed `--basetemp` at a fixed path.
pytest creates that directory itself and fails when it exists, so two
runs in one checkout collide:

```
INTERNALERROR> FileExistsError: [Errno 17] File exists: '.cache/verify/tmp'
```

Lanes, batches and the coordinator all run concurrently in the same
checkout here, so this fires routinely — and an INTERNALERROR mid-run is
a plausible source of the empty collections that were being written off
as flakes.

**Cleanup that silently failed.** Tests seal archive generations
read-only, so `rmtree(ignore_errors=True)` could not unlink them and
left the tree behind — exactly the accumulation #4333 set out to stop.

**Indistinguishable exit 5.** pytest exits 5 both when a selection
genuinely matches nothing and when a path in it does not exist. A
selection derived from `git diff --name-only` contains files the branch
deleted, so the run collects nothing and reads as "no work to do". That
has already produced false conclusions during integration, including a
report that multi-path selections were broken.

## Solution
The basetemp is unique per invocation. Cleanup clears permissions before
removing. On exit 5 the runner names the absent paths, or states that
every path existed so the caller looks at the `-k`/`-m` expression or
contention instead.

## Verification
`devtools verify --quick` → exit 0.
`devtools test tests/unit/devtools/test_run_tests.py` → exit 0.
A selection naming a deleted file prints `collected nothing because
these paths do not exist: tests/unit/gone.py`.
Repeated green runs leave no `.cache/verify/tmp-*` behind; a failed run
keeps its own for inspection.

## Residual risk
A failed collection still keeps an empty temp directory, which is litter
rather than a leak. Callers deriving selections from a diff should still
filter to files that exist — this makes the failure legible rather than
preventing it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Sep 1, 2026
…nds (#4333)

## Summary
A verification run left two things behind for an age sweep to collect
days later. Both are now disposed when the run no longer needs them.

## Problem
**pytest temp.** pytest keeps the last three numbered run directories
under one temp root and deletes older ones. The session TMPDIR is
per-shell, so every `nix develop --command` starts a fresh root and that
pruning never fires. Measured: **17,707 shell directories holding 128
GB**, 191 of them over 100 MB, several at 3.5 GB each.

**dmypy.** `devtools verify` starts mypy's persistent daemon, which is
reparented to the user manager and outlives the run that started it. In
the main checkout that is the point — successive runs reuse the type
cache. A lane or batch worktree gates once and is then disposed, so its
daemon is never reused and never exits. Measured: **ten alive holding
9.2 GB**, from gates finished up to three and a half hours earlier.
Killing them took free memory from 3.5 GB to 11 GB.

This is what looked like a ceiling on concurrent verification. An active
run is ~1.5 GB; the pressure was dead weight.

## Solution
The run owns its basetemp and removes it on success. A failed run keeps
its tree, since that is when the fixtures are worth reading.

A non-primary checkout uses plain mypy. The daemon stays where repeated
runs amortise it.

## Verification
A green `devtools test` leaves no `.cache/verify/tmp`; a failing one
keeps it (2.6 MB observed).
`_is_primary_checkout()` returns False in `/realm/worktrees/batch-14`
and selects `['mypy']`; True in the main checkout, selecting
`['dmypy','run']`.

## Residual risk
Existing shell directories are not retroactively cleaned by this change;
`/realm/tmp/shell` still ages out on the 7-day tmpfiles rule. Plain mypy
is slower than a warm daemon on repeated runs in the same worktree,
which ephemeral worktrees do not do.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Sep 1, 2026
…#4334)

## Summary
Reverts the worktree exemption from #4333 and moves the daemon's
shutdown to the point where the workspace is actually gone.

## Problem
#4333 stopped using dmypy in non-primary checkouts to prevent the leak.
Measured afterwards in a batch worktree:

| | time |
|---|---|
| plain mypy | 50s |
| dmypy, cold start | 51s |
| dmypy, warm | **1s** |

A workspace is gated repeatedly while it is repaired, so only the first
run pays for the cache. The exemption bought memory that a lifecycle
hook releases anyway, at ~49s per re-gate.

mypy's own idle timeout does not solve it either: a daemon started with
`--timeout 10` was still running after twenty seconds idle, so that flag
cannot be relied on.

## Solution
sinnixd stops the daemon when it removes a worktree (sinnix `3f8fcea2`),
which releases the cache exactly when the workspace it describes
disappears. devtools uses the daemon everywhere again.

## Verification
`devtools verify --quick` green in the main checkout with the daemon in
use.
sinnix side: `nix build .#sinnixd` and `nix develop --command check`
green, with a test asserting removal invokes `dmypy stop` and tolerates
a workspace with no provisioned venv.

## Residual risk
A worktree removed outside `agentctl workspace` — by hand, or by `git
worktree remove` directly — still leaks its daemon. The basetemp
lifecycle from #4333 is unaffected and stays.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Sep 1, 2026
…g collected (#4343)

## Summary
Fixes a regression from #4333 plus the diagnosis gap that has repeatedly
misled integration.

## Problem
**Colliding basetemp.** #4333 pointed `--basetemp` at a fixed path.
pytest creates that directory itself and fails when it exists, so two
runs in one checkout collide:

```
INTERNALERROR> FileExistsError: [Errno 17] File exists: '.cache/verify/tmp'
```

Lanes, batches and the coordinator all run concurrently in the same
checkout here, so this fires routinely — and an INTERNALERROR mid-run is
a plausible source of the empty collections that were being written off
as flakes.

**Cleanup that silently failed.** Tests seal archive generations
read-only, so `rmtree(ignore_errors=True)` could not unlink them and
left the tree behind — exactly the accumulation #4333 set out to stop.

**Indistinguishable exit 5.** pytest exits 5 both when a selection
genuinely matches nothing and when a path in it does not exist. A
selection derived from `git diff --name-only` contains files the branch
deleted, so the run collects nothing and reads as "no work to do". That
has already produced false conclusions during integration, including a
report that multi-path selections were broken.

## Solution
The basetemp is unique per invocation. Cleanup clears permissions before
removing. On exit 5 the runner names the absent paths, or states that
every path existed so the caller looks at the `-k`/`-m` expression or
contention instead.

## Verification
`devtools verify --quick` → exit 0.
`devtools test tests/unit/devtools/test_run_tests.py` → exit 0.
A selection naming a deleted file prints `collected nothing because
these paths do not exist: tests/unit/gone.py`.
Repeated green runs leave no `.cache/verify/tmp-*` behind; a failed run
keeps its own for inspection.

## Residual risk
A failed collection still keeps an empty temp directory, which is litter
rather than a leak. Callers deriving selections from a diff should still
filter to files that exist — this makes the failure legible rather than
preventing it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at bf68918):

  • P2 devtools/run_tests.py:419: Not a defect (checked at bf68918): A failed run keeps its basetemp on purpose so its fixtures can be read, and each later run reclaims every tree whose owner process is gone (devtools/run_tests.py:1319-1329). That behavior is the documented retention for failed trees, not an omission.
  • P2 devtools/verify.py:150: Stale: verify.py no longer contains the dmypy route or the primary-checkout probe (devtools/verify.py:1235). (checked at bf68918)

Resolving every thread listed; confirmed defects are fixed under the named bead.

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