Repository navigation
fix(can-hat): PR#15 レビューの低(L-3/L-4/L-5)の追補 - #19
Merged
Merged
Conversation
Follow-up to the PR#15/#17/#14 reviews' remaining low-severity items: - can_diag.sh: when the original restart-ms for an interface could not be read back from `ip -d link show`, stop defaulting to a hardcoded 100 and fall back to the lib's CAN_RESTART_MS (reflects conf via can_read_conf) instead, logging that the fallback happened. The decision is extracted into _diag_resolve_restart_ms(), defined outside the execution guard so it is directly unit-testable (L-3). - can_diag.sh: if the post-lock pause re-assert (M2) itself fails, abort with no changes made instead of silently continuing unpaused, aligning with M1's existing fail-fast behavior; log one line when the pause is successfully re-asserted (L-4). - can_watchdog.sh: a can_setup_iface failure during startup reconciliation now marks the interface degraded with reason=setup_failed_at_startup, instead of dropping the result on the floor (L-4). - can_watchdog.sh: _wd_snapshot's busoff= is the storm-window (~60s) count, not a lifetime total, because it shares its backing file with storm detection's own pruning. Added a separate, never-pruned busoff_total= cumulative counter so a CRIT/NOTICE snapshot carries both (L-5). - can_watchdog.sh: wrapped every bare `can_unlock` call and the startup can_setup_iface call in if/|| per the lib's own calling convention (only can_read_conf/can_unpause/can_log/can_now may be called bare); no behavior change today (set -e is not used here) but future-proofs against it (L-5). Added/extended tests in tests/test_diag_classify_units.sh, tests/test_diag_restore.sh, tests/test_watchdog_degraded.sh and tests/test_watchdog_busoff.sh for each of the above; reverting any one fix makes its corresponding test fail. Refs #9 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
RyodoTanaka
commented
Oct 15, 2026
RyodoTanaka
left a comment
Member
Author
There was a problem hiding this comment.
レビュー(Opus、読み取りと試しのみ、52f7983)
判定: マージ可。 クリティカル・高・中はありません。
確かめたこと
-
試験と CI:
bash tests/run.shは 17/17 PASSED、shellcheck -S warning(repo 直下の*.sh/*.bashとtests/)は空、CI は green、mergeStateStatus は CLEAN です。 -
毎周回の処理(hot loop)は変わっていません。 差分はすべて、まれにしか通らない経路にあります。
-
setup_failed_at_startupが誤って出ることはありません。 この判定に届くのは、PR #15 の M1 の条件をすべて通ったうえで、watchdog 自身が bind し、netdev が現れ、名前の固定(pin)にも成功した後だけです。M1 の条件は、spidev のディレクトリがあること、driverのリンクが無いこと、pause 中でないこと、劣化運転中でないこと、ロックが取れたことです。- 試し A: spidev が無く、偽の can1 も無い(setup を実行すれば失敗する状態)。
iface_missingの WARNING だけが出て、劣化運転にはならず、bind もしません。 - 試し B: spidev があり driver も付いているが、netdev はまだ無い(列挙が遅れている状態)。bind せず、劣化運転にもなりません。
- bind 直後の setup 失敗を劣化運転にするのは、rebind 経路の
setup_failedと同じ扱いで、§1d の「bind / pin / setup の失敗」どおりです。
- 試し A: spidev が無く、偽の can1 も無い(setup を実行すれば失敗する状態)。
-
PR #15 の受け入れの再実行も退行なしです。
- e1: 短絡の嵐で rebind しない。
- e7: 再起動後の setup は
restart-ms 0 berr-reporting off fd offとtxqueuelen 10。
-
can_diag の確認:
- restart-ms を読めなかったときの代わりの値は、lib の
CAN_RESTART_MS(conf を反映した値)になりました。その旨が diag のログにも残ります。 - pause をもう一度張るのに失敗したときは、iface に触る前の時点で
exit 1になります。cleanup では_berr_ifacesが空なので復元は走らず、ロックだけを解放します。pause も、自分が書いた値のときだけ戻します(M2 の規則)。「何も変えずに終了」になっています。
- restart-ms を読めなかったときの代わりの値は、lib の
-
busoff_totalの確認: 刈り取られない累計で、busoff=(ストームの窓の件数)とは別に持ちます。バックオフで後回しにした bus-off は数えないことも、試験で断定しています。
低(任意)
- L-1
can_diag.shの cleanup の復元側(395 行目)は、${CAN_RESTART_MS:-100}のままです。can_read_confの後なので:-100に落ちることはありませんが、表記を:-0にするか既定値なしに揃えると読み手に親切です。 - L-2
setup_failed_at_startupの否定側の試験(spidev が無い/driver が付いている場合は劣化運転にならない)は、M1 の既存の試験で間接的に担保されています。上の試し A・B を、この PR の試験に 1 件ずつ足しておくとより確実です。 - L-3
busoff_total_<if>は/var/lib(SD カード)に bus-off 1 回ごとに 1 回書きます。busoff_timesと同じ頻度なので新たな負荷ではありませんが、嵐の間(10-14 は 14 s で 17 回)は書き込みが続く点だけ留意してください。
RyodoTanaka
added a commit
that referenced
this pull request
Oct 15, 2026
RyodoTanaka
added a commit
that referenced
this pull request
Oct 15, 2026
- M-n1: remove "safe to edit live" framing; unify to "never edit can_tools.conf while the machine is running" for every key, including CAN_IFACES/CAN_SPI_MAP (not previously covered) and CAN_FLUSH_IFACES/ CAN_DEPENDENT_UNITS/WD_* (previously called "safe"). - M-n2: can_pin_name does not take can_lock (only can_setup_iface does); fixed the manual unbind/bind step 5 to take the lock explicitly and short-circuit on a can_pin_name failure instead of running can_setup_iface unconditionally. - L-n1: pause check now uses can_pause_active, not cat. - L-n2: pause_expired only fires for a numeric deadline; a malformed one logs the lib's own WARNING instead. - L-n3: pause is global, not per-interface. - L-n4: canhat_fd_rename.service's real After=/Before= from the unit file. - L-n5: the bus-off-streak fifo baseline resets at each recovery, not just the first. - L-n6: added setup_failed_at_startup (from PR #19) to the startup reconciliation text, the reason table, and the --clear-degraded-safe list. Also re-pointed the can_watchdog.sh file:line citations shifted by #19's busoff_total=/setup_failed_at_startup changes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
変更点
PR#15 最終レビュー(および PR#17/#14 レビュー残り)の「低」指摘への追補。
100ではなく lib のCAN_RESTART_MS(conf 反映後)にフォールバックするよう変更。フォールバックした場合はその旨を診断ログに記録。判定ロジックは_diag_resolve_restart_ms()として実行ガード外に切り出し、単体試験可能にした(L-3)。can_pause自体が失敗した場合、黙って続行せず M1 と揃えて何も変えずにexit 1。再アサートに成功した場合は 1 行 NOTICE ログを追加(L-4)。can_setup_ifaceが失敗した場合、結果を握りつぶさずreason=setup_failed_at_startupで劣化運転にするよう修正(L-4)。_wd_snapshotのbusoff=はストーム検出と同じファイルを共有しているため直近 ~60s(WD_STORM_WINDOW_S)の件数しか出ない点を明記し、起動以降の累計を表すbusoff_total=(他のカウンタとは独立に増分・非プルーン)を併記するよう追加(L-5)。can_read_conf/can_unpause/can_log/can_nowのみ)に従い、can_unlockの素呼び出し全箇所と起動時のcan_setup_iface呼び出しをif/||で包んだ。現状set -eを使っていないため動作に変化はないが、将来のための予防(L-5)。試験結果
bash tests/run.sh: 17/17 PASSEDshellcheck -S warning can_watchdog.sh can_diag.sh tests/test_watchdog_*.sh tests/test_diag_*.sh: 出力なし(クリーン)can_diag.sh/can_watchdog.sh/tests/test_diag_*.sh/tests/test_watchdog_*.shのみ変更。lib・fakes・README・workflow・conf.example は未変更(別 PR 作業中のため)Refs #9
🤖 Generated with Claude Code