Skip to content

実装: cross-contract semantic review に親Goal traceabilityを追加し safety fix のnormal-flow driftを防ぐ #2829

Open

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "issue-refinement-loop の cross-contract safety fix が親Goalの normal operator journey を意図せず変更する contract drift を、既存 Step 2.5 semantic review で実装前に検出・修復できるようにする"
change_kind: workflow
dedupe_key: "issue-refinement-loop:parent-goal-trace:safety-fix-normal-flow-drift:v1"

Parent Issue

none(#2296 の narrow follow-up。発見元は #2827 / #2562 / #2625)。

Parent Goal Ref

  • Goal: 既存 issue-refinement-loop の Step 2.5 semantic design review を活用し、局所的に正しい safety fix / guard change が parent の Goal / Desired Destination / normal operator journey を暗黙に悪化させる failure class を防ぐ。
  • Desired Destination: 新しい approval framework や generic governance layer を作らず、parent付きの cross-contract / orchestration change だけに pre-mutation parent context と targeted semantic invariant review を追加する。

Current Validated Scope

2026-09-29 JST、current main 070f99fc34605178791ccc4969dd3ac9614af6d3 と live Issue / repository assets / external engineering guidance を fresh 確認した。

1. 発見元 failure class

#2827:
#2827

で整理したとおり、Task Context の drift は以下の順で発生した。

  1. parent 導入: Herdr / Claude Code Task Contextで安定識別・誤操作防止・Attention Managementを実現する #2562 は「通常の人間操作を増やさない」「普通の Issue/PR prompt で Task autobind」を Goal に持つ。
  2. /task <target> は 導入: Herdr / Claude Code Task Contextで安定識別・誤操作防止・Attention Managementを実現する #2562 OWNER review では low-frequency deterministic escape hatch として扱われていた。
  3. 実装: Task ContextのUserPromptSubmit wrong-session guardをadvisory-only化し通常workflowをhard blockしない #2625 は SubAgent/internal completion 由来の UserPromptSubmit 誤発火で ordinary workflow が hard-block される事故を直すため、ACTIVE different-primary を advisory/no-mutation にした。
  4. 同時に /task state-changing authority を UserPromptExpansion へ安全に分離した。
  5. この safety fix の contract cascade で「escape hatch が必ず使える」から「ACTIVE Taskを切り替えるには必ず escape hatch を使う」へ意味が拡張した。
  6. parent Goal の「通常操作を増やさない」と矛盾したまま、parent/child/runtime acceptance contract 自体も同じ新挙動へ更新された。
  7. その結果、実装: Claude-GPT model/proxy 更新の runtime migration を完了工程に含め、人間介入を genuine blocker に限定する #2810 の ordinary prompt で別 Issue を作業しても ACTIVE Task は旧 Issue のまま残り、後続 workflow signal が conflict になった。

局所 safety rule は正しかったが、安全修正の適用範囲が normal operator workflow まで一般化されたことが defect である。

2. current Step 2.5 は semantic review を持つが、親Goalのbaselineを見られない

#2296:
#2296

は、deterministic checker が approve しても AC / schema / architecture / workflow contract の semantic defect を見落とさないため、Step 2.5 issue-design-reviewer を追加した。

これは本 failure class を防ぐために再利用できる。

ただし #2296 は adversarial review後、意図的に次を current contract とした。

  • semantic_review_trigger.py は before/after comparison ではなく current signals の applicability classifier
  • before/after diff / previous-body-file は Out of Scope
  • semantic reviewer bundle は current pinned body / anchor feedback / deterministic findings が中心

current .claude/agents/issue-design-reviewer.md も before/after diff・過去body snapshotを受け取らない と明記している。

current semantic_review_trigger.py の signal は:

  • user_requested
  • semantic_rewrite_requested
  • checker_gap_count
  • heuristic_concern_count
  • severity_tagged_anchor_findings
  • owner_decision_conflict
  • cross_contract_change.{schema,protocol,orchestration}

であり、parent Goal baselineそのものは input ではない。

したがって cross-contract semantic review が発動しても、reviewer は「candidate child が live parent の north-star requirement を狭めた / manual step を増やした / escape hatch を normal path に昇格した」という parent-relative regression を安定して評価できない。

3. child本文の Parent Goal Ref だけでは十分でない

implementation Issue には ## Parent Goal Ref があるが、これは child authoring surface であり、child rewrite / contract cascade と同じ操作で意味が変わり得る。

今回も #2625 は parent Goal の一部を引用しながら、同じ contract 内で /task only を normal path に固定した。

つまり 変更対象自身が書いた Parent Goal Ref を唯一の oracle にしてはいけない。

必要なのは refinement run の mutation より前に取得した live parent の Goal / Desired Destination / Decisions Fixed / relevant AC を run-local immutable evidence として保持することである。

4. contract cascade は test oracle 自身を更新できる

#2625 の cascade では parent #2562、child Issues、runtime acceptance #2570 側まで新挙動へ同期した。

そのため通常の「contractとtestが一致しているか」だけでは green になる。

これは implementation drift ではなく expectation / oracle drift であり、

safety fix
→ contract cascade
→ parent expectationも更新
→ verification expectationも更新
→ implementationとtestは一致
→ 元の user journeyだけ失われる

という failure class である。

parent の pre-mutation Goal baselineを独立 evidenceとして残せば、この self-consistent false green を検出できる。

5. 外部 engineering guidance と整合する

NASA Requirements Management は requirement change に対して:

  • parent / child requirement の bidirectional traceabilityを維持する
  • change request の impact を評価する
  • requirements / ConOps / architecture/design の consistency を維持する

ことを要求している。

References:

NASA Software Engineering Handbook は traceability が requirement change の影響先(design / docs / code / tests)を特定するために有効であり、上位requirementとのtraceが欠けた design element は orphan / extra behaviorになり得ると説明している。

Thoughtworks の architecture fitness function は、重要な design objective を inspection だけに依存せず automated / continuous feedback に落とすアプローチを示している。

Reference:

本 Issue ではこれを大規模な traceability matrix / governance system として実装しない。
既存 GitHub parent relation + existing Step 2.5 + run-local artifact + targeted regression のみに限定する。

Remaining Parent Gaps

なし(単独の workflow quality improvement)。

#2827 は Task Context 自身の normal-path behavior を修正する。
本 Issue は 同型の contract drift を issue-refinement-loop が将来見逃さないことを所有する。
互いに非重複。

Outcome

parent付き Issue で Step 2.5 semantic design review が applicable になった場合、reviewer は candidate child本文だけでなく、refinement run開始時点に pin した parent Goal baseline を必ず読み、child/cascadeがその parent intent を満たすか評価する。

最低限、次の semantic regression class を検出する。

- fallback / escape hatch / recovery path が normal success path の必須手順へ昇格
- ordinary operator journey に新しい mandatory command / approval / manual action が追加
- automation が safety fix の副作用として除去される
- incident-specific guard が unrelated normal workflow へ一般化
- parent が要求する friction / autonomy / usability invariant を child が暗黙に弱める
- contract cascade が parent/test oracle まで同時に書き換え、元の Goal を self-consistent に消す

trusted OWNER anchor が parent Goal 自体の変更を明示している場合は、変更を禁止しない。

その場合は:

  • explicit parent-goal change として扱う
  • Scope Delta に旧 invariant / 新 invariant / authority anchor を明記
  • cascade を整合的に実施する

ことで継続する。

新しい人間approval gateは追加しない。
semantic finding が自動rewrite可能なら current bounded loop で修正し、owner choiceが本当に必要な場合だけ既存 requires_owner_choice / human judgment semanticsを使う。

Runtime Verification Applicability

decision: immediate
reason: issue-design-reviewer の入力contextと実review procedureを変更するため、static fixtureだけでは親Goal contextを実SubAgentが読み、findingを返し、rootがjoinすることを証明できない。
applicable_acs: [AC4, AC6, AC7]
execution_environment: current-head Claude Code runtime、current issue-refinement-loop Step 2.5、既存 scripts/agent-ops/run_worktree_agent_runtime_smoke.py。fixture parent/child bodiesはworktree-local test dataを使い、live GitHub Issue mutationを行わない。
skip_conditions: Claude runtime / Agent tool / hook causal evidence capabilityが利用不能な場合はexit 77 + SKIP:で停止し、runtime ACをPASS扱いしない。
fallback_policy: fake transport/unit testのみをactual semantic-review runtime PASSの代替にしない。runtime unavailable時はstatic correctnessのみ報告し、AC4/AC6/AC7 PASSを主張しない。
artifact_requirements: artifacts/runtime-smoke/parent-goal-trace/ 配下に reviewer SubAgent causal evidence、input bundle digest、parent baseline digest、semantic finding JSONを保存する。raw unrelated Issue comments / transcript / secretは保存しない。
runtime_assertion_bindings:

  • profile: subagent-delegation-runtime-smoke
    assertion: delegation_target_actually_invoked
    ac: AC7
  • profile: subagent-delegation-runtime-smoke
    assertion: permission_mode_effective_behavior_matches_parent_classifier
    ac: AC7
  • profile: subagent-lifecycle-causal-evidence-smoke
    assertion: subagent_start_stop_causal_evidence_correlated
    ac: AC7

In Scope

1. pre-mutation parent Goal baseline を run-local に pin する

parent付き Issue で semantic review が applicable な run は、related Issue mutation / contract cascade の前に live parent を readし、次の bounded contextを run-local artifactへ保存する。

  • parent issue number / URL
  • parent body sha256
  • Machine-Readable Contract.goal_ref
  • ## Goal
  • ## Desired Destination
  • ## Decisions Fixed
  • ## Acceptance Criteria
  • captured target issue number / body sha256 / capture timestamp

full parent comment history、raw unrelated sections、raw transcriptは複製しない。

既存 preflight / GitHub read primitiveを再利用し、新しい service / DB / long-lived ledgerを追加しない。

artifactはその refinement invocation のみで使い、cross-run cache authorityにしない。

2. semantic review bundle に parent baseline を追加する

.claude/skills/issue-refinement-loop/scripts/semantic_review_transport.py の invocation-local bundleへ optional な parent Goal contextを追加する。

  • parentなし Issueでは従来どおり no-op
  • parent付きだが semantic review not applicableなら余計なreviewを増やさない
  • parent context missing / stale / wrong parent identityを silent skipしない
  • unrelated full parent bodyをmain promptへ展開しない

新しい global schema family / registry は作らない。
既存 bundle の additive internal contextとして扱う。

3. issue-design-reviewer に parent-relative regression review を追加する

.claude/agents/issue-design-reviewer.md に、parent contextがある場合の追加review観点を限定的に追加する。

reviewerは最低限:

  1. candidate Outcome / In Scope / AC / Out of Scopeを parent Goal baselineと比較
  2. normal success pathとexception/recovery/escape-hatch pathを区別
  3. 新しい mandatory human action / command / approval / intervention の有無を確認
  4. safety fix の適用対象がincident failure classを越えて一般化されていないか確認
  5. contract cascadeがparent Goal/test oracle自体を変更する場合、trusted OWNER anchorにその変更authorityがあるか確認

を行う。

次のようなfindingは severity: high を既定とする。

parent:
  normal workflow = no extra human operation
  /task = low-frequency escape hatch

child safety fix:
  every ACTIVE switch requires /task

trusted OWNER anchorが「今後normal pathでも /task を必須にする」と明示している場合は、この差分自体を unauthorized drift と判定しない。

4. current semantic review triggerを過剰に拡張しない

本Issueの理由だけで全Issueへsemantic reviewをmandatory化しない。

既存 semantic_review_applicable signalを維持する。

特に:

  • cross_contract_change.orchestration=true
  • owner_decision_conflict=true
  • semantic rewrite / severity-tagged finding

等、既に Step 2.5 が適用される run で parent traceability contextを利用する。

current failure classを確実に通すため、parent付きIssueで contract cascade / parent Goal・Desired Destination・Decisions・AC のmutationを予定する場合は cross_contract_change.orchestration=true として canonical producerが出力することを focused regressionで固定する。

ad-hoc prose classifierは追加しない。

5. contract cascadeのoracle driftを検出する

semantic review は candidate childだけでなく、cascade intentが parent Goal baselineを変更する場合に:

parent invariant changed:
  yes/no
explicit owner authorization:
  present/absent
normal-path human burden:
  reduced/same/increased
safety scope:
  incident-bounded / broadened

を評価する。

新しい永続 schema として保存する必要はない。
semantic finding / recommended_fixとして既存 result contractへ返す。

6. #2562 → #2625 failure classを regression fixtureとして固定する

anonymized fixtureを追加する。

parent baseline:

Goal: normal human operationを増やさない
normal path: ordinary promptでauto bind/transition
escape hatch: /task は low-frequency

candidate child:

safety incident:
  internal completionをhuman intentと誤認しない
fix:
  all ACTIVE different-primary = no mutation
  ACTIVE switchは /task only

expected:

  • semantic assessment = findings
  • severity >= high
  • summary/recommended_fix が「safety fixがnormal operator journeyを狭めている」failure classを指す
  • OWNER explicit authorizationなしでは clear にしない

negative control:

  • hard blockをadvisory化
  • internal eventはno-rebind
  • actual ordinary user normal pathのautomationを維持
  • /task はescape hatchのまま

expected:

  • parent Goal regression findingなし

owner-authorized control:

  • trusted OWNER anchorがnormal path変更をexplicitに要求

expected:

  • unauthorized drift findingにはしない
  • Scope Delta / cascade consistency確認へ進む

7. runtime smokeで実 reviewer invocationを確認する

existing worktree-agent-runtime-smoke を使い、fixture parent/candidateを持つ promptから root が実 issue-design-reviewer SubAgentを起動する。

最低限:

  • intended reviewerが実際に起動
  • SubagentStart/SubagentStop causal evidenceがpair
  • parent baseline fileがbundleに存在
  • reviewer resultが assessment=findings
  • blocker/high findingが parent-goal normal-flow driftを指す
  • unrelated mutationなし

を確認する。

Out of Scope

Acceptance Criteria

  • AC1: parent付きcross-contract refinement runで、related mutation前のlive parentから Goal / Desired Destination / Decisions Fixed / AC をbounded run-local parent baselineとしてcapturedし、parent issue identityとbody sha256にbindする。
  • AC2: semantic_review_transport.py の bundleがparent baselineをoptional inputとして保持し、parentなし / semantic-review非適用runの既存挙動を変えない。
  • AC3: issue-design-reviewer がparent context存在時に「normal-path mandatory human stepの増加」「escape hatch→normal path昇格」「incident-specific safety ruleの過剰一般化」「automation removal」をparent-relative findingとして評価する。
  • AC4: 導入: Herdr / Claude Code Task Contextで安定識別・誤操作防止・Attention Managementを実現する #2562→実装: Task ContextのUserPromptSubmit wrong-session guardをadvisory-only化し通常workflowをhard blockしない #2625 failure class fixtureで semantic resultが blocker/high findingを返し、親Goalの「通常操作を増やさない」と /task low-frequency escape hatchを根拠にnormal-flow driftを指摘する。
  • AC5: safety fixがincident classに限定されnormal pathを維持するcontrol fixtureではparent-goal drift findingを返さない。trusted OWNER anchorがparent Goal変更を明示するcontrolでは unauthorized drift扱いせず、Scope Delta/cascade consistency確認へ進む。
  • AC6: parent付きIssueがparent Goal / Desired Destination / Decisions Fixed / AC のcontract cascadeを予定するfixtureで、canonical semantic trigger inputが cross_contract_change.orchestration=true となりStep 2.5をskipしない。
  • AC7: actual Claude runtime smokeで root → issue-design-reviewer delegationのstart/stop causal evidence、parent baseline bundle binding、finding resultのjoinが観測される。
  • AC8: semantic findingがfixableな場合は既存Step 4 semantic rewriteへ進み、新しいhuman approval gateを追加しない。requires_owner_choice が真に必要な場合だけ既存human-judgment routeを使う。
  • AC9: current semantic review no-before/after全体設計をgeneric diff engineへ変更せず、本Issueの追加contextを parent Goal traceability に限定する。
  • AC10: existing issue-refinement-loop semantic review tests、typecheck/lint/test/buildが回帰しない。

Verification Commands

# AC1
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_parent_goal_trace_context.py::test_parent_goal_baseline_is_captured_before_candidate_cascade -q

# AC2
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_semantic_review_transport.py -q -k parent_goal

# AC3
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_parent_goal_semantic_review_contract.py -q

# AC4
# preflight-scope: runtime_only
$ uv run --locked python3 scripts/agent-ops/run_worktree_agent_runtime_smoke.py --runtime claude --mode structured --worktree "$PWD" --prompt-file .claude/skills/issue-refinement-loop/tests/fixtures/parent_goal_drift_semantic_review_runtime.md --output-dir artifacts/runtime-smoke/parent-goal-trace --timeout-seconds 300 --max-turns 8 --expect-marker-source subagent --expect-marker "\"assessment\":\"findings\"" --require-subagent-causal-evidence --require-min-subagents 1 --require-observed-runtime-field effective_permission_profile --require-clean-postcondition

# AC5
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_parent_goal_semantic_review_contract.py -q -k "control or owner_authorized"

# AC6
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_semantic_review_trigger.py -q -k parent_contract_cascade

# AC7
# preflight-scope: runtime_only
$ uv run --locked python3 scripts/agent-ops/run_worktree_agent_runtime_smoke.py --runtime claude --mode structured --worktree "$PWD" --prompt-file .claude/skills/issue-refinement-loop/tests/fixtures/parent_goal_drift_semantic_review_runtime.md --output-dir artifacts/runtime-smoke/parent-goal-trace-causal --timeout-seconds 300 --max-turns 8 --require-subagent-causal-evidence --require-min-subagents 1 --require-observed-runtime-field effective_permission_profile --require-clean-postcondition

# AC8
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_join_review_results.py -q

# AC9
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_semantic_review_trigger.py .claude/skills/issue-refinement-loop/tests/test_semantic_review_transport.py -q

# AC10
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/ -q

# AC10
$ pnpm typecheck

# AC10
$ pnpm lint

# AC10
$ pnpm test

# AC10
$ pnpm build

Allowed Paths

  • .claude/agents/issue-design-reviewer.md
  • .claude/skills/issue-refinement-loop/references/semantic-design-review.md
  • .claude/skills/issue-refinement-loop/scripts/semantic_review_transport.py
  • .claude/skills/issue-refinement-loop/scripts/semantic_review_trigger.py
  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py(parent baseline capture wiringが既存preflight以外で安全に成立しない場合のみ)
  • .claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py(canonical cross-contract signal producerのfocused変更が必要な場合のみ)
  • .claude/skills/issue-refinement-loop/tests/
  • docs/dev/agent-skill-boundaries.md(semantic review input/boundary説明の最小更新が必要な場合のみ)

新しい schema family / registry / permanent ledger は追加しない。
既存 internal semantic bundle の additive fieldで完結できないことがfresh evidenceで判明した場合は、scopeを自動拡張せずStop Conditionへ送る。

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • parent traceabilityのためにrepository-wide requirements DB / new persistent ledger / generic approval frameworkが必要になる設計になった場合
  • issue-design-reviewer にparent Goal contextを追加するだけではfailure classを表現できず、deterministic prose NLP classifierを新設しないと成立しない設計になった場合
  • 実装: issue-refinement-loop に Step 2.5 semantic design review lane を追加する #2296 の bounded / best-effort semantic review 方針を全面的にstrict gateへ変更する必要がある場合

Required Skills

なし。

Required Design References

Scope Delta(任意)

Why this was preventable

今回のdriftは「正しい仕様が誰にも分からなかった」問題ではない。

pre-drift sourceに既に:

  • normal human operationを増やさない
  • ordinary prompt autobind
  • /task はlow-frequency escape hatch

が存在した。

欠けていたのは 安全修正candidateを、その上位intentへbackward traceするreview evidence である。

#2296 が current-body semantic reviewに限定し、before/afterとparent sourceを意図的にOut of Scopeへ置いたことは当時のover-hardening回避として合理的だった。
しかし #2625 のようなcross-contract cascadeでは、その軽量化によるblind spotが実failureになった。

従って本Issueは #2296 を否定せず:

existing Step 2.5
+ parent付きcross-contract runだけ
+ run-local pre-mutation parent baseline
+ targeted semantic checklist
+ one regression fitness scenario

だけを追加する。

Recurrence prevention principle

Safety correction may narrow a dangerous path.
It must not silently narrow the normal user journey beyond the source incident,
unless the trusted owner explicitly changes that parent goal.

を本 failure classのfitness invariantとして扱う。

Related

既存open Issue検索では、parent Goal baselineをStep 2.5へ渡してnormal-flow driftを検知する同一scopeのIssueは確認できなかった。

Delivery Rule

1 Issue = 1 PR。
current canonical impl-review-loop を使用し、Draft PRを既定とする。
merge / auto-mergeは行わない。

Activity

  1. added
    enhancement
    phase/implementation
    agent/implementer
    triage-required
    on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions