Skip to content

SDK assurance: measurements, assertions, lifecycle gates, and durable verdicts - #972

Merged
unbraind merged 4 commits into
mainfrom
feat/sdk-assurance-primitives
Aug 11, 2026
Merged

unbraind merged 4 commits into
mainfrom
feat/sdk-assurance-primitives

Conversation

@unbraind

@unbraind unbraind commented Aug 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

PM lineage

New open report lineages:

Verification

  • 481 test files and 7,201 tests pass
  • exact 100% statements, branches, functions, and lines: 51,922 / 38,124 / 10,679 / 50,153
  • strict ESLint, zero jscpd clones, 100% docstring gates, tracker measurement ratchets, contract snapshots, SDK public-surface snapshot, docs links, and 92 token surfaces pass
  • packed npm install plus direct CLI, npx, and bunx acceptance pass in a temporary project
  • 88-command package-first dogfood passes
  • pnpm audit reports no known vulnerabilities; GitHub dependency, code, and secret alert inventories are empty
  • changelog generated and checked with pm-changelog 2026.8.9
  • the local aggregate release pipeline passes through packed smoke and dogfood, then correctly stops because hosted DeepScan evidence cannot exist until this exact PR head is pushed; hosted analysis remains mandatory here

Summary by Sourcery

Introduce a unified SDK-owned project assurance system with measurements, assertions, lifecycle gates, and durable verdict history, exposed consistently via CLI, SDK, MCP, and runtime contracts.

New Features:

  • Add a declarative assurance model for measurements, assertions, and gates with bounded-cost evaluation and durable verdict recording.
  • Expose a new assurance action across CLI, PmClient, MCP, and contracts, including flag/schema support and positional/flag mappings.
  • Provide workspace-bound assurance runtime helpers that source data from items, history, graph, validate, health, and pluggable providers.
  • Document the project assurance primitives and expose new governance APIs on the public SDK surface.

Enhancements:

  • Extend tool-parameter schemas, enums, and contracts with assurance-specific fields, triggers, and schema-version bumps.
  • Propagate global CLI flag mappings and update action-schema parity tests for the new assurance command.
  • Export history-reading primitives to support durable verdict queries from the SDK.

Build:

  • Update pnpm lockfile and related baselines to reflect refreshed dependencies.

Documentation:

  • Add a dedicated Project Assurance Primitives guide and update the docs index with the new document.
  • Regenerate the generated agent command surface and related documentation baselines.

Tests:

  • Add comprehensive unit, integration, and CLI tests for assurance semantics, runtime bindings, transport normalization, and schema parity.
  • Update fixtures, contract snapshots, token-surface, and SDK public-surface baselines to cover the new assurance APIs.

Chores:

  • Track new open report lineages for projection cost, row-contract cost, and preflight health parity in the PM agents history and issues.
  • Refresh ESLint and @types/node development dependencies and update the changelog accordingly.

Summary by cubic

Adds SDK-owned assurance primitives and a new assurance command across CLI, SDK, PmClient, and MCP with durable verdict history. Hardens contracts, switches the hosted gate registry to stable workflow job IDs, refreshes eslint to 10.8.1 and @types/node to 26.2.0, and parallelizes gate context reads to speed up gate evaluation.

  • New Features

    • Measurements with composable sources (items/dependencies/graph/validate/health/history/links/provider), derived arithmetic, and compute-cost receipts.
    • Assertions with polarity, scope, lifetime, enforcement, required negative controls, typed ownership, and weakening detection.
    • Gates bound to lifecycle triggers; dry-run or recorded runs produce one verdict document and append immutable verdict entries.
    • CLI: assurance command (list, show, put, remove, run, verdicts) with shared flag/schema contracts; SDK and PmClient.assurance(...) route through one normalized action; docs in docs/ASSURANCE.md.
    • Performance: parallelized registry snapshot and workspace context reads before gate evaluation.
  • Bug Fixes

    • Strict kind-specific JSON Schemas for measurement/assertion/gate definitions, explicit terminal Decision authorization, and shared reference integrity.
    • Memoized and bounded evaluation with capped newest verdict reads; typed registry recovery and assurance_registry_invalid error guidance.
    • Public transport types and CLI/MCP parity improvements, including global flag mapping for --pm-path.
    • Hosted gate registry now inventories stable workflow job identities; updated inventory script, contracts, docs, and tests.
    • Added concurrency regression coverage for gate evaluation.

Written for commit 5b5359a. Summary will update on new commits.

Review in cubic

Introduce persisted measurements, assertions, trigger-bound gates, and immutable verdicts across the core CLI, public SDK, PmClient, generic actions, and MCP contracts.

Add generated runtime/tool/public-surface contracts, complete documentation and acceptance coverage, refresh policy-aged ESLint and Node type dependencies, generate the PM changelog, and track GH-969 through GH-971 in canonical PM lineages.

Tracked by pm-2lex4r, pm-lyfu7b, pm-wn6wot, pm-91xeam, and pm-8l1m5t.

@sourcery-ai sourcery-ai 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.

Sorry @unbraind, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@unbraind

Copy link
Copy Markdown
Owner Author

Acknowledged: this review provider is unavailable because its weekly quota is exhausted, so it supplied no code findings and is not counted as approval. The exact-head review loop remains gated on the available reviewers and required checks.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added assurance capabilities for defining measurements, assertions, and lifecycle gates.
    • Added CLI, SDK, and MCP support for managing declarations, running evaluations, performing dry runs, and viewing durable verdicts.
    • Added scoped validation, negative controls, cost limits, authorization checks, and audit history.
    • Added bounded verdict-history queries and deterministic pass, warn, or block results.
  • Documentation

    • Added comprehensive assurance guidance and linked it from the documentation index.
    • Updated the Unreleased changelog.
  • Chores

    • Refreshed compatible development tooling versions.

Walkthrough

The change adds persisted assurance measurements, assertions, gates, and verdicts. It exposes assurance through SDK, CLI, and MCP paths, updates contracts and public surfaces, adds documentation and tests, refreshes development dependencies, updates hosted gate registry identity, and records project-management outcomes.

Changes

Assurance delivery

Layer / File(s) Summary
Governance evaluation and persistence
src/sdk/governance/assurance.ts, tests/unit/sdk/assurance.spec.ts
Adds declaration validation, measurement evaluation, assertion and gate verdicts, cost accounting, audited persistence, authorization checks, and immutable verdict history.
Workspace runtime and transport dispatch
src/sdk/governance/assurance-runtime.ts, src/sdk/governance/assurance-action.ts, src/sdk/runtime.ts, tests/unit/sdk/assurance-action.spec.ts, tests/unit/sdk/assurance-runtime.spec.ts, tests/integration/assurance-runtime.integration.spec.ts
Builds workspace evaluation contexts and routes assurance operations through PmClient, SDK dispatch, and MCP-compatible action envelopes.
CLI and contract integration
src/cli/*, src/sdk/cli-contracts/*, tests/fixtures/contracts/full.json, tests/unit/cli/*, tests/unit/commands/*, tests/unit/sdk/action-schema-parity.spec.ts, tests/integration/assurance-cli.integration.spec.ts
Adds the assurance command, flags, subcommands, parameter schemas, mappings, public exports, contract fixtures, exit-code handling, and integration coverage.
Hosted gate registry identity
scripts/release/gate-registry.json, scripts/release/gate-registry.mjs, tests/unit/scripts/release/gate-registry.spec.ts, docs/TESTING.md
Changes gate discovery and validation to use stable workflow-file#job-id identifiers with registry version 2 and registered-pipeline inventory checks.
Documentation and release metadata
docs/ASSURANCE.md, docs/README.md, CHANGELOG.md, scripts/agent-token-surface-baseline.json, package.json
Documents assurance workflows and updates the changelog, token-surface metrics, and development dependency versions.
Project-management records
.agents/pm/**/*
Closes delivered assurance and dependency-refresh records, adds implementation and test evidence, and records issue entries for GH-969, GH-970, and GH-971.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client as PmClient or CLI
  participant Dispatch as runAssuranceDispatch
  participant Action as runAssuranceAction
  participant Runtime as createAssuranceWorkspaceContext
  participant Registry as Assurance registry
  Client->>Dispatch: submit assurance operation
  Dispatch->>Action: normalize arguments and options
  Action->>Runtime: create evaluation context
  Runtime->>Registry: read workspace declarations
  Registry-->>Runtime: return declarations and workspace state
  Runtime-->>Action: return evaluation context
  Action-->>Client: return declarations, receipts, or verdicts
Loading

Possibly related PRs

  • unbraind/pm-cli#397: Shares the CLI and SDK schema-parity surfaces extended by the assurance action.
  • unbraind/pm-cli#684: Shares the release gate registry and workflow-job identity changes.
  • unbraind/pm-cli#944: Provides related SDK provenance and history infrastructure used by assurance runtime evaluation.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.82% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The description links the PM lineage and GitHub reports and clearly states that reports #969–#971 are tracked, not implemented.
Out of Scope Changes check ✅ Passed The dependency refresh, changelog, gate registry, documentation, and issue tracking changes are described as supporting PR objectives.
Title check ✅ Passed The title clearly identifies the SDK assurance feature set, which is the primary change across the CLI, SDK, MCP, and durable verdict functionality.
Description check ✅ Passed The description directly summarizes the assurance primitives, integrations, contract updates, tests, documentation, dependency refresh, and tracked reports.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a new SDK-owned assurance system (measurements, assertions, lifecycle gates, durable verdict history) and wires it consistently through CLI, SDK, MCP, and runtime contracts, plus minor dependency and documentation updates.

Sequence diagram for running an assurance gate and recording a verdict

sequenceDiagram
  actor User
  participant CLI as pm_assurance_CLI
  participant Runtime as runAssuranceAction
  participant Assurance as evaluateAssuranceGate
  participant Context as createAssuranceWorkspaceContext
  participant Audit as recordAssuranceVerdict

  User->>CLI: pm assurance run <gate_id> --trigger <trigger>
  CLI->>Runtime: runAssuranceAction(action="run", id, trigger, dry_run?)
  Runtime->>Context: createAssuranceWorkspaceContext(pmRoot, tree_id?)
  Context-->>Runtime: AssuranceEvaluationContext
  Runtime->>Assurance: evaluateAssuranceGate(gateId, document, context, trigger)
  Assurance-->>Runtime: AssuranceGateVerdict
  alt non_dry_run
    Runtime->>Audit: recordAssuranceVerdict(pmRoot, verdict, author, message)
    Audit-->>Runtime: void
  end
  Runtime-->>CLI: AssuranceGateVerdict
  CLI-->>User: printResult(verdict)
  opt verdict.exit_code == 1
    CLI->>CLI: process.exitCode = 1
  end
Loading

File-Level Changes

Change Details Files
Introduce core assurance governance primitives (measurements, assertions, gates, verdicts) with validation, evaluation, persistence, and history querying.
  • Add strongly-typed assurance domain model (measurements, assertions, gates, triggers, values, scopes, enforcement, lifetimes, negative controls, derived arithmetic).
  • Implement measurement evaluation engine with built-in sources (items, dependencies, graph, validate, health, history, links), provider hooks, derived expressions, cycle detection, and bounded cost receipts.
  • Implement assertion evaluation (single polarity, negative-control proof, distance calculation, retirement semantics) and gate evaluation (scoping, owner-terminal handling, trigger checks, overall verdict & exit code).
  • Add audited persistence helpers for assurance registry CRUD in assurance.json with validation and loosening-authorization checks, plus immutable verdict recording and querying via workspace history.
src/sdk/governance/assurance.ts
tests/unit/sdk/assurance.spec.ts
Bind assurance evaluation to real workspaces and external adapters (graph, validate, health, provider) and expose it via SDK, MCP, and CLI surfaces.
  • Add runtime binding that builds AssuranceEvaluationContext from workspace items, history, settings, and registries, including Git tree id resolution and provider adapter plumbing.
  • Add transport-neutral assurance action layer (list/show/put/remove/run/verdicts) that normalizes inputs, loads registry, executes evaluations, enforces authorization, and supports id-only receipts.
  • Wire assurance into SDK runtime: new PmClient.assurance(), SDK_ACTION_HANDLERS entry, and public exports for assurance modules and runtime.
  • Add Commander-based pm assurance CLI command that delegates to the shared action layer, supports JSON definition input, trigger/tree/gate filters, dry-run, author/message, and sets exitCode on blocking gate results.
  • Add MCP/SDK parity tests to ensure assurance action is reachable and correctly mapped across CLI, PmClient, runAction, and contracts coverage.
  • Add runtime adapter tests to verify workspace binding, provider resolution, health/validate/graph field selection, and Git vs working-copy tree id behavior.
src/sdk/governance/assurance-runtime.ts
tests/unit/sdk/assurance-runtime.spec.ts
src/sdk/governance/assurance-action.ts
tests/unit/sdk/assurance-action.spec.ts
src/sdk/runtime.ts
src/sdk/index.ts
src/sdk/runtime-primitives.ts
src/sdk/cli-contracts/runtime-contracts.ts
src/sdk/cli-contracts.ts
src/sdk/cli-contracts/enum-contracts.ts
src/cli/register-assurance.ts
tests/unit/cli/register-assurance.spec.ts
tests/integration/assurance-cli.integration.spec.ts
tests/integration/assurance-runtime.integration.spec.ts
Extend CLI/MCP parameter schema and flag contracts to cover the new assurance action, including triggers, trees, gates, and global flag mappings, and bump schema versions.
  • Add assurance-specific parameter properties (treeId, definition, trigger enum, gate) and action-scoped parameters (kind, subcommand) with metadata docs and examples.
  • Define assurance action schema contract: required/optional fields and conditional requirements per subcommand (list/show/put/remove/run).
  • Expose assurance command and flags through flag contracts, runtime contracts, and enum contracts; include mapping for global --pm-path to schema parameter path and assurance-specific flag overrides (e.g., --tree -> treeId).
  • Update completeness mapping for CLI positional parameters and flag->parameter overrides for assurance; ensure MCP schema parity tests cover new mappings.
  • Bump PM_TOOL_PARAMETERS_SCHEMA_VERSION and PM_PROVIDER_TOOL_PARAMETERS_SCHEMA_VERSION to 4.6.0 and 1.3.0 for the additive contracts.
  • Update contracts command tests and fixtures to assert assurance flags and schema coverage, plus regenerate generated surfaces and snapshots.
src/sdk/cli-contracts/tool-parameter-tables.ts
src/sdk/cli-contracts/tool-parameter-tables.ts
src/sdk/cli-contracts/tool-schema.ts
src/sdk/cli-contracts/completeness.ts
src/sdk/cli-contracts/flag-contracts.ts
src/sdk/cli-contracts/runtime-contracts.ts
src/sdk/cli-contracts/enum-contracts.ts
tests/unit/commands/contracts-command.spec.ts
tests/unit/sdk/action-schema-parity.spec.ts
tests/fixtures/contracts/full.json
docs/generated/AGENT_COMMAND_SURFACE.md
sdk/public-surface.json
Add user-facing documentation and changelog entries for assurance primitives and refresh dev dependencies.
  • Add ASSURANCE.md describing project assurance primitives, declaration vocabulary, CLI/SDK workflows, verdict contract, and safety/evolution guidance; link it from docs README.
  • Extend CHANGELOG with bullets for assurance verdict immutability, pm gate/assert/measure commands, and dependency refresh under Security.
  • Update docs-generated agent command surface, token surface baseline, and public SDK surface snapshots for new commands and exports.
  • Bump eslint and @types/node devDependency versions and refresh pnpm lockfile accordingly; track dependency-refresh chore in PM lineage/history.
  • Add new PM issue lineage files and history for pm show --depth brief returns MORE output than --depth standard: the omission receipt costs more than the omitted fields #969/970/971 projections without marking them as fixed.
docs/ASSURANCE.md
docs/README.md
CHANGELOG.md
scripts/agent-token-surface-baseline.json
docs/generated/AGENT_COMMAND_SURFACE.md
sdk/public-surface.json
package.json
pnpm-lock.yaml
.agents/pm/chores/pm-8l1m5t.toon
.agents/pm/features/pm-2lex4r.toon
.agents/pm/features/pm-91xeam.toon
.agents/pm/features/pm-lyfu7b.toon
.agents/pm/features/pm-wn6wot.toon
.agents/pm/history/pm-2lex4r.jsonl
.agents/pm/history/pm-8l1m5t.jsonl
.agents/pm/history/pm-91xeam.jsonl
.agents/pm/history/pm-lyfu7b.jsonl
.agents/pm/history/pm-wn6wot.jsonl
.agents/pm/issues/pm-gjjurs.toon
.agents/pm/issues/pm-gok2km.toon
.agents/pm/issues/pm-zryb9d.toon
.agents/pm/history/pm-gjjurs.jsonl
.agents/pm/history/pm-gok2km.jsonl
.agents/pm/history/pm-zryb9d.jsonl

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codspeed

codspeed Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 2.23%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 10 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ encodeQueryCursor 259.4 µs 253.7 µs +2.23%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing feat/sdk-assurance-primitives (5b5359a) with main (3791ff1)

Open in CodSpeed

@codecov

codecov Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai 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.

Actionable comments posted: 26

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.agents/pm/chores/pm-8l1m5t.toon:
- Line 31: Clarify that the 2026-08-11 completion dates are Europe/Vienna
execution dates while PM event timestamps remain UTC. Update the completion
evidence entries in .agents/pm/chores/pm-8l1m5t.toon:31-31,
.agents/pm/features/pm-2lex4r.toon:29-29,
.agents/pm/features/pm-91xeam.toon:30-30, and
.agents/pm/features/pm-lyfu7b.toon:31-31 to explicitly identify both date
conventions, without changing the UTC event timestamps.
- Around line 37-43: Update the structured tests and test_runs evidence for
.agents/pm/chores/pm-8l1m5t.toon lines 37-43 to link typecheck, lint, coverage,
packed-consumer, dogfood, and audit commands; update
.agents/pm/features/pm-2lex4r.toon lines 37-43 with measurement CRUD,
source-adapter, cost-bound, arithmetic, CLI, and full-suite evidence; update
.agents/pm/features/pm-91xeam.toon lines 37-43 with hash-chain, Decision
authorization, history-compaction, fresh-process, and full-suite evidence; and
update .agents/pm/features/pm-lyfu7b.toon lines 38-44 with polarity, scope,
lifetime, negative-control, authorization, CLI, and full-suite evidence. Every
runnable verification referenced by each close_reason must be executed and
linked through pm test, with command-specific test_runs recorded where needed.

In @.agents/pm/features/pm-91xeam.toon:
- Line 20: Update the acceptance criterion in the actual_result statement so it
requires verdict records for every non-dry evaluation, or explicitly document
dry-run evaluations as an accepted exception before closing the item; keep the
workspace-history and structured-evidence requirements intact and align the
wording with docs/ASSURANCE.md.

In @.agents/pm/features/pm-wn6wot.toon:
- Line 32: Clarify the evidence date in the canonical PM record to state that
event timestamps remain UTC while execution dates use Europe/Vienna, then append
the clarification through pm comments rather than editing hash-chain history.
Apply the canonical clarification to .agents/pm/history/pm-2lex4r.jsonl:16-16,
.agents/pm/history/pm-8l1m5t.jsonl:28-28,
.agents/pm/history/pm-91xeam.jsonl:13-13,
.agents/pm/history/pm-gjjurs.jsonl:1-1, .agents/pm/history/pm-gok2km.jsonl:1-1,
.agents/pm/history/pm-lyfu7b.jsonl:15-15,
.agents/pm/history/pm-wn6wot.jsonl:28-28, and
.agents/pm/history/pm-zryb9d.jsonl:1-1; then regenerate the projections at
.agents/pm/features/pm-wn6wot.toon:32-32 and
.agents/pm/issues/pm-gjjurs.toon:29-29.

In `@docs/README.md`:
- Line 56: Update the Project Assurance Primitives entry in docs/README.md to
include a documentation link to docs/README.md, and ensure pm-u9d0 also has a
documentation link. Make the changes through the pm docs workflow as requested.

In `@sdk/public-surface.json`:
- Line 18198: Export AssuranceActionInput and AssuranceActionResult from both
./sdk/core and ./sdk/runtime so the PmClient.assurance signature is importable
through either entrypoint, then regenerate sdk/public-surface.json to reflect
the updated public API.

In `@src/sdk/cli-contracts/tool-parameter-tables.ts`:
- Line 501: Update the assurance schema’s definition contract near the
definition field so it enforces kind-specific requirements, including id,
source, and assertion_ids as required by the runtime validators; alternatively,
add a contract test explicitly documenting that these checks are runtime-only.
Keep the put contract aligned with the selected approach and prevent unrelated
fields or an empty object from being accepted silently.

In `@src/sdk/governance/assurance-action.ts`:
- Around line 198-209: Validate input.trigger against the declared
AssuranceGateTrigger vocabulary before the cast in the assurance run flow.
Update the existing guard around evaluateAssuranceGate to reject unknown values
with a PmCliError using EXIT_CODE.USAGE and a message that identifies the valid
triggers, while preserving the existing missing-trigger behavior.
- Around line 226-238: The mutation options in the assurance action flow must
stop auto-populating authorized_decision_ids from every workspace item of type
decision. Remove that synthesis from the put/assertion path and require
caller-provided authorization, with validation delegated to the existing
assurance declaration guard so only an explicitly authorized, valid decision can
permit loosening or retirement.

In `@src/sdk/governance/assurance-runtime.ts`:
- Around line 79-90: Update resolveTreeId’s execFileAsync invocation to include
a finite timeout option for the git rev-parse operation, ensuring it cannot hang
indefinitely while preserving the existing working-copy fallback when the
command fails or times out.
- Around line 92-107: Update readWorkspaceHistory to avoid loading history for
item-only callers such as assurance put --kind assertion, making the history
retrieval optional or lazy while preserving empty results for missing history.
When history is required, replace the unbounded Promise.all over items with
bounded concurrency so readHistoryEntries does not open one file per item
simultaneously.

In `@src/sdk/governance/assurance.ts`:
- Around line 724-730: Update validateMeasurementDefinition to validate the
items source: when items.field is set, require items.equals and reject
declarations that omit it. Keep the existing field/value comparison in the
source.kind === "items" filtering logic unchanged for valid declarations.
- Around line 791-814: Introduce a per-evaluation Map<string,
AssuranceMeasurementResult> cache and thread it through
evaluateMeasurementInternal and evaluateExpression. In the measurement branch of
evaluateExpression, return the cached result by measurement id when available;
otherwise evaluate the definition, store the result, and reuse it for later
references. Initialize one cache per evaluateMeasurement call, preserve the
existing stack-based cycle detection, and keep evaluateAssuranceGate’s separate
assertion evaluations isolated.
- Around line 916-954: Replace the unbounded Promise.all assertion evaluation
around the gate assertion mapping with a bounded-concurrency scheduler, limiting
in-flight assertion evaluations and therefore downstream external adapter calls
while preserving result ordering and existing scoping behavior. Update the
AssuranceEvaluationContext.external contract documentation to require
implementations to enforce an appropriate timeout.
- Around line 1121-1131: Update listAssuranceVerdicts to bound history reads by
adding a limit option and returning the newest matching verdicts first. Apply
the limit while querying or iterating entries so the complete workspace history
is not materialized on every call, while preserving the existing gate_id
filtering and verdict validation.
- Around line 694-701: Add a shared collectMeasurementReferences(document)
helper that gathers assertion.measurement_id, filter-scope measurement_id
values, and every AssuranceMeasurementReference in derived-source expression
trees; use it in validateAssuranceDocument and removeAssuranceDeclaration. At
src/sdk/governance/assurance.ts:694-701, reject missing filter-scope and
derived-expression measurements; at src/sdk/governance/assurance.ts:1082-1084,
use the same helper to block removal of measurements referenced by derived
expressions.
- Around line 724-732: Update the `source.kind === "items"` branch so its
returned `population_size` uses the scanned population `context.items.length`
instead of `matches.length`, while leaving the match count as `value` and
preserving the existing contributors and cost.
- Around line 646-649: Update the bound validation near boundFor(definition) to
allow finite negative numeric values for all polarities, while retaining
requireFiniteNonNegative only for the max_cost polarity. Preserve rejection of
non-finite values and ensure signed bounds remain valid for floor, ceiling,
monotone_nondecreasing, and derived measurements.
- Around line 974-978: Update readDocument, putAssuranceDeclaration, and
removeAssuranceDeclaration to catch JSON parsing and assurance-document
validation failures, converting SyntaxError and TypeError cases into PmCliError
with the appropriate exit code and actionable recovery guidance. Preserve the
existing empty-document behavior when assurance.json is absent and continue
returning validated documents for valid data.

In `@src/sdk/runtime.ts`:
- Around line 1155-1159: Add an assertion in the assurance integration test
covering PmClient.assurance to verify the recorded history author is
"runtime-test". Keep the existing forwarding of author and cwd through the
assurance path unchanged.

In `@tests/unit/commands/contracts-command.spec.ts`:
- Around line 2129-2144: Expand the assurance flag assertions in the
runContracts test for command_flags so all seven flags are covered, including
--tree, --gate, --author, and --message. For every value-taking flag, also
assert its expected value_name while retaining the existing checks for
--definition, --trigger, and --dry-run.

In `@tests/unit/sdk/assurance-action.spec.ts`:
- Around line 35-199: Split tests/unit/sdk/assurance-action.spec.ts lines 35-199
into separate it blocks grouped by validation errors, CRUD, dispatch
normalization, gate evaluation, verdicts, and removal; keep only genuinely
order-dependent CRUD steps together. In tests/unit/sdk/assurance-runtime.spec.ts
lines 14-161, split workspace context construction, each external measurement
kind, external error paths, and both Git tree-identity scenarios into separate
it blocks, and move shared withTempPmPath setup into beforeEach.
- Around line 60-69: Update the JSON.parse spy setup in the assurance-action
test so restoration always runs, including when the runAssuranceAction rejection
assertion fails. Wrap the assertion in try/finally with parse.mockRestore(), or
use the test suite’s afterEach cleanup via vi.restoreAllMocks, while preserving
the existing assertion.

In `@tests/unit/sdk/assurance-runtime.spec.ts`:
- Around line 146-151: Update the assertion following
createAssuranceWorkspaceContext in the Git fixture test to compare
gitContext.tree_id with the identity produced by the fixture repository’s
commit, obtained via git rev-parse in fixture.tempRoot. Replace the non-empty
check so the test fails if the context resolves an outer repository’s identity.
- Around line 16-25: Safely restore environment variables in the assurance
runtime test by wrapping the temporary CODEX_CI and CODEX_MODEL assignments and
runCliInProcess call in a finally block. In the finally cleanup, restore each
saved value with assignment when defined and delete the corresponding
process.env key when it was undefined; apply the same handling to the PATH
restoration around the existing setup near the PATH cleanup.

In `@tests/unit/sdk/assurance.spec.ts`:
- Around line 199-209: Update the negative_control cases in
validateAssertionDefinition to use a numeric out-of-bound failing value, such as
2, instead of observed: []; preserve the existing passing case and ensure the
test validates numeric ceiling behavior rather than accepting a type mismatch.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: ef77317c-d2f2-4abf-91f3-e20691aba7ae

📥 Commits

Reviewing files that changed from the base of the PR and between 3791ff1 and eb75471.

⛔ Files ignored due to path filters (2)
  • docs/generated/AGENT_COMMAND_SURFACE.md is excluded by !**/generated/**
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (46)
  • .agents/pm/chores/pm-8l1m5t.toon
  • .agents/pm/features/pm-2lex4r.toon
  • .agents/pm/features/pm-91xeam.toon
  • .agents/pm/features/pm-lyfu7b.toon
  • .agents/pm/features/pm-wn6wot.toon
  • .agents/pm/history/pm-2lex4r.jsonl
  • .agents/pm/history/pm-8l1m5t.jsonl
  • .agents/pm/history/pm-91xeam.jsonl
  • .agents/pm/history/pm-gjjurs.jsonl
  • .agents/pm/history/pm-gok2km.jsonl
  • .agents/pm/history/pm-lyfu7b.jsonl
  • .agents/pm/history/pm-wn6wot.jsonl
  • .agents/pm/history/pm-zryb9d.jsonl
  • .agents/pm/issues/pm-gjjurs.toon
  • .agents/pm/issues/pm-gok2km.toon
  • .agents/pm/issues/pm-zryb9d.toon
  • CHANGELOG.md
  • docs/ASSURANCE.md
  • docs/README.md
  • package.json
  • scripts/agent-token-surface-baseline.json
  • sdk/public-surface.json
  • src/cli/register-assurance.ts
  • src/cli/register-operations.ts
  • src/sdk/cli-contracts.ts
  • src/sdk/cli-contracts/completeness.ts
  • src/sdk/cli-contracts/enum-contracts.ts
  • src/sdk/cli-contracts/flag-contracts.ts
  • src/sdk/cli-contracts/runtime-contracts.ts
  • src/sdk/cli-contracts/tool-parameter-tables.ts
  • src/sdk/cli-contracts/tool-schema.ts
  • src/sdk/governance/assurance-action.ts
  • src/sdk/governance/assurance-runtime.ts
  • src/sdk/governance/assurance.ts
  • src/sdk/index.ts
  • src/sdk/runtime-primitives.ts
  • src/sdk/runtime.ts
  • tests/fixtures/contracts/full.json
  • tests/integration/assurance-cli.integration.spec.ts
  • tests/integration/assurance-runtime.integration.spec.ts
  • tests/unit/cli/register-assurance.spec.ts
  • tests/unit/commands/contracts-command.spec.ts
  • tests/unit/sdk/action-schema-parity.spec.ts
  • tests/unit/sdk/assurance-action.spec.ts
  • tests/unit/sdk/assurance-runtime.spec.ts
  • tests/unit/sdk/assurance.spec.ts

Comment thread .agents/pm/chores/pm-8l1m5t.toon Resolved
Comment thread .agents/pm/chores/pm-8l1m5t.toon Resolved
Comment thread .agents/pm/features/pm-91xeam.toon Resolved
Comment thread .agents/pm/features/pm-wn6wot.toon Resolved
Comment thread docs/README.md Resolved
Comment thread tests/unit/sdk/assurance-action.spec.ts Resolved
Comment thread tests/unit/sdk/assurance-action.spec.ts Resolved
Comment thread tests/unit/sdk/assurance.spec.ts Resolved
@unbraind

Copy link
Copy Markdown
Owner Author

All 26 actionable findings were verified against the code, implemented where valid, individually replied to and resolved, and validated by exact 100/100/100/100 coverage plus the complete static, contract, package, npx, bunx, and dogfood gates.

@unbraind

Copy link
Copy Markdown
Owner Author

Walkthrough acknowledged. The exact-head follow-up also adds strict kind-specific schemas, bounded evaluation and verdict reads, explicit Decision provenance, typed malformed-registry recovery, and public action transport types. The repository-owned docstring gate reports 100%, superseding the bot heuristic warning.

@unbraind

Copy link
Copy Markdown
Owner Author

Reviewer guide acknowledged and used to cross-check the end-to-end CLI, SDK, MCP, persistence, and exit-code flow. Sourcery supplied no actionable code review because its separate review quota was exhausted, so it is not counted as approval.

@unbraind

Copy link
Copy Markdown
Owner Author

Performance report acknowledged. Repository import-cost, CLI transport-floor, context-calibration, token-budget, package, and 88-command dogfood gates are green on the follow-up head.

@unbraind

Copy link
Copy Markdown
Owner Author

Coverage report acknowledged. The repository exact gate independently passed 51,993 statements, 38,154 branches, 10,688 functions, and 50,226 lines at 100/100/100/100 with 7,210 tests.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172270; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172277; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172284; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172286; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172289; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172293; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172299; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172306; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172314; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172317; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172330; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172334; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172337; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172339; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172342; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172346; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Carrier review acknowledged together with inline finding 3754172348; that thread has an explicit disposition, reaction, validation evidence, and is resolved.

@unbraind

Copy link
Copy Markdown
Owner Author

Reviewed this bot review record and incorporated its thread-level disposition into the exact-head inventory.

@unbraind

Copy link
Copy Markdown
Owner Author

Reviewed this bot review record and incorporated its thread-level disposition into the exact-head inventory.

@unbraind

Copy link
Copy Markdown
Owner Author

Reviewed this bot review record and incorporated its thread-level disposition into the exact-head inventory.

@unbraind

Copy link
Copy Markdown
Owner Author

Reviewed this bot review record and incorporated its thread-level disposition into the exact-head inventory.

@unbraind

Copy link
Copy Markdown
Owner Author

Reviewed this bot review record and incorporated its thread-level disposition into the exact-head inventory.

@unbraind

Copy link
Copy Markdown
Owner Author

Reviewed this bot review record and incorporated its thread-level disposition into the exact-head inventory.

@unbraind

Copy link
Copy Markdown
Owner Author

Reviewed this bot review record and incorporated its thread-level disposition into the exact-head inventory.

@unbraind

Copy link
Copy Markdown
Owner Author

Reviewed this bot review record and incorporated its thread-level disposition into the exact-head inventory.

@unbraind

Copy link
Copy Markdown
Owner Author

Reviewed this bot review record and incorporated its thread-level disposition into the exact-head inventory.

@unbraind

Copy link
Copy Markdown
Owner Author

Reviewed this bot review record and incorporated its thread-level disposition into the exact-head inventory.

@unbraind

Copy link
Copy Markdown
Owner Author

Reviewed this bot review record and incorporated its thread-level disposition into the exact-head inventory.

@unbraind

Copy link
Copy Markdown
Owner Author

Reviewed this bot review record and incorporated its thread-level disposition into the exact-head inventory.

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/sdk/governance/assurance-action.ts (1)

255-263: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Run the two independent reads concurrently.

readDocument(pmRoot) and createAssuranceWorkspaceContext(pmRoot, { tree_id: input.tree }) do not depend on each other's result. The code awaits them sequentially as positional arguments to evaluateAssuranceGate. Use Promise.all to run both concurrently and reduce latency on this trigger-evaluation path.

♻️ Proposed refactor
-    const verdict = await evaluateAssuranceGate(
-      input.id,
-      await readDocument(pmRoot),
-      await createAssuranceWorkspaceContext(pmRoot, { tree_id: input.tree }),
-      {
-        trigger: input.trigger as AssuranceGateTrigger,
-        dry_run: input.dry_run === true,
-      },
-    );
+    const [document, workspaceContext] = await Promise.all([
+      readDocument(pmRoot),
+      createAssuranceWorkspaceContext(pmRoot, { tree_id: input.tree }),
+    ]);
+    const verdict = await evaluateAssuranceGate(
+      input.id,
+      document,
+      workspaceContext,
+      {
+        trigger: input.trigger as AssuranceGateTrigger,
+        dry_run: input.dry_run === true,
+      },
+    );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/sdk/governance/assurance-action.ts` around lines 255 - 263, Update the
evaluateAssuranceGate call to start readDocument(pmRoot) and
createAssuranceWorkspaceContext(pmRoot, { tree_id: input.tree }) concurrently
with Promise.all, then pass the resolved values in their existing positional
order while preserving the current trigger and dry_run options.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/sdk/governance/assurance-action.ts`:
- Around line 255-263: Update the evaluateAssuranceGate call to start
readDocument(pmRoot) and createAssuranceWorkspaceContext(pmRoot, { tree_id:
input.tree }) concurrently with Promise.all, then pass the resolved values in
their existing positional order while preserving the current trigger and dry_run
options.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e2028690-f5d8-4f2c-9cbe-6410766864bf

📥 Commits

Reviewing files that changed from the base of the PR and between fdcd298 and 5ba9cd3.

📒 Files selected for processing (23)
  • .agents/pm/chores/pm-8l1m5t.toon
  • .agents/pm/features/pm-2lex4r.toon
  • .agents/pm/features/pm-91xeam.toon
  • .agents/pm/features/pm-lyfu7b.toon
  • .agents/pm/features/pm-wn6wot.toon
  • .agents/pm/history/pm-2lex4r.jsonl
  • .agents/pm/history/pm-8l1m5t.jsonl
  • .agents/pm/history/pm-91xeam.jsonl
  • .agents/pm/history/pm-lyfu7b.jsonl
  • .agents/pm/history/pm-wn6wot.jsonl
  • CHANGELOG.md
  • docs/TESTING.md
  • scripts/release/gate-registry.json
  • scripts/release/gate-registry.mjs
  • src/sdk/cli-contracts/schemas/assurance-definition.ts
  • src/sdk/cli-contracts/tool-parameter-tables.ts
  • src/sdk/governance/assurance-action.ts
  • src/sdk/governance/assurance-limits.ts
  • src/sdk/governance/assurance.ts
  • tests/fixtures/contracts/full.json
  • tests/unit/scripts/release/gate-registry.spec.ts
  • tests/unit/sdk/assurance-action.spec.ts
  • tests/unit/sdk/contracts-full-projection.spec.ts

@unbraind

Copy link
Copy Markdown
Owner Author

Final exact-head CodeRabbit review completed with no new actionable threads on 5ba9cd3; all hosted checks are terminal and green. @greptileai full review

Start the registry snapshot and workspace context reads concurrently before gate evaluation. Add a red-green concurrency regression, refresh canonical PM evidence and changelog ordering, and retain exact 100/100/100/100 coverage.
@unbraind

Copy link
Copy Markdown
Owner Author

Implemented the final outside-diff concurrency finding in 5b5359a. A red/green regression proves registry and workspace-context reads start before either is awaited; canonical test-all passed 6/6 and repository coverage remains exact 100/100/100/100. @coderabbitai full review @greptileai full review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Rate Limit Exceeded

@unbraind have exceeded the limit for the number of chat messages per hour. Please wait 24 minutes and 42 seconds before sending another message.

@unbraind

Copy link
Copy Markdown
Owner Author

Acknowledged: the final exact-head CodeRabbit re-review request was rate-limited after its prior review finding was implemented and independently verified. This response is recorded as provider unavailability, not approval.

@unbraind

Copy link
Copy Markdown
Owner Author

Exact-head merge gate status for 5b5359a: every repository-controlled CI, security, smoke, coverage, contract, and performance check is terminal green. The Codecov uploader accepted both coverage and test-result payloads for this exact commit (HTTP 200, no warnings, queued successfully), but the required codecov/patch context has remained IN_PROGRESS beyond the bounded 20-minute wait and GitHub reports mergeStateStatus BLOCKED. This external pending state is not treated as approval and no protection bypass or merge was attempted. Final review inventory: 32/32 threads resolved; zero unreacted bot comments, reviews, or inline comments. CodeRabbit re-review was rate-limited and Greptile supplied no exact-head response, so those provider limitations are recorded rather than represented as approvals.

@unbraind

Copy link
Copy Markdown
Owner Author

Maintainer authorization update: after the exact head remained unchanged and every repository-controlled required check stayed green, the maintainer explicitly instructed continue and merge now. The sole remaining required context is external codecov/patch, still IN_PROGRESS roughly 84 minutes after Codecov accepted the exact-head coverage and test-result uploads with HTTP 200 and no warnings. Proceeding with a PR-scoped admin merge override only; repository branch-protection and required-check configuration remain unchanged. Review inventory immediately before merge: 0 unresolved threads and 0 unreacted bot comments, reviews, or inline findings.

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