Skip to content

実装: #2197向け remote protocol Git builderを閉鎖型に hardenする #2378

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#2190"
goal_ref: "#2197 の remote default-ref OID protocol を実装可能にする closed typed Git builder と fail-closed hardening を提供する"
change_kind: code

Parent Issue

#2190

Parent Goal Ref

Current Validated Scope

Current-main確認根拠

current main 9f3b2fb7a48354661de325e42b0239a6903c3899 の skill_runtime_exec.py は generic run_control_plane_git_ls_remote(repo)、fetch(repo, refspec)、cat_file(object_id)、update_ref(ref, new_oid)、variadic worktree(action, *args) だけを持つ。この surface は effective remote URL readback、exact git ls-remote --exit-code --symref <literal-url> HEAD、fixed private-ref fetch、CAS delete、fixed-reason detached worktree を表現できない。内部 runner は per-call subprocess.run timeout であり、dedicated Git process-group cleanup と shared deadline plus cleanup reserve を持たない。command policy は global Git option を拒否するが、remote-protocol ref/OID/literal-URL validation を提供していない。

Remaining Parent Gaps

Outcome

Updated scripts/agent-guards/skill_runtime_exec.py and scripts/agent-guards/skill_runtime_command_policy.py provide the closed typed, fail-closed Git builder contract required by #2197, and focused behavioral pytest passes without restoring raw argv or list[str] authority.

Runtime Verification Applicability

decision: immediate
reason: "All builder semantics, validation failures, process-group cleanup, and deadline reserve can be exercised in isolated temporary Git fixtures."
applicable_acs: [AC1, AC2, AC3, AC4, AC5, AC6, AC7]
execution_environment:
  cli_tools: [python3, uv, git]
  auth_required: false
  network_required: false
skip_conditions:
  - "If git is unavailable, record environment_blocked; do not pass via a fallback."
fallback_policy:
  fallback_success_is_pass: false
  notes: "Raw argv, lazy fetch, unbounded subprocess, or uncleaned process-group fallback is a failure."
artifact_requirements:
  - "pytest output for both focused test files"
  - "fixture trace of exact Git argv, process-group cleanup, and deadline reserve"

In Scope

  • Replace remote-protocol-relevant generic builders with closed typed semantic operations. No public or production-reachable internal API may accept arbitrary argv, variadic args, or list[str] authority.
  • Add an effective remote URL readback and whitelist comparison builder, and an exact builder for git ls-remote --exit-code --symref <literal-url> HEAD; validate the literal URL structurally before execution and retain existing sanitized environment and rewrite rejection.
  • Add a fixed private-ref fetch builder that internally fixes --no-tags --no-recurse-submodules --no-write-fetch-head and no-lazy-fetch behavior. The caller cannot choose fetch flags, refspec shape, or private-ref name.
  • Add closed readback builders for private-ref OID and worktree HEAD, a CAS-only private-ref delete builder requiring expected OID, and typed validation for permitted refs, repository object-format OIDs, and an existing commit object before detached worktree input.
  • Add a closed detached locked worktree builder whose lock reason is a fixed internal constant. It may receive only typed validated path and commit OID data; it cannot receive a Git action, flags, or lock reason.
  • Run every builder invocation in a dedicated Git process group. On timeout, probe failure, or exception, terminate and reap the group before returning or raising.
  • Replace independent per-call timeout authority with one shared protocol deadline object that reserves nonzero cleanup time and refuses terminal command spawn when the reserve would be consumed.
  • Extend only the focused tests with behavioral fixtures for exact argv, invalid data rejection, no-side-effect/no-lazy-fetch constraints, CAS mismatch, commit and object-format validation, detached locked fixed-reason worktree plus HEAD readback, group cleanup, and deadline reserve.

Out of Scope

Acceptance Criteria

  • AC1: Focused tests prove effective remote URL readback runs git ls-remote --get-url and compares the exact whitelist literal; mismatch or rewrite attempt fails closed before remote operation.
  • AC2: Focused tests prove the symref builder issues exactly git ls-remote --exit-code --symref <literal-url> HEAD and rejects option-like, non-literal, or rewriteable URL input.
  • AC3: Focused tests prove fixed private-ref fetch emits --no-tags --no-recurse-submodules --no-write-fetch-head and no-lazy-fetch constraints, and exposes no caller-controlled flags, refspec, or private-ref name.
  • AC4: Focused tests prove policy accepts only allowed refs and repository object-format OIDs, reads private-ref OID and worktree HEAD through closed builders, and requires an existing commit object before worktree construction.
  • AC5: Focused tests prove cleanup emits only CAS delete git update-ref -d <private-ref> <expected-oid> and rejects mismatch and generic update or write semantics.
  • AC6: Focused tests prove the worktree builder emits only detached, locked, fixed-reason semantics and accepts success only when post-add HEAD readback equals the validated commit OID.
  • AC7: Focused tests prove every builder uses a dedicated Git process group, terminates and reaps descendants on timeout, probe failure, and exception, and shares one deadline with nonzero cleanup reserve that prevents terminal spawn.

Verification Commands

# AC1
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_control_plane_policy.py -q
# AC2
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_control_plane_exec.py -q
# AC3
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_control_plane_exec.py -q
# AC4
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_control_plane_policy.py -q
# AC5
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_control_plane_exec.py -q
# AC6
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_control_plane_exec.py -q
# AC7
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_control_plane_exec.py -q
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm build
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py -q

Allowed Paths

  • scripts/agent-guards/skill_runtime_exec.py
  • scripts/agent-guards/skill_runtime_command_policy.py
  • scripts/agent-guards/tests/test_skill_runtime_control_plane_exec.py
  • scripts/agent-guards/tests/test_skill_runtime_control_plane_policy.py

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • Semantic builder が exact command shape を表現できない、実装: control-plane preflight の remote default-ref OID observe/fetch/pin/verify プロトコルを実装する #2197 consumer または Allowed Paths 外の変更が必要、または raw argv authority の復活が必要と判明した場合は停止して blocker を記録する。

Required Skills

なし

Required Design References

Dependency / #2197 handoff

Delivery Rule

1 Issue = 1 PR. Use a dedicated worktree and Draft PR. Keep the native blocking dependency to #2197 and do not start #2197 implementation on these paths until this PR and focused tests are in main.

Scope Delta(任意)

N/A

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    triage-required
    on Aug 28, 2026
  2. self-assigned this
    on Aug 29, 2026
  3. added a commit that references this issue on Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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