Skip to content

fix(hooks): 会話外の AskUserQuestion を質問として記録せず、送り主の識別子をログに残す - #3459

Merged
Kewton merged 3 commits into
developfrom
feature/3446-hooks-question-record
Oct 8, 2026
Merged

Kewton merged 3 commits into
developfrom
feature/3446-hooks-question-record

Conversation

@Kewton

@Kewton Kewton commented Oct 8, 2026

Copy link
Copy Markdown
Owner

Summary

#3437(PR #3441)の調査で、2026-10-07T23:41Z に Claude から、会話記録に存在しない AskUserQuestion の pre_tool_use が届いたことが分かった。PR #3441 で新しいターンは開かなくなったが、2 つの問題が残っていた(#3446)。

1. 質問の記録(src/lib/hooks/agent-event-intake.ts の recordQuestionIfAsked): 直近のターンがエージェント自身の Stop で閉じたまま、送信なしで届いた pre_tool_use(AskUserQuestion)(送信を報告するソースのみ。#3437 と同じ判定)は、質問のレコードを残さない。代わりに ask-user-question-outside-turn をログに出す。

  • 残さない方を選んだ理由: 記録の意味は「画面のピッカーがこれを尋ねている」なので、読む側(current-output・respond・push)に「無視する条件」を教えるより、書かない方が意味が 1 つのまま保てる。直前の Stop が以前の質問を解放済みなので、待っている質問も残らない
  • 判定は agent-event-turn の isPreToolUseOutsideTurn(endedByOwnStop と同じ材料)に一本化し、fix(session): Stop 直後の送信の無い pre_tool_use で新しいターンが開く #3437 のターンの分岐と同じ事実で決まる

2. 送り主のログ: hookSenderTags が session_id・agent_id・transcript_path・tool_use_id を SHA-256 の先頭 8 桁(shortSessionTag)で返す。付けるのは質問の記録の行と、ターンを開かないと判断した pre_tool_use の行(agent-event-pre-tool-use-outside-turn)だけで、pre_tool_use 全件には付けない。本文・パス・生の ID は書かない。

ターンの中の AskUserQuestion の記録・応答・push は変わらない(#1726 などの既存テストは無変更で通過)。

Refs #3446(develop 向けのため Closes は使わない)

範囲外(この PR では扱わない)

Test plan

  • commandmatedev verify --task: work-evidence / scope / env-clean / lint / typecheck / unit(テスト全体)すべて PASS(exit 0)
  • 新規 tests/unit/hooks/agent-event-intake-question-3446.test.ts。判定を false に変異させると、今回の事象を再現したケースが落ちることを確認(ワーカー)
  • develop 取り込み後に npx tsc --noEmit、hooks・session・api・guards・docs(471 ファイル / 7165 件)が合格。既存の it/describe の削除 0 件
  • CI

🤖 Generated with Claude Code

Kewton and others added 3 commits October 8, 2026 21:57
- recordQuestionIfAsked: 直近のターンがエージェント自身の stop で閉じたまま、
  送信なしで届いた pre_tool_use(AskUserQuestion)(プロンプトを報告するソースのみ。
  #3437 と同じ判定)は質問のレコードを「残さない」方を選んだ。根拠: エピソードの
  意味は「画面のピッカーがこれを尋ねている」で、読む側(current-output・respond・
  push)に無視の条件を教えるより、書かない方が意味が一つのまま保てる。直前の stop
  が以前の質問を既に解放しているので、待っている質問は残らない。代わりに
  ask-user-question-outside-turn を記録する。
- 判定は agent-event-turn の isPreToolUseOutsideTurn(endedByOwnStop と同じ材料)に
  一本化し、applyTurnTransition の #3437 の分岐と同じ事実で決まる。
- ログ: hookSenderTags が session_id・agent_id・transcript_path・tool_use_id を
  shortSessionTag(SHA-256 先頭 8 桁)で、agent_type は名前の形のときだけそのまま返す。
  付けるのは ask-user-question-recorded / ask-user-question-outside-turn と、新しい
  agent-event-pre-tool-use-outside-turn(ターンを開かないと判断した pre_tool_use)だけ。
  pre_tool_use 全件には付けない。本文・パス・生の ID は書かない。
- ターンの中の AskUserQuestion の記録・応答・push は不変(#1726 等の既存テストは
  無変更で通過。tests/unit/{api,session,hooks,lib/session,lib/hooks} 428 ファイル 6495 件緑)。
  新テストの判定を false に変異させると測定シーケンスのケースが赤になることを確認。

対になる場所:
- src/lib/hooks/permission-decision-service.ts:501 PermissionRequest(AskUserQuestion)
  からも recordAskUserQuestion する写し。直さない(下の指摘)。
- src/lib/hooks/sources/opencode/ingest.ts:213, opencode-v2/ingest.ts:249 の記録は
  question.asked 経由で pre_tool_use の経路を通らず、opencode のターン判定とも別。直さない。
- applyAgentEventToState の promptOpensTurns の計算は intake 内の helper に寄せ、
  同じ値を二か所で写さないようにした。
- docs の ja/en: 対象の docs は scope 外。module-reference 追記案は dev-reports に記載。

本文に無い指摘: src/lib/hooks/permission-decision-service.ts:501 PermissionRequest(AskUserQuestion)
は会話外かどうかを見ずに質問を記録する。今回の事象で PermissionRequest が届いたかは
未確認のため変更していない。届くなら同じ isPreToolUseOutsideTurn で揃えるか要判断。

環境: ~/.commandmate と ~/.local/state 直下のエントリ名は作業前後で同一(ls -la 比較。
hooks/locks/worktree-index の中身の更新は並行ワーカー由来で、本作業はサーバ・tmux を
起動していない)。service.json は存在しない。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Kewton Kewton added the bug Something isn't working label Oct 8, 2026
@Kewton
Kewton merged commit 1fe36ea into develop Oct 8, 2026
3 of 15 checks passed
@Kewton
Kewton deleted the feature/3446-hooks-question-record branch October 8, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant