Skip to content

fix(hooks): run verification tools through the flake dev shell - #132

Merged
furedea merged 9 commits into
mainfrom
fix/verify-hook-dev-shell
Nov 10, 2026
Merged

furedea merged 9 commits into
mainfrom
fix/verify-hook-dev-shell

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

概要

Stop フックの検証が,プロジェクトのテストツールをエージェントの PATH からだけ起動していたため,ツールが flake の dev shell にしか無いリポジトリ(rater の go)では,コードが正しくても毎回 go: unavailable · [Errno 2] No such file or directory: go で検証失敗になっていた.これを設計で直す.

Issue はない(指示に番号なし).Refs 対象なし.

設計

状況 動作
ツールが PATH にある(Python の uv など) 従来どおり直接実行.nix は呼ばない
PATH に無く,flake.nix が dev shell を宣言し,nix が PATH にある nix develop --command sh -c <probe> sh <元の引数> で実行
PATH に無く,dev shell も無い / nix が無い / dev shell にも無い 新しい MISSING_TOOL 状態で報告
  • 検出は flake.nix のテキストに devShell(s) があるかを正規表現で見るだけ.Nix の評価は走らせないので安価.flake-parts のように別ファイルで dev shell を宣言する構成は検出できず,MISSING_TOOL になる(制限として許容).
  • タイムアウト,プロセスグループ kill,出力上限,ログ,レシートの ID(元の引数のハッシュ)は変更なし.ログの command: も元の引数のまま.
  • 環境の問題とテスト自体の失敗を区別するため,sh のプローブが 2 つのマーカーを使う.
    • 「dev shell に入った」マーカー: dev shell を宣言しているプロジェクトは dev shell に入れる前提なので,nix develop がマーカーより前に非 0 で終了した場合(flake.nix の評価エラーなど)は新しい状態 DEV_SHELL_FAILED(失敗扱い,Stop をブロック)とし,nix の出力をログと要約に残す(エージェントが壊した flake.nix を見逃さないため).MISSING_TOOL と同様に再利用せず検証のたびに再実行する(Status.retried).壊れた flake.nix は nix がすぐ失敗するので毎回ブロックし,一時的な nix の問題なら verify --force なしで次の Stop で解消する.一時的か恒久的かの区別は不要.シェル構築中に予算を使い切った場合だけは MISSING_TOOL(毎回再試行).出力が保持上限で切り詰められたときはマーカーが押し出された可能性があるため,判定せずテスト結果を維持する.
    • 「ツールが無い」マーカー + 終了コード 127: dev shell に入ったがツールが無い場合だけ MISSING_TOOL.
  • MISSING_TOOL は「コードを判定していない」状態.Verification unavailable と表示し,Stop をブロックしない.成功でもないため verify は非 0 で終了し,status は unavailable を返す.失敗が同時にあれば従来どおり失敗が優先してブロックする.MISSING_TOOL のレシートは再利用せず,verify/Stop のたびに再試行する(コールドな dev shell や,先行チェックが使い切った予算といった一時的な原因が「利用不可」として固定されないようにするため).status は保存済みレシートを unavailable として表示する.
  • Python / uv リポジトリ:uv は PATH にあるため経路は変わらない.既存の test_session_gate.py などが無変更で通ることで確認.

ac-dn(verification_session.py / check_execution.py の docstring)

対象 扱い 根拠
verification_session.py の公開 main, dispatch, failure を docstring 付きで公開のまま provider_adapter.py:146,148 が verification_session.dispatch/failure を使用
verification_session.py の非公開化 registered_record, check_scope, require_inside, confirm_tool, end_session, explicit_result, hook_payload(7 件) git grep -w で agents/scripts/tests に外部参照なし
check_execution.py Status, Result, Result.failed, execute を文書化.collect を _collect に非公開化 session_gate.py が使うのは Status と execute のみ.collect の外部参照なし
  • ruff check --extend-select D,N(google, D104/D105/D107 を ignore)は,verification_session.py / check_execution.py / 新規 dev_shell.py で 0 件.pyproject.toml の ruff 設定は変更していない.
  • 既存の docstring とコメントは削っていない.関数の並びは公開 → 非公開に並べ替えた(差分が大きく見えるが移動のみ).

設計上の判断(lint 由来)

  • _run の引数が 4 個になり PLR0913(max 3)に当たったため,「コマンド・作業ディレクトリ・環境」を 1 つの意味のある型 _Process にまとめた(無名 tuple/dict にはしていない).
  • 起動方法の判断は dev_shell.py(Launch / MissingTool の和型)に分離し,check_execution.py の責務(実行と分類)から切り離した.
  • Status.failing を 1 箇所に置き,session_gate.py の 3 か所にあった not in {PASSED, SKIPPED} の重複を置き換えた.

検証

  • ruff check / ruff format --check: 通過
  • ty check: 通過
  • pytest 全件(dev shell 経由): 4552 passed, 1 skipped
  • 新規 tests/hooks/test_dev_shell_verification.py(fake の nix と専用名のツール,実ネットワークなし)13 件:PATH 優先 / dev shell 経由 / 失敗・タイムアウト・空実行が dev shell 経由でも維持 / flake なし・devShell なし・dev shell にツールなし・nix なし・シェル構築中の予算切れが MISSING_TOOL / 壊れた flake(マーカー前に nix が非 0 終了)はブロックする DEV_SHELL_FAILED,次の検証で再実行され,nix が成功すれば通る / 出力が切り詰められても失敗は失敗のまま
  • test_session_gate.py:利用不可がブロックしない表示になること,失敗が優先してブロックすること,status の unavailable 判定(5 ケース)
  • 最初の CI の test 失敗は,テストが実在の go を使っており,ランナーに go があって「PATH に無い」前提が崩れたため.実在しないツール名に変更して解消した.
  • 実機の nix develop で rater を検証してはいない(fake のみ).
  • TSDD:テストを先に書いたが,実装前に赤を実行して確認してはいない(書いた順序のみ).

レビュー対応

  • claude-review:P2 と P3 を修正し,各スレッドに返信済み.nix develop の失敗の扱いは,最初は「利用不可」とし,エージェントが壊した flake.nix が Stop を通ってしまうという指摘を受けて,ユーザーの判断で「ブロックする失敗」に変更した(現在の設計).その後,一時的な nix エラーでの失敗レシートが再利用される点を指摘され,ユーザーの判断で DEV_SHELL_FAILED を再利用しない(毎回再実行)設計にした.
  • codex-review:Codex の usage limit("You have reached your Codex usage limits for code reviews")で失敗.合意済みの方針により受容(ready, codex skipped: usage limit).

計画との差異

なし.

🤖 Generated with Claude Code

@furedea

furedea commented Nov 10, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-10T15:49:56.931148Z
We couldn’t complete this review. Comment @codex review to try again.
9b365c0 Manual request
ℹ️ 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

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Comment thread agents/hooks/lib/dev_shell.py Outdated
return MissingTool(f"{tool} not found on PATH and the project has no flake dev shell")
if not shutil.which("nix", path=search_path):
return MissingTool(f"{tool} not found on PATH; the project has a flake dev shell but nix is not on PATH")
return Launch(("nix", "develop", "--command", "sh", "-c", _PROBE, "sh", *arguments), via_dev_shell=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 The time nix develop spends evaluating and building the flake counts against the check's test budget (300s by default, and less once the gate budget has been partly used). On a cold store, entering the dev shell can take minutes, and then the check is reported as TIMEOUT. TIMEOUT counts as failing, so Stop is blocked with "Verification failed" even though no test ran. That is the same kind of false failure this PR is meant to remove. One option is to build the shell first (e.g. nix develop --command true, or nix print-dev-env) under its own budget and report a timeout there as MISSING_TOOL/unavailable. Another is to tell nix-startup time apart from test time before calling it a test timeout.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in ce8e63f. The probe now prints a second marker once sh is running inside the dev shell. If the budget ends before that marker, the result is MISSING_TOOL ("the flake dev shell did not start within the check budget"), not TIMEOUT, so Stop is not blocked. Covered by test_dev_shell_still_building_when_the_budget_ends_is_unavailable_not_a_timeout.

if any(Status(row["status"]).failing for row in rows):
return "failed"
if any(row["status"] == Status.MISSING_TOOL for row in rows):
return "unavailable"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3 The new unavailable state in current_status (what verification_session.py status reports) has no test. The new tests only cover gate/verify. A status test with a current missing_tool receipt would lock in unavailable, and one with missing_tool next to a failed receipt would lock in failed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in ce8e63f. Added test_status_reports_a_missing_tool_as_unavailable_unless_a_check_failed, which locks unavailable for missing_tool alone or next to passed, and failed when a failed or timeout receipt sits next to it.

@github-actions

Copy link
Copy Markdown

Review summary (read-only)

No blocking findings (0 P0, 0 P1).

  • P2 agents/hooks/lib/dev_shell.py: the time nix develop takes to evaluate and build the dev shell counts against the test timeout. On a cold store this can end as TIMEOUT, which counts as failing and blocks Stop before any test has run.
  • P3 agents/hooks/lib/session_gate.py: no test covers the new unavailable state that status reports.

Checks that hold up:

  • If the tool is on PATH, it runs directly, so uv/Python repos are unaffected.
  • The probe reports MISSING_TOOL only when it sees both its marker and exit code 127, so a test that fails on its own is not mistaken for a missing tool.
  • unresolved() still treats MISSING_TOOL as not passed, so verify exits non-zero.
  • A real failure still takes priority over a missing tool and blocks Stop.
  • A MISSING_TOOL receipt is rerun when PATH or the worktree (for example flake.nix) changes.

@furedea

furedea commented Nov 10, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Comment thread agents/hooks/lib/dev_shell.py Outdated
return MissingTool(f"{tool} not found on PATH and the project has no flake dev shell")
if not shutil.which("nix", path=search_path):
return MissingTool(f"{tool} not found on PATH; the project has a flake dev shell but nix is not on PATH")
return Launch(("nix", "develop", "--command", "sh", "-c", _PROBE, "sh", *arguments), via_dev_shell=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: When nix develop itself fails, the check is reported as a failed test and Stop gets blocked. Only the probe's marker plus exit 127 maps to MISSING_TOOL. Any other non-zero exit from nix develop becomes Status.FAILED, and that blocks Stop with "Verification failed", even though no test ever ran. Some cases where this happens:

  • The regex match is text-only, so a flake that declares devShells.aarch64-darwin.default passes the check on an x86_64-linux machine. nix develop then exits 1 with "does not provide attribute devShells.x86_64-linux.default".
  • nix-command / flakes are not enabled.
  • The flake fails to evaluate.

Separately, the first nix develop run may spend the whole test budget building or downloading the shell, which ends in TIMEOUT and also blocks.

This isn't a regression, since the old FileNotFoundError path also blocked. But it goes against the PR's goal of not judging code when the tool environment is the problem. One fix: add a second probe marker that is printed only once sh starts inside the shell. If that marker is absent, nix never reached the command, so classify the result as MISSING_TOOL/unavailable with the nix error tail. A test for a failing nix develop stub would cover this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in ce8e63f with the second marker you suggested. A nix develop failure (missing attribute for the system, flakes disabled, evaluation error) exits without the marker, so it becomes MISSING_TOOL with the last line of nix output as the reason. One guard: when the retained output tail was truncated, the marker may have been dropped, so the test result stands (test_failure_with_output_past_the_retained_tail_stays_failed). Covered by test_nix_develop_that_fails_before_the_command_is_unavailable_not_a_test_failure.

@github-actions

Copy link
Copy Markdown

Review summary: 0 blocking findings (P0/P1), 1 P2.

The overall flow looks correct:

  • A tool found on PATH still runs directly.
  • A tool missing from PATH runs through the flake dev shell.
  • MISSING_TOOL doesn't block Stop, but it keeps unresolved() true, so verify still exits non-zero.
  • A failure alongside a missing tool still takes precedence and blocks.

Receipt identity still picks up PATH and flake.nix changes, so a cached MISSING_TOOL result is re-checked once the environment changes. The tests cover the main paths.

  • P2 (dev_shell.py:50): when nix develop itself fails (no dev shell for the current system, flakes not enabled, flake fails to evaluate, or the first run times out while building the shell), the result is classified as FAILED/TIMEOUT and blocks Stop, even though no test ran.

🤖 Generated with Claude Code

@furedea

furedea commented Nov 10, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Comment thread agents/hooks/lib/dev_shell.py Outdated

def _not_started(self, end: ProcessEnd) -> MissingTool | None:
if end.timed_out:
return MissingTool("the flake dev shell did not start within the check budget")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 — Running out of budget before the dev shell starts is reported as MISSING_TOOL. That status doesn't block Stop, and its receipt is reused.

current_receipt gives each check min(check_budget(), GATE_BUDGET_SECONDS - elapsed), with a floor of 0.01s. If earlier checks in the same Stop use up most of the 540s gate budget, a later dev-shell check gets almost no time. Even a cold-but-healthy nix develop (evaluation or substitution) is then killed before it prints the entered marker. This branch reports that as "did not start within the check budget" → MISSING_TOOL.

What changes compared to the PATH case:

  • On PATH, the same budget starvation gives TIMEOUT, which is failing and blocks Stop.
  • Here, Stop is not blocked, and the receipt is saved with an unchanged identity. Later Stops return the cached "unavailable" result via valid_receipt and never retry, until the worktree, PATH or hooks change.

So a temporary condition (an earlier check eating the budget, a cold nix store, a network hiccup during substitution) ends up as a lasting, non-blocking "unavailable". The code is never checked again.

Suggested fixes, any one of:

  • Keep a timeout before the marker as TIMEOUT.
  • Don't make MISSING_TOOL receipts from timeouts or non-zero nix develop exits reusable.

Either way, add a test where the check runs with a starved budget.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 043ea56. A timeout before the entered marker stays MISSING_TOOL (so a cold store does not block Stop), but a MISSING_TOOL receipt is no longer reused: VerificationRun.current_receipt reruns it on every verify/Stop pass, so a starved budget or cold nix store cannot become a lasting unavailable. status still shows the saved receipt as unavailable. Covered by test_missing_tool_receipt_is_retried_on_the_next_pass_not_reused.

@github-actions

Copy link
Copy Markdown

Review summary

1 finding (P2), 0 blocking.

  • P2 agents/hooks/lib/dev_shell.py:64: if the budget runs out before the dev shell starts, the check is recorded as MISSING_TOOL. That status doesn't block Stop, and the receipt is reused on later Stops without retrying. When earlier checks use up the 540s gate budget, a healthy but cold nix develop becomes a lasting non-blocking "unavailable". The same starvation on the PATH route gives TIMEOUT and blocks. There's no test for this case.

Other parts look correct:

  • PATH-first selection.
  • The two-marker probe, including the guard for truncated output.
  • Status.failing consolidation.
  • current_status/unresolved handling.
  • The verification_session.py renames: callers checked, and provider_adapter only uses dispatch/failure.

All JS, Go, Rust and pytest runners use bare executable names, so the shutil.which lookup in the hook's cwd can't misjudge a relative path.

@furedea

furedea commented Nov 10, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Comment thread agents/hooks/lib/dev_shell.py Outdated
return MissingTool(f"{tool} not found on PATH and the project has no flake dev shell")
if not shutil.which("nix", path=search_path):
return MissingTool(f"{tool} not found on PATH; the project has a flake dev shell but nix is not on PATH")
entered = ("nix", "develop", "--command", "sh", "-c", _PROBE, "sh", *arguments)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: nix develop can change the worktree it is checking.

nix develop writes flake.lock when it is missing, or when flake.nix gained an input that the lock doesn't have yet. Then:

  1. verify() takes a new capture(record.root) after the checks. The lock file is new (untracked files still count toward the digest) or its tracked content changed. Either way the digest differs, so the result is a blocking Verification unresolved · inputs changed during verification; retry required. It is not a real result.
  2. The hook leaves a flake.lock in the user's worktree that the agent never wrote. It then appears in later changed-path selection.

The verifier should not write to the tree it checks. Passing --no-write-lock-file keeps evaluation read-only (nix uses the in-memory lock), or use --no-update-lock-file if a stale lock should fail instead:

Suggested change
entered = ("nix", "develop", "--command", "sh", "-c", _PROBE, "sh", *arguments)
entered = ("nix", "develop", "--no-write-lock-file", "--command", "sh", "-c", _PROBE, "sh", *arguments)

No test covers this. A fake nix that creates flake.lock in its cwd would reproduce it through gate(). Note the fake in test_dev_shell_verification.py asserts arguments[:2] == ["develop", "--command"], so that check would need updating too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in ed59ddd. The dev shell now runs as nix develop --no-write-lock-file --command ..., so a missing or stale flake.lock is resolved in memory and the verified worktree is left untouched. The fake nix in test_dev_shell_verification.py now asserts the flag is passed, which covers every dev-shell test.

@github-actions

Copy link
Copy Markdown

Review summary

1 finding (P2), nothing blocking.

  • P2 agents/hooks/lib/dev_shell.py:84: nix develop writes flake.lock when it is missing or stale. That changes the worktree snapshot during verification, so the hook blocks with "inputs changed during verification" and leaves an unexpected file behind. Suggested fix: add --no-write-lock-file.

What I checked and found sound:

  • The PATH-first lookup.
  • How the two probe markers are classified, including truncated output and timeouts before or after the shell starts.
  • MISSING_TOOL stays out of failures but still counts in unresolved() and current_status.
  • MISSING_TOOL receipts are not reused.
  • Old receipt status values still parse with Status(...).

The new tests cover the dev shell paths and the gate and status handling well.

🤖 Generated with Claude Code

furedea and others added 7 commits November 10, 2026 23:41
Stop ran project test tools from the agent PATH only.

A repo whose tools live in its flake dev shell (go in rater) failed every Stop.

A tool absent from PATH now runs as nix develop --command when flake.nix declares a dev shell.

Timeout, process group, logs and receipts are unchanged.

A tool that neither PATH nor a dev shell provides is the new MISSING_TOOL status.

It is reported as Verification unavailable, is not a failure, and does not block Stop.

Tools found on PATH, such as uv for Python projects, run exactly as before.

check_execution.py also gets its docstrings and private helpers.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…t its API

Only main, dispatch and failure are used outside the module (provider_adapter.py).

Every other helper was module-internal, so it is now private instead of documented.

main, dispatch and failure get contract docstrings; helpers are ordered after them.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A real go on the CI runner satisfied the PATH lookup the tests expect to fail.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A second probe marker shows that nix reached the command inside the dev shell.

Without it, a nix develop error or a budget spent building the shell is MISSING_TOOL.

A truncated output tail may have dropped the marker, so it keeps the test result.

Adds status tests for the unavailable state.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A dev shell that missed the budget once must not stay unavailable for the session.

The receipt is kept for status, but verify and Stop no longer reuse it.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
nix develop creates or refreshes flake.lock, which changed the verified worktree.

The run now passes --no-write-lock-file, and the fake nix asserts the flag.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Also covers status through the public entry point.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea-agent
furedea-agent Bot force-pushed the fix/verify-hook-dev-shell branch from ed59ddd to 030d16f Compare November 10, 2026 14:44
@furedea

furedea commented Nov 10, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Comment thread agents/hooks/lib/dev_shell.py Outdated
return MissingTool("the flake dev shell did not start within the check budget")
if end.returncode:
last_line = next((line for line in reversed(end.output.splitlines()) if line.strip()), "no output")
return MissingTool(f"the flake dev shell did not start: {last_line.strip()[:_REASON_LIMIT]}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 — When nix develop fails before it reaches the probe, the result is always MISSING_TOOL, which doesn't block Stop. That includes a broken flake.nix that the agent itself edited in this session. flake.nix lives in the verified worktree, so this is a change under review, not an outside environment problem.

Scenario: in a repo where go only comes from the dev shell (rater), the agent edits flake.nix and introduces a syntax or evaluation error, and the Go tests would also fail. nix develop exits non-zero without printing the entered marker, so _not_started returns MissingTool. Stop then shows only "Verification unavailable" and lets the session end, even though the code is broken. A deliberate edit to flake.nix gets the same result, so it can also be used to dodge failing tests.

Consider treating a dev-shell startup failure as blocking (or as UNAVAILABLE) when flake.nix or flake.lock is among the changed paths. Keep MISSING_TOOL for timeouts while the shell is still building and for the case where the shell starts but lacks the tool.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f9da52b. A project that declares a dev shell is now expected to enter it: when nix exits before the probe marker (a broken flake.nix, evaluation error, wrong system), the check is a FAILED result that blocks Stop, with nix output in the log and summary. MISSING_TOOL remains only for a working shell that lacks the tool, no declared shell with the tool off PATH, or nix not installed. A budget spent before the shell starts is unchanged (MISSING_TOOL, retried each pass). Covered by test_broken_flake_that_nix_cannot_enter_is_a_blocking_failure_with_nix_output and test_dev_shell_that_lacks_the_tool_is_a_missing_tool.

@github-actions

Copy link
Copy Markdown

Review summary (read-only)

I found 1 problem: 1 × P2, and nothing at P0 or P1.

  • P2 agents/hooks/lib/dev_shell.py:67: if nix develop fails before entering the shell, the check is classified as MISSING_TOOL, which doesn't block Stop. That includes a flake.nix the agent broke during the session, so broken code can pass the gate with only a "Verification unavailable" notice.

Things I checked that looked correct:

  • The tool is still looked up on PATH first, so the uv/Python path doesn't change.
  • Timeouts, a failure inside the dev shell, and the empty-run rule are all kept.
  • A failure still takes priority over a missing tool.
  • MISSING_TOOL receipts are rerun instead of reused.
  • status and unresolved handling are right.

The new tests cover the changed behavior well.

Note: the PR also changes a tool missing from PATH in non-flake repos from blocking to non-blocking. The PR description says this is intended.

🤖 Generated with Claude Code

A project that declares a dev shell is expected to enter it.

nix exiting before the probe marker, such as a broken flake.nix, is now a blocking failure.

MISSING_TOOL stays for a working shell without the tool, no declared shell, or no nix.

A budget spent before the shell starts is still MISSING_TOOL and retried.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea

furedea commented Nov 10, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Comment thread agents/hooks/lib/dev_shell.py Outdated
if _ENTERED_MARKER not in end.output:
# A truncated tail may have dropped the marker, which proves the shell started.
started_late = end.timed_out and not end.truncated
return MissingTool("the flake dev shell did not start within the check budget") if started_late else None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 — Every non-timeout nix develop exit before the shell starts counts as a code failure, not just evaluation errors in a flake.nix edited this session. That includes transient environment errors: the nix daemon is unreachable, a substituter or input fetch fails while offline, or the store is out of disk. Each of these returns None here, so execute reports FAILED. Stop then blocks with "Verification failed" even when flake.nix and the code are unchanged.

FAILED receipts can also be reused (only MISSING_TOOL is excluded in current_receipt). So the transient failure is cached as evidence against the code, and later passes show "Verification unresolved · unchanged; not rerun" until something changes the inputs. This is the reverse of how the PR treats the "budget spent before the shell started" case, which is retried as unavailable.

The PR description also says a nix develop evaluation or build failure becomes MISSING_TOOL, which disagrees with this code and with DESIGN.md.

Possible fixes:

  • Classify this ending as FAILED only when flake.nix or flake.lock changed in the session, and as MISSING_TOOL (retried) otherwise.
  • Or at least don't reuse a FAILED receipt that has no entered marker.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PR description fixed: it still described the earlier design and now says nix failing before the marker is a blocking FAILED, matching the code and DESIGN.md.

On the reuse of a transient FAILED I am keeping the code. That a project which declares a dev shell must enter it is a deliberate decision (a flake.nix the agent broke must not pass Stop). A FAILED receipt from an environment hiccup behaves like any other FAILED check: it blocks once, then shows "unresolved · unchanged; not rerun" until inputs change, and verify --force reruns it (documented in delivery.md and DESIGN.md). Making only some FAILED receipts non-reusable would need a new distinction between transient and permanent nix errors, which nix output cannot give reliably.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed in 9b365c0, as decided. A dev shell entry failure (nix exits before the probe marker) is still a blocking failure with nix output in the log, but it is now recorded as its own status, dev_shell_failed, which like missing_tool is never reused (Status.retried). Every verification reruns it: a broken flake.nix blocks each time because nix fails fast, and a transient nix problem clears on the next Stop without verify --force; once nix succeeds the check passes. No transient/permanent distinction is needed. Covered by test_dev_shell_entry_failure_blocks_then_is_rerun_and_passes_once_nix_succeeds and the updated broken-flake execution test. DESIGN.md, DESIGN_ja.md and the PR description are updated.

@github-actions

Copy link
Copy Markdown

Review summary

Blocking findings: 0 (P0: 0, P1: 0, P2: 1, P3: 0)

  • P2 agents/hooks/lib/dev_shell.py:59: when nix develop exits early without timing out, it is always classified as FAILED. That includes transient environment errors (daemon unreachable, offline fetch, full store). The FAILED receipt can then be reused, so an environment hiccup blocks Stop once and then stays as "unresolved · unchanged" until the inputs change. The PR description also says this case becomes MISSING_TOOL, which disagrees with the code and DESIGN.md.

What I checked:

  • The tool is still looked up on PATH first, so Python/uv repos run exactly as before.
  • Status.failing gives the same result as the old not in {PASSED, SKIPPED} checks, except for the new MISSING_TOOL status. unresolved() still counts MISSING_TOOL as owed verification, so verify exits non-zero as described.
  • MISSING_TOOL receipts are excluded from reuse, and _valid_receipt accepts the new status value.
  • The tests cover PATH priority, running through the dev shell, failure, timeout, and empty-run handling inside the dev shell, every way a tool can be missing, and the gate's display and blocking.

🤖 Generated with Claude Code

The failure still blocks Stop but is recorded as dev_shell_failed.

Like missing_tool, it is never reused, so a transient nix error clears on the next Stop.

A broken flake.nix keeps blocking because nix fails fast.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea

furedea commented Nov 10, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

Copy link
Copy Markdown

レビュー結果(read-only): ブロッキングな指摘はありません(P0/P1: 0 件,P2/P3: 0 件).

確認した点:

  • dev_shell.plan_launch: PATH 優先 → flake の devShell 検出 → nix の有無の順で判定しており,Python/uv の既存経路は変わらない.runner 引数は相対パスを含まないため,shutil.which の cwd 依存は問題にならない.
  • Launch.diagnose: マーカー無し+切り詰め → 結果維持,マーカー無し+タイムアウト → MISSING_TOOL,マーカー無し+非 0 → DEV_SHELL_FAILED,マーカーあり+127+not-found マーカー → MISSING_TOOL の分岐は,ツール自体が 127 で終わる場合(not-found マーカーが無い)も含めて正しく区別できている.
  • session_gate: Status.retried により MISSING_TOOL/DEV_SHELL_FAILED のレシートは再利用されず,DEV_SHELL_FAILED は再実行のたびに new_failure としてブロックする.失敗が missing より優先される._current_status の unavailable も整合している.
  • テスト: 新規 13 件と test_session_gate.py の追加分で,変更した分岐(PATH 優先,dev shell 経由,flake なし/devShell なし/nix なし,壊れた flake,予算切れ,切り詰め)は網羅されている.

設計上のトレードオフ(指摘ではない): PATH に無いツールは従来 UNAVAILABLE(ブロック)だったが,今は MISSING_TOOL(非ブロック)になる.また dev shell の構築が予算を超えた場合も非ブロックになる.PR 本文に意図として書かれているため,指摘にはしていない.

@furedea
furedea merged commit 63dd2f5 into main Nov 10, 2026
22 of 24 checks passed
@furedea
furedea deleted the fix/verify-hook-dev-shell branch November 10, 2026 15:58
furedea added a commit that referenced this pull request Nov 10, 2026
## 概要

ruff の D (pydocstyle, google),DOC,N (pep8-naming) を有効化する最終 PR (#74 stage
1B の持ち越し分).設定は template-python / dotfiles と同じ形にした.先行 lane (#130, #131,
#132, #133) の修正は既にマージ済みで,この PR は残りの違反を直したうえで設定を有効化する.

`ruff check .` は有効化後の設定で 0 件.ブランチは 1 コミットで,lefthook の全フックを除外なしで通過している.

Refs #74

## 設定 (pyproject.toml)

- `select` に `D`,`DOC`,`N` を `W` と `F` の間に追加 (template-python / dotfiles
と同じ並び).`DOC` による新規指摘は 0 件を確認済み
- `ignore` に `D104`,`D105`,`D107` を追加
- `per-file-ignores` の `tests/**` に `D` を追加
- `[tool.ruff.lint.pydocstyle] convention = "google"` を追加

既存の ignore は削除していない.

## この PR での修正

### 改名 (N818)

ドメイン概念はそのまま,`Error` 接尾辞のみ追加し,agents と tests の全使用箇所を更新した.

- `UnexpandableGlob` → `UnexpandableGlobError`
- `UnsupportedSyntax` → `UnsupportedSyntaxError`
- `UnplacedCommit` → `UnplacedCommitError`
- `UnknownTestCommand` → `UnknownTestCommandError`

### 非公開化 (外部から使われないことを `git grep` で agents/ scripts/ tests/ に対して確認)

| ファイル | 件数 | 名前 |
| ---------------- | ---- |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| `guard_file.py` | 10 | `_policy_path`, `_load_policy`,
`_protected_reason`, `_validate_filename_rule`, `_commit_reason`,
`_content_match`, `_scan_content`, `_judged_commit`, `_context`,
`_session` |
| `shell_paths.py` | 1 | `_brace_words` |

### docstring を書いた公開 API

| ファイル | 件数 | 名前 | 理由 |
| ---------------- | ---- |
----------------------------------------------- |
------------------------------------------------------------------ |
| `guard_file.py` | 3 | `commit_filename_rules`, `content_text`, `main`
| テストと CLI から使われる公開 API |
| `shell_words.py` | 1 | `home_directory` |
`tests/hooks/test_shell_words.py` が直接呼ぶため非公開化しなかった |

docstring は名前の言い換えではなく,返す値・拒否する入力・例外を述べている.

## リポジトリ全体の内訳 (ac-dn の全 lane)

| PR | 非公開化 | docstring 追加 | 改名 (N818) |
| -------------------------------------------- | -------: |
-------------: | -----------------: |
| #130 (hooks/lib) | 38 | 23 | 0 (他に表記修正 2) |
| #131 (session_store ほか 4 ファイル) | 48 | 20 | 0 |
| #133 (hooks/\*.py, scripts, skills, tests) | 44 | 15 | 2 |
| #132 (verification_session, check_execution) | 8 | 7 | 0 |
| この PR | 11 | 4 | 4 |
| 合計 | 149 | 69 | 6 |

#130 と #133 の件数は各 PR 本文の表,#131 は本文の合計行,#132 は ac-dn の表 (非公開化 7 +
`collect`,文書化
`main`/`dispatch`/`failure`/`Status`/`Result`/`Result.failed`/`execute`)
による.

## 検証

- `ruff check .`: All checks passed
- `ruff format --check .`: 239 files already formatted
- `ty check`: All checks passed
- `pytest`: 手元 (sandbox) では 2 件を除き通過.失敗は
`tests/hooks/test_formatter_config.py` の dprint 統合テスト 2 件のみで,sandbox が
`plugins.dprint.dev` への通信を遮断するため (この PR の変更とは無関係).CI で確認する
- pre-commit (lefthook) は `LEFTHOOK_EXCLUDE` なしで全フック通過

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

Co-authored-by: furedea <[email protected]>
Co-authored-by: Claude Sonnet 5.5 <[email protected]>
furedea pushed a commit that referenced this pull request Nov 11, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.1.1](v0.1.0...v0.1.1)
(2026-11-11)


### Features

* **hooks:** judge session changes with jev-lint model rules at Stop
([#150](#150))
([946e976](946e976))


### Bug Fixes

* **hooks:** ask for zsh's $=name and $~name expansions
([#152](#152))
([9255c87](9255c87))
* **hooks:** judge a ~user path by the secret-path rules of the own home
([#129](#129))
([64221f6](64221f6))
* **hooks:** match static words by their single-quoted form in precise
command rules
([#147](#147))
([c432a20](c432a20))
* **hooks:** run verification tools through the flake dev shell
([#132](#132))
([63dd2f5](63dd2f5))
* **hooks:** start trusted model-rule programs and send only
in-repository regular files
([#156](#156))
([183496b](183496b))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: furedea-release[bot] <353651101+furedea-release[bot]@users.noreply.github.com>
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