Skip to content

fix(store,chunkcodec): add relation entity support to cloud sync pipeline#329

Open
parraletz wants to merge 5 commits intoGentleman-Programming:mainfrom
parraletz:fix/relation-cloud-sync-support
Open

fix(store,chunkcodec): add relation entity support to cloud sync pipeline#329
parraletz wants to merge 5 commits intoGentleman-Programming:mainfrom
parraletz:fix/relation-cloud-sync-support

Conversation

@parraletz
Copy link
Copy Markdown

Linked Issue

Closes #313

PR Type

  • type:bug — Bug fix

Summary

  • Adds SyncEntityRelation to the legacy mutation evaluator so relation mutations are no longer classified as manual-action-required blockers during cloud sync preflight.
  • Adds SyncEntityRelation to the chunk codec canonicalizer so relation payloads can be exported in push chunks.
  • Fixes the server-side ingestion path automatically because cloudserver delegates chunk validation to the same chunkcodec package.
  • Covers both code paths with focused unit tests.

Changes

File Change
internal/store/store.go Added SyncEntityRelation to supported legacy entities; added full case SyncEntityRelation: in evaluateCloudUpgradeLegacyMutationTx with decode + local-state inference + validation + repairable classification.
internal/store/store_test.go Added legacy relation mutation required fields are detected and repaired from authoritative local state subtest.
internal/cloud/chunkcodec/chunkcodec.go Added SyncEntityRelation to validateSupportedMutation; added mutationRelationPayload struct; added case SyncEntityRelation in normalizeMutationPayload with required-field validation and project canonicalization.
internal/cloud/chunkcodec/chunkcodec_test.go Added tests for relation upsert (project rewrite), missing required fields rejection, and relation delete.

Test Plan

  • Unit tests pass locally: go test ./...
  • Focused tests pass:
    • go test ./internal/store -run TestUpgradeRepairDryRunAndApply -v
    • go test ./internal/cloud/chunkcodec -v
  • Manually tested the affected functionality:
    1. Ran engram cloud upgrade doctor --project addi-challengestatus: ready
    2. Ran engram cloud upgrade repair --project addi-challenge --applyapplied: true
    3. Ran engram sync --cloud --project addi-challengeCloud sync complete (53 mutations exported)

Notes for Reviewers

  • The server-side fix is implicit: cloudserver.go calls chunkcodec.CanonicalizeForProject, which now accepts relation mutations.
  • syncRelationPayload already existed (Phase 2 wire format); this change only bridges it into the cloud sync export/repair paths.
  • No breaking changes to existing entities (session, observation, prompt).

parraletz added 2 commits May 3, 2026 19:58
…ir pipeline

- Add SyncEntityRelation to supported legacy entities in evaluateCloudUpgradeLegacyMutationTx.
- Implement full case SyncEntityRelation with decode, field inference from memory_relations, missing-field validation, and repairable/canonicalization logic.
- Add unit test for relation legacy mutation repair from authoritative local state.

This fixes cloud sync being blocked by upgrade_blocked_legacy_mutation_manual: unsupported legacy mutation "relation"/"upsert" when relation mutations are pending for a project.
…alizer

- Add SyncEntityRelation to validateSupportedMutation.
- Add mutationRelationPayload struct matching syncRelationPayload wire format.
- Add case SyncEntityRelation in normalizeMutationPayload with decode, required-field validation (source_id, target_id, relation, judgment_status, created_at, updated_at), and project canonicalization.
- Add unit tests for relation upsert (project rewrite), missing required fields rejection, and relation delete.

This fixes the client-side chunk export failing with canonicalize cloud chunk: unsupported mutation "relation"/"upsert".
Copilot AI review requested due to automatic review settings May 5, 2026 03:22
@parraletz
Copy link
Copy Markdown
Author

Hi @Alan-TheGentleman,

The fix for cloud sync being blocked by relation mutations is ready for review in PR #329.

It links the approved issue #313 and includes regression coverage for both the legacy mutation evaluator and the chunk codec canonicalizer. Manual end-to-end verification was also completed successfully.

Could you please add the type:bug label so the automated checks can run? Thanks!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes cloud sync being blocked by legacy relation mutations by adding SyncEntityRelation support to both the legacy-mutation upgrade evaluator (preflight/repair) and the cloud chunk canonicalizer, along with unit tests covering the new paths.

Changes:

  • Extend legacy cloud-upgrade mutation evaluation/repair logic to handle relation upserts/deletes.
  • Extend chunk canonicalization/validation to accept and normalize relation mutations (including project rewrite).
  • Add focused unit tests for relation mutation repair and chunk canonicalization behaviors.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
internal/store/store.go Adds relation to supported legacy entities and implements relation payload decode/repair/validation in the upgrade evaluator.
internal/store/store_test.go Adds a regression test ensuring malformed legacy relation payloads can be repaired from local state.
internal/cloud/chunkcodec/chunkcodec.go Adds relation to supported mutations and normalizes relation payloads (required fields + project canonicalization).
internal/cloud/chunkcodec/chunkcodec_test.go Adds tests for relation upsert (project rewrite), missing required fields rejection, and relation delete.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/store/store.go Outdated
Comment thread internal/store/store.go Outdated
parraletz added 2 commits May 4, 2026 21:34
- Use mutation.Project as authoritative fallback for body.Project instead of local.Project (memory_relations has no project column).
- Remove ifnull(..., "") wrappers from nullable columns (marked_by_actor, marked_by_kind, marked_by_model, session_id) in the memory_relations query so NULL stays nil in *string pointers instead of becoming non-nil empty strings.
Copilot AI review requested due to automatic review settings May 5, 2026 15:33
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/store/store.go
Comment thread internal/store/store_test.go
@ricardoarz-dev
Copy link
Copy Markdown

Probé contra una DB con el bug real (3 mutations relation/upsert atascadas bloqueando sync).

Cliente, OK:

  • cloud upgrade doctor: blocked → ready ✅
  • cloud upgrade repair --apply: manual-action-requiredupgrade_repair_noop

Server, me trabé:

  • engram sync --cloud --project X cae con status 400: invalid push payload: mutations[4]: unsupported mutation "relation"/"upsert"
  • El error viene del chunkcodec del lado server. Mi cloud serve está corriendo binario sin este PR, por eso rechaza el payload con relation entity.

O sea, el fix funciona end-to-end siempre que cliente + server cloud estén ambos en el binario con el PR. Si solo se sube el cliente, los push con relation/upsert vuelven con 400.

Sugerencia: dejar nota en release sobre upgrade simultáneo cliente+server. O que el server haga back-compat durante una versión intermedia (acepte y haga skip de relation mutations, en vez de 400).

Bonus, el handler de error con sugerencias de recovery está muy útil:

Known repairable cloud sync failure detected.
Run these commands, then retry sync: ...

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.

fix(store,chunkcodec): cloud sync blocked by unsupported relation mutations

3 participants