Stale Branch Fix
Purpose
Rebase a stale PR branch onto main, repair CI failures, and push fixes back to the PR branch.
Inputs
- •Required:
code
PR_URLS: - https://github.com/ORG/REPO/pull/123 - https://github.com/ORG/REPO/pull/456
- •Optional:
REBASE_BASE: <ref>(default: rustfoundation/safety-critical-rust-coding-guidelines main)
Steps
- •For each PR URL, collect metadata and failing checks.
- •
gh pr viewfor head repo/ref, base, files, and status checks. - •
gh pr checksto identify failed jobs. - •If needed,
gh run view <id> --log-failedto capture the root error.
- •
- •Create or update a plan file at
$OPENCODE_CONFIG_DIR/plans/stale-branch-fix-YYYYMMDD.mdwith each PR, failures, and intended fixes. - •Checkout the PR branch locally.
- •Fetch the head branch from an existing remote that matches the head repo owner.
- •Create a local branch that tracks
REMOTE/BRANCH.
- •Rebase on the latest main (do not merge).
- •Fetch main from the base repo URL without adding a remote:
- •
git fetch https://github.com/rustfoundation/safety-critical-rust-coding-guidelines.git main
- •
- •
git rebase FETCH_HEAD - •Resolve conflicts and continue the rebase.
- •Fetch main from the base repo URL without adding a remote:
- •Diagnose and fix failures based on the failing checks.
- •Rust example failures:
- •
uv run python scripts/extract_rust_examples.py --test --src-dir src/coding-guidelines --prelude src/examples_prelude.rs --json build/examples/guideline-results.json --fail-on-error --verbose
- •
- •Build failures:
- •
uv run python make.py
- •
- •Python changes:
- •
uv run ruff check --fix
- •
- •Rust example failures:
- •Apply common fixes (see below) so examples compile as standalone crates and match expected behavior.
- •Commit fixes using Conventional Commits.
- •Push updates to the PR head remote and branch.
- •Rebases require
git push --force-with-lease.
- •Rebases require
- •Re-check CI status and summarize results.
- •Update this skill with any new failure patterns and fixes discovered.
Common fixes
- •Missing
fn main()in example snippets: wrap withfn main() { ... }or use:no_run:with a complete crate. - •Top-level
let: move intofn main()or a test function. - •Inner attributes in the wrong scope: convert to outer attributes or move to the crate/module header.
- •Unresolved imports in examples: define minimal mock modules/types inline.
- •Unsafe examples: add
:miri:(expect_uborskip) with a short rationale. - •Use
:compile_fail:,:should_panic:, or:no_run:to match expected behavior. - •
:compile_fail:is incompatible with:miri:. If an example must fail under Rust 2024 rules, add:edition: 2024and removeunsafekeywords so Miri is not required. - •Bibliography/citation IDs must match the current guideline ID. Update
:cite:and:bibentry:prefixes (and bibliography:id:) to the guideline’s ID when copied. - •Unsupported directives like
.. enforcement::or.. related_guidelines::should be converted to plain text sections. - •
.rst.incguideline files are not allowed; convert them to.rstand ensure the chapter index uses the.. toctree::+:glob:pattern. - •Replace all
.. code-block:: rustwith.. rust-example::blocks; ensure each example compiles (addfn main()or hidden# fn main() {}as needed). - •Keep existing generator-format IDs. Only replace IDs that are duplicated, non-template (e.g.,
WholeWordsLikeThis), or look like manual incrementation of a trailing number. - •IDs must follow the template generator format (prefix + 12 chars) when replacements are needed.
- •Do not chase unused-citation warnings unless
bibliography_check_unusedis explicitly enabled (default is False insrc/conf.py). - •If you are confident about a
:release:value, verify it against the releases.rs website and cite the exact release. - •Avoid function item casts to integers in examples (new warnings); prefer comparing raw pointers (
as *const ()) to keep examples warning-free.
Notes
- •Do not update
src/spec.lockunless the user explicitly requests it. - •Netlify failures are often downstream of build or rust-example failures. Focus on the root error first.
Output
- •Per-PR summary of failures found, fixes applied, and files changed.
- •Tests or checks run.
- •Commit SHAs and push status.
- •Updated skill notes for new patterns.