Skip to content

実装: worktree bootstrap の origin/default-branch base ref を保持する #1604

Open

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "worktree bootstrap が指定された origin/default-branch ref を stale local default branch へ暗黙に置換せず、検証可能な remote-tracking base から issue branch を作成する"
change_kind: workflow

Parent Issue

none

Parent Goal Ref

  • Goal: implementation worktree が最新 origin/main ではなく stale root local main を起点として divergence を作り、作業開始を停止させない。
  • Desired Destination: canonical bootstrap は request された default-branch ref の remote/local identity を保持し、作成された worktree の HEAD と result を検証可能に報告する。

Current Validated Scope

  • normalize_default_branch_ref(scripts/agent-guards/worktree_bootstrap_command_policy.py)は main、refs/heads/main、origin/main、refs/remotes/origin/main を全て main へ正規化する。control-plane が git show HEAD: で直接確認済み、current main(本 Issue 起票時点の baseline)でもこの縮退は未修正のまま残存している。
  • worktree_bootstrap_exec.py はその値を git worktree add ... <normalized_base_ref> に渡すため、--base-ref origin/main を指定しても local main を base にする。
  • live evidence では local main/bootstrap branch は 885087598eac7453544f08e468bc9b8ff6c29cf4、origin/main は 8e842c1e46a5e0b76621b6373a09357347eaa08e であり、git merge --ff-only origin/main は divergence として拒否された。
  • .claude/skills/implement-issue/SKILL.md の現行呼び出し例は --base-ref main(origin/main ではなく最初から local を指定)であり、本 Issue はこの呼び出し例も origin/<default-branch> 形状へ修正する対象に含む。
  • 実装: worktree bootstrap を direct Python/no-project-mutation launcher に統一する #1588 は launcher token contract(direct Python launcher/malformed input fail-closed)を扱い、executor の branch/path/repo validation または output schema は Out of Scope と明記している(実装: worktree bootstrap を direct Python/no-project-mutation launcher に統一する #1588 改訂後も同様)。

Remaining Parent Gaps

Outcome

worktree_bootstrap_exec.py、shared bootstrap policy、回帰テスト、caller documentation(.claude/skills/implement-issue/SKILL.md/.claude/agents/implementation-worker.md)が揃い、--base-ref origin/<default-branch> で作成した issue worktree の HEAD が更新済み remote-tracking ref を起点とし、result が requested/effective base を曖昧に報告しない状態。

Background

今回の失敗は fast-forward policy の不備ではなく、bootstrap 時に origin/main の意味を local main に落としたことが原因である。raw git worktree add の一般許可、root local main の reset、merge commit/rebase による既存 worktree の書換えは採用しない。#1588(direct executor contract へ改訂済み)merge 後の canonical direct Python launcher を前提に、base-ref の identity preservation だけを閉じた executor/policy contract として修正する。

In Scope

  • origin/<default-branch> と refs/remotes/origin/<default-branch> を、local branch へ置換しない remote-tracking base identity として shared policy/executor が扱うようにする(normalize_default_branch_ref の縮退挙動を修正する)。
  • canonical bootstrap caller/documentation(.claude/skills/implement-issue/SKILL.md/.claude/agents/implementation-worker.md)を origin/<default-branch> 1 形状に固定し、bare local default-branch base を canonical example として残さない。
  • executor が remote-tracking ref の存在、commit resolution、git worktree add 後の HEAD が resolved base commit と一致することを readback し、失敗時は worktree creation success を返さないようにする。
  • result schema の互換性を維持したまま、base_ref が requested/effective base identity を曖昧に local branch 名へ縮退させないことをテストで固定する。
  • isolated bare-origin fixture により local main を意図的に stale にした場合でも、canonical remote base が選ばれること、remote ref が absent/stale/不一致なら fail-closed になることを実証する。

Out of Scope

Acceptance Criteria

  • AC1: canonical --base-ref origin/<default-branch> は executor/policy で remote-tracking identity を維持し、git worktree add は local default branch ではなく resolved remote-tracking commit を起点に issue branch を作成する。
  • AC2: isolated bare-origin fixture で local main が stale のとき、created worktree HEAD は updated remote-tracking default-branch SHA と一致し、local main SHA と一致しないことを回帰テストで固定する。
  • AC3: requested/effective base の result 値は origin/<default-branch> request を main と誤って報告せず、remote-tracking ref absent、unresolved SHA、post-create HEAD mismatch は fail-closed になる。
  • AC4: bare local default-branch base は canonical caller/documentation の positive example から除外され、wrong ref、tag、SHA、flag variants、wrapper、raw worktree add は既存の fail-closed boundary を維持する。
  • AC5: .claude/skills/implement-issue/SKILL.md/.claude/agents/implementation-worker.md が canonical origin/<default-branch> command shape を参照する

Runtime Verification Applicability

runtime_verification_applicability:
  decision: immediate
  reason: "git worktree add の base ref 解決と post-create HEAD identity は実 Git repository/bare origin でのみ検証できる。"
  applicable_acs: [AC1, AC2, AC3, AC4]
  execution_environment: "tmp_path 内の local repository + bare origin、uv-managed pytest。外部 GitHub API は不要。"
  skip_conditions: "git 又は pytest tmp_path fixture が利用できない場合のみ blocked とし、static parser PASS へ置換しない。"
  fallback_policy: "remote-tracking base と created HEAD の実証なしに merge しない。"
  artifact_requirements: "fixture の local SHA、remote-tracking SHA、created HEAD、executor result reason code。"

Verification Commands

# AC1
$ uv run --locked pytest tests/agent_ops/test_worktree_bootstrap_exec_origin_base.py::test_given_origin_default_branch_base_when_bootstrap_runs_then_remote_tracking_commit_is_used -v

# AC2
$ uv run --locked pytest tests/agent_ops/test_worktree_bootstrap_exec_origin_base.py::test_given_stale_local_default_branch_when_bootstrap_runs_then_created_head_matches_remote_tracking -v

# AC3
$ uv run --locked pytest tests/agent_ops/test_worktree_bootstrap_exec.py -v

# AC4
$ uv run --locked pytest tests/agent_ops/test_worktree_bootstrap_exec_argv_validation.py -v

# AC5
$ rg -n -F -- "--base-ref origin/" .claude/skills/implement-issue/SKILL.md .claude/agents/implementation-worker.md

Allowed Paths

  • scripts/agent-ops/worktree_bootstrap_exec.py
  • scripts/agent-guards/worktree_bootstrap_command_policy.py
  • tests/agent_ops/test_worktree_bootstrap_exec.py
  • tests/agent_ops/test_worktree_bootstrap_exec_origin_base.py
  • .claude/skills/implement-issue/SKILL.md
  • .claude/agents/implementation-worker.md
  • tests/agent_ops/test_implement_issue_worktree_bootstrap_docs.py

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • 実装: worktree bootstrap を direct Python/no-project-mutation launcher に統一する #1588 の direct executor contract(改訂後)を互換しない形で変更しなければ canonical remote base を表現できない場合
  • remote-tracking ref の identity と created HEAD を transaction 内で決定論的に readback できない場合
  • 既存 diverged worktree の reset/rebase/rebuild が実装に必要と判明した場合(本 Issue のスコープ外であり着手しない)
  • Hook、settings、Codex rules の変更が実装に必要と判明した場合(本 Issue のスコープ外であり着手しない)

Required Skills

  • Python
  • pytest
  • Git ref safety

Required Design References

  • docs/dev/agent-skill-boundaries.md
  • .claude/skills/implement-issue/SKILL.md

Scope Delta

SCOPE_DELTA_V1:
  decision: reframe_in_place
  reason: "#1860 Owner Decision により、Claude/Codex Hook・settings・Codex rules をこの系列の authority・AC・Allowed Paths にしない executor-only 契約へ改訂したため。remote base identity preservation の core scope は変更しない。"
  removed_contract:
    - "Claude/Codex shared policy/Hook boundary SSOT への記録要求"
    - ".claude/hooks/tests/test_worktree_scope_guard_worktree_bootstrap.py(Hook parity test)"
    - "docs/dev/hook-boundaries.md への記録要求"
  kept_contract:
    - "origin/<default-branch> の remote-tracking base identity preservation(core scope)"
    - "isolated bare-origin fixture による stale local main 検証"
    - "post-create HEAD readback と fail-closed postcondition"
  dependency_change: "blocking dependency を #1588(旧: Hook 中心の launcher 契約)から #1588(改訂後: direct executor contract)へ限定する"

Scope Collision Preflight

ISSUE_OVERLAP_PREFLIGHT_RESULT_V1 は decision: ambiguous_requires_human、reason_code: dependency_ambiguous、policy_class: C2b だった(旧版時点の記録)。related issue は #1588、overlapping paths は bootstrap policy、既存 tests、caller documentation である。

Delivery Rule

Notes for Reviewer

  • 本改訂は issue-refinement-loop(実装: Agent/Skill の重複を削減し progressive disclosure へ移行する #1732 Child C 改訂作業の一部)により、Hook 関連の AC/Allowed Paths/dependency 記述を除去した改訂版である。旧版の historical comment は削除・改変していない。
  • remote-tracking base identity preservation の core scope(AC1〜AC4 相当)は変更していない。current main で normalize_default_branch_ref が origin/<default-branch> を local main へ縮退させる挙動は control-plane が git show HEAD: で直接確認済みであり、本 Issue の問題認識は現在も有効である。
  • 撤回した理由: #1860 Owner Decision により、Hook はこの系列の authority・security boundary・dependency・AC にしないことが確定した。
  • 既存 diverged worktree の reset/rebuild は引き続き対象外とする(人間の通常 Git 操作のみ)。

Activity

  1. added
    enhancement
    phase/implementation
    agent/implementer
    triage-required
    on Jul 18, 2026
  2. squne121 commented on Aug 5, 2026

    @squne121
    OwnerAuthor

    #1732 系列 issue-refinement-loop による本文改訂(2026-08-05)

    #1860(Minimal harness decision)の Owner Decision を反映し、本 Issue の本文を一部改訂しました。remote-tracking base identity preservation の core scope(AC1〜AC4 相当)は変更していません。

    撤回した契約:

    • Claude/Codex shared policy/Hook boundary SSOT(docs/dev/hook-boundaries.md)への記録要求
    • .claude/hooks/tests/test_worktree_scope_guard_worktree_bootstrap.py(Hook parity test)を Allowed Paths に含めること

    理由: #1860 Owner Decision により、Hook はこの系列の authority・security boundary・dependency・AC にしないことが確定しました。

    維持した契約:

    • origin/<default-branch> の remote-tracking base identity preservation(core scope)
    • isolated bare-origin fixture による stale local main 検証
    • post-create HEAD readback と fail-closed postcondition

    dependency の変更:

    normalize_default_branch_ref が origin/<default-branch> を local main へ縮退させる挙動は、control-plane が current main(scripts/agent-guards/worktree_bootstrap_command_policy.py)を git show HEAD: で直接確認済みで、本 Issue 起票時点から未修正のまま残存しています。本 Issue の問題認識は現在も有効です。

    本改訂は #1732 系列の issue-refinement-loop の一部です。旧本文は削除せず、上記コメントの下に新本文として反映します。

  3. squne121 commented on Aug 5, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop iteration 2(review needs-fix 対応)

    前回改訂に対する issue-reviewer レビューで、Verification Commands の VC パターンに関する blocker が2件指摘されました(AC1/AC2 が既存テストファイルへの新規テスト関数追加パターンだった)。以下を修正しました。

    remote base identity preservation の core scope(AC1〜AC4 の検証内容そのもの)は変更していません。issue-contract-review の pre-edit static readiness check で status: go を再確認済みです。

  4. squne121 commented on Sep 5, 2026

    @squne121
    OwnerAuthor

    PR #2512 での実事故(evidence, #2512自体のblockerではありません)

    Issue #2506(ADRリネーム)の実装 PR #2512 の worktree 作成時に、本 Issue が扱う root cause を実際に踏みました。

    本 Issue の実装・Stop Conditions・Out of Scope はそのまま維持してください(この comment は evidence 追記のみが目的です)。

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