Skip to content

feat(ci): bootstrap the initial main on empty org repos - #112

Merged
github-actions[bot] merged 3 commits into
mainfrom
feat/bootstrap-repo-main
Sep 22, 2026
Merged

github-actions[bot] merged 3 commits into
mainfrom
feat/bootstrap-repo-main

Conversation

@aitrawog

@aitrawog aitrawog commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary of changes

The org-wide ruleset (#109) carries the creation rule on refs/heads/main, so a brand-new repo cannot create its first main by any operator path. Measured on the three repos created after the ruleset landed:

$ git push -u origin main
remote: error: GH013: Repository rule violations found for refs/heads/main.
remote: - Cannot create ref due to creations being restricted.
# contents API, repo WITH other refs but no main (branch=main):
$ gh api -X PUT repos/opencharly/pod-qdrant/contents/README.md ... -f branch=main
{"message":"Branch main not found", ... 404}
# contents API, repo with NO refs at all (with or without branch=main):
$ gh api -X PUT repos/opencharly/zz-test-bootstrap2/contents/README.md ...
{"message":"Repository rule violations found ... Cannot create ref due to creations being restricted.", status 409}
$ gh api -X POST repos/opencharly/<repo>/branches/<b>/rename -f new_name=main
{"message":"Validation Failed","errors":["repository rules do not permit renaming branch '<b>' to 'main'"]}
# repo auto_init: the repo's own initial commit is ALSO blocked; repo stays empty.
$ gh repo list opencharly --limit 1000 --json name,createdAt,defaultBranchRef \
    --jq '[.[]|select(.createdAt > "2026-09-22T14:11:00Z")]|.[]|"\(.name) main=\(.defaultBranchRef.name)"'
plugin-qdrant main=        # no repo created after the ruleset has a main ref
pod-qdrant    main=
layer-qdrant  main=

The ruleset's only bypass actor is the charly-auto-merge App, and a repo with no main cannot produce the required validate / validate check (the required workflow does not exist on the default branch) — a genuine deadlock reached from a clean start.

This PR adds the missing bootstrap, in the same shape the org already uses for retire-per-repo-dispatchers (an App-token workflow for a write an operator token may not make):

  • scripts/bootstrap-repo-main.sh — creates refs/heads/main from the repo's current default-branch HEAD via POST /git/refs (the git-data API has no branch-must-exist precondition; the contents API does). It never moves an existing main (skipped), skips a repo with no non-main ref to seed from, and is idempotent. GH_TOKEN is required; a repo-discovery failure aborts.
  • scripts/bootstrap-repo-main_test.sh — the offline mock-gh test (the repo's established pattern), covering: seed from the default feat/x, seed from a non-main default, skip-already-has-main, skip-nothing-to-seed, idempotent re-run, explicit-repo targeting, discovery-failure abort, and missing-GH_TOKEN abort.
  • .github/workflows/bootstrap-repo-main.yml — mints the charly-auto-merge App token and runs the script (optionally scoped to named repos). Needs only the App's existing contents: write; no workflows: write.
    • Threat model / input safety: the repos workflow_dispatch input is passed through the environment (env: REPOS) and expanded quoted (read -ra targets <<<"$REPOS"; "${targets[@]}"), never interpolated into the run: body. Raw ${{ inputs.repos }} inside run: is unsanitized, and this step holds the org-wide App token (the ruleset bypass credential), so an injected x; <cmd> would be a real escalation — the quoted-env form removes the injection. The input only ever reaches the script as repo-name arguments, and the script resolves each name against the org (repos/$ORG/$repo); it never evals an argument. workflow_dispatch already requires write access.
  • README.md — documents the gap, the measured evidence, and the two-command bootstrap (App creates the ref; the operator sets the default branch with an admin token).
  • .github/workflows/validator-harness.yml — runs the new offline test on every PR.

Closes / relates to: closes #111. Follow-up to #109 (the ruleset that introduced the creation rule) and #110 (the App-token precedent).

Breaking change + rollback: none — purely additive (a new script, its test, a workflow, and README prose). Rollback = revert this commit.

Change class

hook/workflow (org-wide CI configuration: a workflow + its owner script).

How R10-tested — exact gate, commands, and pasted output

  • The gate for this change class: the repo's own offline coverage gate — the mock-gh script tests, run in CI by validator-harness.yml on every PR. There is no charly check bed for a .github script change, and none is claimed. The script's core assumption (an App token can create main where an operator cannot) was proven on a live spike before the script was written (RDD — see the RDD line below).
  • Eval beds run: N/A — no charly bed exists for a .github script/CI change class (the validator-harness workflow is the committed gate).
  • Fresh rebuild: N/A — no charly binary involved (bash + GitHub Actions YAML).
  • Did the CHANGED code path execute live? Yes — two live proofs on the real org and a real repo:
    1. App token bypasses the creation rule (spike workflow on layer-qdrant, run 35761704739):
      + gh api --method POST repos/opencharly/layer-qdrant/git/refs -f ref=refs/heads/main -f sha=0d849...
      {"ref":"refs/heads/main","object":{"sha":"0d849...","type":"commit"}}
      --- branches now ---
      feat/qdrant-integration
      main
      spike/bootstrap
      
    2. The contents API cannot (same spike, run 35761561916) and the App token cannot set the default branch:
      + gh api --method PUT repos/opencharly/layer-qdrant/contents/README.md ... -f branch=main
      {"message":"Branch main not found", ... 404}
      + gh api --method PATCH repos/opencharly/layer-qdrant -f default_branch=main
      {"message":"Resource not accessible by integration", ... 403}
      
      The operator's admin token CAN set it ({"default_branch":"main"}), which is why the README documents both steps.
  • Concurrency: N/A — a repo-bootstrap ref creation, not a shared-state change.

1. Fresh-rebuild gate output:

N/A — no charly binary; the gate is the offline script test below.

2. Each changed code path executing:

$ bash -n scripts/bootstrap-repo-main.sh && bash -n scripts/bootstrap-repo-main_test.sh && echo "syntax ok"
syntax ok
$ bash scripts/bootstrap-repo-main_test.sh
bootstrap-repo-main_test: all assertions passed

Plus the LIVE App-token ref creation above (run 35761704739).

3. Docs-only evidence:

N/A — this diff is not docs-only (it adds an executable script + workflow).

Attribution tier

fully tested and validated — the changed script path (the git-data ref creation) executed live against the real org with the real App token (the ref was created), and the offline coverage gate passes. The workflow YAML itself is validated by GitHub on push (the spike workflows ran successfully under the same create-github-app-token action and workflow_dispatch/push grammar).

Harness rulebook compliance — state HOW each is satisfied

  • R0 skills: /charly-internals:git-workflow (branch/PR-only landing), /charly-internals:strict-policy (RDD + live-or-skip), and /charly-check:check (the bed/gate-by-change-class mapping) loaded.
  • R1 RCA + zero warnings: the defect was root-caused to the ruleset's creation rule having no bootstrap path for an empty repo (measured on four paths + the org-wide repo scan), not classified as a flake; fixed at the root with a bypass-actor bootstrap. The review's second block (a documentation divergence on the contents-API status code) is fixed here: the two measured codes are now documented per condition (409 on a repo with no refs; 404 on a repo with other refs but no main) consistently across the script header, the README, and this body. No warnings.
  • R2 no out-of-scope: the gap surfaced while landing the qdrant repos; per R2 the root fix (this PR) lands in the same body of work, not as a parked "follow-up". Issue New repos cannot create their initial main — the org ruleset's creation rule has no bootstrap path #111 tracks the same fix.
  • R3 no duplication: one owner script; the offline test mirrors the existing retire-per-repo-dispatchers_test.sh pattern rather than inventing a second harness style.
  • R4 no workaround: no retry/sleep; the App-token path IS the sanctioned bypass the ruleset defines (no human bypass added, no protection loosened, no direct-push to a protected branch).
  • R5 hard cutover + grep: N/A — purely additive, no identifier removed or renamed. No false claim is swept: no existing doc asserted a bootstrap path existed.
  • R6 git safety: git status checked before staging; no force-push; landed via a feat/ branch + PR (not a direct push to main).
  • R7 runtime gate: N/A — no charly runtime path changed; the live proof is the App-token ref creation above.
  • R8 artifact invariants: N/A — no generated artifact.
  • R9 binary == source + deps: N/A — no charly binary, no new runtime OS dep.
  • R10 disposable + coverage: no charly bed applies to a .github script; per the change class the non-runtime standards apply. Coverage ships and would FAIL without the script: bootstrap-repo-main_test.sh asserts each behaviour (seed, skip, idempotent, explicit-target, abort paths) and runs in CI.
  • RDD / ADE / SDD: RDD — the high-risk assumption ("can the App token create main under the creation rule?") was proven by a live spike BEFORE the script was written; the spike also proved the two negative cases (contents API and default-branch PATCH). No bed on a settled item. ADE N/A — no candy changed. SDD N/A — no schema/.cue.
  • Hard cutover: one atomic commit; no "Phase 2/TODO" in scope.
  • Kernel/plugin boundary law: N/A — org CI config, not core/sdk.
  • Disposable-only autonomy: N/A — no destroy/rebuild.
  • Clean architecture + Go gates: N/A — no Go. Shell syntax checked (bash -n) both files.
  • CHANGELOG: N/A — opencharly/.github keeps no CHANGELOG/ on this branch's diff; the tag-on-merge workflow writes it from this PR body (verified the repo's CHANGELOG entries are all written post-merge by tag-on-merge, docs: add CHANGELOG ... for PR #N).

Assisted-by: opencode deepseek-v4.1-flash (fully tested and validated)

The org ruleset's creation rule blocks a new repo from creating its first main
by every operator path (push, contents API, auto_init, rename). The ruleset's
only bypass actor is the charly-auto-merge App, so add an App-token workflow +
script that creates refs/heads/main via the git-data refs API (no
branch-must-exist precondition), never moving an existing main.

- scripts/bootstrap-repo-main.sh — create main from the default-branch HEAD
- scripts/bootstrap-repo-main_test.sh — offline mock-gh test
- .github/workflows/bootstrap-repo-main.yml — App-token dispatch
- README.md — document the gap + the one-time bootstrap
- validator-harness.yml — run the new offline test on every PR

Assisted-by: opencode deepseek-v4.1-flash
@github-actions

Copy link
Copy Markdown
Contributor

Review — BLOCK

Head SHA: cd375aa70289627673c43e3684a2cac6843bac57 (branch: feat/bootstrap-repo-main)

Change class: hook/workflow (org-wide CI config: one workflow + its owner script + a test wired into the harness).

Security screen: FINDING — T3 command injection in the new workflow (block 2 below).

Blocks

  1. T3 — command injection via ${{ inputs.repos }} in .github/workflows/bootstrap-repo-main.yml (the "Bootstrap the initial main" step).
    The step interpolates the dispatch input straight into the shell body:
    bash scripts/bootstrap-repo-main.sh ${{ inputs.repos }}.
    GitHub does not sanitize ${{ }} interpolation inside run:, so a crafted repos value (e.g. x; <cmd>) executes arbitrary shell in a step whose env holds GH_TOKEN: ${{ steps.app.outputs.token }} — the org-wide charly-auto-merge App token that is the ruleset bypass actor. That is a real escalation from repo-write (workflow_dispatch requires only write access, which can bypass the merge/required-check review) to the org-wide bypass credential, i.e. token theft / egress.
    Fix: pass the input through the environment and expand it quoted (e.g. env: { REPOS: "${{ inputs.repos }}" } then read -ra r <<<"$REPOS"; bash scripts/bootstrap-repo-main.sh "${r[@]}"), or allowlist/validate the repo names, and state the threat model in the body. The body does not address input safety at all.

  2. R1 / B5 — committed docs contradict the body's measured evidence and the script contradicts itself.
    The body's own pasted spike shows the contents API returning 404 "Branch main not found":
    {"message":"Branch main not found", ... 404}.
    But the committed docs claim 409:

    • README.md (new "New repos" section): "…the contents API 409; rename 422 …"
    • scripts/bootstrap-repo-main.sh header: "PUT /repos/.../contents/... -> 409 "Cannot create ref due to creations being restricted"" — which is actually the git-push message, not the contents-API message.
    • The same script's later comment says the opposite: "PUT /contents/... requires the target branch to ALREADY EXIST ("Branch main not found", 404 — measured)".
      A documentation/comment divergence from the measured reality is an R1 incident, and the status codes here are not reconcilable from the diff (the same operation is cited as both 404 and 409).
      Fix: state the single measured status code consistently — or, if genuinely two distinct conditions produce 404 vs 409, document each condition and its code — across README.md, the bootstrap-repo-main.sh header comment, and the body.

Dispositions on non-blocking items

  • Body attribution footer: present and correctly formed (*Assisted-by: opencode deepseek-v4.1-flash (fully tested and validated)*); harness/model cannot be independently verified (tool-limited).
  • Change-class/gate mapping (offline mock-gh test wired into validator-harness.yml): internally coherent; test coverage exercises the new script and would fail without it. Accepted.
  • All other applicable rules (A1 accounting for all 5 files, A2 change-class, B7/B8/B10–B12, B13 ADE/SDD N/A, B15 single atomic commit, B16 placement N/A for non-charly CI config, B17 N/A): PASS or NA.

Verdict: BLOCK


ollama-cloud/deepseek-v4.1-flash — action-review.

View action run

…concile the contents-API status codes

- workflow: expand the workflow_dispatch repos input via a quoted env var, never
  interpolated into run: (the step holds the org-wide App token).
- docs: document the two measured contents-API outcomes per repo state (409 on a
  repo with no refs; 404 on a repo with other refs but no main) consistently in
  bootstrap-repo-main.sh and README.md.

Assisted-by: opencode deepseek-v4.1-flash (fully tested and validated)
@github-actions

Copy link
Copy Markdown
Contributor

Review — BLOCK

Head SHA: 32d08a7a2fac53f9599f6f75a44ceae93c1e9c0a (branch: feat/bootstrap-repo-main)

Change class: hook/workflow (org-wide CI config: a workflow + its owner script + its offline test wired into the harness + README prose).

Security screen: PASS — the prior T3 command-injection is resolved in the current diff. The repos dispatch input now reaches the shell only through env: REPOS (bootstrap-repo-main.yml) and is expanded quoted (read -ra targets <<<"$REPOS"; "${targets[@]}"); no ${{ }} appears in any run: body, so the org-wide App token is no longer reachable from a crafted input.

Blocks

  1. A1 — the body does not END with the Assisted-by: footer. The required sign-off
    *Assisted-by: opencode deepseek-v4.1-flash (fully tested and validated)*
    is placed immediately after the ## Attribution tier section and is followed by the
    entire ## Harness rulebook compliance — state HOW each is satisfied section; the body's
    actual last line is the CHANGELOG bullet. A1 requires the body to END with the
    *Assisted-by: <Harness> <Provider Full Model Name> (<confidence>)* line.
    Fix: move the *Assisted-by: …* line so it is the very last line of the body (after
    the rulebook-compliance section).

Comment disposition — prior github-actions[bot] BLOCK (head cd375aa…): stale-superseded.
Both of its blocks are resolved against the current diff — (1) the injection is fixed by the
env + quoted-array form, and (2) the contents-API codes are now documented per condition
(409 on a repo with no refs; 404 on a repo with other refs but no main) consistently
across scripts/bootstrap-repo-main.sh (header), README.md, and the PR body. Neither is a
surviving finding.

Verdict: BLOCK


ollama-cloud/deepseek-v4.1-flash — action-review.

View action run

Assisted-by: opencode deepseek-v4.1-flash (fully tested and validated)
@github-actions

Copy link
Copy Markdown
Contributor

Review — PASS

Head SHA: 10ad55fc0c06749cb5d131229cb1c1fb2875b210 (branch: feat/bootstrap-repo-main)

Security screen: PASS — no ${{ }} in any run: body; the repos dispatch input reaches the shell only through env: REPOS and is expanded quoted (read -ra targets <<<"$REPOS"; "${targets[@]}"), so the org-wide App token is not reachable from a crafted input; no secrets committed; the App's existing contents:write bypass is used, not widened, and no gate/ruleset is loosened (T4 preserved + justified).

Comments: both prior BLOCKs stale-superseded against the current head —

  • #5781233135 (T3 injection + R1 contents-API code divergence): the injection is fixed by the env+quoted-array form, and the status codes are now documented per condition (409 repo with no refs; 404 repo with other refs but no main) consistently across scripts/bootstrap-repo-main.sh header, README.md, and the body.
  • #5781372923 (A1 footer not last): the body now ends with the *Assisted-by: opencode deepseek-v4.1-flash (fully tested and validated)* line (re-frozen at commit 10ad55f).

Checklist: All applicable rules PASS or NA.

Verdict: PASS


ollama-cloud/deepseek-v4.1-flash — action-review.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) September 22, 2026 18:26
@github-actions
github-actions Bot merged commit eacc0ba into main Sep 22, 2026
2 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Sep 22, 2026
@aitrawog
aitrawog deleted the feat/bootstrap-repo-main branch September 25, 2026 19:08
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.

New repos cannot create their initial main — the org ruleset's creation rule has no bootstrap path

2 participants