Skip to content

feat(lib-ollama-client): DEFAULT_NUM_CTX → 32768 (Phase C / 順位 98 root cause fix)#143

Merged
aloekun merged 3 commits into
masterfrom
feature/phase-c-num-ctx-32768
May 11, 2026
Merged

feat(lib-ollama-client): DEFAULT_NUM_CTX → 32768 (Phase C / 順位 98 root cause fix)#143
aloekun merged 3 commits into
masterfrom
feature/phase-c-num-ctx-32768

Conversation

@aloekun
Copy link
Copy Markdown
Owner

@aloekun aloekun commented May 11, 2026

Summary

Phase d retirement への critical path Phase C (DEFAULT_NUM_CTX 増加) を land。Phase B で確定した「mistral:7b の context overflow が真因」を decisive に解消し、Phase D criteria (fallback rate < 50%) を classifier preview で達成

変更内容

Commit 1: docs only (前 turn carry-over)

順位 109-113 (PR #142 post-merge-feedback 採用分) を docs/todo6.md + docs/todo-summary.md に登録。

Commit 2: Phase C 実装

src/lib-ollama-client/src/lib.rs

-pub const DEFAULT_NUM_CTX: u32 = 8192;
+pub const DEFAULT_NUM_CTX: u32 = 32768;

doc comment を dogfood の進化記録 (2048 → 4096 → 8192 → 16384 → 32768) を含めて更新。Phase B 真因仮説 (overflow 時に Ollama は prompt_eval_count を num_ctx に clamp 報告) を inline で説明。

test 1 件 (num_ctx_is_serialized_into_request_body) を num_ctx:32768 期待値に更新。lib-ollama-client 17/17 pass + cli-finding-classifier evals 20/20 pass。

push-runner-config.toml

-step_timeout = 180
+step_timeout = 600

cargo test -- --ignored (12 件 mistral invoke) が num_ctx 32768 で local 269s 観測 → 180s 超過。600s への拡大で安全マージン込み。

docs/local-llm-offload-analysis.md

Phase C row を ✅ 完了化 + Phase C smoke dogfood table を追加 (3 PRs replay 結果)。Phase D criteria (<50%) を classifier preview で 達成 表示。

Phase C smoke dogfood signal (32768 で 3 PRs replay、本 PR commit 2 後に取得)

PR Diff lines Latency Old (8192) New (32768)
P-1 (#139) 414 48s fallback (truncation) auto_fix (real classification, finding detected)
P-2 (#140) 275 50s fallback (truncation) ⚠️ fallback (invalid severity: error = contract violation、num_ctx 起因ではない)
P-3 (#141) 487 55s fallback (truncation) auto_fix (real classification, finding detected)

結果集計:

  • num_ctx truncation 起因 fallback: 3/3 → 0/3 (100% 解消) — Phase C 主目的を達成
  • 総合 fallback rate: 3/3 (100%) → 1/3 (33%) — Phase D 基準 (<50%) を達成
  • 残り 1/3 は contract violation (severity: "error" を返した = invalid)。Phase b' agreement 75% で説明可能な mistral semantic 精度の別問題、Phase C scope 外

Critical path 進捗 (analysis.md 削除へ)

Phase 状態
Phase A (順位 98 diagnostic) ✅ PR #142 で完了
Phase B (真因確定 = num_ctx) ✅ Phase A 即時 dogfood で確定
Phase C (num_ctx 増加) 本 PR で完了、Phase D 基準達成
Phase D (clean dogfood validation) 🔄 classifier preview 基準達成、real pipeline 経由は順位 109 land 後
Phase E (採否判定 + retirement) ⏭️ 次の next action 候補

Test plan

  • cargo test -p lib-ollama-client 17/17 pass
  • cargo test -p cli-finding-classifier --test lint_screen_evals 20/20 pass (1 ignored = Ollama integration、別途 ignored test で確認)
  • cargo test -- --ignored --test-threads=1 全 pass (local 269s、step_timeout=600s で push pipeline pass)
  • takt pre-push-review 完了 (573s = 9m 33s)
  • markdownlint clean
  • P-1/P-2/P-3 replay で num_ctx overflow 起因 fallback が 0/3 に減少を実機確認
  • deployed .claude/cli-finding-classifier.exe で stderr に warn log emit されなくなったことを確認 (overflow 解消の subset 検証)

Phase D 基準と残課題

Phase D criteria 達成判定の caveat:

残課題 (Phase E までに対応 / out-of-scope):

  • 順位 109 (push-runner stderr 取込) — Phase D 完全達成の前提
  • mistral contract violation (P-2 で観測の invalid severity: error) は semantic 精度問題、Phase b' agreement 75% で説明可能、Phase C scope 外
  • VRAM 消費評価: num_ctx 32768 で mistral:7b の KV cache が増大、RTX 3070 (8GB VRAM) で実 RAM 使用量が swap を引き起こさないかは長期 dogfood で観察

Out of scope

  • 順位 109 実装 (push-runner stderr 取込): 既に todo 登録済、本 PR 後に別 PR で
  • contract violation 対策 (P-2 の invalid severity: error): mistral 出力崩壊系、prompt v4 検討 or model swap 別 phase
  • 派生プロジェクト deploy: lib-ollama-client は本リポ専用、共有 crate 化は未計画

Summary by CodeRabbit

  • バグ修正

    • ローカルLLMの文脈ウィンドウを拡大し、トランケーションによるフォールバックを解消(再テストで改善を確認)
    • 品質ゲート処理のタイムアウトを延長し、処理完了を確保
  • ドキュメント

    • LLMオフロード分析に検証手順と再現結果(フォールバック率・遅延等)を追加
    • TODO/ガバナンス文書に実行順序・テスト計画・判断基準のタスクを追記

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7336cb5a-785e-4ab8-bad1-b1980ef21488

📥 Commits

Reviewing files that changed from the base of the PR and between 2e5816f and 0ca3328.

📒 Files selected for processing (1)
  • docs/todo-summary.md
✅ Files skipped from review due to trivial changes (1)
  • docs/todo-summary.md

📝 Walkthrough

Walkthrough

Ollama クライアントのコンテキストサイズを DEFAULT_NUM_CTX=8192 から 32768 に上げ、関連テストとドキュメントを更新し、push-runner の quality gate タイムアウトを 180→600 秒に延長、Phase C の検証結果と次フェーズ用 TODO を追記しました。

変更内容

DEFAULT_NUM_CTX 段階的増加と Phase C 完了

Layer / File(s) Summary
コア定数とテスト
src/lib-ollama-client/src/lib.rs
DEFAULT_NUM_CTX を 8192 から 32768 に変更。ドキュメントコメントとシリアライズ要求のテストアサーションを新値に合わせて更新。
設定タイムアウト延長
push-runner-config.toml
[quality_gate]step_timeout を 180 秒から 600 秒に延長し、変更理由コメントを追加。
Phase C 完了分析
docs/local-llm-offload-analysis.md
DEFAULT_NUM_CTX の段階的エスカレーション(8192→16384→32768)を記録し、smoke dogfood の PR別再現結果、フォールバック率の更新(トランケーション関連 3/3→0/3、総合 3/3→1/3)および残存フォールバック原因(契約/セマンティック問題)を追記。
推奨実行順序と次フェーズ計画
docs/todo-summary.md, docs/todo6.md
推奨実行順序サマリーに優先度 109–113 のタスク行を追加。push-runner 経由の lint-screen 取込 smoke test、pure function テストテンプレ、docs-governance の routing 規則、ADR-038/ADR-027 の追記タスクを記録。

🎯 3 (中程度) | ⏱️ ~20 分

関連する可能性のあるプルリクエスト

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトルは、メインの変更(DEFAULT_NUM_CTXを8192から32768に増加)を明確に説明しており、Phase CおよびPR番号による文脈も含まれています。簡潔で具体的です。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/lib-ollama-client/src/lib.rs (1)

128-139: 💤 Low value

詳細な進化履歴の配置を検討してください。

DEFAULT_NUM_CTX の doc comment に 12 行の詳細な進化履歴が記録されていますが、このレベルの詳細情報はコード内コメントより ADR-038 や docs/local-llm-offload-history.md に配置する方が適切かもしれません。

推奨: コード内には以下の essential 情報のみを残し、詳細な dogfood 経緯は ADR に委譲する構成:

/// Ollama 既定の `num_ctx` (2048) は本リポジトリの lint-screen prompt に対して不足。
/// mistral:7b の theoretical max である 32768 を default とする。
/// 進化履歴の詳細は ADR-038 参照。
pub const DEFAULT_NUM_CTX: u32 = 32768;

ただし、現状の詳細コメントも「コード近傍で判断根拠を即座に確認できる」利点があるため、プロジェクトの方針次第です。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib-ollama-client/src/lib.rs` around lines 128 - 139, The doc comment for
DEFAULT_NUM_CTX in lib.rs contains an overly long evolution history; trim it to
the essential rationale (that Ollama's default 2048 is insufficient for our
lint-screen prompts and we choose mistral:7b's theoretical max 32768 as the
default) and replace the long timeline with a brief pointer to ADR-038 or
docs/local-llm-offload-history.md for full details; locate the constant named
DEFAULT_NUM_CTX in src/lib-ollama-client/src/lib.rs, remove the 12-line history
block, leave a 2–3 line explanatory comment and add a single-line reference to
the ADR/doc file.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/todo-summary.md`:
- Line 78: The rank-109 mismatch: update the todo item so both sources agree on
Tier; locate the entry for rank 109 (the summary line showing "🚀 Tier 1") and
the detailed todo entry that currently labels "PR `#142` post-merge-feedback
T2-#1" and make them consistent—preferably change the detailed todo label
"T2-#1" to "T1-#1" (or alternatively change the summary Tier to Tier 2) and
ensure the text mentions "Tier 1" where Severity High/Phase C/D dogfood
precondition is asserted so both the summary and detailed todo reflect the same
Tier and label.

---

Nitpick comments:
In `@src/lib-ollama-client/src/lib.rs`:
- Around line 128-139: The doc comment for DEFAULT_NUM_CTX in lib.rs contains an
overly long evolution history; trim it to the essential rationale (that Ollama's
default 2048 is insufficient for our lint-screen prompts and we choose
mistral:7b's theoretical max 32768 as the default) and replace the long timeline
with a brief pointer to ADR-038 or docs/local-llm-offload-history.md for full
details; locate the constant named DEFAULT_NUM_CTX in
src/lib-ollama-client/src/lib.rs, remove the 12-line history block, leave a 2–3
line explanatory comment and add a single-line reference to the ADR/doc file.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 212f08bf-ad7a-46d7-ae47-9817aebf9808

📥 Commits

Reviewing files that changed from the base of the PR and between 7b9e64d and 2e5816f.

📒 Files selected for processing (5)
  • docs/local-llm-offload-analysis.md
  • docs/todo-summary.md
  • docs/todo6.md
  • push-runner-config.toml
  • src/lib-ollama-client/src/lib.rs

Comment thread docs/todo-summary.md Outdated
@aloekun
Copy link
Copy Markdown
Owner Author

aloekun commented May 11, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@aloekun aloekun merged commit 3f2274c into master May 11, 2026
1 check passed
@aloekun aloekun deleted the feature/phase-c-num-ctx-32768 branch May 11, 2026 12:26
aloekun added a commit that referenced this pull request May 11, 2026
…位 109) (#144)

* docs(todo): 順位 114 (PR #143 T3-#1 採用) — docs/todo8.md 新設 + Local LLM context size ADR を登録

* feat(cli-push-runner): lint_screen stage で graceful fallback 時も stderr を report に取込 (順位 109 / Phase D 前提整備)
aloekun added a commit that referenced this pull request May 11, 2026
…4) + workflow gap 反映

Phase D dogfood の 1 本目 (D-1)。3 件 ADR 採用 + Phase D 計画 land + workflow gap 反映を bundled。

順位 112 (PR #142 T3-#3): ADR-038 に 2 section 追記
  - Diagnostic logging scope: eprintln (CLI 前提) と structured logging 移行条件
  - 90% 閾値 rationale: 保守採用根拠 + Phase D 完了時の precision/recall 評価方針

順位 113 (PR #142 T3-#4): ADR-027 に metrics override 判断基準追記
  - Incidental change vs Responsibility change の線引き
  - Override 記述様式 (Override / Reason / Rationale の 3 項目)

順位 114 (PR #143 T3-#1): ADR-040 新規作成
  - mistral:7b context size 実測値 (8K 512MB 5-20s ↔ 32K 2GB 30-90s)
  - step_timeout 3.33x 比例係数の根拠
  - num_ctx 選定 flow chart
  - CLAUDE.md ADR index 追加
  - lib-ollama-client/src/lib.rs L128-139 dogfood evolution コメントを 4 行参照に短縮

Phase D 計画 land + workflow gap (新規):
  - analysis.md に D-1/D-2/D-3 PR 構成 + 計測手順 + 想定リスクを追加
  - D-1 着手時に判明した workflow gap (jj auto-snapshot vs session-only opt-in) を計測手順に反映
  - env var override (LINT_SCREEN_ENABLED) を todo8.md / todo-summary.md (順位 115) に backlog 登録
  - D-1 自身は dogfood skip、env var override land 後に D-2 / D-3 で実 dogfood 実施

D-1 lint_screen 状態: skipped。Phase D guide §1 session-only opt-in workflow が jj auto-snapshot と
本質的に衝突するため、配列 env var override の cli-push-runner 実装 (順位 115) を D-2 前に land 必須。
aloekun added a commit that referenced this pull request May 12, 2026
…4) + workflow gap 反映 (#145)

Phase D dogfood の 1 本目 (D-1)。3 件 ADR 採用 + Phase D 計画 land + workflow gap 反映を bundled。

順位 112 (PR #142 T3-#3): ADR-038 に 2 section 追記
  - Diagnostic logging scope: eprintln (CLI 前提) と structured logging 移行条件
  - 90% 閾値 rationale: 保守採用根拠 + Phase D 完了時の precision/recall 評価方針

順位 113 (PR #142 T3-#4): ADR-027 に metrics override 判断基準追記
  - Incidental change vs Responsibility change の線引き
  - Override 記述様式 (Override / Reason / Rationale の 3 項目)

順位 114 (PR #143 T3-#1): ADR-040 新規作成
  - mistral:7b context size 実測値 (8K 512MB 5-20s ↔ 32K 2GB 30-90s)
  - step_timeout 3.33x 比例係数の根拠
  - num_ctx 選定 flow chart
  - CLAUDE.md ADR index 追加
  - lib-ollama-client/src/lib.rs L128-139 dogfood evolution コメントを 4 行参照に短縮

Phase D 計画 land + workflow gap (新規):
  - analysis.md に D-1/D-2/D-3 PR 構成 + 計測手順 + 想定リスクを追加
  - D-1 着手時に判明した workflow gap (jj auto-snapshot vs session-only opt-in) を計測手順に反映
  - env var override (LINT_SCREEN_ENABLED) を todo8.md / todo-summary.md (順位 115) に backlog 登録
  - D-1 自身は dogfood skip、env var override land 後に D-2 / D-3 で実 dogfood 実施

D-1 lint_screen 状態: skipped。Phase D guide §1 session-only opt-in workflow が jj auto-snapshot と
本質的に衝突するため、配列 env var override の cli-push-runner 実装 (順位 115) を D-2 前に land 必須。
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