Skip to content

Cloud sync fails: session mutations missing directory field when MCP server upserts sessions #249

@quirozino

Description

@quirozino

Bug Description

When using the MCP server with ENGRAM_CLOUD_AUTOSYNC=1, cloud sync fails with:

engram: canonicalize cloud chunk: mutations[N]: session payload directory is required for upsert

Root Cause

The MCP server generates sync_mutations entries for session upserts that are missing the directory field in the JSON payload. Example of a problematic mutation payload:

{"id":"manual-save-ddata","project":"ddata","started_at":"2026-04-18 00:41:04"}

The directory field is absent entirely (not empty string, but missing). The cloud chunk canonicalizer requires this field for session upserts and fails hard with no fallback.

Repro Steps

  1. Configure engram MCP with ENGRAM_CLOUD_AUTOSYNC=1 and a cloud endpoint
  2. Use mem_save tool from the MCP multiple times in a session
  3. Run engram sync --cloud --project <name>
  4. Observe: mutations[N]: session payload directory is required for upsert

Workaround

Manually patch the affected rows before syncing:

UPDATE sync_mutations 
SET payload = json_set(payload, '$.directory', '/path/to/project')
WHERE entity = 'session' 
AND json_extract(payload, '$.directory') IS NULL;

Expected Behavior

Either:

  • The MCP server should always include directory in session mutation payloads
  • OR the cloud sync canonicalizer should be tolerant of missing directory and use a fallback from the sessions table

Environment

  • engram client: v1.14.0 (Windows, scoop)
  • engram server: v1.14.1 (Docker, self-hosted)
  • OS: Windows 11 / PowerShell
  • MCP tools profile: --tools=agent

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions