Skip to content

Fix harness descriptor leak, slot deadlock, and corpus memory sizing - #4709

Merged
Sinity merged 8 commits into
masterfrom
worktree-agent-a0b645ba121b83310
Sep 5, 2026
Merged

Sinity merged 8 commits into
masterfrom
worktree-agent-a0b645ba121b83310

Conversation

@Sinity

@Sinity Sinity commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Summary

Four test-harness defects that slow every lane, fixed at their causes.

Problem

Descriptor leak (polylogue-uvx0q). Eleven tests in one xdist worker died
with OSError: [Errno 24] and unable to open database file. None of them
leaked: with sqlite3.connect(path) as conn manages a transaction, not the
connection, so the descriptor survives the block until collection. Forty-seven
production sites used that form. Measured on initialize_active_archive_root:
3 leaked descriptors per call. The victim is whichever test runs when the table
fills.

Slot deadlock (polylogue-9dbqu). The declared verify_all job ran
devtools verify --all, whose pytest step enqueued a second pytest-group task
and waited for it. The group runs one task at a time and the job held it, so
nothing drained for 30 minutes. The queue runner exports no variable naming the
job's pool and the pytest slice is not visible from every host configuration,
so neither the environment nor the cgroup classified the process.

Gate independence (polylogue-w3at6). The abort-on-first-red behaviour was
already fixed by #4508; nothing pinned it, so it could regress silently.

Corpus killed (polylogue-b054.1.1.2). Width was fixed at 8 regardless of
free memory; two corpus runs were killed by systemd-oomd at ~6.2 GB peak.

Unprovisioned worktree (polylogue-8dfcy). A checkout with no .venv
reported gate_missing_executable for an installed ruff, naming neither cause
nor remedy.

Solution

  • sqlite_connection keeps commit-or-rollback semantics and closes; all 47
    sites converted.
  • A harness guard fails an outright per-test leak on its own test, and on
    exhaustion names the largest cumulative retainers. A per-test bound alone
    would not have caught this cascade — it retained ~3 descriptors per test
    across hundreds of tests — so the report points past the victim.
  • holds_pytest_slot reads the pool from the launch document carried by the
    queue-runner ancestor. Verified against two live queue tasks.
  • Corpus width is derived from MemAvailable using the workload's measured
    per-process peaks, decided inside the slot: a queued run can wait hours, so
    a width chosen when the command was built describes memory that is gone.
  • An absent .venv is reported as gate_unprovisioned_environment with the
    devshell command, and explicitly warns against sharing another checkout's
    venv (its editable install would run that tree's product).

Verification

devtools verify --quick — green, all 13 gates, exit_code: 0:

gate format ok / lint ok / mypy ok (75.3s) / generated-surfaces ok /
layering ok / patterns ok / doc-commands ok / schema-manifest ok /
oracle-integrity ok / testmon-selection ok / consumer-reachability ok /
timestamp-doctrine ok / schema-privacy ok

devtools render all --check — no out of sync lines.

Leak fix measured directly: initialize_active_archive_root × 10 leaks 30
descriptors before, 0 after. Guard attribution verified in a live pytest
session: a test opening 30 unclosed connections is reported as
ERROR ...::test_leaks and the following test passes.

Width sizing measured live: 4707 MiB available yields 3 workers, 5210 MiB
yields 4; eight would need ~6.5 GiB, the peak that was killed.

Residuals

  • The focused pytest run over the new tests was still queued behind other
    lanes' jobs when this PR was opened; the required verify check runs it.
  • The corpus-survival criterion (a full run completing under desktop load)
    needs a full corpus run to confirm end to end; that has not been done here.
  • Per-worker memory is dominated by retained objects, not imports: a worker's
    import baseline measures 137 MiB RSS, so import trimming could recover at
    most ~1 GiB of a 6.2 GB peak and cannot by itself prevent the kill.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DNGJ3awfNrsLaMdHgQZvid

Sinity and others added 8 commits September 6, 2026 00:08
`with sqlite3.connect(path) as conn` manages a transaction, not the
connection: the descriptor survives the block until collection. Forty-seven
production sites used that form, so a long process accumulated descriptors
until it hit its limit, and the call that failed was whichever ran next.

`sqlite_connection` keeps the commit-or-rollback semantics and closes.
Measured on `initialize_active_archive_root`: 3 leaked descriptors per call
before, 0 after.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DNGJ3awfNrsLaMdHgQZvid
`devtools verify --all` inside the declared verify_all job enqueued a second
pytest-group task and waited for it. The group runs one task at a time and
the job held it, so nothing drained until the job was killed by hand.

The queue runner exports no variable naming the job's pool, and the pool's
systemd slice is not visible from every host configuration, so neither the
environment nor the cgroup classified the process. The launch document does:
the runner is an ancestor and carries the document's path as its final
argument. Verified against two live queue tasks.

Also: a red static gate no longer hides pytest state (pinned by test), and an
absent .venv is reported as an unprovisioned environment with its remedy
rather than as a missing ruff.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DNGJ3awfNrsLaMdHgQZvid
Two full corpus runs were killed by the out-of-memory daemon at about 6.2 GB
peak while the desktop and other lanes were resident. The width was fixed at
eight regardless of what was free, so the run assumed memory that was not
there; a killed run measures nothing.

Width is now derived from MemAvailable at run start, using the workload's
measured per-process peaks (worker 686 MiB, controller 1075 MiB) and a fifth
left as headroom, floored at one worker and never above CORPUS_MAX_WORKERS.
The basis is reported, so the width is evidence rather than a silent policy.

Measured on this host under lane load: 4707 MiB available yields 3 workers;
eight would have needed about 6.5 GiB, which is the peak that was killed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DNGJ3awfNrsLaMdHgQZvid
Counting around the teardown wrapper puts the check after fixture finalizers,
so what remains is genuinely retained, and raising there marks the leaking
item's teardown rather than the next test's setup. Verified against a live
session: a test opening 30 unclosed connections is reported as ERROR on
itself and the test after it passes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DNGJ3awfNrsLaMdHgQZvid
A per-test bound alone would not have caught the 2026-09-05 cascade: it
retained about three descriptors per test across hundreds of tests, under any
workable single-test threshold, and surfaced only as EMFILE in eleven
unrelated victims. Exhaustion now reports the largest cumulative retainers
alongside the victim, so the report points at the cause.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DNGJ3awfNrsLaMdHgQZvid
A queued run can wait hours behind the single pytest slot, so a width chosen
when the command was built describes memory that is no longer there. The
sizing moves to devtools/worker_memory.py and is applied in the slot runner,
where the workers actually start, and the narrowing is written to the run log.

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

coderabbitai Bot commented Sep 5, 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: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 71f5c95f-ccf2-4f67-9836-b7ffd4df20a4


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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-05T23:15:51.539333Z 03ecfe8 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Sinity
Sinity enabled auto-merge (squash) September 5, 2026 23:09

@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: 03ecfe8904

ℹ️ 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/pytest_slot.py Resolved
Comment thread devtools/worker_memory.py Resolved
Comment thread tests/conftest.py Resolved
@Sinity
Sinity merged commit d0ec88e into master Sep 5, 2026
3 checks passed
@Sinity
Sinity deleted the worktree-agent-a0b645ba121b83310 branch September 5, 2026 23:15
Sinity added a commit that referenced this pull request Sep 6, 2026
## Summary

Fixes the two reds in `tests/unit/devtools/test_verify.py`. One was a
real
defect (inherited, not from #4709); one was a stale expectation from
#4709.

## Which was which

Measured, not assumed. Both tests were run at `d430734f1`, the commit
immediately before #4709 merged, with `devtools` and `tests` both
checked out
at that commit:

- `test_accepted_flake_clears_both_recorded_exit_statuses` **fails
identically
there**. It is inherited and predates #4709. The `relative_to(ROOT)`
call it
  trips over came from #4536.
- `test_missing_checkout_venv_tool_is_a_typed_failure` **passes there**.
That
one is #4709's, and it is a stale expectation rather than a defect: an
absent
  `.venv` now reports `gate_unprovisioned_environment` instead of
`gate_missing_executable`, which is the intended distinction and is what
the
  new test in #4709 asserts.

So the rerun routing through `run_pytest` is not implicated; it arrived
in
#4581 and is unchanged here.

## Problem

`_rerun_failed_once` formats its receipt with
`rerun_report.relative_to(ROOT)`,
which raises `ValueError` when the step directory is outside the
checkout — a
configured basetemp root, or any caller supplying its own artifact
directory.
A rerun that had already adjudicated its flakes correctly then died
formatting
its own path, and no rerun result was recorded at all.

## Solution

Report the path relative to the checkout when it is inside one, absolute
otherwise. Split the venv test into both conditions so the original
coverage
(a provisioned venv missing one tool) survives beside the new one (no
venv at
all).

## Verification

`POLYLOGUE_ALLOW_BARE_PYTEST=1 POLYLOGUE_PYTEST_RUN_ID=x
.venv/bin/python -m
pytest tests/unit/devtools/test_verify.py -p no:randomly
--override-ini=addopts=`
— **41 passed**, redirected to a file and read, not piped.

## Residuals

- A third red was reported in this file; only these two reproduce at
master
(`04e297bbc`). If the third is real it is ordering-dependent and not
visible
  in a full run of the file.
- The static quick gate ran green via the pre-push hook; the focused run
above
  is the test evidence.

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

https://claude.ai/code/session_01DNGJ3awfNrsLaMdHgQZvid

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

Slot ownership is the pytest pool, and a focused run enters it through
the declared `pytest_focused` operation instead of a private pueue
client. The descriptor gains the `verify` table and `publish` mode
agentctl reads, and drops the keys it does not.

Merged with master's pool-classification work rather than competing with
it: ownership accepts the pool cgroup, the exported pool name, or the
enclosing job's declared pool from the launch document, so the deadlock
fix in #4709 survives here.

Folds #4689 (descriptor cleanup) and #4686 (docs). Also stops the
progress-plugin subprocess writing its pytest cache to /realm: its
selection names a file under the temporary directory, so the child
resolved rootdir to the lake root.

## Evidence

Ran, on this head:

- `tests/unit/devtools/test_pytest_slot.py`,
`test_pytest_slot_pool_classification.py`, `test_agent_env.py`,
`test_agentctl_service_context.py`: 76 passed. This is the changed
mechanism, both sides of the merge.
- `tests/unit/devtools`: 326 passed before stopping at the one failure
below.
- All thirteen static gates, through the commit hook.

Did not run: the corpus, and the hosted `verify` check, which is
disabled repository-wide since 21:06 on 2026-09-05.

Four failures in `tests/unit/devtools` are master's, not this branch's,
confirmed by running master's own `devtools/verify.py`, `run_tests.py`,
`required_gate.py` and `worker_memory.py` inside this worktree and
reproducing each one. Filed as polylogue-s9klx. This branch fixes three
other failures that master's files show here.

A second full `tests/unit/devtools` sweep under concurrent corpus load
hit a thread-hang timeout and is not counted as evidence either way.

---------

Co-authored-by: Claude Fable 5.1 <[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 ef10e59):

Resolving the fixed, stale and refuted threads; tracked threads stay open.

@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 64a9bd0):

  • P1 devtools/worker_memory.py:68: Stale: Width sizing no longer narrows on host MemAvailable: only the pytest cgroup budget, or the declared slice budget, bounds it (devtools/worker_memory.py:651-658, 672-692). The two-worker narrowing at 3500 MiB of host memory, and the cited seven-hour benchmark note, no longer exist. (checked at 64a9bd0)

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

@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):

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