Skip to content

feat(devtools): run managed pytest through the host pytest slot - #4581

Merged
Sinity merged 1 commit into
masterfrom
feat/devtools-pytest-slot
Sep 3, 2026
Merged

Sinity merged 1 commit into
masterfrom
feat/devtools-pytest-slot

Conversation

@Sinity

@Sinity Sinity commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Summary

devtools test and the pytest step of devtools verify acquire the host's single-parallelism pytest pueue group before running pytest.

Problem

pytest started by a session subagent runs outside every load control the daemon applies to its own jobs: it is an ordinary foreground subprocess in session.slice, not a queued task. On 2026-09-03 three concurrent agent runs contended for the same cores and disk and pushed the corpus job past its four-hour timeout. Closes sinnix-9t8i / sinnix-xteo.6.

Solution

devtools/pytest_slot.py owns the slot, and both managed pytest routes go through run_pytest.

  • Already inside the slot — sinnixd-queue-run exports SINNIXD_JOB_ID, or the explicit POLYLOGUE_PYTEST_SLOT=held escape — pytest runs in place and streams as before.
  • Outside it, the exact argv devtools already builds is written to .cache/verify/pytest-slot-<pid>.json and queued as pueue add --escape --group pytest --label polylogue:{test,verify}:<pid> --working-directory <root> --print-task-id -- <venv python> -m devtools.pytest_slot <launch file>. The caller waits on the task, reads the exit code from pueue status --json, and prints the captured log path.
  • pueue 4 persists the pueue add client's whole environment into a user-only state file, so the adder inherits only HOME, PATH, XDG_RUNTIME_DIR, and XDG_DATA_HOME. The managed pytest environment travels in the launch file, which the queued task deletes after reading.
  • An unreachable queue is a typed PytestSlotUnavailableError naming systemctl --user start pueued. There is no unqueued fallback.
  • The receipt records pytest_slot: pueue task <id> or held.
  • verify's single rerun of failed tests holds the slot too, so the adjudication does not escape the control that the run it adjudicates is under.

Verification

devtools test tests/unit/devtools/test_pytest_slot.py -n 2   # 7 passed (POLYLOGUE_PYTEST_SLOT=held)
devtools verify --quick                                      # 12 gates ok
devtools test tests/unit/devtools/test_agent_env.py          # unqueued caller, real pueued

The last one queued as pueue task 12 in group pytest:

 12   Running   polylogue:test:2709503   .../.venv/bin/python -m devtools.pytest_slot .../.cache/verify/pytest-slot-2709503.json

and finished Done/Success, exit 0, 2 passed in the captured log. Its persisted task environment carries HOME PATH XDG_DATA_HOME XDG_RUNTIME_DIR plus pueue's own PUEUE_GROUP/PUEUE_WORKER_ID and nothing else; its receipt records "pytest_slot": "pueue task 12".

Anti-vacuity, named in the test module: deleting the queueing branch in run_pytest makes test_outside_a_task_the_run_is_queued red, because the command executes here and its marker file appears. Widening INHERITED_ENVIRONMENT_KEYS makes test_the_adder_environment_carries_only_the_allowed_keys red.

Residual risk

The queued run is not streamed, so a long focused run shows nothing until it finishes; pueue follow <id> is the live view and the log path is printed on both paths. A caller that sets POLYLOGUE_PYTEST_SLOT=held by hand reintroduces the contention. The corpus is unrun on this branch — only the quick gate and the new module ran.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YGi8wLWGR2HYBh8p8fXFXz

pytest started from a session subagent runs outside every load control the
daemon applies to its own jobs. On 2026-09-03 three concurrent runs pushed the
corpus job past its four-hour timeout.

`devtools test` and the pytest step of `devtools verify` now acquire the host's
single-parallelism `pytest` pueue group before running. A caller already inside
a queued task (`SINNIXD_JOB_ID`) holds the slot and streams as before; a caller
outside it queues, waits, reports the exit code pueue recorded, and prints the
captured log path. An unreachable queue is a typed refusal naming
`systemctl --user start pueued`, never an unqueued run.

pueue 4 persists the `pueue add` client's whole environment into user state, so
the adder inherits only HOME, PATH, XDG_RUNTIME_DIR, and XDG_DATA_HOME; the
managed pytest environment travels in a launch file the queued task consumes
and deletes.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YGi8wLWGR2HYBh8p8fXFXz
@coderabbitai

coderabbitai Bot commented Sep 3, 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: b7a76e07-6306-4229-833e-2abea8015998


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 3, 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-03T04:31:24.605771Z 9027052 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 merged commit c1d2544 into master Sep 3, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feat/devtools-pytest-slot branch September 3, 2026 04:25

@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: 90270526d4

ℹ️ 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/pytest_slot.py Resolved
Comment thread devtools/verify.py Resolved
Comment thread devtools/run_tests.py Resolved
Comment thread devtools/pytest_slot.py Resolved
Comment thread devtools/pytest_slot.py Resolved
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

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/pytest_slot.py:80: Fixed on master (checked at 64a9bd0): holds_pytest_slot treats the slot as held only from the explicit slot marker, the pytest-pool cgroup, or the enclosing job's declared pool; a job id alone is never ownership (devtools/pytest_slot.py:463-470).
  • P1 devtools/run_tests.py:368: Fixed on master (checked at 64a9bd0): test_main_strips_dispatch_json_flag now stubs the slot seam with a fake_run_pytest returning SlotOutcome (tests/unit/devtools/test_run_tests.py:318-321).

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.

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

  • P1 devtools/pytest_slot.py:190: Fixed on master (checked at 64a9bd0): The waiter keeps the submitted job id and reference and wraps the wait in _on_exit(reap_owned_job), which cancels the job through agentctl job cancel when the waiter is signalled or unwound (devtools/pytest_slot.py:747-760, 511-520).

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