Skip to content

fix(cmd462): HF3 contextual retry — fence count diff フィードバック (Q2=A)#215

Merged
halsk merged 2 commits into
mainfrom
feat/cmd462-hf3-contextual-retry
May 11, 2026
Merged

fix(cmd462): HF3 contextual retry — fence count diff フィードバック (Q2=A)#215
halsk merged 2 commits into
mainfrom
feat/cmd462-hf3-contextual-retry

Conversation

@halsk

@halsk halsk commented May 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • translate-protected.ts の HF3 retry を単純 retry から contextual retry に強化(Q2=A)
  • fence count mismatch 検出時に、原文・翻訳のフェンス数差分を --system-prompt-suffix として yuuhitsu translate に渡す
  • LLM が前回エラーの差分情報から修正を学習できるようになる

Context

  • cmd_459 sync で reactivcore-rules.md fence 190→195 で失敗
  • 同一 prompt での単純 retry では同 error が再発するため、diff feedback が必要(軍師分析)
  • 殿確定 Q2=A: HF3 contextual retry を採用

Changes

  • runYuuhitsu()extraArgs: string[] = [] パラメータ追加
  • HF3 mismatch 時に hf3RetryHint を設定し、次の attempt で --system-prompt-suffix として渡す
  • retry メッセージ: "FENCE COUNT CORRECTION: The previous translation had X code fences, but the original has Y. You MUST preserve exactly Y code fences."

⚠️ 依存注意

このPRは yuuhitsu 0.3.1 (PR#91) の --system-prompt-suffix オプションが必要です。
マージ順序:

  1. yuuhitsu 0.3.1 PR#91 merge → 殿が npm publish
  2. geonicdb-docs の yuuhitsu version を ^0.3.1 に bump
  3. 本PRをマージ

Test plan

  • pnpm run docs:build PASS
  • /code-review-expert --auto P0: 0 / P1: 0 確認
  • CI PASS
  • CodeRabbit reviewThreads=0

Summary by CodeRabbit

リリースノート

  • 改善点

    • 翻訳検証の再試行を強化し、コードフェンス(```)の不一致検出時に元のフェンス数を解析して文脈的なヒントを付与することで、再試行の精度と成功率を向上しました。
    • 実行時引数の伝搬を改善し、再試行時に追加の指示を確実に反映できるようにしました。
  • その他

    • 内部マーカーの更新など軽微なメンテナンスを行いました。

Review Change Stack

…Q2=A)

translate-protected.ts の HF3 retry を単純 retry から contextual retry に強化。
fence count mismatch 検出時に原文・翻訳のフェンス数差分を system prompt suffix として
yuuhitsu translate --system-prompt-suffix に渡し、LLM が前回エラーから学習して修正できるようにする。

runYuuhitsu に extraArgs: string[] = [] パラメータを追加。
HF3 mismatch 時: hf3RetryHint に "FENCE COUNT CORRECTION: previous had X fences, original has Y..." を設定し、
次の attempt で --system-prompt-suffix として渡す。

NOTE: yuuhitsu 0.3.1 (PR#91) の --system-prompt-suffix オプションが必要。
      yuuhitsu 0.3.1 publish 後 + geonicdb-docs version bump (^0.3.1) 後に merge すること。
@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2e4c3843-7f36-47b6-9bc7-20eacec77fa6

📥 Commits

Reviewing files that changed from the base of the PR and between 34f2e1f and c23d29b.

📒 Files selected for processing (1)
  • scripts/translate-protected.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/translate-protected.ts

📝 Walkthrough

ウォークスルー

翻訳スクリプトに HF3 コードフェンス不一致への文脈的リトライ機能を追加。ヘルパー関数が CLI 引数をサポートし、バリデーション失敗時にフェンス数を抽出・解析して次の試行に指示を渡す。加えて .code-review-done のコミットハッシュを更新。

変更内容

HF3 リトライ最適化

レイヤー / ファイル 説明
ヘルパー関数シグネチャ拡張
scripts/translate-protected.ts
runYuuhitsu 関数に extraArgs: string[] = [] パラメータを追加。
CLI 呼び出しの更新
scripts/translate-protected.ts
npx フォールバックでコマンド引数に ...extraArgs を追加。
リトライループの文脈管理
scripts/translate-protected.ts
リトライループで hf3RetryHint を追跡し、試行前に --system-prompt-suffix として runYuuhitsu に渡す extraArgs を構築。
バリデーション失敗時のヒント抽出
scripts/translate-protected.ts
validateCodeBlocksreason から original=(\d+), translated=(\d+) を抽出して、元のフェンス数を保持するよう指示する hf3RetryHint を生成。抽出に失敗した場合は汎用ヒントを生成。
レビュー完了マーカー更新
.code-review-done
ファイル内のコミットハッシュを新しい HEAD に更新。

Sequence Diagram(s)

sequenceDiagram
  participant TranslateScript as translate-protected.ts
  participant Runner as runYuuhitsu
  participant Validator as validateCodeBlocks
  TranslateScript->>Runner: invoke with args + extraArgs ( --system-prompt-suffix )
  Runner->>Validator: return translated output for validation
  Validator-->>TranslateScript: code block check result (reason)
  TranslateScript->>TranslateScript: parse reason -> hf3RetryHint
  TranslateScript->>Runner: retry with hf3RetryHint in extraArgs
Loading

推定レビュー工数

🎯 2 (Simple) | ⏱️ ~12 分

フェンスの数を えいっと数えて
翻訳モデルに そっと囁く
不一致はヒントへと変わり
次の試行で ぴたり合わせる ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed タイトルは HF3 コンテキスト依存リトライの実装というプルリクエストの主要な変更内容を明確に示しており、changeset と完全に関連している。
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.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/cmd462-hf3-contextual-retry

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 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 `@scripts/translate-protected.ts`:
- Around line 395-399: The current logic builds hf3RetryHint using
originalFences/translatedFences even when fenceMatch is null, producing "exactly
?" which degrades retries; change the branch so that if fenceMatch is truthy you
set originalFences/translatedFences and the strict hf3RetryHint, but if
fenceMatch is falsy do NOT build an "exactly ?" hint—instead set hf3RetryHint to
a fallback instruction derived from codeBlockCheck.reason (a general "preserve
code fences as in the original" guidance) and keep the console.warn with
codeBlockCheck.reason and attempt; update handling around fenceMatch,
originalFences, translatedFences, hf3RetryHint, and codeBlockCheck.reason
accordingly.
- Around line 301-302: The script unconditionally pushes
'--system-prompt-suffix' into extraArgs (see extraArgs and hf3RetryHint in
translate-protected.ts) but `@geolonia/yuuhitsu` pinned at 0.2.4 may not support
that option; either update package.json to a version that supports the flag
(e.g., bump `@geolonia/yuuhitsu` to ^0.3.1 and lock) or add a runtime guard that
checks the installed yuuhitsu version before pushing the flag (query
package.json or run `yuuhitsu --version` at startup, parse and compare to the
minimum supported version, and only push '--system-prompt-suffix' when the
version meets the requirement) so the retry logic won’t fail with an
unknown-option error.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1a25e409-82f3-4b3f-bf6f-dabc09a409f3

📥 Commits

Reviewing files that changed from the base of the PR and between b2a10f3 and 34f2e1f.

📒 Files selected for processing (2)
  • .code-review-done
  • scripts/translate-protected.ts

Comment thread scripts/translate-protected.ts
Comment thread scripts/translate-protected.ts
fenceMatch が null の場合でも '?' の代わりに codeBlockCheck.reason を
そのままフォールバックとして使用するよう修正。
@halsk
halsk merged commit 2d7df78 into main May 11, 2026
4 checks passed
@halsk
halsk deleted the feat/cmd462-hf3-contextual-retry branch May 11, 2026 05:29
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