Make GitHub issue imports atomic and crash-resumable

Merged
UN
4mo ago
+1191-117

Summary

  • add opt-in --atomic GitHub issue imports using the pm 2026.7.20 commitItemMutations SDK primitive
  • make transaction identity and ordered mutation plans stable across reordered API responses and partially applied retries
  • compensate mixed create/update/close failures, report recovered batches truthfully, and keep native comment annotations post-commit
  • adopt the field-aware PM merge driver and convert the last JavaScript test helper to TypeScript

Why

The previous importer issued one pm mutation per GitHub issue. A failure or concurrent agent could expose partially imported state, while a reordered retry could not safely resume a durable batch. This change makes the full tracker write atomic, crash-resumable, and workspace-writer-locked without changing the default non-atomic path.

PM context

Validation

  • npm run release:check
  • npm test — 134/134 passing
  • real local-package installation and two consecutive atomic imports of current unbraind/pm-cli issues; the second run recovered the same transaction with no duplicates
  • mixed-batch failure test proves pre-existing updates and closes are snapshot-restored
  • production dependency audit: 0 vulnerabilities
  • npm pack dry-run and changelog check: clean
  • full 110-commit credential-signature scan: 0 findings; current PM records use portable workspace paths
  • Greptile pre-push reviews a895c1d7-69a7-4b83-b679-e2ab9d022b71, e7e6bbcc-8d7f-470f-85fd-ca677873e6ee, and 3f9186b2-a856-47bf-b436-733bdf4056fc; final review: 5/5, safe to merge, no comments

Summary by Sourcery

Add an opt-in atomic mode for GitHub issue imports that uses pm-cli bulk item mutations to ensure crash-resumable, non-partial tracker updates while keeping the legacy import path unchanged.

New Features:

  • Introduce an --atomic flag on the GitHub import commands that commits all issue changes as a single workspace-writer-locked transaction.
  • Expose additional TypeScript types and helpers for GitHub issues, comments, import options, and atomic import configuration.
  • Provide a new atomic import pipeline that derives stable transaction and item identities from GitHub issue content and provenance.

Enhancements:

  • Improve native comment annotation handling so comments are synced only after a successful atomic commit while preserving existing deduplication behavior.
  • Update CLI help text, README usage examples, and option documentation to describe atomic imports and their failure semantics.
  • Raise the minimum pm-cli version and manifest requirement to align with the newer commitItemMutations SDK primitive.

Build:

  • Bump pm-cli and pm-changelog dev/peer dependency versions to match the new atomic import capabilities.

Documentation:

  • Document the new --atomic flag, its behavior, and how it interacts with provenance, retries, and native comment annotations in the README.

Tests:

  • Add a comprehensive atomic import test suite covering transaction identity stability, crash-resumable behavior, rollback guarantees for failed batches, and actionable SDK-version errors.
  • Adjust existing concurrent comment-sync tests to use the new TypeScript helper entrypoint instead of the old JavaScript module.

Summary by cubic

Adds an opt-in --atomic mode to GitHub issue imports that commits all creates/updates/closes in one crash-resumable transaction. Dry-run previews now mirror the atomic plan exactly, and recovery is hardened to avoid collisions across retries.

  • New Features

    • --atomic for both pm github import and pm gh-issues import, backed by commitItemMutations in @unbrained/pm-cli 2026.7.20.
    • Deterministic item IDs and a transaction identity that fingerprints the exact ordered mutation plan and provenance; safe across reordered/partial retries.
    • --dry-run routes through the same rendering and provenance matching as commit for truthful previews (the SDK commit path remains disabled).
    • On failure, creates are rolled back and updates/closes snapshot-restored, with clear reporting for interrupted and compensated transactions; native comment annotations sync only post-commit with cross-process dedupe; README documents --atomic.
  • Migration

    • Requires @unbrained/pm-cli >= 2026.7.20.
    • Default (non-atomic) behavior is unchanged.
    • To use it: run imports with --atomic; --dry-run works as before.