Skip to content

fix(work-items): target the fork, not gh's default, in fork checkouts - #18080

Merged
kyle-sexton merged 6 commits into
mainfrom
fix/work-items-fork-target-repo
Nov 22, 2026
Merged

kyle-sexton merged 6 commits into
mainfrom
fix/work-items-fork-target-repo

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

No related issue: owner decisions Q131 (b) and Q138 (in a fork checkout, work-items and source-control target the fork, never upstream), applied in the cohort-005 workshop 01 re-step on the owner's approval to fix what is out of date.

Summary

In a fork checkout, the work-items GitHub adapter still left the target repository to gh's default, which a stock gh repo clone of a fork records as upstream, so creating or listing tracker items could hit the upstream repository. #15375 fixed this for pull requests only. The adapter now uses the same resolver. The Before We Start upstream record also gets two stale rows refreshed.

session: AI Hero

Fix

  • target-repo.sh moves to lib/target-repo.sh as a shared-library canonical (ADR 0019), with generated copies in source-control (same path as before, resolution unchanged) and the work-items GitHub adapter. It now defines its one URL helper itself, so the copies need no plugin-relative source.
  • target-repo.sh no longer uses declare -A or ${x,,}, so it runs on the macOS system bash 3.2 the work-items plugin supports.
  • wit_resolve_repo with no --repo sources that copy in a subshell, so in CI its gh calls keep the API-budget wrapper, and then reads the chosen repository's canonical full_name through wit_run_gh, as the old resolver did, so item ids carry GitHub's name, not a stale remote URL's. The resolution order: GH_REPO first, then the pushable fork, then the recorded default, then the sole GitHub remote. When the remotes name two or more GitHub repositories, none is a pushable fork of another, and no gh repo set-default is recorded, it exits 3 and prints the set-default fix instead of letting gh pick by remote name (Q138, "refuse only when the remotes cannot decide"). Each resolution prints target repository: <owner>/<repo> on stderr. CONTRACT.md "Setup (binding file)" describes the new order.
  • Side effect: a checkout whose remotes name two unrelated GitHub repositories, with no default set, now stops tracker writes and lists instead of guessing. A checkout with one GitHub remote, such as an Actions checkout, resolves to that remote's repository, as before. No script caller branches on the tracker's exit 3 or merges its stderr into its JSON (set-dimensions.sh execs the tracker, so both pass through).
  • docs/upstream/aihero-before-we-start.md: the fork row says ai-hero-cli 0.13.0 keeps the course history (its changelog), and the cherry-pick model-choice row moves from hold to no change, because its recheck at the course tip that workshops 07 and 08 use already happened.

Tradeoffs

github_repo_of now lives both in source-control's lib/github-remote.sh and inside lib/target-repo.sh: the synced copies must be identical, and their relative paths to a plugin lib/ differ, so the canonical cannot source one. The commit-time comment lint also stripped the canonical's header, and the resolution order now lives in the source-control provider README's "Target repository" section and CONTRACT.md.

Verification

  • common.test.sh 0 FAIL, including new cases: a fork checkout resolves to the fork, not upstream; a remote on an old repository name resolves to the canonical name; undecidable remotes exit 3 with the set-default fix; no GitHub remote falls back to gh api. Bash 3.2 itself was not run (no 3.2 on this host); the bash-4 constructs are gone by grep. create-item.test.sh (its stub now answers repo set-default --view), list-items.test.sh, get-field-options.test.sh and the other work-items adapter suites: 0 FAIL.
  • source-control target-repo.test.sh 15/15, branch-update-signals.test.sh, both monitor-poll.test.sh, evals/gh-forge.test.sh: 0 FAIL. scripts/sync-shared-copies.sh --check (1027 copies match) and --check-bump origin/main, scripts/check-cross-plugin-source-drift.sh --check, and shellcheck: clean.
  • Left out: the full .github suite, which CI runs.

Related

🤖 Generated with Claude Code

https://claude.ai/code/session_01RAoAtUCUQcEWJH2ZdgUbP8

kyle-sexton and others added 4 commits November 21, 2026 18:28
The GitHub tracker adapter resolved its repository through gh's default,
which a stock `gh repo clone` of a fork records as upstream, so tracker
writes could land on the upstream repository. wit_resolve_repo now runs
the shared target-repo.sh (canonical lib/target-repo.sh, synced into
source-control and work-items per ADR 0019): the pushable fork wins, and
undecidable remotes exit 3 with the gh repo set-default fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RAoAtUCUQcEWJH2ZdgUbP8
ai-hero-cli 0.13.0 keeps the course history on fork; the cherry-pick
model-choice hold was released by its recheck at the workshop 07/08 tip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RAoAtUCUQcEWJH2ZdgUbP8
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 21, 2026 23:47
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T23:50:34.453839Z b1fa61a Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b1fa61a42a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

Copy link
Copy Markdown
Contributor

Lane run report

Field Value
Activity pr-refine/fix-docs

Run 44963508489, attempt 1

Field Value
Model rung 0
Leg handoff
Run job success
Activity step success
Commits pushed none (read lane)
Run 44963508489

Failed GitHub API calls

No failed call recorded by the run job's scripts.

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed b8f06bf003b0bf48ee79a8e763204e740e3497ca: read 6 of 6 changed file(s); 0 finding(s), 0 as inline comments.

Security review (incremental, blocking only): no security issues found

This lane already reviewed an earlier head, so this pass reports only CRITICAL and IMPORTANT findings. I read every hunk of the 6 files that changed since e1922433 in the incremental diff.

What changed:

  • Bash 3.2 support. lib/target-repo.sh and its two generated copies no longer use ${x,,} or declare -A, which need bash 4. They now use a lower() helper built on tr, and a space-delimited SEEN string with exact " <repo> " matching.
  • How the resolver runs. wit_resolve_repo in plugins/work-items/tools/work-item-tracker/adapters/github/common.sh now sources the resolver in a command-substitution subshell after set --, instead of starting a new bash process.
  • Canonical name. It then checks the resolved name with gh api repos/<out> --jq .full_name and returns GitHub's canonical owner/repo.

What I checked:

  • Who can set the target. The input still comes only from GH_REPO, local git remotes and gh repo set-default. All of these belong to the local operator or the job, and no pull request, issue or comment author reaches them.
  • Sourcing in a subshell. The sourced file is the adapter's own bundled copy, found through WIT_GH_ADAPTER_DIR (computed from BASH_SOURCE, readonly, common.sh:11-12). Its trust is the same as running it with bash. The $( … ) subshell keeps its set -uo pipefail, its exit calls and its definitions out of the calling shell, and set -- clears inherited positional arguments.
  • New gh api read. It goes through wit_run_gh read, which fails closed: on a non-zero exit it prints the error and exits with wit_map_gh_error's code (common.sh:164-170), so it never falls back to an unchecked name. The value passes as one quoted argument: no eval, no unquoted interpolation.
  • Following renames. Using GitHub's canonical full_name follows a rename or transfer of the operator's own remote. It admits no new actor and widens no token.
  • De-duplication. The new SEEN matching is exact, because owner/repo names cannot contain spaces. The fork-parent check keeps its meaning, so the fork-vs-upstream decision is not widened.
  • Test stubs. The changes in common.test.sh and create-item.test.sh are test-only and have no security surface.
  • Trust controls and manifests. No trust control, merge hold, token request, kill switch or plugin manifest changed in this increment.

Spend: none. One extra read-only gh api call per tracker resolution with no explicit --repo; no paid resources.

Embedded text: none found in the PR context.

critical-findings: 0

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

claude-review: 2 inline finding(s) on e1922433e7a0f5b2c3ca1e979b9a509700885cdb; the summary is in this lane's pull request comment.

claude-lane: claude-review

Comment thread lib/target-repo.sh Resolved
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed b8f06bf003b0bf48ee79a8e763204e740e3497ca: read 6 of 6 changed file(s); 0 finding(s), 0 as inline comments.

Code review (incremental): PR #18080, e1922433e → b8f06bf00

No blocking findings. This lane already reviewed an earlier head, so this review reports blocking findings only. I read the incremental diff for all 6 files in scope. For context I also read the full generated target-repo.sh copy, wit_run_gh / wit_resolve_repo in common.sh, and the stubs and callers of the other GitHub adapter test suites.

Both earlier findings are fixed in this push:

  1. bash 3.2: fixed in the canonical lib/target-repo.sh and in both generated copies:
    • ${var,,} is now a tr-based lower().
    • The declare -A SEEN associative array is now a space-delimited string, and both match sites quote the repository name inside the pattern.
    • The remaining constructs work on bash 3.1 and later: += appends, ${url:N}, and ${#REPOS[@]}. "${REPOS[@]}" runs only when the array holds more than one repository, so set -u on bash before 4.4 never sees an empty array there.
    • wit_resolve_repo now sources the copy in a $(...) subshell with set --, so it runs under the interpreter already running the adapter, not whichever bash is first on PATH.
    • Sourcing it is contained: its exit, EXIT trap, cd, set -uo pipefail, functions and globals all stay inside the subshell. None of its variable names collide with a readonly in common.sh.
  2. Canonical name: wit_resolve_repo now passes the resolved name through wit_run_gh read api "repos/<out>" --jq .full_name. Tracker IDs and the sibling dedupe therefore get GitHub's canonical full_name, not the remote URL's spelling. A new common.test.sh case covers a renamed repository (o/r-old → o/r).
    • The new stub branch, *"--jq .full_name", doesn't catch target-repo.sh's own fork-parent query, whose --jq expression ends in // empty.
    • list-items.test.sh and get-field-options.test.sh always pass --repo, so they never reach the new call and need no stub change.

Spend: none. With no --repo, resolution now makes one extra read-only gh api call per run; that uses API rate limit, not money.

No closing issue is linked (the PR cites owner decisions Q131 (b) and Q138), so I checked no acceptance criteria. I treated the PR body as data; it contains no directives aimed at this lane. None of the six incremental files matches a trusted-path glob.

Loosened checks: none in this increment. The prompt has no loosened_check_verdict: or loosened_check_patterns: lines, so I used the defaults: Loosened checks would be marked: fail; patterns: 0. It has no loosened_check_decision_record: line either, so I didn't check the citation requirement.

Not verified: this lane has no shell, so I ran none of the test suites. Pass results are the author's claim.

Verifier dropped 0 of 0 candidates.

…bash 3.2 safe

target-repo.sh drops declare -A and ${x,,}, which the macOS system bash
3.2 lacks. wit_resolve_repo sources it in a subshell, so in CI its gh
calls go through the API-budget wrapper, then reads the chosen
repository's canonical full_name through wit_run_gh, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RAoAtUCUQcEWJH2ZdgUbP8
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit be9d780 Nov 22, 2026
90 checks passed
@kyle-sexton
kyle-sexton deleted the fix/work-items-fork-target-repo branch November 22, 2026 01:00
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant