#5459·gbrain

Managed sync: an unfinished cursor from an older cursor key is never resumed, and doctor reports it as an unresolved failure forever

Author: Masashi-Ono0611Created Sep 24, 2026Updated Sep 30, 2026

Version: observed on 0.54.1.1 (managed, writer-claimed, local Postgres). The code paths quoted below are unchanged on master at 0.56.2.0 (db56c778e).

What happens

gbrain doctor has reported sync_failures: warn — 2 unresolved sync failure(s) for two days, and nothing an operator can run clears it:

  • gbrain sync --source <id> --no-pull --retry-failed prints Retrying 1 previously-failed file(s)..., then Already up to date., and exits 0. The warning stays.
  • gbrain sync --source <id> --no-pull --skip-failed is refused with Managed sync cannot bypass ignored-file or failed-receipt guards.
  • The file named in the failure now matches its committed blob (git diff is empty), and HEAD has moved on.

What the rows are

There are no managed-sync-failure rows. The two "failures" are unfinished managed-sync cursors from 2026-09-23 (done unset, pending set, index: 0), one per source. Their pending receipts failed with source_changed. Later runs for the same source, incarnation and writer principal ran under a different cursor fingerprint and completed (done: true). We upgraded between those runs. We did not establish which input to the fingerprint changed.

Why it can't clear

  • The run reads its cursor only by the current key: performManagedSync computes key = digest({ source: incarnation, principal, authority, ... }) and calls readCursor(engine, key) (src/core/persistence/sync-run.ts:189, :206). A cursor written under an older key is never resumed.
  • Doctor reads every unfinished cursor, whatever its key: readManagedSyncFailures selects op='managed-sync' AND done<>'true' joined only on source and incarnation (src/core/persistence/sync-failures.ts:50-66).
  • clearManagedSyncFailureAfterSuccess(engine, key) only touches the current key (sync-failures.ts:44-47).

So once the key changes, an unfinished cursor becomes unreachable by sync but stays visible to doctor. Neither --retry-failed nor --skip-failed reaches it. After #5381, --retry-failed follows the durable cursor, but only the cursor for the current key.

Question

What resolution fits the managed model? Some options: (a) Resume or adopt an unfinished cursor for the same source and incarnation even when its key differs. (b) Have doctor treat such a cursor as superseded once a newer cursor for that source and incarnation has completed. (c) Add an explicit, receipt-checked command to retire it.

I have not opened a PR because the choice changes cursor semantics. I can write one once a direction is picked.