Repository navigation
fix(session): 同じツール呼び出しの巡回ループを確認画面なしで止め、巨大PDFの添付を断る - #52
Merged
Merged
Conversation
…efuse oversized PDFs A general subagent read the same six PDFs in a cycle ~150 times each in one turn (943 tool calls), storing a ~28 MB base64 copy of each PDF per call and growing the local DB to 25 GB. The doom_loop guard only looked at the last 3 calls being identical, so a cycle (A,B,...,A,B) never triggered it. - processor: repeat guard per turn (in memory). From the 3rd call whose input and result are both unchanged, the model gets a tool error instead of the result (attachments not stored); the 6th ends the turn. No dialog. doom_loop "allow" disables it; "deny" keeps the consecutive-3 stop. The default "ask" no longer opens a dialog (and skips the history scan). - read: refuse PDFs over 10 MB and media the current model cannot accept, with a hint to extract text (pdftotext). - tests reproduce the cycle (fails on the old code: 20 steps, no stop). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
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.
症状
2026-10-28、セッション
ses_e8d630282ffeKs3LbtbHKskTTh(generalサブエージェント、moonshotai/kimi-k3、対話画面から起動)が1回の応答(全アシスタントメッセージが同じ parentID)の中でreadを943回実行しました。PDF を読むたびに base64 の data: URL(1件あたり最大約28.6MB)がpart.data.state.attachmentsとeventテーブル(message.part.updated)に保存され、ローカルDBが25GB(うち約17.5GB)まで膨らみ、TUIの起動が止まりました。原因(DBの実データで確認)
processor.tsDOOM_LOOP_THRESHOLD=3)は「直近3件のツール呼び出しがすべて同一」のときだけ発火するため、巡回には反応しませんでした。設定や承認で許可されていたわけではありません(permissionテーブルは空、doom_loop の allow 設定もなし)。修正
session/processor.ts、確認画面なし): 同じ応答の中で、入力も結果も前回と同じ呼び出しを数えます。3回目からはモデルに結果の代わりにツールエラー(「結果は変わらないので再実行しない」)を返して添付も保存せず、6回目で応答を止めます。巡回(A,B,A,B…)も対象です。結果が変わる呼び出し(ポーリング)は数えません。カウントはメモリ上だけで持ち、応答単位で最大64件までです。"ask"では確認画面を出さなくなりました(上のガードが代わりに止めます)。"deny"は従来どおり3回連続で停止し、"allow"はガードごと無効にします。ask/allow のときはツール呼び出しごとの履歴スキャン(巨大な部分を含むメッセージを読み込む処理)も省きます。tool/read.ts: 10MB(MAX_PDF_BYTES)を超えるPDFと、現在のモデルが受け付けない画像・PDFは添付せず、テキストの抜き出し方(pdftotext)を示すエラーを返します。画像は従来どおり保存前に縮小されるため、サイズ上限は設けていません。ツール説明とドキュメント(permissions.mdx の英語版・日本語版)も更新しました。検証
bun typecheck(packages/sente): 成功bun test test/session/processor-effect.test.ts test/tool/read.test.ts test/agent/agent.test.ts test/permission: 297件成功・失敗0test/session test/tool test/agent test/permission test/cli/runの全体: 1345件成功・13件失敗。13件(prompt.test / security-boundary-audit / run-process)は変更前のコードでも同じ13件が失敗しており、今回の変更とは関係ありません。戻し方
このPRのマージコミットを revert します。設定だけで戻す場合は、
permission: { "doom_loop": "allow" }でガードを無効にできます(PDFの上限は設定では戻せないため、revert が必要です)。🤖 Generated with Claude Code