Skip to content

refactor: unwrap cleanup + 5-layer supply chain security#208

Merged
send merged 9 commits intomainfrom
refactor/unwrap-cleanup
Apr 3, 2026
Merged

refactor: unwrap cleanup + 5-layer supply chain security#208
send merged 9 commits intomainfrom
refactor/unwrap-cleanup

Conversation

@send
Copy link
Copy Markdown
Owner

@send send commented Apr 2, 2026

Summary

コード品質

  • 本番コードの .unwrap() を全て .expect() に置き換え(パニック時のデバッグ情報改善)
  • trie_dict_io.rsas u32try_into() に修正(隣接コードとの一貫性)

サプライチェーン防御(5層)

  1. cargo-deny — 脆弱性・ライセンス・ソース制限・重複チェック
  2. cargo-vet — 監査追跡(Google/Mozilla/ISRG/zcash の共有監査で73件カバー、199件は exemption)
  3. Quarantine(7日) — Cargo.lock の新バージョンが公開7日未満なら CI で拒否(allowlist で override 可)
  4. build.rs 監視 — 依存ツリーに新たな build.rs クレートが追加されたら CI で検出
  5. Cargo.lock 同期cargo check --locked で意図しない変更を検出

依存更新

  • candle-core/candle-nn 0.9 → 0.10(yanked zip 7.4.0 → 7.2.0 修正)

Test plan

  • cargo fmt/clippy/test 全 pass
  • cargo deny check — advisories ok, bans ok, licenses ok, sources ok
  • cargo vet check — 73 fully audited, 199 exempted
  • scripts/check-quarantine.sh — all deps pass 7-day policy
  • scripts/check-build-scripts.sh — baseline matches (34 crates)
  • CI pass

🤖 Generated with Claude Code

send and others added 2 commits April 3, 2026 02:10
Replace all .unwrap() calls in production code (non-test) with
descriptive .expect() messages for better panic diagnostics:

- user_dict: RwLock read/write (7 sites) → "user_dict lock poisoned"
- reranker: .min().unwrap() → "paths guaranteed non-empty"
- resegment/predictive/scoring: .last().unwrap() → invariant docs
- wal: try_into/file unwraps → context messages
- snippets/variables: chars.next().unwrap() → match invariant

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The surrounding trie_len/pool_len/entries_len already use try_into()
with proper error handling, but reading_count used bare `as u32` which
silently truncates on overflow. Align to the same pattern.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 2, 2026 17:13
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

本番コード内のパニック要因になり得る .unwrap().expect() に置き換えて、パニック時の診断情報を改善しつつ、trie_dict_io.rs の数値キャストを安全な変換に揃えるリファクタです。

Changes:

  • WAL / ユーザー辞書 / 変換・スコアリング周辺で .unwrap().expect() に置換し、不変条件をメッセージで明示
  • snippets/variables の日付フォーマット処理で .expect() に置換
  • trie_dict_io.rsas u32try_into() に変更して範囲外をエラー化

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
engine/crates/lex-core/src/user_history/wal.rs WAL フレーム解析・ファイルハンドル取得の unwrap を expect に置換
engine/crates/lex-core/src/user_dict/mod.rs RwLock read/write の unwrap を expect に置換(poison 時の診断改善)
engine/crates/lex-core/src/snippets/variables.rs 日付フォーマットの未知指定子処理で unwrap を expect に置換
engine/crates/lex-core/src/neural/scoring.rs セグメント境界計算の unwrap を expect に置換
engine/crates/lex-core/src/dict/trie_dict_io.rs reading_countas u32try_into() + エラーに変更
engine/crates/lex-core/src/converter/resegment.rs EOS 遷移計算で segments.last() の unwrap を expect に置換
engine/crates/lex-core/src/converter/reranker.rs min() 結果の unwrap を expect に置換(不変条件を明示)
engine/crates/lex-core/src/candidates/predictive.rs path.last() の unwrap を expect に置換(空チェック後の不変条件)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread engine/crates/lex-core/src/dict/trie_dict_io.rs
Comment thread engine/crates/lex-core/src/user_history/wal.rs Outdated
send and others added 4 commits April 3, 2026 02:20
…t messages

- trie_dict_io: 8 header field try_into().unwrap() → expect("4-byte header field")
- wal: distinguish "4-byte length field" from "4-byte CRC field" in expect messages

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update candle-core and candle-nn to 0.10 and downgrade zip from yanked
7.4.0 to 7.2.0 to fix cargo-audit failure in CI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Layer 1 - cargo-deny: advisories, licenses, sources, bans
Layer 3 - Quarantine: reject deps published <7 days ago (crates.io API)
Layer 4 - build.rs monitoring: detect new crates with build scripts
Layer 5 - Cargo.lock sync: cargo check --locked in CI

cargo-vet (Layer 2) will be added separately.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ports

Set up cargo-vet with shared audit imports covering 73 crates.
Remaining 199 crates are exempted and will be audited incrementally.

Also adds cargo-vet to CI and mise audit task.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@send send changed the title refactor: replace production unwrap() with expect() and fix unsafe cast refactor: unwrap cleanup + 5-layer supply chain security Apr 2, 2026
@send send requested a review from Copilot April 2, 2026 18:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 20 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/check-quarantine.sh
Comment thread scripts/check-quarantine.sh Outdated
Comment thread scripts/check-build-scripts.sh Outdated
Comment thread mise.toml
- quarantine: fail-closed on API/parse errors instead of skipping
- quarantine: use explicit registry+ pattern for Cargo.lock source match
- check-build-scripts: remove stderr suppression on cargo metadata
- mise.toml: include cargo-vet in audit task description

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 20 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/check-quarantine.sh Outdated
Comment thread scripts/check-quarantine.sh
Comment thread scripts/check-quarantine.sh
Comment thread scripts/check-build-scripts.sh Outdated
- Use printf '%s\n' instead of echo for comm input (shell portability)
- Validate QUARANTINE_DAYS is a positive integer before arithmetic
- Add curl timeouts and retry for crates.io API resilience
- Apply same printf fix to check-build-scripts.sh

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 20 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/check-quarantine.sh
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@send send merged commit 1b0bcde into main Apr 3, 2026
10 checks passed
@send send deleted the refactor/unwrap-cleanup branch April 3, 2026 08:40
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.

2 participants