Skip to content

fix: close observation source reason code contract (#1259) - #1293

Merged
squne121 merged 4 commits into
mainfrom
worktree-issue-1259-observation-source-reason-codes-non-free
Jul 2, 2026
Merged

squne121 merged 4 commits into
mainfrom
worktree-issue-1259-observation-source-reason-codes-non-free

Conversation

@squne121

@squne121 squne121 commented Jul 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

この PR は observation source reason code の公開面 contract を閉じた形に揃える変更です。

  • public_safety.observation_sources[].safety.reason_codes を閉じた許可コード契約に固定し、自由記述や unknown、重複、件数超過、長さ超過を adapter と schema の両方で fail-closed にしました。
  • unavailable / partial のときに必要な semantic reason を schema と runtime validator にそろえ、inverse semantic drift も schema 側で reject するようにしました。あわせて validate-final-report と retro-index-builder で reason code violation を digest mismatch とは別の理由で拒否するようにしました。
  • negative fixture と targeted tests を追加し、prompt 風、path 風、必須 reason 欠落などの drift を再発しないようにしました。

Checks

主要な検証コマンドはすべてこの worktree 上で実行して成功しました。

  • pnpm typecheck を実行済みです。
  • pnpm lint を実行済みです。
  • pnpm test を実行済みです。
  • pnpm build を実行済みです。

受け入れ条件の達成状況

  • AC1-AC5: adapter と schema の両方で閉じた allowlist と invariant を強制しました。
  • AC6-AC7: source_unavailable / partial_projection の semantic requirement を強制しました。
  • AC8: reason code violation を専用の runtime / blocked reason に分類しました。
  • AC9: prompt 風や semantic reason 欠落を含む negative test と fixture を追加しました。
  • AC10-AC11: entirecli_safety.reason_codes と shared validator 本体は scope 外のまま維持しました。

検証コマンド結果

  • pnpm typecheck: PASS。型エラーはありません。
  • pnpm lint: PASS。lint エラーはありません。
  • pnpm test: PASS。88 files / 1314 tests が通過しました。
  • pnpm build: PASS。production build が成功しました。

Allowed Paths 遵守

Schema Change Applicability

  • decision: schema_change
  • reason: docs/schemas/agent-run-report.schema.json の observation source reason code contract に pattern / maxLength / maxItems と semantic contains / not-contains 制約を追加したためです。

Schema Consumer Inventory

変更対象 schema: agent_run_report/v1 ($defs.observationSourceSafety, $defs.observationSourceReasonCode)

before/after 差分:

# before
observationSourceSafety.reason_codes:
  type: array
  uniqueItems: true
  items:
    enum:
      - partial_projection
      - synthetic_only_evidence
      - host_inventory_only
      - source_unavailable

# after
observationSourceReasonCode:
  type: string
  pattern: ^[a-z][a-z0-9_]{0,79}$
  maxLength: 80
  enum:
    - partial_projection
    - synthetic_only_evidence
    - host_inventory_only
    - source_unavailable
observationSourceSafety.reason_codes:
  type: array
  maxItems: 32
  uniqueItems: true
  items:
    $ref: '#/$defs/observationSourceReasonCode'
observationSourceResult:
  available -> safety.reason_codes must not contain source_unavailable
  unavailable -> safety.reason_codes contains source_unavailable
  supported|unsupported|unverified -> safety.reason_codes must not contain partial_projection
  partial+available -> safety.reason_codes contains partial_projection

Consumer 列挙(rg コマンド例と結果):

rg -l "observationSourceReasonCode|report_observation_sources_reason_codes_invalid|observation_source\\.reason_code|validateAgentRunReport|agent-run-report:check|agent-run:check|agent-retro-index:check" docs scripts tests package.json
docs/schemas/agent-run-report.schema.json
package.json
scripts/check-agent-run-reports.mjs
scripts/lib/agent-run-report-validation.mjs
scripts/agent-logs/lib/observation-source-adapter.mjs
scripts/agent-logs/lib/validate-final-report.mjs
scripts/agent-logs/lib/retro-index-builder.mjs
tests/agent-logs/retro-index-builder.test.ts

Consumer 更新状況:

Consumer ファイル 更新有無 備考
scripts/check-agent-run-reports.mjs 不要 shared validator consumer。schema 側で inverse semantic drift を閉じることで吸収
scripts/lib/agent-run-report-validation.mjs 不要 shared validator 本体は scope 外。schema change により consumer 経路を fail-closed 化
package.json (agent-run-report:check / agent-run:check / agent-retro-index:check) 不要 checker script の入口。shared validator consumer として inventory に明示
scripts/agent-logs/lib/observation-source-adapter.mjs 更新済み closed allowlist / semantic check を adapter と projection validator に追加
scripts/agent-logs/lib/validate-final-report.mjs 更新済み reason code violation を report.observation_sources_reason_codes_invalid に分類
scripts/agent-logs/lib/retro-index-builder.mjs 更新済み blocked reason を digest mismatch から分離
tests/agent-logs/observation-source-adapter.test.ts 更新済み prompt-like / duplicate / too-many / semantic requirement を追加
tests/agent-logs/generated-report-validation.test.ts 更新済み runtime validator の reason code drift を追加
tests/agent-logs/retro-index-builder.test.ts 更新済み retro blocked reason の dedicated expectation を追加
tests/fixtures/agent-run-report/*reason-code* 更新済み prompt-like / unavailable-missing / valid unavailable fixture を整合
docs/dev/agent-run-report.md 更新済み contract wording を schema/runtime と同期

Compatibility Decision / 互換性判断

  • change_type: semantic_change。意味契約の強化です。
  • compatibility: breaking。旧来の自由記述寄り payload は reject されます。
  • migration_required: yes。producer は closed allowlist に合わせる必要があります。
  • migration_or_followup: N/A。この PR で consumer 側の整合まで含めています。
  • reason: free-form に近い既存 producer は reason code contract 違反として fail-closed になります。ただし現行 allowlist producer を正とし、consumer 側も同 PR で更新済みです。

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
observation source reason_codes が public-safe closed contract だけを通す yes(実装済み) none pnpm test, tests/agent-logs/observation-source-adapter.test.ts, tests/agent-logs/generated-report-validation.test.ts none
runtime / retro consumer が reason code contract violation を digest mismatch と分離して拒否する yes(実装済み) none pnpm test, tests/agent-logs/retro-index-builder.test.ts none
entirecli 側や shared validator の policy まで統一した no(未実装) scripts/lib/agent-run-report-validation.mjs と entirecli_safety.reason_codes は scope 外 issue #1259 の Allowed Paths / Stop Conditions #1259
PR preview を merge 判断の証拠に使う no(未使用) preview bot は asset-level live check 未検証 GitHub Actions preview comment に未検証と明記 #1259

プレビュー証跡

preview_evidence:
  status: not_used_for_merge_decision
  reason: asset-level live check is not verified by PR preview bot

Notes

@squne121
squne121 marked this pull request as ready for review July 2, 2026 13:01
@github-actions

github-actions Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #1293 closed).

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Verdict: APPROVE

Mergeability

  • mergeable=MERGEABLE, merge_state_status=CLEAN

Evidence Check

  • AC coverage: issue #1259 の AC1-AC11 に対応する closed allowlist、regex/maxItems/maxLength invariant、semantic required code、reason-code 専用 blocked reason、negative fixture/test が current head に実装されています。
  • Allowed Paths: allowed_paths_review_gate.py で contract snapshot #issuecomment-4865832429 と照合し status: ok でした。
  • CI Verification: ci_verdict_summary.py は expected head b49e7bb7bd67cc1dd9df9108eee71564b096ab1c に対して status: all_pass を返しました。
  • 検証コマンド結果: current head の CI で pnpm typecheck / pnpm lint / pnpm test / pnpm build が成功しています。

Blockers

  • なし

LOOP_VERDICT_V2

verdict: APPROVE
reviewed_head_sha: "b49e7bb7bd67cc1dd9df9108eee71564b096ab1c"
merge_ready: true
mergeability:
  mergeable: "MERGEABLE"
  merge_state_status: "CLEAN"
blockers: []
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests: []
allowed_paths_gate:
  status: ok
allowed_paths_gate_source: review_subagent

@squne121

squne121 commented Jul 2, 2026

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES。
PR #1293 は #1259 の主目的である「reason_codes を closed allowlist + regex invariant + fail-closed にする」方向にはほぼ合っています。ただし、現状の差分では schema 単体の admission 面と runtime/final validator の semantic enforcement が一致していません。このままだと、validateFinalReport / retro index では落ちるが、agent-run-report:check 系の schema+generic validator では通る payload が残る可能性があります。

確認対象は PR #1293、関連 Issue #1259 / #1153 / #1222 / #1223 / #1245 / #1261、関連 PR #1243 / #1247 / #1254、PR コメント、変更ファイル、repo 内 validator/checker/docs/tests/fixtures です。PR #1293 は open / mergeable、12 files、+519/-23 の schema change を含む変更です。

良い点

この PR は、#1259 の anchor comment が要求した「regex だけではなく closed registry + regex invariant」に実装を寄せています。Issue #1259 は、reason_codes が自然言語・指示文・path 断片・secret-looking fragment を運ばない closed contract になること、unknown/free-form/prompt-like/path-like/secret-like 値を adapter / schema / final validator / retro index で fail-closed にすることを求めています。

実装上も、adapter に OBSERVATION_REASON_CODE_PATTERN、maxItems: 32、maxLength: 80、4 要素の allowlist が追加され、normalizeObservationReasonCodes() が array 型、件数、string 型、長さ、pattern、allowlist、重複をすべて reject しています。これは以前の「黙って dedupe/sanitize」型の危険を潰す方向として妥当です。

schema 側も reason_codes を maxItems: 32 + uniqueItems: true + $defs.observationSourceReasonCode に寄せ、item 側で type: string、maxLength: 80、anchored pattern、enum を併用しています。JSON Schema の enum は許可値を固定集合に制限するための語彙で、pattern は通常部分一致なので完全一致には anchor が必要です。今回の schema はこの点では正しい設計です。 ([JSON Schema]1) ([JSON Schema]2)

final validator と retro index 側で reason-code violation を digest mismatch から分離した点も正しいです。validate-final-report.mjs は observation_source.reason_code* 系エラーを report.observation_sources_reason_codes_invalid に変換し、retro index も同じく report_observation_sources_reason_codes_invalid に分類しています。


Blocker 1: schema と runtime の semantic contract が一致していない

runtime は次の semantic を強制しています。

availability === unavailable なら source_unavailable 必須
availability === available なら source_unavailable 禁止
capability_verdict === partial && availability === available なら partial_projection 必須
supported / unsupported / unverified なら partial_projection 禁止

このうち後半 2 つ、特に 「available で source_unavailable 禁止」 と 「non-partial で partial_projection 禁止」 は runtime にしかありません。adapter の assertObservationReasonCodeSemantics() は明確にこれを reject しています。

一方、schema は positive constraint だけです。availability: unavailable なら reason_codes に source_unavailable を contains で要求し、partial + available なら partial_projection を contains で要求していますが、逆向きの禁止条件は見当たりません。

したがって、例えば次のような payload は schema 上は拒否されない可能性があります。

{
  "capability_verdict": "supported",
  "availability": "available",
  "safety": {
    "reason_codes": ["source_unavailable"]
  }
}

または:

{
  "capability_verdict": "unsupported",
  "availability": "unavailable",
  "safety": {
    "reason_codes": ["source_unavailable", "partial_projection"]
  }
}

validateFinalReport() は validateObservationSourceProjection() を先に呼ぶためこれらを落とせますが、scripts/check-agent-run-reports.mjs は JSON/Markdown file を validateAgentRunReport() に渡すだけです。 そして validateAgentRunReport() は schema validation、generic semantic validation、public-safety scan を合成するだけで、observation source projection runtime validator は呼んでいません。

これは #1259 が求める「adapter / schema / final validator / retro index の各層で fail-closed」とズレます。agent-run-report:check は package script として公開されているため、この経路で false green が出るのは contract change として看過できません。

要求修正:

schema に runtime と同等の negative semantic を追加してください。JSON Schema では if / then / else、allOf、not、contains を組み合わせて表現できます。contains は配列内に条件を満たす item があることを検証し、not は該当 schema に一致しないことを表現できます。([JSON Schema]3) ([JSON Schema]4) (JSON Schema)

例:

{
  "if": {
    "properties": {
      "availability": { "const": "available" }
    },
    "required": ["availability"]
  },
  "then": {
    "properties": {
      "safety": {
        "properties": {
          "reason_codes": {
            "not": {
              "contains": { "const": "source_unavailable" }
            }
          }
        }
      }
    }
  }
}

さらに、capability_verdict が partial でない場合、または availability が available でない場合の partial_projection 禁止も schema に入れるべきです。最低限、以下の fixture を追加してください。

invalid-public-observation-source-available-with-source-unavailable.json
invalid-public-observation-source-supported-with-partial-projection.json
invalid-public-observation-source-unsupported-with-partial-projection.json

これらは validateFinalReport() だけでなく、agent-run-report:check / validateAgentRunReport() 経路でも fail する必要があります。


Blocker 2: schema consumer inventory が不完全

PR 本文の consumer inventory は、schema、adapter、final validator、retro index、tests を列挙していますが、公開 checker 経路である scripts/check-agent-run-reports.mjs と、その実体である scripts/lib/agent-run-report-validation.mjs の影響が十分に扱われていません。PR 本文の inventory snippet でも対象は docs scripts tests の一部に留まっています。

実際には、check-agent-run-reports.mjs は validateAgentRunReport を import し、JSON/Markdown report を検証しています。 そして shared validator は Ajv2020 strict mode で schema を compile し、validateAgentRunReport() では schema + generic semantic + public-safety scan を合成しています。

#1259 は scripts/lib/agent-run-report-validation.mjs の変更自体を out-of-scope / stop condition にしていますが、それは「consumer として影響しない」という意味ではありません。むしろ schema change で吸収する必要がある consumer です。

要求修正:

PR 本文の Schema Consumer Inventory に次を追加してください。

scripts/check-agent-run-reports.mjs
scripts/lib/agent-run-report-validation.mjs
package.json scripts: agent-run-report:check / agent-run:check / agent-retro-index:check

そのうえで、validateAgentRunReport() 経路で Blocker 1 の inverse semantic drift が落ちることを fixture または focused test で固定してください。shared validator を変更しない方針を守るなら、schema 側の not contains が必須です。


Major 3: AC9 の adversarial fixture coverage がまだ薄い

追加テストは有効です。adapter test は ignore_previous_instructions、duplicate、encoded path-like、secret-like、自然言語、markdown_fence___、uppercase、hyphen、too many、too long、partial auto-add を見ています。 generated report validation も unknown reason code、unavailable missing、partial available missing を追加しています。 retro index も unknown reason code を dedicated blocked reason に落とすテストを追加しています。

ただし #1259 / anchor comment の敵対的リストに対して、まだ抜けがあります。Issue は natural language、HTML/Markdown breakout、path-looking、secret-looking、too many、too long、uppercase / punctuation drift を negative fixture に含めることを明示しています。

現状の adapter test には、少なくとも次が見当たりません。

reason_codes が array でない
reason_code が string でない
reason_code が empty string
literal HTML marker: <!-- CHATGPT_RETRO_CONTEXT_V1 start -->
literal markdown fence: ```
raw Unix path: /home/alice/.claude/settings.local.json
dot drift: source.unavailable
slash drift: source/unavailable
unicode underscore drift: source_unavailable
available + source_unavailable
supported/unverified/unsupported + partial_projection

特に最後の 2 つは Blocker 1 の schema/runtime drift を固定するために必要です。invalid-public-observation-source-reason-code-promptlike.json は良い fixture で、ignore_previous_instructions を digest 更新済みの invalid projection として置いています。 しかし、AC9 の threat classes をすべて regression fixture として残しているとは言いにくいです。

要求修正:

adapter unit test だけでなく、schema/checker fixture と final validator fixture の両方で AC9 を代表させてください。最低限、schema-level fixture で「runtime だけが知っている禁止 semantic」をなくす必要があります。


Major 4: PR preview / 配布物は merge evidence として扱えない

PR コメントには GitHub Actions bot の preview URL が出ていますが、コメント自身が “asset-level live check 未検証 / Pages source 設定後に有効化” と明記しています。また、Pages source 設定が必要な場合があり、base path 修正だけでは hosted runtime 復旧を保証しないとも書かれています。

この PR の主対象は schema / validator / fixture なので、preview が未検証であること自体は blocker ではありません。ただし、PR 本文やレビューで preview を品質証跡として扱うべきではありません。package.json 上は Vite app / build / preview scripts と agent-run/check scripts が共存しており、PR preview は UI 配布物としての確認経路に見えます。

関連する #1261 は、Latitude telemetry distribution / real pilot activation について exact semver、dist integrity、tarball digest、entrypoint/preload/hook digest、argv exposure、remote cleanup gate を fail-closed にする別 issue です。 npm provenance も、package がどこで build/publish されたかの verifiable link を与えるものであって、悪意あるコードがないこと自体を保証するものではありません。([npmドキュメント]6) GitHub Actions で npm provenance を出す場合も id-token: write、hosted runner、npm publish --provenance などの条件があります。([npmドキュメント]6)

要求修正:

この PR では、preview を evidence から明示的に外すか、次を PR comment / checklist に残してください。

preview_evidence:
  status: not_used_for_merge_decision
  reason: asset-level live check is not verified by PR preview bot

PR #1293 の合否は pnpm test や fixture/schema/runtime validator の deterministic evidence で判断すべきです。なお、PR 本文の test/build PASS は自己申告であり、私はこの場で local checkout の pnpm 実行まではしていません。


推奨パッチ方針

優先順位は次です。

  1. schema に inverse semantic の禁止を追加する。
    available で source_unavailable 禁止、non-partial で partial_projection 禁止。これで validateAgentRunReport() / agent-run-report:check と runtime validator の受理面を一致させる。

  2. consumer inventory を更新する。
    scripts/check-agent-run-reports.mjs、scripts/lib/agent-run-report-validation.mjs、package.json の checker scripts を明示する。

  3. AC9 fixture を追加する。
    not-array、non-string、empty、literal marker、literal fence、raw path、dot/slash/unicode、inverse semantic drift を追加する。

  4. preview は evidence から外す。
    PR preview comment 自体が asset-level live check 未検証なので、merge 判断材料にしない。

最終評価

実装の中核はかなり良いです。closed enum + anchored regex + max length/items + adapter fail-closed + final/retro taxonomy 分離は #1259 の主目的に合っています。
ただし、schema-only checker 経路で semantic drift が通る余地が残っているため、このまま merge は避けるべきです。 Blocker 1 と Blocker 2 を直せば、レビュー判定は approve 寄りに変えられます。

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Verdict: REQUEST_CHANGES

Mergeability

  • mergeable=MERGEABLE, merge_state_status=CLEAN

Evidence Check

  • owner comment #issuecomment-4866306195 の blocker だった schema-only checker 経路の inverse semantic drift は、current head 95f0578049896a182b018aa49caf46aa1ed346e8 で schema not contains 制約と fixture 追加により解消されています。
  • CI Verification: ci_verdict_summary.py は expected head 95f0578049896a182b018aa49caf46aa1ed346e8 に対して status: all_pass を返しました。
  • PR body には current-head の Schema Consumer Inventory と preview_evidence.status: not_used_for_merge_decision が記載されています。
  • Allowed Paths: allowed_paths_review_gate.py を issue snapshot #issuecomment-4865832429 で再計算した結果、tests/agent-run-report-schema.test.ts が issue #1259 の Allowed Paths 外で status: fail_closed でした。

Blockers

  • issue #1259 の Allowed Paths に tests/agent-run-report-schema.test.ts は含まれていません。current head は semantic blocker を直していますが、この scope 逸脱が残るため current-head APPROVE にはできません。

LOOP_VERDICT_V2

verdict: REQUEST_CHANGES
reviewed_head_sha: "95f0578049896a182b018aa49caf46aa1ed346e8"
merge_ready: false
mergeability:
  mergeable: "MERGEABLE"
  merge_state_status: "CLEAN"
blockers:
  - "allowed_paths_gate failed: tests/agent-run-report-schema.test.ts is outside issue #1259 Allowed Paths"
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests: []
allowed_paths_gate:
  status: fail_closed
allowed_paths_gate_source: review_subagent

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Verdict: APPROVE

Mergeability

  • mergeable=MERGEABLE, merge_state_status=CLEAN

Evidence Check

  • owner comment #issuecomment-4866306195 の blocker だった schema-only checker 経路の inverse semantic drift は、current head 95f0578049896a182b018aa49caf46aa1ed346e8 で schema の not contains 制約と追加 fixture により解消されています。
  • Allowed Paths: current contract snapshot #issuecomment-4866920444 と issue body sha256:fdf436d7bcf13edd2d5f60b4e008294590af1d14c24878cb06240fdb78597597 を使って allowed_paths_review_gate.py を再計算し、status: ok でした。
  • CI Verification: live rtk gh pr checks 1293 を current head で再確認し、Passed: 14 / Failed: 0 でした。先ほどの ci_verdict_summary.py の PR Body Japanese Check 集計より live check state を正本として採用します。
  • 検証コマンド結果: PR body に pnpm typecheck / pnpm lint / pnpm test / pnpm build の実行結果と Schema Consumer Inventory / Safety Claim Matrix / preview exclusion が記載されています。

Blockers

  • なし

LOOP_VERDICT_V2

verdict: APPROVE
reviewed_head_sha: "95f0578049896a182b018aa49caf46aa1ed346e8"
merge_ready: true
mergeability:
  mergeable: "MERGEABLE"
  merge_state_status: "CLEAN"
blockers: []
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests: []
allowed_paths_gate:
  status: ok
allowed_paths_gate_source: review_subagent

@squne121
squne121 merged commit d4894b4 into main Jul 2, 2026
17 of 18 checks passed
@squne121
squne121 deleted the worktree-issue-1259-observation-source-reason-codes-non-free branch July 2, 2026 21:36
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.

実装: observation source reason_codes を non-free-form code に制限する

1 participant