Skip to content

records(finalize): canonical bytes, completion rules, and the immutable version - #37

Merged
TusanHomichi merged 6 commits into
mainfrom
claude/milestone-2-org-rename-q8b2q8
Aug 31, 2026
Merged

TusanHomichi merged 6 commits into
mainfrom
claude/milestone-2-org-rename-q8b2q8

Conversation

@TusanHomichi

@TusanHomichi TusanHomichi commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

Primary Issue

Closes #36
Refs #32

Problem And Outcome

Milestone 4 slice 1 — the transition the whole milestone rests on, and the close of Milestone 0's one open deliverable (the canonical-record-bytes specification). After merge, an approved daily draft whose completion rules pass becomes an immutable EvaluationVersion: canonical bytes under a fixed format, a SHA-256 content hash, and a domain-separated chain hash — refused every later mutation by the database and presented from its stored envelope, never from live joins.

Changes

  • ADR 0011: the canonical format — RFC 8785 JCS semantics over a closed integer-safe subset (ASCII member names, integers below 2^53, floats refused as defects); the record-schema-1 envelope carrying the complete historical presentation of docs/domain-model.md's EvaluationVersion (attribution stream, trainee identity as presented including the profile fields Milestone 3 design: sessions, drafts, and attribution (owner decisions needed) #22 reserved, program/form/competency/scale definitions with anchors and task prompts, ratings with the explicit not-observed marker, narratives, review decisions, covered sessions with local-time representation, finalizing actor and the policy in force, instance identity, predecessor_content_hash committing lineage into the bytes); both fingerprints with the missing-predecessor treatment fixed (32 zero bytes); honest hash limits per ADR 0010; who finalizes (review_evaluation); Finalized as a derived status; completion rules enforced at submission as well as sealing so no state is a dead end
  • Migration 0010: evaluation_version — immutable (update/delete refuse), first versions only until amendments (slice 3 replaces that trigger), the review-approval workflow gate held raw against the pinned version's policy (missing policy fails closed); finalization_policy as versioned configuration frozen by publication — newly authored versions default all-on, while pre-existing versions are backfilled with review approval on and the two content rules off, because a completeness contract their drafts were never authored under could wedge an already-approved copy with no recovery (ADR 0011 records the retroactivity refusal); draft_rating.not_observed as a typed marker with its shape triggers (value and marker never combine); the frozen derivation gains the terminal finalized case, extending every existing freeze and event-stream guard through one owner
  • Services: canonical (the serializer that refuses what the format forbids, plus both hash constructions) and finalization (typed completion-rule evaluation shared with submission, the sealing transaction — carrying the sealer's viewed revision, rechecked in-transaction — building the envelope from committed rows, the sealed read presenting stored bytes, hash verification); drafts gain Finalized/DraftFinalized and the two completion refusals; saves accept the not-observed marking with ValueNotAllowed guarding the combination; program authoring, export, and import carry the policy (older exports import with conservative defaults)
  • Endpoints: POST /api/drafts/{id}/finalize (with the viewed revision), GET /api/drafts/{id}/version, GET /api/drafts/{id}/version/verify; refusal codes not_approved, narratives_incomplete, ratings_incomplete, already_finalized, stale_save, draft_finalized
  • Web: finalize action for reviewers with refusals surfaced verbatim, refusing to seal over a failed save or stale reload; the finalized record — header, instructions, content, finalizer, attribution, and review decisions — rendered entirely from the stored envelope with both fingerprints and verification (worded as consistency, never tamper-proofing), failing closed when the envelope cannot load; the not-observed checkbox on rating rows; the three policy toggles in version authoring
  • Tests: tests/canonical_format.rs — golden vectors for member ordering, exact JCS escapes, the integer boundaries, the content hash, and both chain cases; tests/finalization.rs — completion rules at submission and sealing, the stale-seal race in both policy modes, the not-observed marker and its refusal beside a value, byte-for-byte reproducibility of the stored envelope against its hash, the presentation field walk, raw forgeries (content edits, event appends, version mutation/deletion, a second version, an unapproved raw version, coverage shrink) all refused, audit and notice counts, and the API round trip; web/e2e/drafts.spec.ts extended to finalize the approved draft, read the sealed view, and verify the fingerprints in a real browser

Scope

  • In scope: slice 1 of Milestone 4 design: defensible records (owner decisions needed) #32 — canonical bytes, finalization, completion rules, hashes, database-enforced immutability
  • Out of scope: acknowledgments and the trainee timeline (slice 2), amendments and successor versions (slice 3 — the predecessor slot and chain rule ship now so slice 3 extends a defined chain), weekly summaries and task signoffs (slice 4), signatures (held), exports and PDFs (Milestone 5)

Verification

  • Listed the exact verification commands run below
  • Added or updated tests when behavior changed
  • Added or updated an ADR when a durable decision changed (ADR 0011)
  • All fixtures and examples are invented; no real agency data
Run at the final head (6ef2891) and at every pushed head:
- cargo fmt --check
- cargo clippy --workspace --all-targets -- -D warnings
- cargo test --workspace            (17 suites, 0 failed; +canonical_format, +finalization)
- npm run check                     (web/: 0 errors, 0 warnings)
- npm run build                     (web/)
- npm run e2e                       (web/: 5 passed; drafts.spec.ts extended with finalize → sealed view → verify)
- pr-gate CI green on every pushed head

Review And Merge Notes

  • Review focus: ADR 0011's format specification against the golden vectors; the 0010 triggers (immutability, the raw approval gate, first-versions-only, the not-observed shape); the completion-rule placement at submission and sealing (the dead-end analysis in the ADR); and the envelope builder's presentation completeness
  • Four Codex review rounds: seven confirmed findings fixed with tests (the viewed-revision sealing contract, the unsaved-edits sealing guard, envelope-sourced presentation across header, attribution, and finalizer identity, the fail-closed sealed view, and the retroactive-policy wedge removed at the backfill); one declined with rationale on the thread (an envelope-wide concurrency token over system-owned session metadata — the seal captures committed operational state at the sealing instant by design, and the token would add an acknowledgment loop, not integrity)
  • User or operator impact: existing installations migrate additively; pre-existing versions keep review approval required with the content rules off, new versions default all-on; reviewers gain the finalize action and sealed record view; drafts gain the not-observed marking

🤖 Generated with Claude Code

https://claude.ai/code/session_01DNP3dkn9c84v2YoNwx7KTg


Generated by Claude Code

claude added 3 commits August 31, 2026 04:41
ADR 0011 fixes the canonical record format Milestone 0 left open: RFC
8785 JCS semantics over a closed integer-safe subset, the record-schema
1 envelope carrying the complete historical presentation, the SHA-256
content hash, and the domain-separated chain hash with the
missing-predecessor treatment pinned. Migration 0010 adds the immutable
evaluation_version (update and delete refuse; first versions only until
amendments; the approval gate holds raw against the pinned version's
policy), finalization_policy as versioned per-version configuration
backfilled all-on and frozen by publication, the typed not_observed
rating marker, and the frozen derivation's terminal case. The
finalization service evaluates the completion rules typed, builds the
envelope from committed rows inside the write transaction, and the
finalized record presents from stored bytes only, with hash
verification reads. Drafts gain the Finalized status and refusal;
saves accept the explicit not-observed marking; program authoring,
export, and import carry the policy.

Refs #36.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DNP3dkn9c84v2YoNwx7KTg
The workspace gains the sealing surface: reviewers finalize with the
completion rules answering typed at the act; a finalized record swaps
the editing panels for a view rendered from the stored envelope —
trainee identity as presented, ratings with explicit not-observed
markings, narratives, both fingerprints, and hash verification with
the honest wording (consistency from what is stored, not proof against
a direct database writer). Rating rows take the typed "not observed"
marking, which clears and disables the value. Program version
authoring carries the three finalization rules with conservative
defaults.

Refs #36.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DNP3dkn9c84v2YoNwx7KTg
Designing the completion-rule tests surfaced a reachable dead end: with
review required, a reviewer could approve an incomplete draft, leaving
it frozen by approval yet refused by finalization, with no thaw path.
The rules now also gate submission — a draft never enters review
missing what finalization will demand — and with review off they answer
at the sealing attempt, where the copy is still editable; no state is a
dead end (ADR 0011 records the rule). The shared rule evaluators live
in one place and both paths call them.

tests/canonical_format.rs pins the format with golden vectors: member
ordering, exact JCS escapes, the integer subset's boundaries, the
content hash, and both chain cases. tests/finalization.rs drives the
rules through submission and sealing (including the explicit
not-observed marker and the marker-beside-value refusal), proves the
stored envelope reproduces its content hash byte-for-byte, walks the
presentation fields, and forges raw: content edits, event appends,
version mutation and deletion, a second version, an unapproved raw
version, and coverage shrink — every one refused. The API round trip
covers the typed refusal codes end to end, and the browser e2e
finalizes the approved draft, reads the sealed view, and verifies the
fingerprints. Review-era test fixtures pin their policies to the rules
they exercise.

Refs #36.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DNP3dkn9c84v2YoNwx7KTg
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-08-31T05:32:05.298025Z 6ef2891 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: fc46d37b24

ℹ️ 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 web/src/routes/drafts/[id]/+page.svelte Resolved
Comment thread web/src/routes/drafts/[id]/+page.svelte Resolved
Codex review, three confirmed findings. Finalization now carries the
revision the sealer viewed and rechecks it inside the write
transaction — the submission contract — so under a policy without
required review a racing save resolves as a typed stale refusal
instead of being sealed sight unseen; the API takes the revision and
the page passes it, reloading visibly on the stale answer. The page
also refuses to seal over a failed save or a stale reload, mirroring
the submission guard. And the finalized header (form, trainee,
program, covered sessions, instructions) now renders from the stored
envelope like the rest of the sealed view, so a later rename or
session close changes nothing the record presents. Tests drive the
exact race — a save landing between viewing and sealing — plus the
stale refusal after approval, and the API round trip carries the
revision.

Refs #36.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DNP3dkn9c84v2YoNwx7KTg

@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: ad3f9d3a67

ℹ️ 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 web/src/routes/drafts/[id]/+page.svelte Resolved
Comment thread web/src/routes/drafts/[id]/+page.svelte Resolved
Codex review, two confirmed follow-ups completing the
presents-from-envelope rule: on a finalized record the attribution
stream and review decisions now render the sealed identities from the
envelope instead of workspace rows that join current display names,
and the finalizer line reads the hashed envelope identity rather than
the metadata join — a contributor, reviewer, or finalizer renamed
later keeps the name the record was sealed with.

Refs #36.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DNP3dkn9c84v2YoNwx7KTg

@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: 7e8bf6be95

ℹ️ 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 web/src/routes/drafts/[id]/+page.svelte Resolved
Codex review, two confirmed findings. The 0010 backfill no longer
imposes the two content-completeness rules on versions that predate
them: an existing approved draft missing a required narrative — legal
when it was authored — would have wedged with no recovery (frozen
since submission, no further decision possible, finalization
refusing). Pre-existing versions keep review approval on with the
content rules off; newly authored versions default all-on, and ADR
0011 records why retroactive configuration is refused. And the
finalized page now fails closed: the envelope loads before the view is
presented, so a failed envelope fetch shows the error and nothing from
live joins — never a finalized record rendered from mutable rows.

Refs #36.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DNP3dkn9c84v2YoNwx7KTg

@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: 6ef2891b5a

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

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.

Milestone 4 slice 1: canonical bytes, finalization, and completion rules

2 participants