Skip to content

Harden SDK execution, extension topology, contracts, and exact coverage - #916

Merged
unbraind merged 5 commits into
mainfrom
feat/trustworthy-sdk-execution-contracts
Aug 6, 2026
Merged

unbraind merged 5 commits into
mainfrom
feat/trustworthy-sdk-execution-contracts

Conversation

@unbraind

@unbraind unbraind commented Aug 6, 2026 •

Copy link
Copy Markdown
Owner

Outcome

This broad SDK/CLI tranche strengthens the universal context-management substrate across six coupled trust boundaries:

  • makes strict cross-owner seeded Plan creation atomic;
  • preserves ancestor runtime dependency resolution in fresh extension activation probes;
  • keeps extension package assets outside item merge drivers while retaining structured managed-state merges;
  • makes pm contracts --full monotonic by retaining command summaries and output policy;
  • enforces exact 100/100/100/100 coverage locally and in hosted merged coverage, with fail-closed malformed-report and rounded-percentage negative controls;
  • refreshes compatible tooling to tsx 4.23.8 and pm-changelog 2026.8.6 while retaining the separately tracked incompatible major-version deferrals.

PM lineage

Fixes #910
Fixes #911
Fixes #912

Verification

  • 438 test files and 6,887 tests pass.
  • Exact coverage: statements 49,165/49,165; branches 35,658/35,658; functions 10,051/10,051; lines 47,645/47,645.
  • Static quality, 100% docstrings, SDK import boundary, token/context calibration, tracker measurement, changelog freshness, production audit, secret scan, and 88-command package-first dogfood pass.
  • Fresh-workspace manual proof covers strict cross-owner Plan persistence, full contracts, Git attribute resolution, package activation, and zero module-snapshot residue.
  • Tracker storage/history and merge-fence integrity are clean; the existing historical missing-resolution population remains an explicit warning, not new drift.

Summary by cubic

Hardens SDK/CLI trust boundaries: atomic Plan creation, accurate extension activation, safe merge-driver scope, monotonic contracts, and an exact coverage gate enforced after shard merge. Fixes #910, #911, and #912, and updates tsx to 4.23.8 and pm-changelog to 2026.8.6.

  • New Features

    • Enforced exact 100% coverage using integer counts; CI merges shard reports using coverage-shard then runs scripts/release/coverage-threshold-gate.mjs; added a negative-control unit test.
    • Made contracts monotonic; the full projection preserves command_summaries and output_policy; refreshed the full structured contract fixture.
  • Bug Fixes

    • Restored atomic seeded cross-owner Plan creation under strict ownership; commits all-or-nothing.
    • Preserved hoisted runtime dependencies during extension activation probes by snapshotting under the project parent and cleaning all temp graphs.
    • Excluded .agents/pm/extensions/** from item merge drivers; kept JSON merge for .managed-extensions.json.

Written for commit d5c146c. Summary will update on new commits.

Review in cubic

Deliver a broad SDK and CLI trust-contract tranche across Plan lifecycle atomicity, extension runtime dependency topology, merge-driver scope, monotonic runtime contracts, exact local/hosted coverage enforcement, and compatible tooling updates.\n\nAdd strict and manual regressions, preserve managed extension merge state, refresh tsx and pm-changelog, and record complete PM evidence for pm-hxuqsa, pm-pg9599, pm-t9qbmp, pm-x0iv17, pm-2qqcgl, and pm-l9fv1e.

@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

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@unbraind, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 26 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

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

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 6824142c-ced2-4f4a-bf0e-6157743d29a4

📥 Commits

Reviewing files that changed from the base of the PR and between 42b7baa and d5c146c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (37)
  • .agents/pm/chores/pm-do5b.toon
  • .agents/pm/chores/pm-ksr40d.toon
  • .agents/pm/chores/pm-l9fv1e.toon
  • .agents/pm/extensions/.managed-extensions.json
  • .agents/pm/history/pm-2qqcgl.jsonl
  • .agents/pm/history/pm-do5b.jsonl
  • .agents/pm/history/pm-hxuqsa.jsonl
  • .agents/pm/history/pm-ksr40d.jsonl
  • .agents/pm/history/pm-l9fv1e.jsonl
  • .agents/pm/history/pm-pg9599.jsonl
  • .agents/pm/history/pm-t9qbmp.jsonl
  • .agents/pm/history/pm-x0iv17.jsonl
  • .agents/pm/issues/pm-2qqcgl.toon
  • .agents/pm/issues/pm-hxuqsa.toon
  • .agents/pm/issues/pm-pg9599.toon
  • .agents/pm/issues/pm-t9qbmp.toon
  • .agents/pm/issues/pm-x0iv17.toon
  • .gitattributes
  • .github/workflows/ci.yml
  • CHANGELOG.md
  • package.json
  • pnpm-workspace.yaml
  • scripts/release/coverage-threshold-gate.mjs
  • scripts/release/gate-registry.json
  • scripts/run-tests.mjs
  • src/sdk/cli-contracts/runtime-contracts.ts
  • src/sdk/extension.ts
  • src/sdk/lifecycle/plan.ts
  • src/sdk/merge/install.ts
  • tests/fixtures/contracts/full.json
  • tests/integration/ci-workflow-contract.spec.ts
  • tests/unit/commands/plan-lifecycle-regressions.spec.ts
  • tests/unit/scripts/release/coverage-threshold-gate.spec.ts
  • tests/unit/scripts/run-tests.spec.ts
  • tests/unit/sdk/contracts-full-projection.spec.ts
  • tests/unit/sdk/merge-extension-asset-scope.spec.ts
  • vitest.config.ts
✨ Finishing Touches
📝 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 6, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds an exact coverage JSON gate to both local and CI test flows, hardens extension runtime activation topology and merge-attribute scoping for extension assets, and ensures CLI contracts keep compact command semantics monotonic between summary and full projections while updating tooling versions.

Sequence diagram for extension install runtime activation topology

sequenceDiagram
  participant Install as performExtensionInstallUnderLock
  participant Probe as probeRuntimeCommandPathsForInstall
  participant Queue as extensionRuntimeProbeQueue
  participant Loader as loadExtensionRuntimeCommands
  participant Activator as activateExtensions

  Install->>Probe: probeRuntimeCommandPathsForInstall(pm_root, parent, settings, extensions, global)
  Probe->>Queue: extensionRuntimeProbeQueue.enqueue(async () => { ... })
  Queue-->>Probe: async callback
  Probe->>Probe: fs.mkdtemp(path.join(parent, ".pm-module-graph-")) as snapshotRoot
  Probe->>Loader: loadExtensionRuntimeCommands({ module_graph_snapshot_root: snapshotRoot, cache_bust: true })
  Loader-->>Probe: { loaded, failed, contribution_inventories }
  Probe->>Activator: activateExtensions(loadResult)
  Activator-->>Probe: activationResult
  Probe-->>Install: { activationResult, contribution_inventories, runtime_failures }
  Probe->>Probe: fs.rm(snapshotRoot, { recursive: true, force: true })
Loading

Sequence diagram for runtime contracts summary and full projections

sequenceDiagram
  participant CLI as runContracts
  participant Helper as attachAgentCommandContractsResult

  CLI->>CLI: resolve selection (summary, fullOutput)
  alt selection.summary or selection.fullOutput
    CLI->>Helper: attachAgentCommandContractsResult(result, outputCommands)
    Helper-->>CLI: result with command_summaries, output_policy
  end
  alt selection.summary
    CLI-->>CLI: return result
  else selection.fullOutput
    CLI->>CLI: buildCommandAliasSurface(commands)
    CLI-->>CLI: return full contracts with command_summaries and output_policy
  end
Loading

Sequence diagram for exact coverage gate in CI and local runs

sequenceDiagram
  actor Developer
  participant CI as GitHubActions
  participant Vitest as vitest
  participant Gate as coverage_threshold_gate.mjs
  participant Finder as findCoverageDeficits

  Developer->>Vitest: pnpm exec vitest --coverage
  Vitest-->>Vitest: write coverage/coverage-summary.json
  Developer->>Gate: node scripts/release/coverage-threshold-gate.mjs
  Gate->>Gate: main(summaryPath)
  Gate->>Gate: readFileSync(summaryPath)
  Gate->>Finder: findCoverageDeficits(summary)
  Finder-->>Gate: deficits[]
  alt deficits.length === 0
    Gate-->>Developer: log "Exact coverage gate passed"
  else deficits.length > 0
    Gate-->>Developer: log uncovered files and metrics
    Gate-->>Developer: process.exitCode = 1
  end
  CI->>Vitest: pnpm exec vitest --merge-reports=.vitest-reports --coverage
  CI->>Gate: node scripts/release/coverage-threshold-gate.mjs
  Gate-->>CI: same exact coverage enforcement as local
Loading

File-Level Changes

Change Details Files
Enforce exact 100% coverage using a JSON summary gate in local and CI runs.
  • Updated scripts/run-tests.mjs to run a post-vitest coverage-threshold gate when in coverage mode and propagate its exit code.
  • Added scripts/release/coverage-threshold-gate.mjs to parse coverage-summary.json, validate integer counts for all metrics, and fail on any uncovered items or malformed entries.
  • Extended tests/unit/scripts/run-tests.spec.ts and added tests/unit/scripts/release/coverage-threshold-gate.spec.ts to cover normal, signal-terminated, malformed, and deficit scenarios.
  • Modified vitest.config.ts thresholds comments and .github/workflows/ci.yml plus tests/integration/ci-workflow-contract.spec.ts so merged coverage also passes through the exact gate.
scripts/run-tests.mjs
scripts/release/coverage-threshold-gate.mjs
vitest.config.ts
.github/workflows/ci.yml
tests/unit/scripts/run-tests.spec.ts
tests/unit/scripts/release/coverage-threshold-gate.spec.ts
tests/integration/ci-workflow-contract.spec.ts
Harden extension runtime activation topology and module-graph snapshot handling.
  • Changed probeRuntimeCommandPathsForInstall to write module graph snapshots into a .pm-module-graph- directory under the selected root instead of os.tmpdir, and ensured snapshots are always removed.
  • Propagated a parent directory argument into probeRuntimeCommandPathsForInstall callers so activation probes share the correct ancestry and topology.
  • Adjusted activation metadata to report module_graph_verification as fresh_in_topology_snapshot for installed extensions.
src/sdk/extension.ts
Refine merge-attribute patterns so extension package assets are excluded from item merge drivers while preserving managed extension inventory as structured JSON.
  • Extended buildMergeAttributePatterns to append an explicit -merge rule for extensions/** so extension package files are not treated as tracker item streams.
  • Reinstated merge=pm-json specifically for extensions/.managed-extensions.json after the asset exclusion.
  • Added a regression test to verify Git attributes for tasks, custom item folders, extension assets, and the managed-extensions inventory.
src/sdk/merge/install.ts
tests/unit/sdk/merge-extension-asset-scope.spec.ts
.gitattributes
Ensure contracts full projections remain monotonic with compact command semantics and output policy.
  • Introduced attachAgentCommandContractsResult to centralize construction of command_summaries and output_policy.
  • Updated runContracts to call this helper whenever summary or fullOutput is requested so full projections retain the same compact semantics as summaries.
  • Added a regression test verifying that full projections preserve command_summaries and output_policy while including extended fields like commands, schema, and runtime_schema.
src/sdk/cli-contracts/runtime-contracts.ts
tests/unit/sdk/contracts-full-projection.spec.ts
Make cross-owner seeded Plan creation atomic under strict governance ownership enforcement.
  • Updated planCreate to keep the assignee as the resolved author so the initial Plan creation mutation remains author-owned, allowing later ownership seeding to be applied atomically.
  • Extended the Plan lifecycle regression test to enable strict governance_ownership_enforcement before creating a seeded cross-owner Plan.
src/sdk/lifecycle/plan.ts
tests/unit/commands/plan-lifecycle-regressions.spec.ts
Refresh tsx tooling while keeping release gating and PM metadata synchronized.
  • Bumped the tsx devDependency to 4.23.8 and updated pnpm-workspace.yaml minimumReleaseAgeExclude to match.
  • Refreshed gate-registry.json and PM agent issue/history/chores entries to track the new compatible tooling refresh.
  • Regenerated pnpm-lock.yaml entries consistent with the tsx update.
package.json
pnpm-workspace.yaml
scripts/release/gate-registry.json
.agents/pm/**
pnpm-lock.yaml

Assessment against linked issues

Issue Objective Addressed Explanation
#910 Update merge attribute generation so that .agents/pm/extensions/** package assets are excluded from item merge drivers, while preserving item-directory protection and explicitly restoring the JSON merge driver for .agents/pm/extensions/.managed-extensions.json. ✅
#910 Add test coverage to verify merge-driver behavior for extension assets and item files (via git check-attr), ensuring correct patterns for default/custom tracker roots and extension asset scopes after pm merge install. ✅
#911 Ensure the pm install activation probe preserves ancestor node_modules resolution so hoisted runtime dependencies (e.g., at the project root) are correctly resolved and working extensions are not misreported as ok:false/extension_load_failed. ✅
#911 Prevent activation probe snapshot directories from leaking (growing without bound under /tmp) by ensuring they are cleaned up or otherwise scoped safely. ✅
#912 Restore atomic cross-owner seeded Plan creation in pm plan create so that either the Plan and all seeded steps are committed together without ownership conflicts, or no Plan is persisted when enrichment fails. ✅

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

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

@greptileai review

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 59 minutes.

Record exact-head delivery links, final gate evidence, and active quality lineage for all six SDK/CLI tranche items.
@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

@greptileai review

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 58 minutes.

@codspeed

codspeed Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 11 untouched benchmarks


Comparing feat/trustworthy-sdk-execution-contracts (d5c146c) with main (42b7baa)

Open in CodSpeed

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

@greptileai review

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 52 minutes.

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

@greptileai review

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 37 minutes.

@codecov

codecov Bot commented Aug 6, 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!

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

Disposition for CodeRabbit summary: the bot did not perform a review because its free review quota was exhausted. Exact head fea4ba9 is green, but this is recorded as a review limitation, not approval.

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

Disposition for this CodeRabbit invocation: action not completed due to rate limiting; no finding was produced and no approval is inferred.

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

Disposition for this CodeRabbit invocation: action not completed due to rate limiting; no finding was produced and no approval is inferred.

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

Disposition for this CodeRabbit invocation: action not completed due to rate limiting; no finding was produced and no approval is inferred.

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

Disposition for the latest CodeRabbit invocation on fea4ba9: action not completed due to rate limiting. All hosted gates are green, but the missing review remains an explicit limitation.

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

Disposition for Sourcery review guide: useful and accurate architecture summary. It identified no actionable defect; its coverage flow description matches the corrected shard-to-merged exact gate topology on fea4ba9.

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

Disposition for CodSpeed: accepted. The exact-head report shows no performance change across 11 benchmarks, consistent with the local SDK entrypoint and CLI transport checks.

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

Disposition for Codecov: accepted. All modified coverable lines and tests are green, while the repository exact-count gate independently proves 100/100/100/100 without percentage rounding.

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

Disposition for Sourcery review: the formal review was not completed because the weekly diff-character quota was exhausted. The separate reviewer guide was useful, but this rate-limit response is a limitation, not approval.

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

@greptileai review

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 26 minutes.

@unbraind

unbraind commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

Disposition for the final-head CodeRabbit invocation on d5c146c: action not completed due to rate limiting. No finding was produced and no approval is inferred; all exact-head hosted gates remain green.

@unbraind
unbraind merged commit a44daba into main Aug 6, 2026
32 checks passed
@unbraind
unbraind deleted the feat/trustworthy-sdk-execution-contracts branch August 6, 2026 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant