Skip to content

feat(fleet): gh sync verbs for scripted flows (#10973) - #13155

Open
dezren39 wants to merge 1 commit into
mainfrom
xaltha/10973-gh-queue-sync
Open

dezren39 wants to merge 1 commit into
mainfrom
xaltha/10973-gh-queue-sync

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Step 2.2 of #9016 — the Queue/GitHub sync verbs. Refs #10973.

What landed

Eight typed fleet gh sync-* shadow verbs (new module pkgs/fleet/crates/fleet/src/gh_sync.rs): each declares its whole command line, validates it strictly (the #3352 contract — undeclared arguments are usage errors), and rewrites to the canonical gh call. The rewrite is applied in gh::run before the close guard, the closure layer and the metadata create path parse the arguments, so a sync call inherits the step-1 token rotation, the retry-safety rule, value-free errors and the audit trail exactly as the hand-written passthrough call it replaces — and the caller's stdout contract stays gh's own output, byte-exact.

Verb Canonical call
sync-labels --repo R <issue|pr> N <kind> view N --json labels --jq [.labels[].name]
sync-view --repo R <issue|pr> N <kind> view N --json labels,state,title
sync-comment --repo R <issue|pr> N --body T | --body-file P <kind> comment N --body T (file read by the verb layer; unreadable file refuses before any write)
sync-issue-create --repo R --title T --body … [--label L]… issue create … (metadata stamping applies downstream)
sync-issue-get --repo R N api repos/R/issues/N
sync-labels-add --repo R N --label L… issue edit N --add-label L…
sync-label-ensure --repo R --label L --color C --description D label create L --force …
sync-issue-close --repo R N --reason <fleet reason> issue close N --reason <fleet reason> (closure layer appends the reason comment + record)

Registry help inventory (fleet-registry) and pkgs/fleet/docs/verbs.md updated in the same change.

Caller evidence

  • pm-stack/opencode-claimant/claimant.py — the label read now runs sync-labels (same fail-closed contract, test(pm-stack/claimant): test/test_claimant.py Slice-1 suite run by no workflow and broken against the live claimant API — 4/4 error, held-label pin has no live counterpart #7670); the three agent-note posts (launch / hand-back / stuck-holder) were deduplicated into one helper over sync-comment. No raw gh composition remains in the file.
  • pm-stack/opencode-claimant/launch_one.py — the hard-stop read runs sync-view; the launch note post runs sync-comment --body-file (it already staged the note to a file). Its callers in send_to_opencode.py inherit both.
  • pm-stack/dispatch/src/github.ts — the whole gh fallback route runs through the packaged fleet binary (PM_DISPATCH_FLEET_BIN, default ~/.local/bin/fleet, the claimant's packaged location): ensureLabel → sync-label-ensure, createIssue → sync-issue-create, getIssue → sync-issue-get, addLabels → sync-labels-add, closeIssue → sync-issue-close, comment → sync-comment. The pm-stack App REST route stays primary and untouched. Disclosure: the verb close speaks the fleet closure taxonomy (fleet gh: closure records + reason-required closes (audit trail by construction) #9221), so dispatch's not_planned maps to cancelled and completed to implemented; GitHub's own state_reason granularity is not preserved. Every live caller closes with not_planned, compensating a dispatch-created tracking issue whose launch failed (launch_failure.ts).
  • Job-body flows (program tending, stewardship verdict posting, pool reviews) — their GitHub operations are the same two shapes these verbs cover (comment posts, label/state reads). Their bodies live outside this repo, so they adopt the verbs from their own definitions; that adoption is the remaining acceptance item, which is why this PR says Refs, not Closes.

Overlap with step 2.1 (#10972)

Built independently from main, per the sequencing: no dependency on the 2.1 branch. Both steps need strict verb parsing; here it lives inside gh_sync.rs as a small declared-flags parser. If 2.1 lands its own, factoring a shared helper is a small follow-up either way.

Verification (remote dispatch, per the current build rule)

Submitted via fleet queue dispatch against this branch; at PR time all three are still queued for placement (the fleet's GitHub-hosted surfaces are saturated and the placer's load reads are erroring tonight — the jobs are recorded and will run):

  • cargo test --manifest-path pkgs/fleet/Cargo.toml -p fleet -p fleet-registry — handle fp_783d9b73c28e881223ebd1dfe0ea78dd
  • python3 pm-stack/opencode-claimant/run_hermetic_tests.py — handle fp_371f0a95ed7d942259d32c7671ad4696
  • cd pm-stack/dispatch && bun install --frozen-lockfile && bun test test/github.test.ts && bunx tsc --noEmit — handle fp_3fdf5efaa63319c5f8a237075227666a

Run ids/URLs and outcomes will be appended on #10973 as they land. This PR's own CI also covers the caller suites (pm-stack-tests.yml runs the dispatch bun suite and the claimant Python suites) and the fleet Rust crates. Locally, only a Python syntax parse of the edited files was run — no suites were compiled or run in the sandbox or on the laptop.


Proof this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Step 2.2 of #9016: the Queue/GitHub sync verbs. Eight typed
 shadow verbs (gh_sync.rs) declare their whole
command line, validate it strictly (#3352), and rewrite to the
canonical gh call before the close guard, closure layer and
metadata create path run — inheriting the step-1 token rotation,
the retry-safety rule, value-free errors and the audit trail.

Callers retired onto the verbs:
- opencode-claimant/claimant.py: the label read (sync-labels) and
  the three agent-note posts, deduplicated into one helper over
  sync-comment.
- opencode-claimant/launch_one.py: the hard-stop read (sync-view)
  and the launch note post (sync-comment --body-file).
- pm-stack/dispatch github.ts: the whole gh fallback route now
  runs sync-label-ensure / sync-issue-create / sync-issue-get /
  sync-labels-add / sync-issue-close / sync-comment through the
  packaged fleet binary. The verb close speaks the fleet closure
  taxonomy (#9221): dispatch's not_planned maps to cancelled,
  completed to implemented.

Registry help inventory and pkgs/fleet/docs/verbs.md updated in
the same change. The #9016 job-body flows (program tending,
stewardship verdicts, pool reviews) compose the same two caller
operations — comment posts and label/state reads — and adopt
these verbs from their own bodies, which live outside this repo.
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 48 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 92b8d4a3-052b-4bbf-baf9-bea5556c0c7e
Commits

Reviewing files that changed from the base of the PR and between 14904d7 and d142839.

Files selected for processing: 9

  • pkgs/fleet/crates/fleet-registry/src/lib.rs
  • pkgs/fleet/crates/fleet/src/gh.rs
  • pkgs/fleet/crates/fleet/src/gh_sync.rs
  • pkgs/fleet/crates/fleet/src/main.rs
  • pkgs/fleet/docs/verbs.md
  • pm-stack/dispatch/src/github.ts
  • pm-stack/opencode-claimant/claimant.py
  • pm-stack/opencode-claimant/launch_one.py
  • pm-stack/opencode-claimant/test_claimant.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 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-23T09:29:44.907471Z d142839 PR opened
ℹ️ 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: d142839be8

ℹ️ 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".

Comment on lines +426 to +428
#[cfg(test)]
mod tests {
use super::*;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add property-based coverage for the sync parser invariants

The new parser has meaningful invariants—undeclared arguments must be refused, supported argument forms must rewrite equivalently, and non-sync calls must pass through unchanged—but its test module contains only example-based tests and names no test oracles. Root AGENTS.md explicitly requires property tests where code has invariants and requires every automated test to name its oracle. Add generated coverage for these parser invariants with an explicit oracle; the existing examples can remain as acceptance coverage.

AGENTS.md reference: AGENTS.md:L34-L39

Useful? React with 👍 / 👎.

Comment on lines +397 to +398
"sync-issue-close" => {
let p = parse_declared(verb, tail, &["--repo", "--reason"])?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Allow a successor when closing an issue as superseded

For sync-issue-close --reason superseded, this parser accepts the reason because it belongs to gh_closure::REASONS, but the subsequent gh_closure::parse call rejects it because superseded closures require --successor. The sync verb neither declares that option nor forwards it, so there is no successful invocation for this advertised closure reason. Accept and forward --successor, including the downstream requirement that it be present for superseded closures.

Useful? React with 👍 / 👎.

Comment on lines +1523 to +1524
let sync_rewrite;
let args: &[String] = match gh_sync::parse(args) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve migrated reads under the raw-mode environment

When a claimant or dispatch process inherits FLEET_GH_RAW=1, the early return in gh::run at lines 1485–1488 executes before this rewrite and forwards sync-* arguments unchanged to the real gh binary. Raw mode is a documented identity-pinning escape hatch (doc/fleet/gh-credential-lifecycle.md:204–213), and checking gh sync-labels --help confirms the result: unknown command "sync-labels" for "gh". Previously the migrated callers supplied ordinary issue/pr commands that worked in that environment; now their label/state reads fail, causing the claimant's fail-closed checks to prevent launches. Account for the sync translation when handling inherited raw mode.

Useful? React with 👍 / 👎.

/** The packaged fleet binary the fallback's sync verbs run through:
* PM_DISPATCH_FLEET_BIN overrides; the default is the packaged
* location the opencode claimant also uses (~/.local/bin/fleet). */
const FLEET_BIN = process.env.PM_DISPATCH_FLEET_BIN ?? join(homedir(), ".local", "bin", "fleet");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include fleet in the packaged dispatch runtime

For a Nix-managed dispatch deployment without an imperative fleet installation, this default points to a binary the package does not provide. pkgs/pm-dispatch/package.nix:56–66 still supplies only gh and git, and nixos/services/pm-stack/default.nix:356 launches that package directly without configuring PM_DISPATCH_FLEET_BIN. Repository-wide searches found no declarative installation of ~/.local/bin/fleet. Consequently, when App credentials are absent or the App route fails, the previously packaged gh fallback now fails to spawn instead of performing the GitHub operation. Include fleet in the runtime dependency closure and configure its packaged path.

Useful? React with 👍 / 👎.

Comment on lines +316 to +317
"--body".into(),
body,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve file transport for large comment bodies

On Linux, sync-comment --body-file now moves the entire file into a single --body argument, so bodies exceeding the per-argument size limit prevent gh from starting with E2BIG. For example, 45,000 CJK characters occupy 135,000 UTF-8 bytes; a local subprocess reproduction confirmed that passing this text as an argument fails while passing its file path succeeds. This loses the file transport supported by the replaced command (gh issue comment --help: “Read body text from file”). Preserve --body-file after validating readability, or pass the contents through stdin, rather than placing them in argv.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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.

1 participant