Skip to content

feat(app): add atomic learning promotion verify hook - #96

Merged
riquelmechile merged 2 commits into
mainfrom
feat/learning-verify-work
Aug 22, 2026
Merged

riquelmechile merged 2 commits into
mainfrom
feat/learning-verify-work

Conversation

@riquelmechile

Copy link
Copy Markdown
Owner

Linked issue

Closes #89

PR type

  • Bug fix (type:bug)
  • New feature (type:feature)
  • Documentation only (type:docs)
  • Code refactoring (type:refactor)
  • Maintenance / tooling (type:chore)
  • Breaking change (type:breaking-change)

Summary

  • Work unit 3 child W3D1 (auto-split, stacked-to-main on merged W3C3 test(app): add learning evaluation seam typed coverage matrix #95, 394 + 23-line review correction ≤ 400+correction budget): the atomic learning verify hook (task 2.6) + real-rollback proof tests.
  • verifyWorkWithProofAtomically in packages/app/src/worker/verify.ts: ONE transaction owns BOTH writes — the completed → verified CAS win AND the append-only verification proof (verifier actor, delegation principal, fresh active Delegation, policy reference, canonical scope). Failures abort + roll BOTH back and return as typed VALUES (work-not-found, invalid-work-state, verifier-not-distinct, version-conflict, delegation-unavailable, proof-conflict) — finalize twin pattern, zero partial writes.
  • Review correction R3-001 (reliability lens, CRITICAL): the documented DISTINCT-verifier requirement is now ENFORCED — a proposer cannot verify their own work (verifier-not-distinct, rejected before any state transition or proof append).
  • Strict TDD: RED (missing export) → GREEN 3/3 core; correction adds the self-approval rejection test (4/4 focused); real rollback assertions via capture/restore stores (work back to completed, no proof row after conflict abort). Full gate pnpm check exit 0 — 1580 passed | 6 skipped, 0 new warnings.

Changes

File or area Change
packages/app/src/worker/verify.ts Atomic verify hook + typed failures + SoD guard (+122/−2 with correction)
packages/app/test/worker-verify-work.test.ts Atomic win + no-partial-writes + self-approval tests (new, 293)

Verification

  • Focused checks pass: pnpm exec vitest run packages/app/test/worker-verify-work.test.ts → 4/4
  • The affected runtime scenario was exercised, or is not applicable (transaction semantics proven with real capture/restore rollback doubles; PG adapter arrives in work unit 4)
  • Full gate: pnpm check GREEN — 1580 passed | 6 skipped, 0 new warnings
  • Native RDD: lineage review-58d7deee4fb6f229 (medium, reliability lens) — one bounded correction transaction for CRITICAL R3-001 (23 ≤ 197 budget), targeted validator + correction evidence captured, final state approved; pre-pr gate allow

Contributor checklist

  • The linked issue is open and has status:approved.
  • Exactly one PR type is selected and its matching type:* label is applied.
  • The branch name follows type/lowercase-description.
  • Tests and documentation are updated where behavior changed.
  • Commits use Conventional Commit format and contain no attribution trailers.
  • No secrets or unrelated changes are included.

Work unit 3 child 7 (learning-promotion): ONE transaction owns the
completed-to-verified CAS win and the append-only verification proof
(distinct verifier, fresh active delegation, policy reference); every
failure rolls both writes back - no half-verified work, no orphan proof.
@riquelmechile riquelmechile added the type:feature Feature pull request label Aug 22, 2026
@riquelmechile
riquelmechile merged commit 0df70e7 into main Aug 22, 2026
2 of 3 checks passed
@riquelmechile
riquelmechile deleted the feat/learning-verify-work branch August 22, 2026 00:04

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

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

const now = deps.now?.() ?? Date.now();
if (freshDelegation.validFrom > now || freshDelegation.validUntil <= now)
throw new VerifyWorkAbortError('delegation-unavailable');
const cas = await work.updateIfVersion({ ...current, state: 'verified' }, current.version);

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 Validate the delegation grant before verifying work

When the delegation is active and in-window but its authorityScope.actions omits learning.promote or its scope belongs to another subject, this CAS still permanently transitions the Work to verified and appends a proof. InMemoryPromotionAuthorityRepository.resolve subsequently rejects that proof on the action/scope checks, leaving terminal Work with unusable promotion authority and no legal verification retry. Validate the delegation action and canonical promotion scope before performing the CAS.

Useful? React with 👍 / 👎.

Comment on lines +148 to +149
if (deps.verifier === current.proposer)
throw new VerifyWorkAbortError('verifier-not-distinct', current);

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 Compare the verifier with the work executor

When the principal that executed and completed the Work invokes this hook as verifier but differs from the proposer, this guard passes and permits self-verification. The existing worker SoD contract makes executor/verifier an absolute distinct pair; checking only current.proposer does not enforce that invariant. Carry the completed Work's executor identity, such as the receipt actor or trusted execution context, into this transaction and reject an equal verifier before the CAS.

Useful? React with 👍 / 👎.

Comment on lines +173 to +174
scope: promotionScopeFor(input.companyId, input.subject),
policyRef: input.policyRef,

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 Validate verification inputs before starting the transaction

A structurally typed but semantically invalid subject can make this function reject instead of returning its advertised VerifyWorkResult; for example, an unpaired surrogate in skillId makes promotionScopeFor throw here, while a non-positive skillVersion reaches appendProof and throws there. These failures occur after the Work CAS, relying on rollback while escaping the typed failure contract entirely. Validate the subject and policy reference before any read/write and return an invalid-input result.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:feature Feature pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Wire promotion evaluation app seam, fakes, and atomic verify hook

1 participant