Skip to content

fix(devtools): Record execution content in focused receipts - #5544

Merged
Sinity merged 1 commit into
masterfrom
fix/queued-focused-content-provenance
Sep 25, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/queued-focused-content-provenance

Conversation

@Sinity

@Sinity Sinity commented Sep 25, 2026

Copy link
Copy Markdown
Owner

Summary

Record the execution-time Git HEAD, dirty state, and deterministic SHA-256 of tracked and untracked worktree content in focused test receipts.

Problem

A direct devtools test call creates its run.json before the pytest slot is available. A queued job can then execute after files change, while the receipt's original HEAD and dirty state describe submission time. Bead polylogue-nhs3u records a red and green pair whose second job was submitted before the edit that made it green.

Solution

The pytest slot captures the Git-visible worktree just before launching focused pytest and returns the snapshot in its typed result. devtools test writes that execution snapshot to run.json and refuses a queued result without one. The digest includes paths, file type, executable state, regular file bytes, and symlink targets; ignored artifacts are excluded by Git. A regression mutates tracked and untracked files at the queue seam and checks that the receipt matches execution content, while restored content yields the original digest.

Verification

  • devtools test tests/unit/devtools/test_run_tests.py: PASSED, 41 passed, receipt .cache/verify/runs/20260925T194850Z-focused-test-3371198-99fdefd3/run.json; its git_head and final_git_head equal 7f2719754855667bed7dc47ea3dc73615527f6a5, with git_dirty=false, worktree_capture_source=pytest_slot_start, and SHA-256 66ce82bceb4634914fdfd715d1fc3ba2b59793abcb074798a7c3ee70fda749d7.
  • devtools verify --quick: PASSED, receipt .cache/verify/runs/20260925T194254Z-quick-3346496-e44d5275/run.json. This static gate ran after the source edits and before the commit.

Residual

Hashing scales with the bytes in unignored untracked files. An unreadable path or unsupported file type prevents a focused run from claiming an execution digest.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@coderabbitai

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 17 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 557369eb-9711-478d-88bf-88984d9f3cfa

📥 Commits

Reviewing files that changed from the base of the PR and between f2f342d and 7f27197.

📒 Files selected for processing (4)
  • devtools/pytest_slot.py
  • devtools/run_tests.py
  • devtools/verify_runs.py
  • tests/unit/devtools/test_run_tests.py

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 25, 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-25T19:56:23.795339Z 7f27197 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.

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

ℹ️ 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/run_tests.py Resolved
Comment thread devtools/pytest_slot.py Resolved
@Sinity
Sinity enabled auto-merge (squash) September 25, 2026 19:56
@Sinity
Sinity merged commit 8543e47 into master Sep 25, 2026
3 checks passed
@Sinity
Sinity deleted the fix/queued-focused-content-provenance branch September 25, 2026 20:04
Sinity added a commit that referenced this pull request Sep 29, 2026
…#5802)

## Summary

Salvages ChatGPT fleet worker 15 (Codex review debt, beads
polylogue-1tyq5.45, .47, .48, .51, .52: devtools parts 4/6/7, docs,
nix). Of 79 findings: 13 fixed here, 56 already fixed on master, 4
stale, 6 not reached. The worker's patch was built on snapshot
`e1510b53ea`, not master. It was ported hunk by hunk onto current
master, keeping the newer OOM attribution and trusted-parent work in
`verify.py`, `verify_runs.py`, `run_tests.py` and `pytest_slot.py`.

## Problem

- `devtools test --outliers` globbed `last-pytest-*.json` shards. No
verifier writes these any more: each pytest step's report is rebound
into its run step directory, and only `last-pytest.json` is projected.
The command therefore read nothing or stale files (45.01, 45.02).
- A focused `devtools test` that got SIGTERM died in `subprocess.run`.
It wrote no terminal receipt, history or evidence (45.06).
- Queued slot interruptions dropped the start-time worktree provenance
(45.08).
- When a selected directory was missing, pytest exited 4 (usage error).
The missing-path diagnostic only ran on exit 5 (45.10).
- The focused verdict printed a checkout-relative receipt path. `main()`
has `chdir`ed to ROOT, so the path did not resolve from the caller's
directory (45.12).
- `canonical_verification_receipt` preferred `final_git_head`. It
attributed passing tests to a head that moved under the run and was
never executed (45.14).
- The verifier's interruption handlers did not cover selection,
admission or verdict assembly. A signal there left the run `running`
(47.03).
- A refused affected plan returned before any static gate ran (47.21).
- The Home Manager readiness lane required the removed role-ladder
expressions. It rejected the intact module and could not detect a
dropped capability switch (47.22).
- Pattern help and docs advertised `path:sha1[:count]`, but the parser
requires `path:sha1:context_sha1[:count]` (48.01). The SHA-1 anchors
used the security-default constructor (48.03).
- Reconciliation retried publication only for abandoned runs adopted as
failure. A run adopted as success whose first publication was
interrupted never reached history (48.20).

## Solution

- `print_outliers` selects every pytest lane of the newest completed
`--all` receipt (tier `all`, status `success`,
`complete_corpus_covered`). It refuses when a lane report is missing.
The shard glob, its constant and the verifier's `_clear_full_run_shards`
are removed.
- `devtools test` installs a SIGTERM handler around the launch. The
slot's own handler chains into it after it stops the child. The run
finishes with exit 143 and `termination_reason=sigterm`, and the prior
handler is restored.
- Both slot interruption writers pass the captured
`worktree_provenance`.
- The missing-path diagnostic runs on exit 4 and exit 5. The "every path
exists" hint stays exit-5 only.
- Receipt and artifact paths print absolute.
- `source_revision` is set only when the ending head equals the executed
head. It is also unset when the tree is unknown or dirty.
- `_main` runs selection, admission, steps and verdict assembly inside
the interruption handlers. Publication
(`_finish_and_record_verification`) stays outside so a signal cannot
finish a run twice. A refused plan now runs the quick gates through the
same path, keeps the first failing gate's exit and diagnosis, and
otherwise returns exit 2 with `affected_admission_refused`.
- The HM lane checks the three `cfg.mcpEnable*` mappings.
- The pattern gate hashes with `usedforsecurity=False`. The help,
catalog, regenerated `docs/devtools.md` and `docs/structured-logging.md`
name the context-anchor format.
- Reconciliation retries publication for abandoned runs adopted as
success too. The existing per-run dedup keeps it idempotent.

Diverges from the worker: its 47.03 change put publication inside the
handler. That could append a second history row for a run already
finished. Publication is kept outside, and crash-consistent publication
stays with 47.12 (not reached). Its 47.25 change is dropped because
master already rejects malformed registries more strictly.

## Verification

All through AgentCTL on the pushed head's tree or its immediate
predecessor:

- `agentctl job start polylogue verify_quick --workspace
/realm/worktrees/salvage-w15 --wait`: job 2319 on `75059a9ddc` (rebased
head): `verify: PASSED exit=0`.
- `agentctl job start polylogue pytest_focused --workspace
/realm/worktrees/salvage-w15 --wait --
tests/unit/devtools/test_verification_terminal_receipts.py
tests/unit/devtools/test_verify.py tests/unit/devtools/test_run_tests.py
tests/unit/devtools/test_verify_patterns.py
tests/unit/devtools/test_agent_integration_module.py
tests/unit/devtools/test_verify_runs.py
tests/unit/devtools/test_verification_evidence_lane.py
tests/unit/devtools/test_pytest_slot.py`: job 2300 on `4e72110e57`: `2
failed`, both inherited (see residuals); everything else passed.
- After the mypy typing commit: job 2312, `pytest_focused --
tests/unit/devtools/test_verification_terminal_receipts.py
tests/unit/devtools/test_verify_patterns.py
tests/unit/devtools/test_run_tests.py`: `devtools test: PASSED exit=0`.
- Red on master: job 2242 ran the new and changed tests in a detached
master worktree (`e14b47662d`) with production code unchanged. Every new
regression failed: 13 in `test_verification_terminal_receipts.py`, the
sha1 pattern test, the HM lane pass case, both
`test_affected_admission_refuses_without_launching_pytest` params and
the adapted outliers test. The `ending == executed head` canonical
parameter passed there as expected. The same job reproduced the two
inherited failures.
- Derived-identity closure: scratch job 2202 ran `python -m devtools
schema closure` on all 8 changed production files, and every one
reported `out`. The same job regenerated `docs/devtools.md` with
`devtools render devtools-reference`.

## Self-review

- **Sibling sites.** The artifacts line got the same absolute-path fix
as the receipt (45.12). `docs/structured-logging.md` carried the same
stale anchor spelling (48.01). Both slot interruption writers are fixed
(45.08). The verifier's shard clearing was the other half of the dead
shard protocol and is removed with the reader.
- **Cancellation and shutdown.** The focused SIGTERM handler is
installed after the temp-tree guard and restored in `finally`. The held
slot's handler restores it and re-signals, so the two chain. Verifier
publication is outside the handler, which avoids double finishing.
- **Unbounded reads.** The outliers reader globs `runs/*/run.json`,
which retention already bounds (8 successful runs).
- **Fail-open fallbacks.** Outliers refuse on a missing or malformed
lane rather than fall back to older reports. An unknown ending head
yields no `source_revision`.
- **Compatibility shims.** None. The shard constant and clearing are
deleted, not kept alongside.
- **Removed symbols.** `PYTEST_PARALLEL_REPORT_PATTERN` and
`_clear_full_run_shards` have no remaining references in code, tests or
docs.
- **Production route.** The tests drive `run_tests.main`, `verify.main`,
`pytest_slot._run_launch`, `reconcile_and_record_abandoned_verify_runs`,
`verify_patterns.main` and the real lane function. Only host
observations (Git, processes, signals) are replaced.

## Findings

| key | disposition | evidence | test |
|---|---|---|---|
| 45.01 #4162 run_tests.py:116 | fixed | shards unwritten since per-step
report binding (`verify._bind_pytest_reports_to_step`) |
test_verification_terminal_receipts.py::test_outliers_read_all_lanes_of_one_completed_receipt,
::test_outliers_refuse_a_missing_lane_instead_of_falling_back_to_older_reports
|
| 45.02 #4162 run_tests.py:116 | fixed (same change; worker had
fixed-already via shard clearing, which cleared names nobody writes) |
receipt-bound selection |
::test_outliers_read_all_lanes_of_one_completed_receipt |
| 45.06 #4267 run_tests.py:352 | fixed | no SIGTERM handling on master |
::test_focused_sigterm_finishes_receipt_and_publications |
| 45.08 #5544 run_tests.py:427 | fixed | `_write_interrupted_result`
lacked provenance |
::test_queued_interruption_keeps_start_time_worktree_provenance |
| 45.10 #4343 run_tests.py:485 | fixed | `if rc == 5` only |
::test_focused_missing_directory_has_a_path_specific_usage_diagnostic |
| 45.12 #4726 run_tests.py:626 | fixed | `run.relative_run_dir` printed
| ::test_focused_verdict_receipt_is_absolute_from_a_nested_invocation |
| 45.14 #5544 run_tests.py:649 | fixed | `final_git_head or git_head` |
::test_canonical_receipt_never_attributes_an_untested_ending_head |
| 47.03 #4109 verify.py:505 | fixed (publication kept outside; see
47.12) | selection/tail outside `try` |
::test_verifier_finalizes_interruptions_outside_the_step_loop |
| 47.21 #4898 verify.py:1019 | fixed | early `return 2` before
`build_verify_steps` |
::test_refused_affected_admission_still_executes_static_gates;
test_verify.py::test_affected_admission_refuses_without_launching_pytest
|
| 47.22 #4266 verify_agent_integration.py:472 | fixed | role-ladder
tokens absent from module |
test_agent_integration_module.py::test_home_manager_lane_checks_independent_capability_switches
|
| 47.25 #4161 verify_patterns.py:37 | fixed-already (worker claimed
fixed) | `_rules` raises on every malformed shape,
verify_patterns.py:36-63;
test_verify_patterns.py::test_malformed_pattern_registry_fails_closed |
none |
| 48.01 #4199 verify_patterns.py:59 | fixed | help said
`path:sha1[:count]` | generated reference refreshed |
| 48.03 #4199 verify_patterns.py:113 | fixed | default-security
`hashlib.sha1` |
test_verify_patterns.py::test_pattern_entrypoint_marks_sha1_as_non_security_use
|
| 48.20 #5299 verify_runs.py:1282 | fixed | retry branch matched `status
== "failed"` only |
::test_successful_abandoned_adoption_retries_an_interrupted_publication
|
| 45.22, 45.25, 47.12, 48.05, 48.06, 48.17 | not reached | still open;
need design (receipt-bound config, resumable GC, crash-consistent
publication, stale-baseline policy, located violations, unknown
duration) | none |
| 47.08, 47.10, 47.15, 47.20 | stale | code paths removed
(`--recompute`/`--commit`, bootstrap selection, parent-root refusal,
graph publication) | none |
| remaining 55 | fixed-already | worker's line evidence, spot-checked on
current master | none |

## Derived-identity closure

None. All 8 changed production files are outside the closure (`devtools
schema closure`, job 2202).

## Residuals

- These two failures reproduce on master `e14b47662d` (job 2242) and are
unrelated to this change:
-
`tests/unit/devtools/test_verification_evidence_lane.py::test_reconciled_abandoned_run_joins_the_durable_lane`:
the relocated-cache evidence target conflicts with the test's
durable-lane expectation.
-
`tests/unit/devtools/test_verify.py::test_zero_exit_without_a_report_is_a_failed_pytest_step`:
pytest-benchmark options are unrecognized in the free-threaded venv.
- A signal that arrives during publication itself still escapes. That is
47.12.
- Abandoned runs with no recorded ending head now publish no
`source_revision`. This is intended: the head was never observed at the
end.

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

https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg

---------

Co-authored-by: Claude Opus 5.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/run_tests.py:469: Fixed on master (checked at 64a9bd0): rerun_failed_once receives the first run's worktree provenance and compares it with the rerun's, and a mismatch keeps every failure (devtools/pytest_rerun.py:367-375, 437-442). The focused runner passes first_provenance from the initial receipt (devtools/run_tests.py:1080-1082).

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