Skip to content

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

Open
parraletz wants to merge 6 commits into
Gentleman-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 6 commits into
Gentleman-Programming:mainfrom
parraletz:fix/relation-cloud-sync-support

Conversation

@parraletz
Copy link
Copy Markdown

@parraletz parraletz commented May 5, 2026

Linked Issue

Closes #313

PR Type

⚠️ REQUIRED: This PR needs the type:bug label to be merged.
Add the type:bug label from the PR labels sidebar or run:
gh pr edit 329 --add-label 'type:bug'

  • type:bug — Bug fix

Summary

...

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: ...

…nc relation mutation conflicts

- Combines main with relation mutation support from branch
- Validates relation mutations with required fields (MarkedByActor, MarkedByKind, CreatedAt, UpdatedAt)
- Ensures relation entity only supports Upsert operation
- Updates tests to match combined validation logic
Copilot AI review requested due to automatic review settings May 17, 2026 05:08
@parraletz parraletz force-pushed the fix/relation-cloud-sync-support branch from 0e73891 to 5f89cb0 Compare May 17, 2026 05:09
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 3 out of 3 changed files in this pull request and generated 5 comments.

Comment thread internal/store/store.go
Comment thread internal/store/store.go
Comment thread internal/store/store.go
Comment thread internal/store/store_test.go
Comment thread internal/cloud/chunkcodec/chunkcodec.go
@parraletz
Copy link
Copy Markdown
Author

Hi @Alan-TheGentleman,

The merge with main is complete and all tests pass. However, the automated PR validation workflow requires a type:* label for the PR to be mergeable.

Could you please add the type:bug label to this PR? This is needed for the GitHub Actions workflow check-type-label to pass.

Thanks!

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