Skip to content

fleet gh: Metadata create path — parse, stamp, insert (#9073) - #12988

Merged
dezren39 merged 4 commits into
mainfrom
felix/9073-metadata-create-path
Nov 23, 2026
Merged

dezren39 merged 4 commits into
mainfrom
felix/9073-metadata-create-path

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

For #9073 — amendment slice 9, the native fleet gh Metadata create path: parse, stamp, insert.

What lands

fleet gh issue create / pr create now, in pkgs/fleet/crates/fleet/src/gh_metadata.rs (hooked into gh.rs's run() before the token rotation):

  1. Parse — the call is recognized and its body located in every form gh accepts (--body separate/=/attached -b, --body-file, or no body with a non-terminal stdin). The caller's pm-metadata block is parsed with the hosted edition's fail-closed rules: a malformed block (dangling marker, unfenced payload, invalid JSON, non-object, pm_meta != 1) refuses the create with exit 2 before any GitHub write. Creates whose body fleet cannot own pass through byte-exact: --web, --fill* without a body, --template without a body, --body-file -, and the interactive (terminal-stdin, no-body) flow.
  2. Stamp — the full §5/§13 provenance set is assembled from fleet sources only and replaces any caller-supplied provenance wholesale; caller-owned fields (direct_parent, links, lineage) are preserved exactly, with required-field defaults injected when absent. Sources: the queue record read from the broker for the caller's session binding (queue id, scheduled start, pickup time, work-start from progress, lane, model, and every issue the same lane start holds), session state (§14's resolution), host, worktree + workspace ref from git, the caller's agent identity, and the service clock.
  3. Sign — the impl(fleet): stamp signature — sign/verify canonical provenance (stamp_sig, stamped_by, auth_subject), both editions #12586 stamp signature, ported: same canonical form, same v1.ed25519.<kid>.<sig> shape, Ed25519. The hosted edition's golden vectors are reproduced byte-exact in the native test suite (canonical bytes and signature, both the hosted-key and native-key fixtures), so the two editions sign and verify each other's stamps. Signing is provisioned by name: when FLEET_GH_STAMP_KEY_ID is set, the key material is resolved from the secrets broker as fleet-gh.stamp-signing-key-pkcs8 (the hosted config's base64url PKCS#8 encoding); a resolution failure stamps unsigned with a stderr note rather than breaking every lane create on a provisioning gap (no stamp key is provisioned anywhere yet, and "unsigned" is a first-class reported state in §15). Unset key id = unsigned, quiet.
  4. Insert — after a successful create, the created item's URL is read from gh's own output and the full record is inserted into the metadata store: impl(fleet): metadata database + fleet Metadata query surface #9074's pm_metadata schema and extraction rules, ported verbatim over SQLite (rusqlite), so the native writer and the aggregator's reader agree field-for-field, extras included. A failed insert leaves the GitHub item intact, keeps gh's exit code, and prints a stderr note naming the miss for the §16 ingestion sweeper (the hosted impl(fleet-hosted): ingestion receiver — GitHub webhook route + scheduled-Worker sweeper (#9076 hosted) #12590 implementation) to heal — the same miss shape its sweeper test covers.

Design calls (ambiguities resolved; recorded on #9073 as well)

  • queue_id stamps as a string (the task id in string form): impl(fleet): metadata database + fleet Metadata query surface #9074's extractor indexes queue_id only as a nonempty string and the hosted route's runtime type is string; the golden vector's numeric queue_id is a canonicalizer fixture, not a type statement.
  • artifact_id = gh:<repo>#<kind>:<number> — impl(fleet): metadata database + fleet Metadata query surface #9074 left the construction open (its test uses a placeholder); the id is deterministic from the item's identity, and repo/kind/number are also columns, so a future convention change reconciles on them.
  • scheduled_start is stamped as a provenance key (§5 lists it; §12's example doesn't name the key — the hosted route made the same call).
  • Store home: $FLEET_METADATA_DB, else ~/.local/state/fleet/metadata.db (the fleet state dir). impl(fleet): metadata database + fleet Metadata query surface #9074's store is a bun:sqlite library in the aggregator, not yet wired into a runtime; the native store is the same schema over the same extraction rules, ready to be pointed at the production DB file when the wiring lands.
  • Failure posture mirrors the close guard's: broker errors fail open to null queue fields (a broker outage must not block or mis-stamp a create); insert errors never fail the create.

New dependencies (for the fleet crate)

  • ed25519-dalek 3 — deterministic RFC 8032 signing as a library call; the conformance surface is byte-exact agreement with the hosted golden vectors, which a subprocess signer cannot guarantee. Same major version as pkgs/id's id-worlds.
  • rusqlite 0.42, bundled — impl(fleet): metadata database + fleet Metadata query surface #9074's schema over SQLite; the same pin fleet-queue already carries in this workspace.
  • base64 0.23 was already an optional dependency of the crate; the gh feature now also enables it.

Evidence

  • cargo test -p fleet --features full on amd-6 under ~/tools/fleet-build-lock: 127 passed / 0 failed (118 main-binary unittests — 23 of them new gh_metadata tests — plus 9 integration tests; the pre-existing gh rotation/guard/closure suites pass unchanged).
  • Golden vectors: both hosted fixtures byte-exact (canonical form + signature + cross-verification).
  • E2E with a fake gh (records argv, prints a created-issue URL), run on amd-6 against the built binary: 23/23 checks pass — no-block / partial-block / complete-block creates all stamp correctly with caller values intact and forged provenance replaced; the DB row round-trips by query (extracted columns + link rows); a forced insert failure (FLEET_METADATA_DB under /proc) leaves the "created" item standing with exit 0 and the stderr heal note; a malformed caller block exits 2 with gh never invoked.
  • Fail-before: the same e2e against the laptop's pre-change installed fleet binary fails 13 of the 23 checks (bodies pass unstamped, no DB row is written, the malformed block sails through to gh with exit 0).

Keys and secrets are referenced by name only throughout.


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

felix added 4 commits November 23, 2026 06:11
Native slice 9 of the #9073 amendment (design
doc/2026-11-12T22-50-00Z_design_pm-board-hierarchy-genealogy §12-§15,
extending #9016 step 2): fleet gh issue/pr create calls now

- parse the caller's pm-metadata block (fail-closed on a malformed
  block, before any GitHub write),
- stamp the full provenance set from fleet sources (queue record
  via the broker, session state, host, worktree, agent identity)
  and sign it with the #12586 stamp signature when a key is
  configured (FLEET_GH_STAMP_KEY_ID + the broker secret
  fleet-gh.stamp-signing-key-pkcs8, by name only),
- insert the full record into the metadata store (#9074's
  pm_metadata schema over SQLite) after a successful create; a
  failed insert leaves the item intact and is reported for the
  §16 ingestion sweeper to heal.

The block layer, canonical form, signature, and extraction rules
port the hosted edition (pkgs/fleet/hosted-worker, #12585/#12586)
and #9074's reader; the hosted golden vectors are reproduced
byte-exact in the native test suite.

New dependencies for the fleet crate: ed25519-dalek 3 (deterministic
RFC 8032 signing as a library call — the conformance surface is
byte-exactness with the hosted vectors) and rusqlite 0.42 bundled
(#9074's schema over SQLite; same pin fleet-queue already carries).
base64 0.23 was already an optional dep of the crate and joins the
gh feature.
The gh module imports its siblings explicitly; the create-path
hook's references did not resolve without the use line.
Owned String in the queue-record max_by key (the borrowed &str
tuple outlived its closure), Debug derives for the parse types
(the refusal tests unwrap_err them), and a needless mut.
@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 13 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: 457a871e-675d-444d-9ef7-ceb9a9722b09
Commits

Reviewing files that changed from the base of the PR and between a08915d and 07c2f04.

Files ignored due to path filters: 1

  • pkgs/fleet/Cargo.lock is excluded by !**/*.lock
Files selected for processing: 5

  • pkgs/fleet/crates/fleet/Cargo.toml
  • pkgs/fleet/crates/fleet/src/gh.rs
  • pkgs/fleet/crates/fleet/src/gh_guard.rs
  • pkgs/fleet/crates/fleet/src/gh_metadata.rs
  • pkgs/fleet/crates/fleet/src/main.rs
  • 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-23T06:36:26.326341Z 07c2f04 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.

@dezren39
dezren39 merged commit 3c3f307 into main Nov 23, 2026
2 checks passed
@dezren39
dezren39 deleted the felix/9073-metadata-create-path branch November 23, 2026 06:33

@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: 07c2f04413

ℹ️ 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 +1415 to +1417
"--fill" | "--fill-first" | "--fill-verbose" => {
saw_fill = true;
out.push(token.clone());

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 Recognize the short fill flag before injecting a body

For a noninteractive fleet gh pr create -f without an explicit body, -f falls through without setting saw_fill, so this path appends a metadata-only --body. The installed gh pr create --help documents -f, --fill as “Use commit info for title and body” and states that an explicit body takes precedence over autofilled content. Consequently, the previously generated commit description is silently replaced by metadata. Recognize -f alongside --fill so these calls retain the intended passthrough behavior.

Useful? React with 👍 / 👎.

.filter(|v| !v.is_empty())
.map(|h| PathBuf::from(h).join(".config"))
})?;
let text = std::fs::read_to_string(config_home.join("fleet").join("agent.json")).ok()?;

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 Honor the configured agent profile when stamping identity

When FLEET_AGENT_PROFILE selects a nondefault enrolled profile and FLEET_AGENT is unset, this lookup ignores the selected profile and reads the default agent.json instead. The existing profile resolver in fleet-agent/src/enroll.rs::profile_path explicitly honors FLEET_AGENT_PROFILE, so other Fleet commands use the selected identity while newly created issues and PRs receive a null or different provenance.auth_subject. Resolve the same configured profile here to avoid persisting incorrect attribution.

Useful? React with 👍 / 👎.

kind: item.kind.clone(),
number: item.number,
url: item.url.clone(),
metadata: block.clone(),

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 Store the final metadata for editor-driven creates

For an editor-driven create with an initial body, such as fleet gh issue create --editor --body-file draft.md, the parser stamps the initial body but still passes --editor to gh. The installed gh issue create --help describes this flag as opening an editor to write the title and body. If the user changes caller-owned metadata such as direct_parent or links there, GitHub receives the edited block while this insert stores the original prepared block, silently making metadata queries disagree with the created item. Either leave editor-driven creates to ingestion or read back the final body before inserting its metadata.

Useful? React with 👍 / 👎.

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