Skip to content

feat(breg): keep files on records and name the Proposal behind a revision - #2797

Merged
jeremi merged 33 commits into
mainfrom
feat/breg-record-proposal-and-attachments
Nov 26, 2026
Merged

jeremi merged 33 commits into
mainfrom
feat/breg-record-proposal-and-attachments

Conversation

@jeremi

@jeremi jeremi commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Record history names the Proposal that wrote a revision when the caller can read that Proposal.
  • An immediate Action can store a file with the record it creates. Availability and target conditions can be checked before invocation. Invoke accepts an attachments member in its JSON body and refuses files whose verification has already rejected them.
  • An applied Proposal can promote an existing file to a write-once record slot without copying the bytes. Rust, Node.js and Python clients can download record files.
  • History erasure keeps current record files by default and clears attachment attribution when it erases the revision that filled a slot. The same acknowledged command erases files named by their slot ID in eraseFiles, even if earlier erasure already removed the record’s retained revisions. The result and audit entry count erased and kept file references and removed Proposal links.
  • Erased Record and Proposal slot markers keep their identity and erasure time. The storage cleanup ledger retains confirmed external object keys for later rechecks of interrupted writes.

Upgrade and operation

Install this version on a fresh database. The managed schema fingerprint changes. Update registry revision pins, including for projects with no attachment slots.

Declare record slots under attachments and give readers the applicable slots through readableAttachments. Downloads enforce the same lifecycle, disclosure and row checks as the record GET. The operation audit identifies attachment reads and refusals. An undeclared slot gets the general attachment operation.

A current Proposal read omits links to erased revisions. While the original receipt is retained, the same authorized caller can replay the apply with the original idempotency key. A live Proposal keeps its own attachment and related held responses after erasure of a promoted Record slot. Erase the Proposal submission under the applicable retention policy when both references must be removed. Bytes remain while a live reference needs them. Erase-and-rebaseline keeps the record’s files.

Evidence

  • At 217ba9891b, the portability suite passed all 12 tests on both PostgreSQL 17.11 and 18.4. Both produced the same managed schema fingerprint after the attachment metadata constraints changed. The full production-shaped Docs check passed locally after the retention page’s first-use wording fix.

  • At facd434db1, 27 PostgreSQL attachment tests passed through the existing router fixture. This includes preflight, known rejected files, role and lifecycle visibility, default and named file erasure, a later erasure without retained revisions, erasure counts, stripped metadata and audit identities.

  • Five native retention tests and six CLI history erasure checks passed. The retained object key recheck is covered by the native retention suite. A focused ordinary history erasure case and the route parser check also passed.

  • Focused BReg and bregctl Clippy, formatting, product validation, identifier reference checks, source neutrality, documentation data tests and evidence anchors passed.

  • Earlier on this branch, the library suite passed 921 tests. The Proposal, Proposal security, Proposal storage, history erasure and migration suites passed 59, 22, 13, 22 and 61 tests. The contract and client contract gates passed.

  • The current review fixes were exercised on fresh disposable PostgreSQL. An in-place upgrade, direct immediate-Action external storage rollback/replay, and the remaining client streaming assertions remain unverified. Full workspace CI runs separately.

Record slots are write-once. Proposal Apply rechecks the file and its verification inside the write transaction. History checks the Proposal grant, ownership and row boundaries before exposing a link. See the security matrix BREG-SEC-217 through BREG-SEC-223.

Every commit carries a DCO signoff.

Closes #2794, closes #2795

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 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-26T21:30:51.201139Z 9bc3d9b New commits
ℹ️ 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: c639ad28d2

ℹ️ 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 thread crates/registry-breg/src/api/actions.rs Resolved
@jeremi

jeremi commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Independent review (Claude, read-only, at the author's request)

What was reviewed. Commit ac8408a292, the full diff against main, through four lenses: read access and disclosure, the write path and storage, erasure and schema, and clients and docs. Findings come from reading code and tests. The reviewers built and ran nothing, so nothing below is reproduced. Line numbers are at ac8408a292.

Verdict. The access control is sound. The download route and the history link both fail closed, and I found no way to read a file or a Proposal link without the grants the docs describe. The one bug that blocked the reviewed commit is fixed by 7fb8b2e87f, pushed while this review ran. Three behaviours need a product decision before merge, because they are irreversible for an operator or a record. The rest is audit detail, tests and docs.

Blocked the reviewed commit, now fixed

B1. Availability and target-conditions routes answered 400 for any immediate Action that declares files. crates/registry-breg/src/api/actions.rs:325-329 validated request files on every route, but only the invoke route parses them. This is the open Codex thread, and it was correct. 7fb8b2e87f moves the validation into the invoke arm. I read that commit and the fix is complete: the mutation layer validates again, and the other routes still refuse an attachments member at parse time. One addition for its test: assert that an attachments member is still refused on those two routes. The thread can be resolved.

Needs a decision

D1. Erasing old history removes a live record's file for good.

  • erase_record_attachments (crates/registry-breg/src/attachment_store.rs:933-963, called from history_erasure.rs:271-280) erases every reference with attached_revision <= erase_through_revision. History erasure starts at revision 1, and a file stored at create sits at revision 1.
  • So any history erasure of such a record removes its file. Example: a licence record gets its certificate at revision 1 and is now at revision 5. The operator erases revisions 1 to 3 to drop an old misspelt name. The download now answers 404, the write-once slot can never be filled again, and the bytes go once nothing else refers to them.
  • The PR's own test history_erasure_removes_a_promoted_file_and_the_link_to_the_erased_revision does this: the record is at revision 2, erasure runs through 1, and the file is gone.
  • docs/site/src/content/docs/operate/breg-retention.mdx:154-157 says this happens when "erasing history through the current revision". The code does it for any erasure that reaches the revision that filled the slot.
  • Options: erase a file only when the erasure covers the current revision, require an explicit opt-in to erase files, or keep the behaviour and say so plainly with a count in the outcome (see S1). I lean to the first, with medium confidence, because the file describes the live record and not only the revision that carried it in.

D2. An immediate Action can commit a file that is unverified or already rejected, which leaves a dead slot.

  • attach_record_reference and put_record_attachment (attachment_store.rs:749-802 and following) never look at the verification verdict. request_verification is ON CONFLICT DO NOTHING, so bytes that already carry a rejected verdict are accepted again.
  • The file is never served. Downloads stay concealed until a verdict permits content. But the record commits with a slot nobody can read, and write-once means it can never be refilled, including after erasure.
  • Promotion from a Proposal refuses a pending or rejected file with 412, so the two write paths disagree.
  • At minimum, refuse bytes whose stored verdict is already rejected. Separately, decide what a later rejection means for a write-once slot.

D3. The marker left by erasure keeps the file's SHA-256, media type and size indefinitely.

  • The erase UPDATE nulls only attached_by and attached_at (attachment_store.rs:949-956). The columns are NOT NULL, and no path scrubs the row. The retention page documents this.
  • Write-once needs only the key and erased_at. A retained digest of a personal document lets anyone who holds a copy confirm that the record once held it.
  • This matches what Proposal attachment tombstones already do, so it is a consistent choice. It deserves an explicit yes for record files, which will often be identity documents.

Should fix

S1. The erasure outcome and audit entry do not say what was destroyed. The count returned by erase_record_attachments is discarded, and delete_proposal_result_links returns nothing (history_erasure.rs:271-283, :456-475). HistoryErasureOutcome and the audit entry have no field for file references or Proposal links removed. History erasure has no dry run. With D1, an operator can destroy a certificate and no report or audit record says so.

S2. A refused download is audited as a refused record GET, with no slot. The early returns in download (crates/registry-breg/src/api/record_attachments.rs:43-50, :58-66, :74-82, :99-107) call the shared refusal helpers, which write the route's own operation id. Only a download that reaches the service gets the :attachment:<slot> identity. A profile without the slot grant can probe many records, and a search of the audit for attachment operations finds nothing. The security page describes the per-slot name without this limit.

S3. BREG-SEC-218 claims lifecycle and record-level disclosure for downloads, and no test pins either. The visibility check in crates/registry-breg/src/postgres/record_attachment_read.rs:88-99 is its own SELECT 1 over the same relation the GET uses. It is correct today. No test downloads from a tombstoned record or from a record hidden by a withhold: record condition. Add both cases, each asserted against the GET answer, so the shared-relation claim becomes a regression test.

S4. A file-carrying invoke holds the whole request in memory through the transaction. Files travel as base64 inside the JSON body. At the compile-time maxima (8 slots of 16 MiB) one request is about 179 MB, and parsing holds the raw body, the JSON value and the decoded bytes at once. body stays alive across invoke_action because only its length is needed (api/actions.rs:369), so it is held through the database transaction and any object-store PUT. I found no limit on concurrent bodies in this crate. Dropping body after parsing is a one-line gain. A cap on total file bytes per Action, or a streaming route, is the larger answer. The download path has a smaller version of the same thing: up to three copies of the file (record_attachment_read.rs:205, record_attachments.rs:153).

S5. The immediate-Action write path on external object storage has no test, and it stages before guards. postgres_proposal_s3.rs adds only promotion cases, and postgres_record_attachments.rs uses the database backend. Unpinned: a rollback after the PUT, a replay, and a PUT racing the deletion retry. Staging also commits before guard evaluation (mutation/action.rs:605), so every refused request with new bytes leaves a durable staged row that only operator-run cleanup clears.

S6. "Install on a fresh database" is not enforced. The PR adds a managed table and two indexes but no engine feature gate, unlike the Record timer store precedent. Reading suggests a successor apply would create the table in place before catalog verification, which is an untested upgrade path that contradicts the changelog. Reading also suggests the new binary on an old database fails with the generic catalog-drift message and not a fresh-install message. Either test and document the in-place path, or add the gate and the message. Related: the operator upgrade pages do not carry the requirement (the changelog does), and the changelog bullet about registry revision pins (products/breg/CHANGELOG.md:49-52) is not marked BREAKING although pinned deployments stop matching.

S7. Docs that would mislead.

  • The PR description says files go through "the multipart REST route". There is no multipart handling. The invoke route requires application/json and reads attachments from the JSON body, each with contentType, a lowercase hex sha256 and base64 content. The changelog and configure/breg.mdx are right. The description should be corrected, and configure/breg.mdx could state the content type.
  • docs/site/src/content/docs/security/breg.mdx:231-232: the new sentence about record downloads writing a subject access log entry sits directly before "Those reads are recorded only in BReg's audit records", which now reads as a contradiction.
  • docs/site/src/content/docs/reference/breg-api.mdx:606-622 and docs/site/src/data/breg-api.yaml:33 never document the attachments member, which is required on invoke for an Action that declares files.
  • docs/site/src/content/docs/configure/breg.mdx:174 does not tell authors that a slot's classification does not gate downloads. Readable fields that outrank their record type get a compiler finding, and readableAttachments gets none.

S8. Tests that cannot fail, or that assert presence but not the promised absence.

  • postgres_record_attachments.rs:1544 checks "bytes no reference holds are removed" through a helper that filters state='live' (:555). Bytes left in delete_pending would pass.
  • every_refusal_leaves_no_record_and_no_file (:1016): every case is refused before any attachment write, so its no-blob and no-reference assertions cannot fail.
  • promotion_rechecks_a_verdict_rejected_after_the_manifest_check flips approved to rejected through SQL, a transition the worker cannot make.
  • Missing: external-storage cleanup after history erasure, verdict retirement after a record reference is erased, and a negative test that another caller cannot replay the apply receipt after erasure. The code enforces that last one.
  • The rebaseline test writes its flip ledger rows with SQL instead of a real field-encryption activation.
  • Client tests: none hits the streaming size bound, the Node.js and Python digest tests assert only that some protocol error occurred, and the Rust 404 case does not check the status or code.

Nits

  • crates/registry-breg/src/postgres/revision_read.rs:374-392: a history read writes the subject access log and commits before the Proposal link check, which can then answer 503. The data subject sees a read that returned nothing.
  • revision_read.rs:857-894: the link check runs one sequential transaction per distinct Proposal under one 30 second budget. A record amended by many Proposals can make history unreadable under load, for callers who hold the Proposal grant only.
  • crates/registry-breg/src/mutation/proposal/context_projection.rs:102: review-context reads take content-hash locks in field-name order, and apply now takes them in hash order. Two Proposals sharing two identical files can deadlock. PostgreSQL aborts one side, which answers 503.
  • api/actions.rs:755-766: the body bound leaves no room for JSON escapes inside the base64 text. A client that escapes / gets 413 for a file within maximumBytes. An oversized input on a route that takes files is also labelled attachment.too-large (:316), which breg-api.yaml:86 does not say.
  • products/breg/CHANGELOG.md:34-35: "History erasure removes a record's file references" is too broad. It removes those attached at or before the erased revision.
  • docs/site/src/data/breg-api.yaml:14: the download row omits that any other query key answers 400 query.invalid and that a caller with no principal gets the concealed 404.
  • docs/site/src/content/docs/operate/breg-retention.mdx:37: the table row says history erase removes the held responses that could replay revisions, while lines 113-121 say the apply receipt is kept.
  • docs/site/src/content/docs/configure/breg.mdx:196: a file name also cannot reuse an input's apiName, not only its ID.
  • crates/registry-breg-client/README.md:298-305: a missing blank line merges the record download text into the Proposal attachment paragraph.
  • Node.js and Python record downloads take no cancellation option, the same as the Proposal download.
  • docs/site/src/content/docs/operate/breg-changes.mdx:546: the reflowed line keeps a semicolon.
  • registry-project.schema.json: writeOnce is a plain boolean, but the compiler requires true. It could be const: true. A slot that nothing fills and no profile reads compiles without a finding. In single-role mode, write-once rests on Rust alone.
  • The Proposal retention dry run does not tell the operator that a promoted file stays readable through the record.

Open questions I could not settle by reading

  • Can a hook-driven path name an immediate Action that declares files? Those paths pass no files, and the count check then answers 503 and not a terminal refusal. The compiler excludes only Evidence and timer Actions.
  • Does a successor package that drops a slot or a record type leave live file references the migration planner never sees?
  • On external storage, a download holds a transaction, a pool session and the content-hash lock while it fetches up to 16 MiB. Is that hold bounded by a client or request timeout?
  • The history link discloses a Proposal identifier without writing a Proposal read audit entry. The docs list this as a limit. It is a policy call.

Read and found sound

  • Download access. The same admission as a record GET, the slot grant checked before I/O and again in the service, visibility through the GET's own relation in the same row-level-security transaction, and one concealed 404 for every refusal, so status codes give no existence oracle. Unverified and erased files are never served. Bytes are released only after size and digest match.
  • Response headers. Constant Content-Disposition: attachment with no file name, nosniff, no-store, a validated media type, and an RFC 9530 digest.
  • History link. It calls the Proposal read's own authorization per Proposal for the history caller, fails closed on any error, and excludes task-grant callers and standing agents structurally. Snapshot and as of reads never carry it.
  • Write path. Write-once by primary key with insert-only rights for the runtime role, both write paths atomic with the record, and every deleter rechecking references under the same content-hash lock every inserter holds, on both backends. Idempotency binds name, media type, digest and size.
  • Erasure. No order of history erasure and Proposal erasure strands bytes or deletes bytes a live slot needs. Receipt replay returns identifiers only, to the same authorized caller. Erase-and-rebaseline keeps the record's files.
  • Projects without slots. They compile as before apart from four added problem codes, so the statement that every registry revision changes is true and tested.
  • Clients. The download is bounded while streaming, redirects are never followed, nothing is written to disk, the digest is verified, and the three bindings and their typings agree.
  • Security matrix. All 21 tests named under BREG-SEC-217 to 223 exist.
  • Hygiene. No internal names, hosts or paths in the diff, and no em dashes in changed prose.

@jeremi

jeremi commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Ruling on D2 (from the maintainer): option (a). The immediate-Action write path refuses bytes whose stored verification verdict is already rejected, so it agrees with promotion on the known-bad case. Please add a failing-first test for it. What a later rejection means for a write-once slot stays open and is not part of this change.

D1 and D3 are still being researched. Please hold both until a ruling is posted here.

@jeremi

jeremi commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Rulings on D1 and D3 (from the maintainer)

These complete the three decisions in the review above. D2 (a) was posted earlier. All three ship in this pull request, each with a failing-first test.

D1: history erasure does not remove a live record's file

A slot file is current state of the record. It is write-once, so it never has an earlier version, and the download takes no revision. History erasure removes earlier state. This matches what the retention page already promises ("it does not remove the current record") and how a field value set at revision 1 survives erasure of revision 1. It is also how FHIR delete-history and object-store noncurrent-version expiry behave: both leave the current version alone.

  1. History erasure keeps the file. When the erasure reaches the revision that filled a slot, it clears who attached the file and when. It keeps the reference, so the download still works.
  2. Erasing a file is an explicit choice. The erasure request names the slots to erase, for example "eraseFiles": ["certificate"]. Without it, no file is erased. A named slot that the record type does not declare is refused before anything is erased. The member name is a suggestion. Keep the one command, its acknowledgement flag and its audit entry.
  3. The report and the audit entry say what happened. Both count file references erased, file references kept, and Proposal links removed. This closes S1 in the review.
  4. Erase-and-rebaseline is unchanged. It keeps the record's files. A later history erasure no longer removes them either, because of point 1.
  5. Docs. Rewrite "Files kept with the record" and its caution on the retention page, the "What cannot be undone" row for history erase, the changelog entry, and the security page and matrix text for the erasure invariant, so each says that a file goes only when the request names its slot.
  6. Tests. The existing erasure test currently proves the old behaviour. It should now prove that erasing through the filling revision keeps the file and clears its attribution. Add cases for a named slot (file gone, download 404, counts in the outcome and the audit entry), an undeclared slot name (refused, nothing erased), and a record at a later revision than the erasure boundary.

D3: the erased marker keeps no digest

After a file is erased, the slot's marker keeps the key (record type, record, slot) and when it was erased. That is all write-once needs. It drops the SHA-256 digest, the media type and the size.

A hash of a personal document is pseudonymised personal data, not anonymous data: anyone who holds the document can recompute the hash and confirm the record once held it. Records-management practice says the same. A destroyed item leaves a residual with identifiers and timestamps, and other metadata is pruned.

  1. Null sha256, content_type and byte_size on erase, and relax the column constraints for erased rows only. A live reference keeps all three, enforced in the database.
  2. Confirm that no audit entry, outbox payload or held response keeps the digest of an erased record file. If one does, say so here.
  3. Update the retention page sentence that lists what the marker keeps.
  4. Test that an erased marker holds no digest, media type or size, and that the slot still refuses a second fill.

D3b: the same rule for the existing tombstones

Proposal attachment tombstones and confirmed external-deletion tombstones keep digests in the same way today. Apply the same rule to them in this pull request, so the product has one answer.

  • An external-deletion row needs its digest until the deletion is confirmed, because the digest is the object key. Scrub it once the deletion is confirmed.
  • If this turns out to be large, or something needs those digests for a reason not traced here, say so on this pull request before cutting it. Do not drop it silently.

Still open from the review

The should-fix items S2 to S8 and the nits stand as written. S1 is covered by D1 point 3. The retention caution in S7 and the erasure test in S8 are rewritten by D1.

jeremi commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

D3b has one storage dependency. The Proposal attachment row can drop its digest, media type and size after erasure, leaving only its slot identity and erasure timestamp.

The confirmed external-deletion row serves a different purpose. Cleanup still uses its digest as the object key on later runs. An upload that was interrupted locally can finish after the object store first confirmed absence. The retained key lets the next cleanup detect and remove that object. Scrubbing the key on first confirmation would remove that guarantee. Cleanup code · Existing retention test

I’ll keep the record and Proposal reference changes in this PR. The external cleanup row needs to stay in place until we can prove that an interrupted write has finished, or give cleanup a different durable object key.

jeremi commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

A still-live Proposal can also retain the same file digest after its promoted Record slot is erased. The held Proposal response can include that Proposal's live attachment metadata. The existing Proposal erasure path scrubs the submission's linked responses. This retention boundary matters when the request is to erase all copies of a promoted file. Held Proposal response · Proposal response erasure

Record history items and single-revision reads gain an optional proposal member (actionId, proposalId, submissionVersion) derived from the stored Proposal result. It appears only when the caller can read that Proposal under the existing Proposal read authorization, and is absent for immediate Actions. The link survives operator erasure.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Record types can declare attachment slots in the Proposal slot shape. An
immediate Action create effect can fill a slot with a file sent in the
same request, and the reference commits with the record, its history,
the idempotency receipt and the outbox. A profile granted the slot
through readableAttachments can download it from the record's route
inside its row boundary. The response carries the stored digest and
media type.

Record erasure removes the reference and retires bytes nothing else
refers to. Proposal retention counts record references before it
deletes content. The Rust client gains download_record_attachment.

Record file references live in a new managed table, so the managed
schema fingerprint changes. Install the release on a fresh database.

Every registry revision moves because the problem code list grew, while
per-action contract revisions stay the same. The explain examples were
regenerated with the test's own serialization and the ODRL examples are
bregctl generate odrl output.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Describe how a record type declares a slot, how an immediate Action
writes it, who can download it, and how record retention and erasure
treat the file.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
A revision read now returns its record connection to the pool before it
checks Proposal links, so a pool of one connection no longer fails the
read. All the checks of one read share one deadline. The check reads the
applied Proposal without a row lock, so a lifecycle command holding that
row no longer delays history. Only a refused read or a failed
precondition omits the member. A conflict, a store failure or the
deadline fails the read with 503 instead of hiding the link.

Proposal result rows gain an index by target record and revision, which
the link lookup uses. The managed schema fingerprint changes with it, so
install the release on a fresh database.

Links attach in a stable order. The generated OpenAPI document declares
the proposal member only for a registry with a Proposal Action, and the
caller-filtered document only on revision routes where the caller would
receive it.

New PostgreSQL tests cover the task-grant exclusion, the Proposal row
boundary, a byte comparison with an unlinked response, the single
revision read, a held row lock, a failing check and the caller-filtered
document. Each omission test has a positive control. The security and
API reference pages name the residual risks: response timing, no
Proposal-read audit for the check, and the link disappearing once a
target is tombstoned. The Python client README describes the member. The
compiler contract test lists the attachment problem codes the generated
OpenAPI document already carries.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
A reviewed decision often rests on a supporting document. Before this, a
record slot could only take a file from an immediate Action request, so a
file reviewed with a Proposal could not stay on the record it changed.

The create or patch effect of a Proposal Action can now name a Proposal
attachment slot to promote, as attachments.<record slot>.fromAttachment.
bregctl check refuses a promotion from an undeclared Proposal slot, into a
slot the target record type does not declare, from a Proposal slot that
accepts a content type or size the record slot does not, into a record
slot classified less restricted than the Proposal slot, from a tombstone
effect, and a second promotion into one slot of one record. Promotions are
part of the Action definition revision.

The request-file bindings of an immediate Action were missing from its
definition revision, so renaming the request part a slot takes its file
from left the revision unchanged. They are now part of it. An Action
without promotions or request files keeps its revision byte for byte.

Apply adds a record reference to the content hash the frozen Proposal file
already holds, so no bytes are copied. It rechecks the file against the
record slot and the frozen submission inside the apply transaction. A
filled slot answers 409 attachment.slot-write-once, and a file whose
verification is pending or was rejected answers 412 precondition.failed.
Either refusal rolls back every effect of the apply. An empty optional
Proposal slot leaves the record slot empty. Proposal erasure keeps the
bytes a record refers to and removes the rest.

The authoring schemas are regenerated. The apply OpenAPI 409 description
names the write-once refusal only for a profile that may apply a
promoting Action. New invariants BREG-SEC-221 to BREG-SEC-223 cover the
check bounds and verification, the write-once rollback, and erasure.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
The Rust client could already download a record's file, but Node.js and
Python callers could not, so an application in either language had to
reconstruct the request and its response checks itself.

Node.js gains downloadRecordAttachment and Python gains
download_record_attachment. Both call the canonical Rust client, so the
bytes are returned only when they match the service's Repr-Digest, and the
bounded body and redacted errors carry over. The capability inventory, the
type declarations and the stack facade copies are updated. Tests also check
that the Proposal link on a record revision reaches callers in both
languages.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Authors need to know how a Proposal file reaches a record, what bregctl
check refuses, and what apply answers when it cannot promote. Operators
need to know that erasing a Proposal keeps a promoted file on the record.

The Proposal configuration page gains a section with an example and the
refusals. The record type, retention, security and API reference pages and
the changelog describe promotion.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Three committed values went stale earlier on this branch. The four record
attachment Problems joined the generated Problem schema, which moves every
pinned fixture's artifact revision and the registry revision in the
evidence-source export example. The index of Proposal results by target
revision and the record attachment live-reference index moved the portable
managed schema fingerprint. The changelog already announces both changes.
SQL digests and Action fingerprints stay fixed. The example is rewritten
with the `bregctl generate evidence-source` command its test documents.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
An immediate Action that declares record attachments read its body with a
plain bounded read, so a file far over its slot answered 400 with no code.
The handler now reads frames itself and tells a body that is too long apart
from a broken one. On an invocation that takes files, too long answers
413 attachment.too-large. Availability and target conditions take no files,
so they keep the snapshot bound with no file slack.

The generated OpenAPI document now lists attachment.too-large (413),
attachment.content-type (415), attachment.digest-mismatch (422) and
attachment.slot-write-once (409) on an invocation that takes files.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
The security page said a promoted file never loses protection. The
classification label never drops, but bregctl check reads it once, and who
downloads the file is decided by the record grants' readableAttachments.

An erased slot's marker is not value-free. It keeps the digest, media type,
size and the filling revision, and drops who filled the slot and when.

The security page now also says that an immediate Action's file commits
before verification, so a rejected file leaves a slot that cannot be filled
again, and that field disclosure conditions and field encryption do not
cover file slots. The retention page warns that erasing history through the
current revision removes a live record's file for good.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
The client READMEs said the record download reads only files an applied
Proposal promoted. It also reads files an immediate Action wrote. A slot
holds up to 16 MiB while the clients read 8 MiB by default, so each README
names the option that raises the bound. The clients cannot send request
files yet, so an immediate Action that declares attachments is not
invocable from them, and the READMEs, the capability page and the changelog
now say so.

The Node.js and Python binding tests now pin a concealed download's Problem
and a file larger than the response bound.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
A store failure after a record file download's attempt returned without
the Refused terminal that GET writes, so the audit showed only an
unfinished request. The failure now goes through the read service's
refused-read path.

The download's operation identity also names the slot, as
<get operation>:attachment:<slot>. Slot ids are configuration, not values,
so the audit and the subject access log can tell two slots apart.

The record download test now asserts the attempt and Returned terminal, the
Refused terminal of a concealed 404 and of a store failure, and one subject
access log row per released file.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
The Proposal's own author, acting as an agent without a task grant, holds a
profile that reads the record history and owns the Proposal. Only the
standing-agent ceiling keeps the link from it. The test pins that ceiling
on record history, beside the task-grant case, with a traceability row.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
BREG-SEC-221's cited test got its 412 from the manifest check, so removing
the promotion's in-transaction recheck broke no test. The new test pauses
the apply inside its effect write with a trigger and an advisory lock,
rejects the file while it waits, and expects 412 with no record reference
and no new revision. With the recheck disabled, the test fails.

The matrix now names what the tests pin: the recheck runs under the
content-hash lock and requires a verdict that still permits the content.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Apply locked each promoted file's content hash in effect order, while the
immediate path sorts its files by hash. Two applies that share files in
opposite effect orders could each hold the hash the other waits for.
Promotions now run in hash order.

The test holds the lower hash, lets an apply whose first effect promotes
the higher hash wait on it, and checks that the higher hash is still free.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
write_action_attachments returned at once on an empty file list, even for
an Action that declares files. Only a request carries files, and bregctl
check keeps them off timer, Evidence and handler Actions, but a compiled
registry that binds a file to such an Action committed the record without
its file. A file count that differs from the declared count now answers
Unavailable and rolls the write back.

The test binds a file to a create-only timer Action in the compiled
registry and checks that the timer commits no record, revision, outbox
row, receipt, application or result.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
The schema fingerprint comment listed the record attachment index but not
the registry_record_attachments table that holds record file references.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
authorize_proposal_document read every install_target error as a refusal.
install_target turns a database error into a connection error and keeps
rejected contexts as configuration errors, so a store failure was taken
for a refusal. A record history link check then left the Proposal link out
instead of answering 503 as the docs promise. A rejected context still
refuses, and any other error now answers Unavailable.

install_target keeps no SQLSTATE, so the mapping cannot use
map_database_error. No test seam can make the context statement fail
between the checks around it, so a unit test pins the mapping.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
The docs style check flags a sentence over 25 words in the Rust README.
The three bindings keep the same wording.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
A Proposal's result row names the revision its application wrote, and
its foreign key made history erasure through that revision roll back.
The erasure now deletes those result rows in the same transaction, so a
file the Proposal promoted is erased with the revision. The foreign key
stays as it is.

A stored application receipt may link a subset of its frozen targets,
possibly none, so the Proposal still reads and names no erased
revision. The apply itself still links every target. An applied
Proposal's read checks its frozen targets as well as its result rows,
so a record whose link was erased still bounds who reads the Proposal.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
The retention, configuration and security pages and the changelog say
that history erasure removes a Proposal's link to an erased revision,
that the Proposal keeps its state and application, and that a promoted
file's bytes stay until the Proposal's detail is erased.

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
…receipt

Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
@jeremi jeremi added the ci:full Run the heavy integration tier on this pull request label Nov 26, 2026 — with ChatGPT Codex Connector
@jeremi
jeremi force-pushed the feat/breg-record-proposal-and-attachments branch from 217ba98 to 62b2bf2 Compare November 26, 2026 20:28

@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: 62b2bf29fa

ℹ️ 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 thread crates/registry-breg/src/package.rs Resolved
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
@jeremi
jeremi added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit 6b71864 Nov 26, 2026
77 checks passed
@jeremi
jeremi deleted the feat/breg-record-proposal-and-attachments branch November 26, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:full Run the heavy integration tier on this pull request

Projects

None yet

1 participant