Skip to content

Use the pm SDK for GitHub import lifecycle writes - #180

Merged
unbraind merged 3 commits into
mainfrom
refactor/sdk-adoption-1025
Oct 25, 2026
Merged

unbraind merged 3 commits into
mainfrom
refactor/sdk-adoption-1025

Conversation

@unbraind

@unbraind unbraind commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

GitHub import lifecycle finalization manually locked items, wrote documents, appended history, rolled back failed appends, and dispatched hooks. It now uses the pinned pm SDK's mutateItem boundary while preserving exact source lifetimes, release retention, normalization, no-op retries, and both import hooks. The SDK owns the native clock and no-op handling. Hook fields are projected lazily from its live document so they match the actual appended patch even across a clock tick or format enrichment.

Tracker: pm-github-d26g, linked to earlier SDK adoption pm-github-gh83. Related lifecycle contract: pm-github-c093.

Audit finding Replacement / disposition Evidence
import-fidelity.ts:445-454: manual item lock and document/history boundary mutateItem owns locks, clock, no-op handling, persistence, rollback, index refresh and hooks. createHistoryEntry only lazily projects the established JSON-pointer hook fields; local persistence and clock code are deleted. test/sdk-adoption.test.ts; existing test/import-fidelity.test.ts; differential replay
Assess commitItemMutations for ordinary conditional fields Already used by atomic import. Ordinary update options cannot replace the callback for exact reserved lifecycle timestamp edits; finalization stays in one mutateItem boundary. No missing SDK API blocker. Existing atomic import/compensation/retry tests; docs/sdk-adoption-1025.md
closeout.ts:357-368 chronology/attribution Already uses the history SDK. Keep provider rules, as explicitly directed by the audit. Existing closeout tests; no code replacement

Differential proof: built origin/main 1cb49ac06bfee8d1193137367f86a36798a1040e versus this implementation on disposable, non-git copies of complete public pm-github and pm-brief trackers: 14/14 scenarios pass. Normal cases compare exact item/history bytes and import hook payloads with a frozen clock and tracker-relative paths. Retries preserve bytes and emit no import hooks. Source snapshot digests remain unchanged. The replay harness and exact snapshot commits are documented in docs/sdk-adoption-1025.md.

Intentional SDK differences: transactional guard/strict ownership refusals use conflict exit code 4; missing-item diagnostics use not-found exit code 3 instead of generic exit 1; derived-index maintenance adds runtime lock observations; legacy document updates use SDK-native TOON storage. README and the evidence document describe these contracts. Public differential inputs use native TOON.

Revert proof: restore only persistImportFidelity and its imports to origin/main, then run node --test test/sdk-adoption.test.ts: 2 pass / 2 fail because guard and ownership refusals disappear; hook/retry and clock-boundary compatibility pass. Reverting only the lazy field projection to the eager SDK adapter yields 3 pass / 1 fail, omitting updated_at from hook fields despite its presence in the history patch. The corrected implementation passes 4/4 under Node and native Bun, with real trackers and no SDK mocks.

Validation: npm run typecheck, npm run build:test, npm run lint, npm run docstring, npm run duplication, linked pm test --run --progress, changelog generation/check, and isolated strict tracker health pass. Local Node and native Bun regressions each pass 4/4; production differential replay passes 14/14.

The final-head CI matrix passed 4/4 jobs for c4604a6d1a6932e68d40bc50c56de53a5c11ac99:

CI job Full release gate Additional native Bun acceptance
npm / Node 22 1,499 passed; zero failed/cancelled/skipped 1,499 passed; zero failed
npm / Node 26 1,499 passed; zero failed/cancelled/skipped 1,499 passed; zero failed
Bun release / Node 22 1,499 passed; zero failed/cancelled/skipped Covered by npm job above
Bun release / Node 26 1,499 passed; zero failed/cancelled/skipped Covered by npm job above

Every release gate retains exact 100/100/100/100 across 19 authored modules at unchanged thresholds. CodeQL and Semgrep also passed. Independent review remains pending; unavailable/skipped/neutral automated responses are not approval.

Production diff: 24 removed / 17 added lines ignoring indentation (34 removed / 27 added including indentation), net seven fewer lines. No dependency bump.

@sourcery-ai

sourcery-ai Bot commented Oct 25, 2026

Copy link
Copy Markdown

Sorry @unbraind, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 2 days and 1 hour by commenting @sourcery-ai review. Upgrade to get a review now.

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 47ca4a13-acf6-47bc-8234-cb39449e9d69
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 Oct 25, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR migrates GitHub import lifecycle finalization from handwritten lock, persistence, rollback, history, and hook handling to the pinned SDK’s mutateItem boundary while preserving domain-specific lifecycle behavior. It adds real-SDK tests and cross-version differential replay to prove transactional guard enforcement, ownership checks, hook compatibility, no-op retry stability, and intentional diagnostic differences, with supporting README and audit evidence documentation.

Sequence diagram for SDK-backed GitHub import finalization

sequenceDiagram
    participant Import as GitHub import
    participant Finalize as persistImportFidelity
    participant SDK as mutateItem
    participant Hooks as Import hooks
    participant Store as Item and history storage

    Import->>Finalize: persistImportFidelity(pmRoot, id, fidelity)
    Finalize->>SDK: mutateItem(pmRoot, id, mutate)
    SDK->>SDK: Apply governance and ownership guards
    SDK->>Finalize: mutate(document)
    Finalize->>Finalize: Normalize lifecycle fields and validate chronology
    Finalize-->>SDK: changedFields or no-op
    SDK->>Store: Persist item and append history
    SDK->>Store: Refresh derived index
    SDK->>Hooks: Dispatch import and import:history hooks
    SDK-->>Finalize: Complete or refuse before writes
    Finalize-->>Import: Finalization result
Loading

Flow diagram for transactional import lifecycle mutation

flowchart TD
    A[GitHub import finalization] --> B[mutateItem boundary]
    B --> C{Governance and ownership guards pass?}
    C -- No --> D[Refuse before item or history writes]
    C -- Yes --> E[Apply normalized lifecycle fields]
    E --> F{Chronology valid and fields changed?}
    F -- No change --> G[No-op retry]
    F -- Changed --> H[Persist item and history atomically]
    H --> I[Refresh derived index and dispatch both import hooks]
Loading

File-Level Changes

Change Details Files
Replaced manual GitHub lifecycle persistence with the pinned SDK’s atomic item mutation boundary.
  • Delegated locking, item/history writes, rollback, index refresh, and write hooks to mutateItem.
  • Kept lifecycle normalization, source timestamp/retention rules, chronology validation, and no-op detection in the mutation callback.
  • Retained the existing JSON-pointer projection used by import hooks without manually persisting history.
  • Updated missing-item expectations to use the SDK diagnostic.
import-fidelity.ts
test/import-fidelity.test.ts
Added focused and differential coverage for SDK governance, compatibility, and transactional behavior.
  • Verified guards and strict ownership reject before durable writes.
  • Verified both import hooks, changed-field projections, retries, and exact byte stability.
  • Added a disposable snapshot replay harness covering seven scenarios across two public trackers, including intentional diagnostic and lock-observation differences.
test/sdk-adoption.test.ts
test/sdk-adoption-differential.ts
Documented the stricter lifecycle persistence contract and audit disposition.
  • Explained SDK ownership of transactional persistence and native storage/index behavior.
  • Recorded audit findings, differential methodology, intentional behavior differences, and revert proof.
  • Updated README guidance for lifecycle guards, diagnostics, hooks, and legacy document handling.
README.md
docs/sdk-adoption-1025.md
Recorded tracker metadata for the SDK adoption work.
  • Added the task record and history entry for the lifecycle persistence migration.
.agents/pm/tasks/pm-github-d26g.toon
.agents/pm/history/pm-github-d26g.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

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@unbraind unbraind left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orchestrator review (built-in Claude review agent, verified by the orchestrator; bots are not waited for since 2026-10-22):

Pre-merge review (codex gpt-6.1-sol read-only review agent; merged by the orchestrator's pipeline after a MERGE verdict and a private-data scan of the added lines).

VERDICT: MERGE
FINDINGS:

  • none
    SUMMARY: The PR moves import lifecycle persistence into the pm SDK mutation boundary while preserving source dates, hooks, and retry behavior. The tests cover guards, ownership, hook fields, clock changes, and rollback; I reviewed them without executing them.

@unbraind
unbraind merged commit fcd9f93 into main Oct 25, 2026
11 checks passed
@unbraind
unbraind deleted the refactor/sdk-adoption-1025 branch October 25, 2026 18:19
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