Skip to content

fix(datasource,github): one token-realm rule, forge notes budget, and a cleanup pass - #307

Merged
sweepies merged 3 commits into
mainfrom
refactor/sloppy-datasource-github
Nov 14, 2026
Merged

sweepies merged 3 commits into
mainfrom
refactor/sloppy-datasource-github

Conversation

@sweepies

@sweepies sweepies commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

A cleanup pass over code written during the refactor, covering crates/datasource, notes, http, cache, github, config, testkit, report, versioning, process and mise.

Behaviour fixes

  • Docker token realm: checked by one rule instead of two that disagreed. The token service must be on the registry's own origin, or on port 443 at Docker Hub's or gitlab.com's known token service. Self-hosted GitLab's registry.X → X/jwt/auth stays allowed. A realm on the registry's host but another port is now refused. See guide/sources.md.
  • Forge release notes: they follow the same budget as GitHub's: newest versions first, at most 32, stopping when the byte budget is spent. Previously they went in API order and kept scanning past the budget. See guide/release-notes.md.
  • Release-note reads: the first failed read keeps its original error, so a rate limit or a 404 is classified correctly. Memoised failures keep their kind.
  • GitHub client, response parsing: the client no longer JSON-parses every response body. It parses only a rate-limit status or a GraphQL answer.
  • GitHub client, installation tokens: mints lock per installation and scope, not globally. The repository id for a scoped token is cached.
  • GitHub client, error detail: transport errors keep a redacted kind (timeout or connect). A redirect loop gets its own error, and undecodable page nodes give the safe Decode error.
  • IDs: installation ids past i64::MAX are rejected everywhere.
  • Settings: a registry problem names its field, and an unreadable secret file keeps its io error.
  • Mirror misses: they go to GitHub in one batched call, retried one by one if the batch fails.
  • Local throttling: it is now a Throttled error, not a fake 429. Generic HTTP errors no longer say "registry".
  • Cache: the cleanup for the retired +<build> key scheme is a one-shot migration (014.sql), not two deletes on every open. A corrupt cache entry is a Metadata error, not "invalid registry URL".
  • URL checks: one check, slightly tighter: json() refuses userinfo, and token_get requires a host.

Cleanup (no behaviour change)

  • Removed: the dead token_get and the unused regex dependency in datasource. Error::Notes is replaced by notes' own error type.
  • Moved: the http tests' copy of datasource's Docker rules moved to datasource. Docker Hub's 6-hour fallback lives in the datasource rules.
  • Merged duplicates:
    • the parity harness, now in testkit;
    • Version::new, plain, unix_now, the User-Agent and the hex helpers;
    • the SGML and Go tag-tree builders;
    • the request headers, the id validator, the .rs walkers and the retry-cause SQL.
  • Constants and visibility: magic numbers are named, and visibility is narrowed.
  • Docs and comments: misplaced docs (valid_api_url, release_catalogs) and stale ones (registry.rs, report manager) are fixed, and history-narrating comments are rewritten.
  • Tests: assert!(…is_ok()) checks now assert the answer, and the schema version comes from the migration count.

Review fixes

  • Self-hosted GitLab: a registry on a port of its own instance (gitlab.example.com:5050, realm https://gitlab.example.com/jwt/auth) works again, with token trust only. The docs name the layout that stays refused: a token service on another port of the registry's host.
  • Mirror misses: if the batch fails, only the cold misses are retried, concurrently, and the warm heads already fetched are kept.
  • Scoped mints: a mint checks that the repository GitHub minted for matches the one requested. On a mismatch it reads the id again once, and fails closed if it still doesn't match.

Notes

  • State rows are rehashed with no version bumps; no stored state changes meaning.
  • A scoped token cached before a rename-and-recreate can still be served until it expires (under an hour). It's read-only metadata for a repository in the same installation.
  • One transcript line changed: a second scoped mint for the same repository no longer re-reads GET /repos/{repo}.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
count-patchula 67f60fd Commit Preview URL

Branch Preview URL
Nov 14 2026, 05:08 AM

…b crates

Behaviour fixes:
- datasource: one realm-trust rule for registry token services. A realm
  off the registry's origin must be on port 443 and be Docker Hub's
  auth.docker.io/token, gitlab.com/jwt/auth for registry.gitlab.com, or a
  self-hosted GitLab's <instance>/jwt/auth (tokens only); anything else is
  refused before any request.
- notes: owns its error type; a failed read returns its own error the
  first time and its kind and message when memoised. GitHub and forge
  notes share one release budget (newest versions first, 32 releases,
  12,000 bytes, stop when spent) and one finish step.
- http: a local cooldown past the longest wait is Error::Throttled, not a
  fake 429; corrupt cached metadata is Error::Metadata; transport errors
  keep a redacted kind (timeout, connect), which GitHub errors keep too.
- github: the governor parses a body only for a rate-limit status or a
  GraphQL answer; installation ids are bounded like every other id;
  redirect loops are Error::Redirect; mints lock per mint and scoped mints
  cache the repository id.
- config: settings validation names the failing field, registry key
  included; an unreadable secret file keeps its io error.

Cleanups: the retired +<build> cleanup is migration 014; Docker Hub's
pull window moves into the datasource rules and the http tests no longer
copy them; shared helpers replace duplicates (Version::new, one tag-tree
builder, the parity harness and file walker in testkit, hex, base
headers, queue SQL consts); named constants replace magic numbers;
history-narrating and stale comments are rewritten.
…ack and scoped mints

- datasource: a self-hosted GitLab registry on a port of its instance
  (registry_external_url 'https://gitlab.example.com:5050') takes tokens
  from the instance's /jwt/auth again, with token trust only. The guide
  names the layout that stays refused: a token service on another port of
  the registry's host.
- datasource: when the batched release read for mirror misses fails, the
  warm heads it read are kept and only the cold misses are asked again,
  concurrently.
- github: a scoped mint must come back narrowed to the repository asked
  for; a mismatch forgets the cached id, reads it again and mints once
  more, and a second mismatch is an error.
- mise: the io helper no longer splits a doc comment from its constant.
@sweepies
sweepies force-pushed the refactor/sloppy-datasource-github branch from 3474f41 to 67f60fd Compare November 14, 2026 05:07
@sweepies
sweepies merged commit d07e565 into main Nov 14, 2026
13 checks passed
@sweepies
sweepies deleted the refactor/sloppy-datasource-github branch November 14, 2026 05:17
@sweepies-ops sweepies-ops Bot mentioned this pull request Nov 14, 2026
sweepies added a commit that referenced this pull request Nov 14, 2026
sweepies added a commit that referenced this pull request Nov 14, 2026
…s, logged causes, and a cleanup pass (#308)

* fix(update): name a failed release-notes fetch and keep its body unsettled

A release-notes fetch that fails is logged with its cause and gets its own
section ("the Count could not read these release notes this run") instead of
"source repository could not be resolved". A body with a failed fetch carries
a content marker no intent computes, so the next run fetches again instead of
reusing it as settled.

`automerge::merged`, the server's public-page reader of the auto-merge
history, returns cache errors and filters on the actor, as the inventory's
reader does; the two are one function now. The server logs a read failure.

Cleanups in the crate:
- delete the cutover oracles: `pr/view/oracle.rs` (its fail-closed
  admission tests move to `pr/view/tests.rs`), the legacy inventory document,
  `read_legacy_inventory` and the `Documents` indirection; the inventory
  tests compare the unfiltered and filtered reads and assert counts directly
- the frozen-bytes test calls `branch_identity` for the identity and branch
- drop the dashboard receipt read `reconcile` never used
- shared helpers: published-status checks, the open PR on a plan's branch,
  the GraphQL pull projection, the compare read and ownership constants,
  `is_key`, one repository scope constructor, `with_digest`, the batch label,
  the lockfile-pending wording, `Plan::new` as the base literal, `Plan::hold`
  through `keep`, one held-target pass in `Controls::apply`, `restore_closed`
- `one()` returns a `MergeNote`; `requested` is gone
- one code-span helper (`text::code`); `truncate` is `cut_bytes`
- named body budgets, closed-PR chunk and page sizes, head retries, write
  parallelism and refs per update
- `PlanError::MissingBase` merges into `MissingExtractionCommit`
- `tooling` uses a named `Unknown` instead of `Result<_, ()>`
- test fixtures `action` and `change` in `plan::testing`; unused
  `contents_mut`/`deleted_mut` removed
- comments state the present rule instead of narrating history

* fix(engine): a failed plan keeps the saved catalog controls

`save_catalog_controls` saved an empty set when planning failed, which
un-retried every ticked box on the next run. It now logs the plan error and
keeps the saved controls.

Cleanups in the crate:
- one repository validator (`patchula_config::settings::valid_repo`) and one
  concurrency check against `MAX_CONCURRENCY`, which the CLI uses too
- shared `extract_files`, `Work::from_extraction`, `credential_scope`,
  `held_targets`, the no-config reason, the Git tree mode constants and
  `mark_sent`
- `report.rs` reads the catalog and the resolved version once, compiles
  `security.quietImages` once per repository, and shares the security
  label and notice construction
- `lookup.rs` indexes catalogs by package once and shares the reused-tags
  predicate
- the catalog reuse window is computed once per key; milliseconds per hour
  are named
- the token and transport constructors are behind a `testing` feature
- `installation_repositories` and `repo_report` are public for the server
- `write.rs` reads the dry run off the absent inventory
- tests read stored write receipts through `patchula_update::stored_receipts`
- comments state the present rule instead of narrating history

The state table's rows are rehashed for the source changes; no stored state
changes meaning.

* fix(server): log the cause of batch, remote and startup failures

A batch whose engine run failed, and a remote run that failed, now log the
engine error before the stand-in report or the generic remote message. Server
errors carry their cause, so startup and IO failures say why ("invalid GitHub
App credentials: …").

Cleanups in the crate:
- the webhook payload's `pull_request` is a typed `model::PullRequest`;
  redundant `#[serde(default)]` and the test-only `Payload::parse` are gone
- one installation-client helper; a remote run that cannot build one logs
  why its public record is skipped
- installation discovery uses the engine's listing; the batch error report
  uses `repo_report`
- batches use `SlotGuard`, as remote runs do; `discard_on_panic` is gone
- the public API's rejection body is `RejectBody`; open PRs decode once
  without a clone
- one bot-login comparison (case-insensitive) and shared installation
  checks in the webhook classifier
- the startup contention test drops its sleep; `MAX_JOBS` counts running
  jobs too

* refactor(cli): shared exit helpers, one git command builder

- `fail`/`usage` helpers with named exit codes replace hand-built tuples;
  one engine-error mapping and one `PATCHULA_RECHECK` message
- the concurrency check is the engine's
- `source` no longer filters remote flags twice
- the TUI wraps with `textwrap`
- the git runners share `git_command`; tests share `copier::test_git`
- tests read stored write receipts through `patchula_update::stored_receipts`

* fix(update): only a transient notes failure stays unsettled, and no receipt settles it

A release-notes fetch that fails is classified by the notes error's kind:
the network, a timeout, a server error or a rate limit may pass on a later
run; a registry 404, an unsafe name, a Go vanity host without go-get
metadata or an upstream answer the notes cannot use fails the same way every
run. Only the transient class gets the "could not read … this run" section
and the unsettled content marker; a lasting failure renders as before
("source repository could not be resolved") and settles.

A body with a transient failure no longer settles through write receipts:
`save_receipts` keeps no receipt for its branch, so the next run is not
restored from one and renders the body, and fetches the notes, again. The
receipt-path test fails the fetch on run 1 and checks run 2 fetches again.

* fix(engine): a failed plan still saves this run's held-back targets

A plan error keeps the plan-derived controls the last run saved and still records the package files' held-back targets, instead of skipping the whole save.

* test(update): admit consults only the closed reads it selects

Over every one-PR history and a spread of two-PR histories, with and without a bring-back tick, admit decides the same whether the other heads are unanswered, answered in full or unread.

* test(server): deliveries under lock contention answer only once durable

A parked-runtime barrier (paused clock on the current-thread runtime) replaces the sleep: no delivery is acknowledged while its write is locked out; one that gives up on the lock answers 503 and its redelivery is accepted.

* chore: rehash state rows on the #307 base

* fix(update): a notes failure settles only when it would repeat, and keeps a resolved source

The classifier now lists the lasting conditions and keeps everything else
unsettled: an unsafe package name or a tool name mise's policy refuses, a
package or release the upstream does not know (`NotFound`), `Upstream` and
`Source(Invalid)`. The network, rate limits, `Auth`, `Parse` and every local
fault (the cache, a missing tool store, GraphQL or pagination errors) may
pass, so their bodies stay unsettled and keep no receipt. A memoised failure
keeps only its kind, so of those only `NotFound` reads as lasting.

A lasting failure after the source repository resolved keeps the source:
the section says the notes could not be read and links upstream, settled.
"Source repository could not be resolved" is left for a source that was
never found.

The guide describes both classes, the resolved-source wording, and that a
host that no longer resolves retries its notes every run.

* test(update): drop the admit comparison that held by construction

A head closed_reads does not name already reads as Unread, so filling the other heads as unread could never differ; the comparison against heads answered in full stays.

* test(server): the contention barrier waits on the delivery, not the clock

Under the workspace's `patchula-cache/paused-clock` feature every cache call
runs in `spawn_blocking`, so a paused clock cannot auto-advance and the old
barrier waited out SQLite's busy timeout; every delivery answered 503 and the
contention path never ran. The resolver now logs, at debug, the installation
mapping write it is about to make, and the test waits for that event through
a tracing layer: one delivery is then writing against the locked database and
the others wait on its single-flight lookup. None may have answered, and
after the commit every delivery is accepted, with one shared lookup.
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