Skip to content

Make SDK context integrity durable across clones - #952

Merged
unbraind merged 3 commits into
mainfrom
feat/sdk-durable-context-integrity
Aug 9, 2026
Merged

unbraind merged 3 commits into
mainfrom
feat/sdk-durable-context-integrity

Conversation

@unbraind

@unbraind unbraind commented Aug 9, 2026 •

Copy link
Copy Markdown
Owner

Summary

This broad SDK/CLI tranche makes context-integrity evidence durable, version-safe, observable, and deterministic:

  • version the managed merge-driver fence so older clients cannot silently rewrite a newer fence during unrelated commands
  • persist hash-only merge-decision evidence in the tracked project store while retaining raw recovery values only in clone-local Git state
  • expose an explicit not_configured provenance outcome distinct from attempted resolver failures
  • scan immutable history with bounded reads for privacy-safe invalid provenance value classes
  • isolate shared foreign AI_AGENT signals without hiding dedicated same-harness resolver inputs
  • refresh the public SDK surface, health vector documentation, merge-safety guidance, tests, and generated changelog

Why

Project management is context management. Merge decisions and provenance are part of the durable context graph: they must survive clone boundaries, remain understandable across client versions, distinguish absence from failure, and never leak host-specific or raw private values.

PM lineage

Verification

  • node scripts/run-tests.mjs coverage: 464 files, 7,100 tests, exact 100/100/100/100
  • pnpm lint: ESLint, zero duplicate clones, and full static-quality pipeline passed
  • pnpm quality:static: SDK parity/snapshot, docstring, package boundary, surface replication, token/context, registry, and performance gates passed
  • pnpm audit --audit-level high: no known vulnerabilities
  • pnpm security:scan: no credential-like secrets
  • pm health --check-only, history drift, storage integrity, and dry-run merge reconciliation passed
  • latest pm-changelog@2026.8.7 generated and verified CHANGELOG.md
  • packed tarball installed in an isolated temporary consumer; init/create/comment/get/health/validate/storage/history and clean Git round-trip passed

Fixes #921
Fixes #922
Fixes #948

Summary by Sourcery

Persist privacy-safe merge decision receipts in tracker storage and make merge fences and provenance health checks durable and version-safe across clones.

New Features:

  • Track merge decision receipts in a durable merge-receipts store within the project tracker, preserving hash-only decision evidence across clones.
  • Expose provenance resolver health findings for invalid legacy value classes as aggregate, privacy-safe diagnostics.
  • Support a new not_configured provenance outcome to distinguish missing resolvers from unavailable harness signals.
  • Version the managed Git merge-driver fence so legacy pm-cli releases cannot rewrite the current contract during routine commands.

Bug Fixes:

  • Ensure provenance health and storage checks ignore foreign AI_AGENT signals and only treat harness-specific inputs as attempted resolver probes.
  • Prevent sandboxed and legacy harness environments from recording out-of-domain boolean and single-digit provenance values without detection.
  • Make merge-decision receipts visible in fresh clones and CI via durable hash-only summaries while keeping raw values confined to clone-local Git state.
  • Avoid legacy init and merge installers silently rewriting the tracked merge-driver fence under version skew.

Enhancements:

  • Unify merge receipt listing to deduplicate local and durable evidence while reporting availability of recoverable values.
  • Extend health and validation storage checks to surface provenance resolver outcomes and invalid-value aggregates without leaking raw history.
  • Refine agent identity diagnostics and test harness utilities to isolate shared environment signals and keep SDK behavior deterministic across environments.

Documentation:

  • Document durable merge decision receipts, privacy-safe sidecars, and provenance value domain scanning in the merge safety and context integrity guides.
  • Refresh SDK agent session context documentation to describe the expanded provenance outcome statuses and resolver attempt semantics.

Tests:

  • Add unit and integration coverage for durable merge receipts across clone boundaries and for version-skewed merge fence behavior.
  • Extend provenance health and storage health tests to cover invalid legacy value classification, warnings, and projection through health vectors.
  • Update SDK runtime and init/merge safety tests to reflect the new provenance outcomes, fenced attributes markers, and environment isolation.

Chores:

  • Update public SDK surface, changelog entries, and PM agent history/issue records to capture the new context-integrity and provenance behavior.

Summary by cubic

Makes context integrity durable across clones and safe across client versions. Adds a privacy-safe merge-receipts store, versions the managed merge fence, tightens provenance outcomes, and improves health diagnostics.

  • New Features

    • Persist merge-decision receipts as hash-only sidecars in the tracker; keep raw values clone-local; expose unified listing and a value_availability flag.
    • Version the managed .gitattributes merge-driver fence (pm-cli:merge-drivers:v2) so older pm releases don’t rewrite it; auto-migrate and repair on install.
    • Add a not_configured provenance outcome; health/validate scan bounded history and publish aggregate invalid-value classes (boolean/single-digit) without leaking values.
  • Bug Fixes

    • Treat only same-harness inputs as resolver attempts; ignore foreign AI_AGENT signals and sandbox bleed-through in tests.
    • Make merge receipts visible in fresh clones and CI via durable summaries; block version-skewed commands from rewriting the merge fence.

Fixes #921, #922, #948

Written for commit 02d6043. Summary will update on new commits.

Review in cubic

Version merge fences for cross-client safety, persist privacy-safe merge receipt evidence, expose explicit provenance outcomes and corpus diagnostics, and isolate foreign harness signals in SDK tests.

@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 9, 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: 51 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: 02b1ad6c-9193-4aa7-aa19-3666899dd903

📥 Commits

Reviewing files that changed from the base of the PR and between f9b1df6 and 02d6043.

📒 Files selected for processing (32)
  • .agents/pm/features/pm-lu6sca.toon
  • .agents/pm/history/pm-1j5j21.jsonl
  • .agents/pm/history/pm-eq9dlw.jsonl
  • .agents/pm/history/pm-l56d0o.jsonl
  • .agents/pm/history/pm-lu6sca.jsonl
  • .agents/pm/history/pm-xgah3a.jsonl
  • .agents/pm/issues/pm-1j5j21.toon
  • .agents/pm/issues/pm-eq9dlw.toon
  • .agents/pm/issues/pm-l56d0o.toon
  • .agents/pm/issues/pm-xgah3a.toon
  • .gitattributes
  • CHANGELOG.md
  • docs/MERGE_SAFETY.md
  • docs/SDK_AGENT_SESSION_CONTEXT.md
  • docs/SDK_CONTEXT_INTEGRITY.md
  • sdk/public-surface.json
  • src/core/shared/author.ts
  • src/sdk/governance/health.ts
  • src/sdk/governance/provenance-health.ts
  • src/sdk/governance/validate.ts
  • src/sdk/merge/index.ts
  • src/sdk/merge/install.ts
  • src/sdk/merge/receipts.ts
  • tests/helpers/withTempPmPath.ts
  • tests/integration/merge-fence-version-skew.integration.spec.ts
  • tests/integration/provenance-value-health.integration.spec.ts
  • tests/unit/commands/init-command.spec.ts
  • tests/unit/sdk/agent-runtime-primitives.spec.ts
  • tests/unit/sdk/health-vector-boundary.spec.ts
  • tests/unit/sdk/merge-receipts.spec.ts
  • tests/unit/sdk/merge-safety.spec.ts
  • tests/unit/sdk/provenance-health.spec.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 9, 2026

Copy link
Copy Markdown

Reviewer's Guide

Makes merge-decision receipts durable and privacy-safe across clones, versions the managed Git merge fence, refines agent provenance outcome semantics, and adds bounded provenance value diagnostics surfaced through health checks.

Sequence diagram for durable merge-decision receipts across clones

sequenceDiagram
  actor Developer
  participant MergeDriver
  participant GitDirectory as git_workspace_receipts
  participant TrackerRoot as pm_tracker_merge_receipts

  Developer->>MergeDriver: writeMergeReceipt(cwd,item_path,decisions)
  MergeDriver->>GitDirectory: resolveReceiptDirectory(cwd)
  MergeDriver->>GitDirectory: ensureDir(directory)
  MergeDriver->>GitDirectory: writeFileAtomic(receiptFileName)
  MergeDriver->>TrackerRoot: resolveTrackerRootFromItemPath(cwd,item_path)
  MergeDriver->>TrackerRoot: durableReceiptDirectory(pmRoot)
  MergeDriver->>TrackerRoot: writeFileAtomic(receiptFileName)

  Developer->>MergeDriver: listMergeReceipts(cwd,{includeLossless,pmRoot})
  MergeDriver->>GitDirectory: resolveReceiptDirectory(cwd)
  MergeDriver->>GitDirectory: readReceiptsFromDirectory(directory,options)
  MergeDriver->>TrackerRoot: durableReceiptDirectory(pmRoot)
  MergeDriver->>TrackerRoot: readReceiptsFromDirectory(durableDirectory,options)
  MergeDriver-->>Developer: merged receipts (clone_local + hash_only)

  Developer->>MergeDriver: markMergeReceiptReconciled(cwd,receipt)
  MergeDriver->>GitDirectory: writeFileAtomic(updated local receipt)
  MergeDriver->>TrackerRoot: resolveTrackerRootFromItemPath(cwd,receipt.item_path)
  MergeDriver->>TrackerRoot: writeFileAtomic(updated durable receipt)
Loading

Sequence diagram for bounded provenance health scanning with invalid value diagnostics

sequenceDiagram
  actor Operator
  participant HealthService as runHealth
  participant ProvenanceScanner as scanProvenanceResolverHealth
  participant HistoryStore as readHistory
  participant StorageCheck as buildStorageHealthCheck

  Operator->>HealthService: runHealth(pmRoot)
  HealthService->>ProvenanceScanner: scanProvenanceResolverHealth(pmRoot)
  ProvenanceScanner->>HistoryStore: readHistory(pmRoot)
  HistoryStore-->>ProvenanceScanner: history.content
  ProvenanceScanner->>ProvenanceScanner: collectHistoryContent(content,aggregates,invalidValues,eventLimit)
  ProvenanceScanner->>ProvenanceScanner: collectResolverOutcomes(entry,aggregates,invalidValues)
  ProvenanceScanner-->>HealthService: {outcomes,invalid_values,warnings}
  HealthService->>StorageCheck: buildStorageHealthCheck(...,provenanceResolverOutcomes,provenanceInvalidValues)
  StorageCheck-->>HealthService: storage health report (includes provenance_invalid_values)
  HealthService-->>Operator: health summary with provenance warnings and invalid_value aggregates
Loading

Flow diagram for versioned Git merge attribute fence management

flowchart TD
  A[runMergeInstall / refreshMergeAttributeFenceIfInstalled] --> B[reconcileGitattributesBlock]
  B --> C[removeManagedBlock using PM_GITATTRIBUTES_V2_START and PM_GITATTRIBUTES_V2_END]
  C --> D[removeManagedBlock using PM_GITATTRIBUTES_START and PM_GITATTRIBUTES_END]
  D --> E[write v2 block using PM_GITATTRIBUTES_V2_START/PM_GITATTRIBUTES_V2_END]

  F[auditMergeAttributeFence] --> G[read .gitattributes]
  G --> H{includes PM_GITATTRIBUTES_V2_START?}
  H -->|yes| I[usesV2 = true<br/>startMarker = PM_GITATTRIBUTES_V2_START<br/>endMarker = PM_GITATTRIBUTES_V2_END]
  H -->|no| J[usesV2 = false<br/>startMarker = PM_GITATTRIBUTES_START<br/>endMarker = PM_GITATTRIBUTES_END]
  I --> K[extract committed patterns between startMarker/endMarker]
  J --> K

  L[refreshMergeAttributeFenceIfInstalled] --> M{fence present?}
  M -->|yes| N{includes PM_GITATTRIBUTES_V2_START or PM_GITATTRIBUTES_START}
  N -->|no| O[status = not_installed]
  N -->|yes| P[reconcileGitattributesBlock with v2 fence]
Loading

File-Level Changes

Change Details Files
Persist merge decision receipts both clone-locally and in a privacy-safe durable store, and surface availability across list/read/reconcile flows.
  • Add value_availability flag to merge receipts to distinguish clone-local vs hash-only evidence.
  • Introduce tracker-root resolution and a merge-receipts directory under the pm tracker for durable, hash-only sidecar receipts.
  • Change listMergeReceipts to merge clone-local and durable receipts, keyed by id, with optional pmRoot override.
  • Ensure markMergeReceiptReconciled updates both clone-local and durable receipts when present.
  • Extend receipt summarization to respect prehashed pm_value_hash values while still hashing non-prehashed content.
src/sdk/merge/receipts.ts
tests/unit/sdk/merge-receipts.spec.ts
docs/MERGE_SAFETY.md
docs/SDK_CONTEXT_INTEGRITY.md
Version the managed merge fence in .gitattributes so older releases cannot silently rewrite the fence, and update installation/audit logic and tests.
  • Define v2 start/end markers for the PM-managed merge-driver fence and export them from the public SDK surface.
  • Refactor merge fence reconciliation to remove both v1 and v2 managed blocks, then write a v2 block with current patterns.
  • Update auditMergeAttributeFence and refreshMergeAttributeFenceIfInstalled to recognize either v1 or v2 fences and to audit using the active version.
  • Add integration coverage for migrating legacy fences to v2 while making older releases treat the fence as opaque.
  • Update existing init and merge-safety tests to assert the v2 markers and behavior when fences are truncated or modified.
src/sdk/merge/install.ts
src/sdk/merge/index.ts
tests/unit/commands/init-command.spec.ts
tests/unit/sdk/merge-safety.spec.ts
tests/integration/merge-fence-version-skew.integration.spec.ts
.gitattributes
sdk/public-surface.json
Refine agent provenance outcome semantics with an explicit not_configured status and more precise input detection for resolvers, isolating foreign AI_AGENT signals.
  • Extend AgentProvenanceOutcome.status union with not_configured to distinguish absence from unavailability or failure.
  • Tighten ai_agent_version probe to only consider AI_AGENT values that match the detected harness descriptor, avoiding foreign harness bleed-through.
  • Introduce provenanceResolverHasInput helper and use it in resolveProvenanceOutcome to decide attempted vs unavailable outcomes.
  • Treat dimensions not listed as provenance_unavailable_dimensions as not_configured instead of unavailable, with resolver_not_configured reason.
  • Adjust diagnoseAgentIdentity tests to cover new not_configured behavior and updated harness/input semantics.
src/core/shared/author.ts
tests/unit/sdk/agent-runtime-primitives.spec.ts
docs/SDK_AGENT_SESSION_CONTEXT.md
Add bounded diagnostics for invalid legacy provenance values and surface them through health checks as privacy-safe aggregates and warnings.
  • Introduce ProvenanceValueHealthFinding and invalid_values array on ProvenanceResolverHealthScan.
  • Scan agent_provenance values in history for boolean and single-digit classes using dedicated classifiers and aggregate by harness/dimension/kind.
  • Include invalid value aggregates and derived warnings in scanProvenanceResolverHealth output alongside resolver outcomes.
  • Plumb provenance_invalid_values through storage health check details and health vector boundary tests.
  • Add integration coverage for provenance value health projection through runHealth and unit tests that assert invalid values and warnings.
src/sdk/governance/provenance-health.ts
src/sdk/governance/health.ts
tests/unit/sdk/provenance-health.spec.ts
tests/unit/sdk/health-vector-boundary.spec.ts
tests/integration/provenance-value-health.integration.spec.ts
docs/SDK_CONTEXT_INTEGRITY.md
Align validation/health integrity checks and test harness environment isolation with new merge receipt durability and harness signal treatment. src/sdk/governance/validate.ts
src/sdk/governance/health.ts
tests/helpers/withTempPmPath.ts
tests/unit/sdk/health-vector-boundary.spec.ts
CHANGELOG.md
.agents/pm/history/*.jsonl
.agents/pm/issues/*.toon

Assessment against linked issues

Issue Objective Addressed Explanation
#921 Make merge-decision receipts durable across clones so that fresh checkouts (including CI) can still detect pending lossy merge decisions even when the original clone-local receipt directory is absent. ✅
#921 Ensure health and validation checks (pm health --strict-exit and related storage/integrity checks) consume the durable merge-decision evidence so that unacknowledged lossy merges cannot produce a green CI result in a fresh clone. ✅
#921 Document the new durable merge-receipt behavior and CI boundary guarantees in the SDK/merge safety documentation and changelog. ✅
#922 Persist merge-decision receipts (or equivalent evidence) in the tracked project store so that evidence of discarded edits is durable across clones and not confined to gitignored, clone-local runtime state. ✅
#922 Ensure pm health / pm validate consume this durable merge-decision evidence so that a fresh clone of a lossy merge commit reports pending merge decisions and can fail pm health --strict-exit in CI. ✅
#948 Make the pm-managed .gitattributes merge-driver fence idempotent across pm versions so that older and newer releases do not silently rewrite each other’s fence (including the extension patterns), preventing version-skewed invocations from dirtying the tracked file. ✅

Possibly linked issues


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 9, 2026

Copy link
Copy Markdown
Owner Author

@greptileai please review the exact current head. @coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

@unbraind, I will perform a full review of the exact current head for #952.

⚠️ 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.

@codspeed

codspeed Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 11 untouched benchmarks


Comparing feat/sdk-durable-context-integrity (02d6043) with main (f9b1df6)

Open in CodSpeed

@codecov

codecov Bot commented Aug 9, 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 9, 2026

Copy link
Copy Markdown
Owner Author

CodeRabbit artifact acknowledged: #952 (comment). The provider was rate-limited and produced no code findings, so this is recorded as unavailable review coverage, not approval.

@unbraind

unbraind commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

Sourcery guide acknowledged: #952 (comment). Its architecture summary matches the intended durable-receipt, versioned-fence, and bounded-provenance design; no actionable finding was raised.

@unbraind

unbraind commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

CodeRabbit command reply acknowledged: #952 (comment). The requested exact-head review remained rate-limited and supplied no findings; deterministic checks and other review surfaces remain the evidence.

@unbraind

unbraind commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

CodSpeed report acknowledged: #952 (comment). The exact-head comparison reports no performance change across all 11 benchmarks.

@unbraind

unbraind commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

Codecov report acknowledged: #952 (comment). It confirms all modified coverable lines are covered and all tests succeeded.

@unbraind

unbraind commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

Sourcery submitted review acknowledged: #952 (review). The provider reached its weekly diff quota and supplied no code findings, so it is documented as unavailable rather than approval.

@unbraind

unbraind commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

Exact head updated to 02d6043 with PM evidence only. @greptileai please review this exact head. @coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

@unbraind, I will perform a full review of pull request #952 at exact head 02d6043d4.

⚠️ 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 51 minutes.

@unbraind

unbraind commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

CodeRabbit exact-head retrigger acknowledged: #952 (comment). The bot confirmed head 02d6043 but remained rate-limited and supplied no code findings; this is provider-unavailable evidence, not approval.

@unbraind
unbraind merged commit 9992030 into main Aug 9, 2026
32 checks passed
@unbraind
unbraind deleted the feat/sdk-durable-context-integrity branch August 9, 2026 16:15
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