Skip to content

feat: share capability preflight deadline - #2394

Merged
squne121 merged 6 commits into
mainfrom
worktree-issue-2322-capability-preflight-deadline
Aug 29, 2026
Merged

squne121 merged 6 commits into
mainfrom
worktree-issue-2322-capability-preflight-deadline

Conversation

@squne121

@squne121 squne121 commented Aug 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • root consumer が absolute monotonic deadline を producer へ渡し、watchdog を cooperative deadline より 2 秒長くしました。
  • producer の Spark、GitHub auth、repository read、controlled read probe が残り時間を共有し、timeout・deadline exhaustion・spawn error を識別可能な reason として返します。
  • non-zero producer stderr は redaction、制御文字除去、500 文字制限の後に診断 reason へ保持します。

受け入れ条件の達成状況

  • AC1: root consumer が単一の absolute monotonic deadline を --deadline-monotonic-ns で producer へ渡すことを、focused pytest の test_root_transports_one_deadline_and_keeps_watchdog_grace で確認しました。
  • AC2: optional deadline と standalone producer 互換性を、test_producer_cli_without_deadline_creates_local_deadline で確認しました。
  • AC3: 4 probe の共有残り時間と expiry 後の no-spawn を、test_all_four_probes_share_decreasing_remaining_timeout と test_expired_deadline_spawns_no_new_process で確認しました。
  • AC4: spark_mode=None の env-only skip、preferred fallback、および required block を test_spark_none_skips_env_probe_and_timeout_semantics_are_preserved で確認しました。
  • AC5: timeout、deadline exhaustion、spawn error の stable reasons は focused hermetic pytest で確認しました。
  • AC6: cooperative deadline より長い watchdog grace と watchdog taxonomy を focused hermetic pytest で確認しました。
  • AC7: non-zero stderr の redaction、ANSI/NUL 除去、500 文字上限を test_watchdog_and_nonzero_stderr_taxonomy_are_distinct_and_redacted で確認しました。
  • AC8: fake monotonic clock と monkeypatched subprocess による hermetic suite を実行し、41 passed でした。
  • AC9: public result schema のキー集合を維持する互換性テストを focused hermetic pytest で確認しました。

Runtime Verification Evidence(動作検証証跡)

  • applicability: immediate(hermetic local pytest、認証・ネットワーク不要)
  • command: uv run --locked pytest scripts/claude-gpt/tests/test_workflow_capability_preflight.py scripts/claude-gpt/tests/test_workflow_capability_preflight_deadline.py scripts/claude-gpt/tests/test_timeout_taxonomy_compat.py .claude/skills/issue-refinement-loop/scripts/tests/test_root_entry_router_workflow_capability.py -q --junitxml=artifacts/issue-2322-focused-runtime-verification.xml
  • result: 41 passed in 17.76s
  • artifact: artifacts/issue-2322-focused-runtime-verification.xml(worktree 内で生成)

Checks

  • uv run --locked pytest scripts/claude-gpt/tests/test_workflow_capability_preflight.py scripts/claude-gpt/tests/test_workflow_capability_preflight_deadline.py scripts/claude-gpt/tests/test_timeout_taxonomy_compat.py .claude/skills/issue-refinement-loop/scripts/tests/test_root_entry_router_workflow_capability.py -q (41 passed)。対象の hermetic runtime verification は成功しました。
  • uv run --locked pytest scripts/claude-gpt/tests -q (331 passed, 1 skipped, 1 deselected)。関連する Python 回帰 suite は成功しました。
  • uv run --locked ruff check .claude/scripts scripts schemas .claude/skills(Ruff F401/E501 を含む lint は成功)。

Schema Change Applicability

  • decision: not_schema_change
  • reason: 公開 JSON result の decision、checks、actor_capabilities、reasons のキー集合は不変です。追加した optional CLI deadline は既存の直接起動を維持します。

Schema Consumer Inventory

N/A: 公開 schema のフィールド、型、consumer contract は変更していません。root consumer と producer の optional CLI transport を同一 PR 内で更新し、互換経路をテストしました。

Compatibility Decision(互換性判定)

  • change_type: N/A
  • compatibility: N/A
  • migration_required: N/A
  • migration_or_followup: N/A
  • reason: deadline 引数なしの producer 起動は producer 自身が既定 budget から deadline を作成します。

Safety Claim Matrix

schema: SAFETY_CLAIMS_V1
safety_claims:
  - claim: 親 watchdog は producer の協調 deadline より長く、watchdog timeout と協調終了を区別する
    implemented: "yes"
    evidence:
      - focused hermetic pytest 41 passed
    not_controlled: []
    follow_up: []
  - claim: stderr の credential、OAuth URL、ANSI、NUL を redaction 前置で出力 reason から除去する
    implemented: "yes"
    evidence:
      - test_watchdog_and_nonzero_stderr_taxonomy_are_distinct_and_redacted
    not_controlled: []
    follow_up: []

Notes

Pass one monotonic deadline from the root consumer through every producer probe so timeout results remain structured and actionable.

Co-Authored-By: Claude Code <[email protected]>
@github-actions

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #2394 closed).

@squne121

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES

レビュー対象は、最新の main を取り込んだ head 80b6b482454805eb3f0cdfa4ab1318f8b42f37ec です。PR は現在 Draft・OPENで、base は現行 main の 888fcd8dc323ab4476e4781fdbbb13de0db217d1 と一致しています。最新 head の CI は成功していますが、後述する重要ケースがテストモデルから抜けているため、green CI をもってマージ可能とは判断できません。

現時点で review submission はなく、PR上のコメントも preview bot の投稿だけです。


P0-1: optional Spark probe が全deadlineを消費し、必須GitHub probeを未実行のまま blocked にする

これはこのPRの中核仕様を壊す実装バグです。

現在の producer は次の順序で実行します。

  1. spark_env_only
  2. github_auth
  3. github_repo_read
  4. controlled_github_read

一方、workflow全体の既定budgetと spark_env_only のprobe capは、どちらも30秒です。したがって spark_mode=preferred、spark_fallback=allowed の場合でも、最初のSpark probeが30秒いっぱいまでhangすると、後続のGitHub probeが使える時間は残りません。

実際の流れは次のようになります。

t=0s
  shared deadline = t+30s

spark_env_only:
  timeout = min(30s cap, 30s remaining) = 30s
  → 30秒後に TimeoutExpired

github_auth:
  remaining <= 0
  → subprocessを起動せず deadline_exhausted

github_repo_read:
  auth=falseのため未実行

controlled_github_read:
  remaining <= 0
  → subprocessを起動せず deadline_exhausted

最終結果:
  spark = fallback_only
  github_auth = false
  controlled_github_read = unavailable
  decision = blocked

preflight.sh --env-only は単なるPATH検査ではありません。claude-code-proxy codex auth status を実際に起動するため、認証プロセスやproxyが応答しなければprobe capまで待つ可能性があります。

Pythonの subprocess.run(timeout=...) は、timeout発生時に即座に制御が戻る抽象モデルではなく、子プロセスを終了して待機した後に TimeoutExpired を再送出します。そのため、30秒timeoutを設定したprobeが共有deadlineを実時間でほぼ使い切るという前提は正しいです。([Python documentation]1)

しかしIssue #2322は、preferred + fallback allowed の timeout/budget exhaustionを fallback_only とし、workflow全体をterminal blockしないことを明示しています。これはIssue #2340から継承している既存のfallback意味論でもあります。

なぜ現在のテストが見逃すのか

test_spark_none_skips_env_probe_and_timeout_semantics_are_preserved は、Spark subprocessに対して TimeoutExpired をその場で即座に投げています。fake monotonic clockを30秒進めていないため、直後のGitHub probeにはbudgetが丸ごと残っています。つまり、「timeoutした」という例外種別だけを再現し、「timeoutによって共有deadlineが消費された」という本質を再現していません。

これは典型的なfalse-greenです。

最小修正

新しいschedulerやdeadline managerは不要です。必須probeをoptional probeより先に実行してください。

trusted uv
github_auth
github_repo_read
controlled_github_read
spark_env_only

この順序なら、

  • GitHub必須条件が正常なら、残り時間でSparkを試せる
  • Sparkが残り時間を使い切っても preferred + allowed は正しく degraded
  • GitHub側がtimeoutした場合は、もともと必須能力が確認できないため blocked
  • required + forbidden のSpark失敗は従来どおり blocked

となります。

追加すべきテストは1件で十分です。Spark timeout時にfake clockをdeadlineまで進め、GitHub probeが先に完了していて、最終decisionが degraded になることを固定してください。optional probe用のbudget予約機構や新しい恒久harnessまでは必要ありません。


P1-1: malformed_output を導入したのに、構造的に壊れたSpark JSONが未捕捉例外になる

_run_env_only_preflight() はstdoutをJSON parseした後、トップレベルが dict であることしか検査していません。その結果、次の出力は PROBE_COMPLETED と判定されます。

{
  "binary_available": true,
  "chatgpt_auth": null
}

その後、assess() が同じstdoutを再度 json.loads() し、_spark_capability() で次に相当する処理を行います。

env_only_result.get("chatgpt_auth", {}).get("available")

chatgpt_auth が null、boolean、文字列、配列などの場合、2つ目の .get() が AttributeError になります。

すると producer はwell-formed assessmentを返さずexit 1となり、root側では最終的に次のようなgeneric transport failureへ縮退します。

producer_invocation_failed:exit_1:<traceback excerpt>

Issue #2322では malformed_output をtyped internal outcomeとして追加し、preflight_probe_malformed_output:spark_env_only のような安定reasonへ変換することがスコープに含まれています。現実装はJSON syntax errorだけには対応していますが、JSON schema/shape errorには対応していません。

最小修正

_run_env_only_preflight() のparse境界で、少なくとも次を検査してください。

binary_available:
  bool

chatgpt_auth:
  dict

chatgpt_auth.available:
  bool

不一致なら、例外を後段まで流さず次を返します。

ProbeOutcome(PROBE_MALFORMED_OUTPUT)

そして次の1ケースを追加すれば十分です。

{"binary_available": true, "chatgpt_auth": null}

期待値は以下です。

producer exit = 0
reason contains preflight_probe_malformed_output:spark_env_only
preferred + allowed = degraded
required + forbidden = blocked

JSON Schema packageや共通validation frameworkを追加する必要はありません。小さなローカルvalidatorで足ります。


P2-1: test_producer_cli_without_deadline_creates_local_deadline は、その名前どおりの動作を証明していない

このテストは assess() を丸ごとfakeへ置換し、CLIから渡された deadline_ns が None であることを確認しています。

assert captured["deadline_ns"] is None

つまり証明しているのは、

deadline CLI引数を省略した場合、main() は None を assess() に渡す

という点だけです。

実際のlocal deadline生成は assess() 内の次の処理で行われます。

deadline_ns = _local_deadline_ns() if deadline_ns is None else deadline_ns

したがって、将来この処理が削除されたり、各probeが別deadlineを生成するよう壊れたりしても、現在のテストは成功します。

コード自体は現時点では正しくlocal deadlineを作っています。そのためproduction blockerではありませんが、PR本文での「AC2を確認した」という主張は過大です。

修正案

既存テストは次のように改名します。

test_producer_cli_without_deadline_passes_none_to_assess

そのうえで、

  • _local_deadline_ns() をsentinel値へmonkeypatch
  • 4つのprobeへ同一sentinelが渡ることを記録
  • _local_deadline_ns() の呼び出しが1回であることを確認

する小さなテストを追加してください。


P2-2: 「focused suiteは完全hermetic・ネットワーク不要」という証跡が正しくない

PR本文のfocused commandには、test_workflow_capability_preflight.py ファイル全体が含まれています。

しかし同ファイルの test_workflow_capability_returns_structured_result() は、実際に次のshell経路を起動します。

sh scripts/claude-gpt/preflight.sh
  --workflow-profile issue-to-impl

この経路はreal producerへ入り、real gh auth status、gh repo view、controlled gh api probeを実行し得ます。したがってfake subprocessだけで完結するhermetic suiteではありません。

認証がなくても decision=blocked の構造化結果を返すのでテスト自体は成功し得ますが、外部CLIやネットワークへ触れないという意味でのhermeticではありません。Issue #2322のruntime verification contractは「fake monotonic clock・monkeypatched subprocess・no live GitHub API」を要求しています。

これは安全性よりも、個人開発のワークフロー品質に関わります。環境依存テストをhermetic suiteに混ぜると、GitHubや認証環境の一時的な遅延でfocused verification自体が遅くなります。

最小修正

次のどちらかで十分です。

  • 構造確認テストでは外部probeをmonkeypatchする
  • focused commandをnode-id指定にして、本当にhermeticなケースだけを列挙する

real integration testを削除する必要はありません。単に「hermetic focused suite」と「環境依存integration test」を証跡上で分けるべきです。


P3: ファイル名ブラックリストテストは削除した方がよい

次のテストは実装品質をほとんど保証していません。

forbidden_names = (
    "shared_deadline",
    "nested_timeout_manager",
    "timeout_ownership",
)

これは、

  • 正当な理由で将来 shared_deadline.py を追加しても失敗する
  • 同じ重複実装を deadline_budget.py という名前で追加すれば成功する

という名前依存のharnessです。

IssueのOut of Scopeを今回のレビューで確認するための一時的な rg は妥当ですが、恒久テストにする価値はありません。個人開発での変更自由度を不必要に下げるため、test_no_new_competing_timeout_ownership_module_introduced は削除するのが適切です。

これは単独ではmerge blockerにしません。


妥当な実装判断

以下は維持すべきです。

absolute monotonic deadlineのtransport

time.monotonic_ns() の絶対値を同一ホスト上の親子プロセス間で渡す設計は妥当です。Pythonのmonotonic clockはシステム時刻調整の影響を受けず、現在のPythonではプロセス間で同じclockを使用します。整数nanosecondsを使う判断もfloat精度問題を避けられます。([Python documentation]2)

parent watchdogをcooperative deadlineより2秒長くする設計

producer自身がdeadline exhaustionを構造化して返す余地と、producerが協調終了しないケースを分離できています。producer_watchdog_timeout と内部probe timeoutを別taxonomyにしたことも正しいです。

bounded stderr sanitizer

redactionをtruncateより前に行い、credential、OAuth URL、ANSI、NUL、C0 control characterを落とすローカルhelperは、このPRの用途には十分です。リポジトリ全体の共通redaction packageに拡張する必要はありません。

追加しなくてよいもの

この修正のために、以下を導入する必要はありません。

  • process-group supervisor
  • daemon/broker
  • 新しいClaude Code hook
  • authorization ledger
  • deadline専用package
  • permanent security sandbox
  • JSON Schema framework

Issue #2322もこれらを明示的にOut of Scopeとしています。今回必要なのはprobe順序の修正と小さな入力shape検証だけです。


マージ前の最小修正セット

  1. GitHub必須probeをSpark optional probeより先に実行する。
  2. Spark timeoutが実時間相当のbudgetを消費しても、preferred + allowed が degraded になる回帰テストを追加する。
  3. chatgpt_auth のnested shapeを検査し、壊れた出力を PROBE_MALFORMED_OUTPUT にする。
  4. local deadline生成を実際に証明するテストへ修正する。
  5. focused verificationの「完全hermetic・ネットワーク不要」という記載とコマンドを実態に合わせる。
  6. ファイル名ブラックリストテストを削除する。

ブロッカーは1と3です。
2は1の修正証明、4〜6は証跡の正確性とワークフローの軽量性を保つための修正です。

最新CIが成功していること、deadline transportやwatchdog separationの基本設計が良いことは評価できます。しかし現状では、まさにfallbackで継続すべきSpark障害時にworkflowを止めるため、Issue #2322を完了した状態とは判断できません。

GitHub上へのレビュー投稿は行っていません。

Classify malformed successful Spark probe output without raising from assess().

Co-Authored-By: Claude Code <[email protected]>
@squne121
squne121 marked this pull request as ready for review August 29, 2026 09:34
@squne121
squne121 merged commit 966b492 into main Aug 29, 2026
26 checks passed
@squne121
squne121 deleted the worktree-issue-2322-capability-preflight-deadline branch August 29, 2026 11:29
squne121 added a commit that referenced this pull request Aug 29, 2026
…test fidelity (#2401) (#2410)

* fix: capability-preflight probe ordering, Spark validation, deadline test fidelity (#2401)

Bounded follow-up for the merged PR #2394 review findings:
- Reorder capability-preflight probes so required GitHub probes
  (github_auth -> github_repo_read -> controlled_github_read) run before
  the optional spark_env_only probe, sharing one absolute deadline.
- Add a Spark JSON payload validator that normalizes malformed/invalid
  shapes (non-dict top level, non-bool binary_available, missing/non-dict
  chatgpt_auth, non-bool chatgpt_auth.available) into the existing
  structured malformed-output reason instead of risking an uncaught
  AttributeError.
- Add scripts/claude-gpt/tests/test_capability_preflight_review_fixes.py
  covering probe ordering (AC1), spark-starvation degrade semantics (AC2),
  malformed Spark payload handling (AC3), the single shared absolute
  deadline (AC4), and a hermetic real root-to-producer subprocess boundary
  test faking only the external gh leaf CLI (AC5).
- Remove the filename-based timeout-ownership blacklist test (AC6).
- Mark the real-subprocess test_workflow_capability_returns_structured_result
  with @pytest.mark.github_live (optional live coverage, not part of this
  Issue's hermetic close evidence).
- Update the pre-existing shared-deadline probe-order assertion in
  test_workflow_capability_preflight_deadline.py to the new gh/gh/gh/sh
  order (required by implementing AC1).

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix: AC5 root-to-producer deadline transport観測とAC2/AC3境界テストをOWNERレビュー指摘へ整合させる (#2401)

PR #2410 への OWNER REQUEST_CHANGES (P1-1/P2-1/P2-2) fix_delta。

- AC5 (test_root_to_producer_transports_deadline_with_fake_external_clis):
  実 subprocess.run をラップして root が構築した producer argv を記録し
  `--deadline-monotonic-ns` の一意存在と整数値を検証。fake `gh` wrapper
  自体が sys.argv[1:] を JSON line で記録するようにし、fixture の
  calls[] (非厳密トレース) に頼らず 3 回の gh 呼び出しの exact argv/order
  を照合。spark_mode=None 固定条件で decision=="ready" を厳密化。
  --deadline-monotonic-ns 0 で実 producer を直接起動し GitHub subprocess
  が一切 spawn しないことを確認する境界テストを追加。
- AC2 (test_required_probes_run_before_optional_spark_and_starvation_degrades):
  spawn 前 deadline 消費シナリオ(既存 test_expired_deadline_spawns_no_new_process
  でカバー済み)ではなく、spark probe が正の残り timeout で spawn し
  TimeoutExpired を受ける実シナリオへ変更。
- AC3: 実 _run_env_only_preflight() を直接呼び出し (assess() 経由の
  monkeypatch 迂回なし) chatgpt_auth: null の malformed 判定境界を検証
  する追加ケースを1件追加。既存6ケースは維持。
- test_producer_cli_without_deadline_creates_local_deadline を
  test_producer_cli_without_deadline_passes_none_to_assess へリネーム
  (挙動変更なし、AC4新規テストとの役割分担を明記)。

Allowed Paths内2ファイルのみ変更。focused suite 25 pass、full
scripts/claude-gpt/tests/ suite 344 pass, 1 skip。

Co-Authored-By: Claude Sonnet 5 <[email protected]>

---------

Co-authored-by: Test <[email protected]>
Co-authored-by: Claude Sonnet 5 <[email protected]>
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.

実装: capability_preflight_result() の nested timeout 構造を単一 deadline 共有方式へ改善する

1 participant