bug(sync): autosync blocks local writes every cycle while a non-enrolled legacy backlog exists (v3.6.0)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Read internal/cloud/autosync and internal/store/store.go, especially Manager.push and QuarantineIrreparableSyncMutations. Trace why each poll scans pending cloud mutations for projects that are not enrolled and how that holds the SQLite write lock; the report provides a reproducible large-backlog scenario and an offline server setup. Done when autosync no longer repeatedly blocks local requests on undeliverable backlog rows, while enrolled project sync continues to work.
Written by the indexing model from the issue text.
Description
Existing Issue Search
- I searched existing issues and will add evidence to a canonical tracker when applicable.
📝 Observed Consequence
After enabling cloud autosync (one enrolled project), the local engram serve stops responding for most of every 30-second cycle:
- Agent memory writes time out (
mem_save,mem_delete, session registration). One delete was applied but reported as unconfirmed. GET /healthandGET /sync/statustime out (2 s client limit) for about 25 of every 30 seconds.engram doctorfails withmigration: database is locked (5) (SQLITE_BUSY).- The process uses close to one CPU core continuously.
The enrolled project itself syncs correctly.
The store holds 35,239 pending cloud mutations from 85 non-enrolled projects, journaled from 2026-05-20 to 2026-09-13, before cloud was configured on this machine. None are newer.
🔄 Steps to Reproduce
- Take a store with a large backlog of pending
cloudmutations for non-enrolled projects (here: 35,239 rows, ~25 MB of payload, 228 MB database). - Run
engram servewithENGRAM_CLOUD_AUTOSYNC=1, a cloud server and a token. - Poll
GET /healthevery few seconds across the first poll cycles.
No network is needed: I reproduced it on a copy of the store with ENGRAM_CLOUD_SERVER=https://127.0.0.1:1 (unreachable).
✅ Expected Behavior
A backlog that autosync never delivers should not block local writes on every cycle.
❌ Actual Behavior
On the store copy with the unreachable server, /health timed out (>2 s) when the first poll cycle ran, at about 40 s. The process had used 14.3 s of CPU by then.
The same copy with only those 35,239 rows changed behaves normally. Same measurement (engram 3.6.0, offline):
| Store copy | /health at the first cycle |
CPU after ~40 s | Autosync phase after the cycle |
|---|---|---|---|
| Unchanged | timeout (>2 s) | 14.3 s | no answer |
Rows moved to target_key='cloud:inbox' |
~0.1 s | 1.9 s | degraded / transport_failed (expected offline) |
Rows set to disposition='superseded' |
~0.1 s | 2.2 s | degraded / transport_failed (expected offline) |
Both changed copies kept every memory table and the sync_mutations row count identical; nothing was deleted. Running engram cloud enroll <project> on them backfilled the project's current state (67 observations, 23 sessions, 47 prompts, 12 relations), which matches its live rows.
Workaround applied on the live store: the inbox variant, in one transaction. Afterwards /health answered all 30 probes over ~65 s, the process used 2.4 s of CPU, autosync reported healthy, and a new memory of the enrolled project saved at once and reached the cloud.
Operating System
Windows
Release Version (Report Context)
3.6.0
Agent / Client
Other
📋 Relevant Logs
[autosync] started (server=https://<redacted>)
[autosync] quarantined 214 irreparable pending mutation(s); inspect with `engram doctor --check sync_mutation_required_fields`
engram: engram: migration: database is locked (5) (SQLITE_BUSY)
/sync/status last_error: "pending cloud sync mutations are blocked because project(s) are not enrolled: … (85 projects)"
💡 Additional Context
Client: Pi with gentle-engram, which starts engram serve with ENGRAM_CLOUD_AUTOSYNC=1. OS: Windows 11 Pro.
Possible cause. This is my reading of the source, not proven by a test:
Manager.pushcallsQuarantineIrreparableSyncMutations(targetKey, "", true)on every cycle: the 30 s poll, plus the debounce after each write.- With an empty project, that scans every pending
cloudrow of every project, including non-enrolled ones. It validates each row insidewithTx, and the store opens transactions with_txlock=immediate, so the write lock is held for the whole scan. - The backlog is never delivered, so the scan repeats every cycle.
internal/cloud/autosyncandinternal/store/store.goare unchanged betweenv3.6.0andmain@9824739.
Related:
- #1896: same symptom, different path (enrolled repair backfill); closed.
- #1013: non-enrolled backlog; list/claim/drop not shipped.
- #1188: inbox.
docs/CLOUD-INBOX-STATE.mdsays legacy migration is not implemented, so moving old rows to the inbox has to be done by hand with SQL.
- Dominant language
- Go
- Stars
- 7.1k
- Forks
- 729
- Avg merge
- 9h 12m
- Merged PRs (30d)
- 331
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Gentleman-Programming/engram
-
status:needs-review type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Gentleman-Programming/engram#2138 ·
Maintainers usually reply within 1 day
-
status:needs-review
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Gentleman-Programming/engram#2065 ·
Maintainers usually reply within 1 day
-
bug(opencode): early local identity failures hide actionable recovery diagnosticsPossibly taken @dnlrsls claimed this today. Openstatus:approved type:bug
Gentleman-Programming/engram#2170 · 1 assignee ·
Maintainers usually reply within 1 day
-
bug(tests): investigate session-owned startup failure assertion under Linux race CIPossibly taken @dnlrsls claimed this 1 day ago. Openstatus:needs-review type:bug
Gentleman-Programming/engram#2169 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
fix(test): prevent autosync requests racing with TLS fixture cleanupPossibly taken @dnlrsls claimed this 1 day ago. Openstatus:approved type:bug
Gentleman-Programming/engram#2165 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in Gentleman-Programming/engram
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
nebari-dev/nebi#630 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
router-for-me/CLIProxyAPI#7084 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
speakeasy-api/openapi#284 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
yetone/magpie#4095 · 1 comment ·
Maintainers usually reply within 1 day