Skip to content

Cloud repair should backfill and report legacy mutation required fields #340

@IrrealV

Description

@IrrealV

📋 Pre-flight Checks

  • I have searched existing issues and this is not a duplicate
  • I understand this issue needs status:approved before a PR can be opened

📝 Bug Description

This is the product-repair slice split out from umbrella issue #299, per maintainer feedback to separate product repair behavior from wrapper/script hardening.

Legacy local SQLite databases can contain frozen sync_mutations.payload snapshots that violate current cloud canonicalization requirements. Current engram cloud upgrade doctor / repair does not give users a complete local-only repair path for the observed required-field blockers.

Observed blocker classes:

  • session payloads with missing or empty directory.
  • sessions.directory='' rows that should be backfilled before repairing corresponding mutation payloads.
  • observation payloads with required fields missing or empty, observed as type='' in the WSL/Beta repair and content missing/empty in the macOS confirmation comment on Cloud sync legacy repair misses empty project/type mutations and autosync can fail silently #299.
  • legacy/project-consolidation cases where sync_mutations.project no longer matches the canonical current project name, leaving repair inference incomplete unless aliases or project mappings are considered.
  • old mutations with project='' / directory='' that need to be reported or canonicalized before project filtering hides them from project-scoped sync diagnostics.

🔄 Steps to Reproduce

  1. Start from a legacy Engram database with pending sync_mutations rows captured before current cloud-required payload fields existed.
  2. Include one or more rows such as:
    • entity='session' with payload.directory='' or missing.
    • local sessions.directory='' for the same project/session.
    • entity='observation' with payload.type='' or missing required content/title/scope fields.
    • sync_mutations.project='' for old imported/projectless mutations.
  3. Run engram cloud upgrade doctor --project <project> and/or engram sync --cloud --project <project>.
  4. Observe blocked sync requiring manual SQL rather than a complete dry-run/apply repair report.

✅ Expected Behavior

Product code should provide an explicit, local-first repair/diagnostic path that:

  • dry-runs by default and supports an explicit --apply mode before mutating SQLite;
  • backfills sessions.directory when an inferable canonical directory exists;
  • updates frozen sync_mutations.payload snapshots for repairable required fields, including session.directory and observation required fields;
  • reports unfixable rows with seq/entity/op/project/entity_key and the exact missing/empty field;
  • handles project rename/consolidation cases through explicit alias/mapping input or clear manual guidance;
  • reports projectless (project='') legacy mutations instead of letting project-scoped sync hide them;
  • never edits last_acked_seq, never deletes mutations silently, and never auto-repairs during autosync.

❌ Actual Behavior

Real repairs required manual SQLite edits:

  • WSL/Beta: 17 engram sessions with directory='', 5 old project='' / directory='' mutations, and one observation with type=''.
  • Windows/Beta: 5 old project='' / directory='' mutations blocking scheduled sync for opencode and engram.
  • macOS confirmation on Cloud sync legacy repair misses empty project/type mutations and autosync can fail silently #299: 560 sync_mutation_required_fields blockers reduced to 9 via manual SQLite repair; 558 were sessions missing directory, and 2 observations were missing content.

Operating System

Windows (WSL)

Engram Version

1.15.x / Beta cloud sync environments

Agent / Client

OpenCode

📋 Relevant Logs

# macOS confirmation from #299
sync_mutation_required_fields blocked findings: 560
entity=session, missing_fields=[directory]: 558
entity=observation, missing_fields=[content]: 2
blocked findings after manual SQL repair: 9

💡 Additional Context

Parent umbrella: #299.

Related but distinct issues:

Suggested product shape from #299 discussion: a local SQLite repair command such as engram cloud repair backfill-directory --project <name> [--dry-run|--apply], potentially generalized to cloud repair legacy-mutations, plus improved cloud upgrade doctor reporting.

This issue intentionally excludes operator Bash/PowerShell wrapper behavior; that is split into a separate child issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions