Skip to content

fix(hooks): judge only the session's own changes in Stop model rules - #237

Closed
furedea-agent[bot] wants to merge 14 commits into
mainfrom
fix/stop-rules-own-changes
Closed

furedea-agent[bot] wants to merge 14 commits into
mainfrom
fix/stop-rules-own-changes

Conversation

@furedea-agent

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

Copy link
Copy Markdown
Contributor

概要

Stop hook の model rules が,セッション中に fast-forward・pull で取り込んだ他人の commit のファイルまで判定対象にしていた.セッションが自分で作った変更だけを対象にする.判定の仕組み(Jev,advisory,Stop だけで動く)は変えていない.

Closes #234
Refs #169

原因

対象ファイルを 2 か所で選んでいて,どちらも取り込んだ commit を含んでいた.

  • commit 済みの変更: git diff <セッション開始時の HEAD> HEAD なので,fast-forward で進んだ範囲がすべて入る(issue の再現)
  • 未 commit の変更: セッション開始時の baseline との差を取るので,fast-forward で working tree に現れたファイルも「変わった」ことになる(issue には無く,テストで見つけた)

選んだ方法

HEAD の reflog で,セッション自身が作った commit を見分ける.

  • committed_paths を own_committed_paths に置き換えた.登録後の reflog の各 step のうち,件名が commit・commit (amend)・commit (cherry-pick)・cherry-pick・revert・am・rebase (pick など)・pull --rebase … (pick) のものだけを数える
  • 各 step の変更は,その前に HEAD が指していた commit との差で測る(amend は追加した分だけ).開始時の commit から内容が変わっていない path は数えない
  • その commit が HEAD に含まれる間は全 path を数える.破棄・amend・rebase で消えた commit は,HEAD がその内容を今も持つ path だけ数える
  • merge・pull・checkout・rebase (start)・commit (merge) は数えない.merge commit は自分の部分と取り込んだ部分を分けられないため常に数えない
  • 未 commit の側は,baseline との差に加え,git status で HEAD・index と異なる(または未追跡の)ファイルに限る(uncommitted_paths).開始時の commit が無い repository では絞り込まない
  • reflog で判断できないとき(登録時に記録できなかった,古い記録,reflog 無効)は,従来どおり開始時の commit からの全 commit を判定する(committed_paths)
  • receipt の fingerprint に,数えた path と dirty な path を含める
  • ADR の選択(_is_changed_adr,ReviewedSpan(record.head, "HEAD"))は,渡される path が上の選択を通った後のものなので変更していない

新しい状態

登録時の reflog の印だけを baseline.json の reflog(entry 数と最も新しい entry の行)に追加した.時刻で区切ると秒精度で登録直前の commit と区別できず,件数だけで区切ると古い entry の期限切れでずれるため,最も新しかった entry を探し直す.

退けた案

案 退けた理由
author・committer で判定 取り込まれた他の PR の作者も同じユーザーで区別できない
--first-parent fast-forward で入った他人の merge も first-parent 上に並ぶ
.cc-writes の記録 編集の記録で commit を指さない
verification record 検証対象の選択用で commit を記録していない
セッションが commit 一覧を記録する新しい状態 印 1 つで足りる(YAGNI)
reflog の時刻・件数だけで区切る 秒精度・期限切れでずれる(レビュー指摘)

制限

  • fast-forward で取り込んだ commit を,その後 git rebase で載せ替えると,replay された commit が自分のものとして数えられる(余計な advisory の方向)
  • 別の worktree・clone で作った commit を fast-forward で取り込むと,同僚の commit と区別できず数えない.issue の再現と同じ形のため許容する
  • merge commit に書いた衝突解消は数えない
  • reflog が判断できないときは全 commit を判定するので,余計な advisory は出うる

テスト・checks

  • tests/hooks/test_model_rules_own_commits.py(新規 43 件)と test_session_head.py の 1 件.fast-forward・pull,自分の commit,amend,rebase,cherry-pick,revert,am,登録前の commit,期限切れ,reflog 無し,破棄した commit,receipt の fingerprint,Stop hook 経由の確認.主要なものは修正を外すと失敗することを確認した
  • uv run pytest tests/hooks: 5036 passed,2 skipped.ruff,ty,lefthook も通った
  • CI の all-green は pass

レビュー指摘の扱い

P0/P1 は常に修正し,P2/P3 は変更を誤らせるものだけ修正した.それ以外は brief の範囲外として返信して resolve した.

指摘 重要度 対応
pull --rebase の reflog 件名に合わない P2 修正.テスト追加
登録前の reflog entry を数える P1 修正.登録後の entry だけ数える
開始時の HEAD を amend すると変えていないファイルまで数える P1 修正.開始時から内容が変わった path に限る
登録と同じ秒の登録前 commit を時刻で区別できない P1 修正.時刻をやめ reflog の印で区切る
fast-forward した tip の amend で取り込んだファイルまで数える P1 修正.step ごとに前の HEAD との差で測る
reflog が無いと黙って対象外になる P2 修正.判断できないときは全 commit 判定に戻す
reflog_entries が git の失敗を 0 として記録(fail-open,security review) 中 修正.失敗は None,None なら全 commit 判定
commit (cherry-pick): が数えられない P2 修正.テスト追加
選択が receipt の fingerprint に入っていない(commit 済み・未 commit) P2 修正.テスト追加
最初の commit が無い repository で commit 済みのファイルが落ちる P2 修正
破棄した commit の path が外部の変更を自分のものにする P1 修正.テスト追加
自分の commit の後に外部が同じファイルを変えると落ちる/mode 変更 P2 修正.HEAD に含まれる commit は全 path を数える
git am の件名が数えられない/am (continue) の正規表現の誤り P2 修正.件名ごとの表のテスト追加
splitlines が件名の Unicode 改行で割れる P3 修正.テスト追加
reflog の期限切れで件数がずれる P1 修正.最新 entry を探し直す.テスト追加
Stop hook の Jev 6 件(エラー文言,関数の責務) advisory 文言と fingerprint の抽出を修正.own_committed_paths と test の責務の指摘は分けない
fast-forward 後の git rebase の replay P2 範囲外(余計な advisory の方向).「制限」に記録
別 worktree・clone の commit/commit-tree+update-ref P2 範囲外.同僚の commit と区別できず,後者は敵対的な迂回
assume-unchanged・skip-worktree P2 範囲外(敵対的な迂回)
同じファイルの外部 hunk が審査範囲に入る/初回 commit の審査が 0 件 P1/P2 範囲外(Jev の審査の仕組み.変更前から同じ)
uncommitted_paths の git 失敗,期限切れ再指摘,重複行,効率,merge の衝突解消,非 UTF-8 パス,登録時の競合 P2/P3 範囲外として回答

🤖 Generated with Claude Code

Select committed files from the commits HEAD's reflog says the session made, and
drop uncommitted candidates that match HEAD (fast-forwarded or pulled in).

Closes #234
Refs #169

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 18, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T08:16:06.770356Z ca3986f 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.

Comment thread agents/hooks/lib/model_rules_files.py Resolved
@github-actions

Copy link
Copy Markdown

Review summary

Reviewed read-only. The change looks sound. Using HEAD's reflog to separate the session's own commits from fast-forwarded or pulled ones is reasonable, and the uncommitted-side filter against git status is correct. Ignored files are excluded by both capture and status, so they don't diverge.

Finding

  • P2 (inline): the reflog subject regex does not match pull --rebase ... (pick) entries. The session's own commits rebased by git pull --rebase are therefore dropped. This is a false-negative, and the hook is advisory. The PR also has no tests for pull --rebase, cherry-pick or revert.

No P0 or P1 issues found. I did not run the test suite.

🤖 Generated with Claude Code

@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: 65b9735644

ℹ️ 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 agents/hooks/lib/model_rules_files.py Resolved
Also accept the commits that pull --rebase replays as the session's own.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 18, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary

I found no P0, P1 or P2 problems, so I posted no inline comments. This was a read-only review. I did not run the test suite.

What I checked:

  • Reflog selection: _OWN_REFLOG_SUBJECT matches commit, commit (amend), cherry-pick, revert, and the rebase (pick|...) and pull --rebase ... (pick) forms. It does not match merge, pull: Fast-forward, checkout, rebase (start), rebase (finish) or commit (merge).
  • Reachability filter: Intersecting with rev-list base..HEAD drops the old hashes left behind by amend and rebase.
  • Merge commits: diff-tree without -m or -c prints nothing for a merge commit. That agrees with the rule that merge commits are never counted.
  • Uncommitted side: git status --porcelain=v1 -z --no-renames entries are XY path, so entry[3:] is correct. Intersecting with the baseline diff removes files that were only fast-forwarded in. Files edited after the fast-forward stay in.
  • Registration time: created_at is written as time.time() in epoch seconds. The registered_at fallback of 0 for older records fails open, so such a record counts every own-looking entry.
  • Error handling: uncommitted_paths can now raise ValueError even when HEAD has not moved. The gate already catches ValueError and skips with advice, so a git failure will not crash the hook.

Remaining points, none blocking:

  • P3: The ValueError text from _git_output ("the commits since the session started cannot be listed") is also used for the git status failure. The message is slightly misleading, but it only shows up in a skip reason.
  • P3: A rebase or cherry-pick that replays commits from another author that were already fast-forwarded in will count them as the session own. This is rare, advisory only, and in line with the stated threat model.
  • P3: There is no direct unit test for SessionRecord.registered_at (missing or non-numeric created_at). The time-cutoff test covers the main path.

Overall: the approach and the documented limitations (cross-worktree fast-forward, expired reflog) are reasonable, and the new tests cover the main scenarios.

@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: 46d610b120

ℹ️ 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 agents/hooks/lib/model_rules_files.py Resolved
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 18, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary

No P0, P1 or P2 findings. I read the diff and checked the following.

  • Reflog parsing: %gd with --date=unix gives HEAD@{<epoch>}, so the registered_at comparison works. created_at is written as time.time(), which matches.
  • registered_at fallback: a missing value becomes 0.0. Every entry then counts, which is the intended fallback for older records.
  • Subject regex: commit (merge): is correctly excluded. The pull --rebase ... (pick) form is covered.
  • Reachability and base filters: intersecting with base..HEAD drops commits that were amended or rebased away. Filtering on base..HEAD content drops files an amend left unchanged.
  • Paths in uncommitted_paths: git status --porcelain paths are relative to the repo root. record.root comes from rev-parse --show-toplevel, so they match the baseline paths.

Remaining P3 gaps, all in the over-inclusion direction:

  • P3: squash merges. git merge --squash and git pull --squash finish with a commit: reflog entry, so the squashed foreign changes count as the session's own.
  • P3: foreign edits to a session-touched file. If the session commits a.py and a later fast-forward also modifies a.py, the whole base..HEAD span for that file is sent, including the foreign edits. File-level selection cannot separate them. Advisory-only, so I would accept it, but it deserves a line in the docstring.
  • P3: tests. uncommitted_paths is only exercised through the Stop hook test. A direct test would help, covering a staged-only change, a deletion, an untracked file and a file brought in and unedited. There is also no test for registered_at == 0 (an older record).

I did not run the tests.

@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: 9093f60ac3

ℹ️ 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 agents/hooks/lib/model_rules_files.py Resolved
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 18, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread agents/hooks/lib/model_rules_files.py Resolved
@github-actions

Copy link
Copy Markdown

Review summary

I found no P0 or P1 issues. I read the diff only and did not run the tests.

What I checked

  • The reflog subject regex matches commit, commit (amend), commit (initial), cherry-pick, revert and rebase (pick|…), including the pull --rebase … (pick) form. It excludes commit (merge), merge, pull and rebase (start|finish).
  • uncommitted_paths parses git status --porcelain=v1 -z --no-renames correctly, with an XY prefix and paths relative to the repo root.
  • Snapshot covers tracked and non-ignored untracked files, which is the same set as git status, so the new dirty filter drops no ignored files that were judged before.
  • Git failures in the new git status call raise ValueError, which advise() already catches.
  • Records without reflog_entries fall back to 0. That counts more reflog entries, but the base..HEAD reachability filter and the changed_since_base intersection limit the effect.

Finding

  • P2 (inline): a later git rebase onto a target that does not contain commits fast-forwarded in earlier replays them as rebase (pick). They then count as the session's own commits and are sent to the model again. It is advisory-only and rare, but it is the fix(hooks): judge only the session's own changes in Stop model rules #234 symptom coming back by another route, and no test covers it. It is also not listed under 制限.

Other notes (no action needed)

  • Reflog expiry removes the oldest entries, so len(entries) - registered_entries undercounts new entries. That errs toward missing commits, which is the safe direction for an advisory hook.
  • Rebasing a branch whose pre-session commits get new hashes can count files that upstream also changed. This is the same class of false positive as the finding above.

@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: 33361fd3c8

ℹ️ 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 agents/hooks/lib/model_rules_files.py Resolved
Comment thread agents/hooks/lib/model_rules_files.py Resolved
…ut a reflog

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 18, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread agents/hooks/lib/model_rules_files.py Resolved
@github-actions

Copy link
Copy Markdown

Review summary

Read-only review of the Stop hook change that limits model rules to the session's own commits. I found one issue and have not run the test suite.

P2 (inline comment on model_rules_files.py): _OWN_REFLOG_SUBJECT does not match commit (cherry-pick):. I believe git logs that subject when a conflicted cherry-pick or revert is finished with a manual git commit, but I did not run it to confirm. Those commits would be dropped from the session's own changes, which hides real work from the advisory. Allowing cherry-pick in the optional group fixes it, and a conflict-resolved cherry-pick test would cover it.

Checked, no finding:

  • The other reflog subjects (commit (merge), pull --rebase … (pick), fast-forward and checkout entries) are classified as the PR describes.
  • The snapshot already excludes ignored files, so filtering uncommitted paths with git status is consistent with it.
  • A missing, uncounted or inconsistent reflog raises ValueError, so the failure mode is "skipped", not silently wrong.
  • Sessions registered before this change have no reflog_entries. If HEAD moves in such a session, the check is skipped. This is acknowledged in the PR description.

No security problems found. Git is invoked with an argument list, -- terminates the pathspecs, and reflog subjects are only matched by prefix.

🤖 Generated with Claude Code

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

ℹ️ 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 agents/hooks/lib/model_rules_gate.py Resolved
…selection

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 18, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread agents/hooks/lib/model_rules_gate.py Resolved
Comment thread agents/hooks/lib/model_rules_files.py Resolved
@github-actions

Copy link
Copy Markdown

Review summary: no P0 or P1 findings. I left two inline P2 comments.

  • P2, model_rules_gate.py: when a session starts in a repository with no commits (record.head is None), files the session commits are dropped from both selections. They aren't in committed, and they aren't dirty.
  • P2, model_rules_files.py: the ValueError for a missing or unusable reflog skips the whole review, including uncommitted files. This affects sessions registered before this PR (no reflog_entries) and repositories with reflogs disabled. Reflog expiry mid-session would also quietly drop the oldest own commits.

I read the diff only and did not run the tests. The reflog-based attribution looks sound for commit, amend, cherry-pick, revert, rebase, ff and merge, and the tests cover those cases.

🤖 Generated with Claude Code

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

ℹ️ 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 agents/hooks/lib/model_rules_files.py Resolved
@github-actions

Copy link
Copy Markdown

Review summary: no blocking findings.

I read the changes to model_rules_files.py, model_rules_gate.py, session_snapshot.py and session_store.py, plus the new tests. I did not run the test suite. I found nothing at P0 to P2 and have no inline comments.

What I checked:

  • Reflog subject regex. It counts commit, commit (amend), cherry-pick, revert and rebase pick/reword/edit/squash/fixup/continue steps. It leaves out commit (merge), fast-forward, pull, checkout and the rebase start/finish entries, as intended.
  • Per-step diffs. Each step is diffed against the previous reflog entry, so an amend counts only what it added. _still_in_head and the final intersection with base..HEAD drop paths that were discarded or later changed by outside commits.
  • Fallbacks. An uncounted reflog, or HEAD moving with no reflog entry, raises ValueError, and the gate falls back to committed_paths (all commits since the session started). Judging too much is the safe direction.
  • Review cache key. _inputs now includes the session-commit paths and the dirty set. Reaching the same tree by fast-forward and by cherry-pick therefore gives different keys, and the tests cover this.
  • Uncommitted filter. _uncommitted_selection keeps only the paths that are both changed from the baseline and dirty in git. The filter is skipped when record.head is None.

Minor observations, no action needed:

  • Reflog expiry (P3). If git gc expires old reflog entries during a long session, len(steps) - registered_entries shrinks and the oldest own commits could go unjudged. Sessions are retained for 7 days against a 90-day default expiry, so this is very unlikely.
  • git status locking (P3). uncommitted_paths runs plain git status, which can refresh the index and take index.lock. --no-optional-locks would avoid contending with a concurrent git command from the session.
  • PR description mismatch. The description is about package-manager settings (denyWrite, secret_path_policy.json, tests/test_package_manager_settings.py). The diff is entirely about Stop model-rule hooks and reflog handling. Please check the description and linked issue belong to this PR.

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

ℹ️ 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 agents/hooks/lib/model_rules_files.py Resolved
Comment thread agents/hooks/lib/model_rules_gate.py Resolved
… not a count

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 18, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread agents/hooks/lib/model_rules_files.py Resolved
@github-actions

Copy link
Copy Markdown

Review summary

I found nothing blocking. The reflog-based selection of the session's own commits looks sound. I read the diff and did not run the tests.

  • P2, inline: _still_in_head drops a session-authored path when a later outside commit, for example a fast-forward pull, changes the same file. That file then never reaches the Stop model rules. The tests cover the discarded-commit case but not this one.
  • Description mismatch (not a code finding): the PR body describes package-manager settings, denyWrite and tests/test_package_manager_settings.py. The title and the six changed files are about Stop model rules and the session reflog. Please check that the description belongs to this PR.

Things I checked that look fine:

  • Old baselines without a reflog field fall back to committed_paths.
  • A reflog that expired at its old end is handled.
  • A commit subject containing a Unicode line break doesn't split an entry.
  • Merge commits are excluded on purpose.

@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: 19b904c793

ℹ️ 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 agents/hooks/lib/model_rules_files.py Resolved
Comment thread agents/hooks/lib/model_rules_files.py Resolved
…s, and count git am

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 18, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread agents/hooks/lib/model_rules_files.py Resolved
Comment thread agents/hooks/lib/session_snapshot.py Resolved
Comment thread agents/hooks/lib/model_rules_gate.py Resolved
@github-actions

Copy link
Copy Markdown

Review summary

I read the diff only and did not run the tests. There are no P0 or P1 findings. The reflog-based "own commits" logic looks sound. The reflog_lines parsing, the fallback to committed_paths, and the _inputs fingerprint change are all handled consistently.

  • P2: the am (continue) regex alternative in model_rules_files.py:31 has an over-escaped backslash. It can never match, and nothing tests it. A commit made through git am --continue is silently left out of the review.
  • P3: reflog mark matching in session_snapshot.py:94 is by whole-line equality. Identical lines within the same second can make newer_entries undercount.
  • P3: model_rules_gate.py:308 computes _session_commits_paths twice per Stop. Each call costs several git subprocesses per reflog step.

Separately, the PR description is about package-manager settings (denyWrite, secret_path_policy.json, tests/test_package_manager_settings.py). The diff is about Stop model rules and the HEAD reflog. The description looks stale or belongs to another PR, so please fix it before merge.

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 2410027db8

ℹ️ 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".

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 18, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread agents/hooks/lib/model_rules_files.py Resolved
@github-actions

Copy link
Copy Markdown

Review summary (read-only)

Reviewed the reflog-based "own commits" selection in model_rules_files.py, model_rules_gate.py, session_snapshot.py and session_store.py, along with the new tests. I did not run the test suite, because the sandbox blocked it.

  • P2 (1 finding, inline): commits the session made that reach HEAD by fast-forward or merge, or through plumbing with no matching reflog subject, are silently left out of the review. There is no fallback to committed_paths in that case.
  • Git errors from the new uncommitted_paths call surface as ValueError, and advise() already catches that. I found no crash path.
  • Git arguments come from validated commit ids and git output, so I saw no injection issue.
  • Reflog entries are matched by line, and the line includes a unix timestamp. Two identical entries in the same second could miscount, which is very unlikely.
  • The PR description I fetched talks about package-manager settings, which doesn't match the files changed here. You may want to check the body.

No P0 or P1 findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 2d0db85563

ℹ️ 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".

…ection fingerprint

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 18, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread agents/hooks/lib/model_rules_files.py Resolved
@github-actions

Copy link
Copy Markdown

Review summary

I read the diff read-only and did not run the tests. The reflog-based attribution is carefully built, and the tests cover most of its edge cases. The fallback to `committed_paths` when the reflog can't say is sound. `advise()` also catches `ValueError`, so a failing git call degrades to a skipped advice instead of crashing the Stop hook.

Findings

  • P2 (inline, `model_rules_files.py`): Anything the session folds into a merge commit is never judged. This covers conflict resolutions and `merge --no-commit` plus edits. It is an unintended hole in the gate, and no test covers a conflict resolved by the session.

Notes (not blocking)

  • The PR description appears to belong to a different change. It describes package-manager settings, `denyWrite`, and `tests/test_package_manager_settings.py`. This PR changes only the hooks and the model-rules tests. Please update the body so the merge commit message is accurate.
  • `own_committed_paths` spawns up to three git processes per reflog entry since registration. `_Changes.of` and `_inputs` each run it, so a long session with many checkouts and rebases pays that cost twice per Stop. I did not measure it. Check it if Stop latency matters.
  • Existing session records have no `reflog` key. They take the "judge every commit" fallback, which is the safe direction.

🤖 Generated with Claude Code

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

ℹ️ 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 agents/hooks/lib/model_rules_gate.py Resolved
Comment thread agents/hooks/lib/session_store.py Resolved
@furedea-agent

furedea-agent Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Closing: the reflog analysis is too heavy for what it buys. #234 will be redone with the merge-base approach described in #234.

@furedea-agent furedea-agent Bot closed this Nov 18, 2026
furedea added a commit that referenced this pull request Nov 19, 2026
…#247)

## 概要

Stop hook の model rules が,default branch に取り込まれた
commit(他の作業,または既にレビュー済みの自分の PR)のファイルまで判定していた.判定の基準を単純な方法で見直す.

Closes #234
Refs #169

## 方法

commit 済みの変更の基準(base)を,セッション開始時の HEAD と `git merge-base HEAD
refs/remotes/origin/HEAD` のうち新しい方にする.

- 後者が前者の子孫のとき(`git merge-base --is-ancestor`)だけ使う
- remote の default branch が分からないとき,または子孫でないときは,従来どおりセッション開始時の HEAD
- `committed_paths`,ADR の選択(`ReviewedSpan`),`Review` の `--base` が同じ base
を使う(`review_base` を `model_rules_files.py` に追加)

#237 の reflog 解析は重すぎるため使っていない.

- receipt の fingerprint(`_inputs`)に解決後の base を含める(review の指摘 P1/P2 への対応)

## テスト

- default branch に入った commit は判定せず,その後の自分の commit だけ判定する
- default branch が開始時の commit につながらないときは,開始時の HEAD を base にする
- default branch が Stop の間に進んだら,古い receipt を再利用せず判定し直す
- 既存テストのうち `_Changes` を直接組み立てる 2 件に base を渡すよう更新

## 範囲外(Issue #234 のコメントと brief による)

自分の commit を隠す迂回(fast-forward,default branch への rebase,reflog 編集),merge
commit の conflict 解決,default branch を持たない repository,#245.

## レビュー指摘の扱い

- P1/P2(fingerprint に base が無い): 修正済み
- MEDIUM(agent が書ける ref から base を決める,security review): 範囲外.agent が自分の
commit を隠す迂回(default branch への rebase,ref の書き換え)に当たり,rules は advisory
で,漏れても 1 件を見逃すだけ(brief の threat model)
- P2(Stop 中の背景 `git fetch` が fingerprint と review の 2 回の `review_base`
の間に ref を動かす競合): 範囲外.rules は advisory で,漏れても次の Stop までの 1 件を見逃すだけ(brief
の threat model)

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

---------

Co-authored-by: furedea <132188853+furedea@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.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.

fix(hooks): judge only the session's own changes in Stop model rules

1 participant