sync start retry: launchd restarts after exit 3, config re-read, and loop test gaps #78
Labels
No labels
boundary:crosses
bug
enhancement
epic
needs-info
needs-triage
ready-for-agent
ready-for-human
svd:go
svd:hold
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dev/messages-mind-mcp#78
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Findings from the two fresh reviews of PR #77 (#38) at
5d8a488, and from the architect's hand mutations. Neither review found a blocker. Line numbers are at5d8a488.Should fix (documents)
README.md:80-96; pre-existing). The sync plist setsKeepAlivetrue withThrottleInterval 60, so launchd restarts the process after exit 3 (docs/install-single-host.md:195says so). Under the shipped agent,tombstones-schema-aheadand every other stop code still restart about every 60 s. The #38 spec's claim that "the plist already handles exit 3" is false. Decide: say plainly in the table that the agent restarts after exit 3, or change the plist so that exit 3 is not restarted (KeepAlivewithSuccessfulExit/exit-code rules). The plist is a deployment surface; the operator decides.sync.py:697-708). The base re-read them on each launchd restart. Experiment: no Mirror, a damaged Tombstone store and no export configured at start, then the store is deleted during the wait andtombstone_export_pathis added to the config. The base would restart and refuse withtombstones-not-restored. #77 goes on with the old config, creates empty stores and syncs the history back, Forgotten messages included. Fix: one README sentence ("a retry does not re-read the config or the secrets; restart the agent after you change them"), or re-read the config on each retry.README.md:142; a marked Mirror beside a 0-byte Tombstone file) now showTries again.. The steps (move the Mirror aside, then--rebuild) do not say to stop the agent first, and there is no single-instance lock (nofcntl/flock), so a retrying loop can race a Rebuild. The same window existed underKeepAlive.Test gaps
tests/test_sync.py:886-950). Deletingstop.wait(cfg.feeder.poll_seconds)from the start branch passes all 4 cases oftest_an_open_failure_is_retried_at_start_as_during_a_pass(the waits move after two passes). Assertlen(lines) == 2, or that the second open follows the first wait.if stop.is_set(): return EXIT_OK, and retrying every code (if stop is None:). Each makestest_a_stop_request_ends_the_wait_after_a_start_failureortest_a_schema_ahead_..._mirror[loop]loop forever. The suite has no per-test timeout. Make theStopdoubles set after N waits and assert the count.tombstones-unreadablebeside an existing Mirror writesfailed_ateach attempt (the spec's Risk Flag: this keeps/healthz/syncfailing). Recording only on the non-retry path passes the four suites (663 tests)._failure(conn)from the outerexceptin_runpasses the four suites at the head (663) and at the base (654). That handler is reached only when building the Feeder source fails.failed_atwritten, open-file count unchanged); the Tombstone file deleted during the wait (tombstones-missing, exit 2, nothing created); a newer-schema store swapped in (tombstones-schema-ahead, exit 3); no Mirror, an export configured, and the damaged store deleted (tombstones-not-restored, exit 2).stop.waits == []in theoncecase (tests/test_sync.py:871-881) is vacuous.Notes
tombstones-unreadableuntil the store is repaired, then stops withstore-unreadable. The base output is the same; it is now an in-process retry._start_failurecheckspath_existsand then calls_open_mirror, which can create a Mirror. If the Mirror vanishes between the two, an empty marked Mirror appears. No message can come back, because the Tombstone guard holds. Considerstore.open_writer. On the 0.1.0 legacy path (0-byte Tombstone file, Mirror without the marker), a transienttombstones-unreadablemakes_start_failurewrite the marker, and every later attempt then refuses permanently. Same as the base underKeepAlive, but the loop now spins atpoll_seconds.tombstones-schema-aheadin practice (restore_tombstonesrefuses an existing store;_verify_exportrequiresSCHEMA_VERSION). The spec's "exits 3 in a Rebuild" is untested and theoretical.Triage decisions (2026-11-16)
The operator accepted these decisions ("Yes, my way").
KeepAliverule cannot pick out one exit code. The README code table says plainly that the shipped agent restarts about every 60 s after a stop code (exit 3), and that the code shows in the log and in/healthz/synceach time.docs/install-single-host.mdsays the same.tombstone_export_pathis added, so the retry refuses withtombstones-not-restoredand syncs nothing back.fcntl.flockon a lock file beside the Mirror) forsyncand--rebuild. A second instance refuses with a named code. The recovery steps also say to stop the agent first.Stopdoubles set after N waits and assert the count, so a wrong implementation fails and never hangs. Item 9 gets a real assertion.store.open_writerin_start_failure, so that a missing Mirror is not created there.Sequencing
Run SVD after #65 merges, because both write
README.md. Run it before #75 and #72, because item 2 can bring back Forgotten messages.Filed under: #38 merge gate, fresh reviews of PR #77 at
5d8a488.The operator accepted the triage decisions on 2026-11-16. They are now in the issue body under "Triage decisions (2026-11-16)". State: ready-for-agent.
⏸ SVD architect gate: dev/messages-mind-mcp#78 sync-start-retry-launchd-restarts-after-exit-3-config-re-rea
Status: CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity
substrate· dispatch efforthighRun:
20261116T004911Z-60ccad9dHeld because: CLEAN but 5 open risk(s) (2 verification · 3 decision) — HOLD-ALL parks everything. The risks, verbatim:
Open risks:
messagesmind sync --config FILErunning,messagesmind sync --config FILE --oncemust printsync=error code=sync-runningand exit 2. [verification]make checkon pristine2f42311(host, macOS) and record the counts; after the change it asserts the failure set is unchanged. Directory-snapshot tests other than tests/test_deletion.py:803-818 may need the .lock exclusion; the full run finds them. [verification]Change: (1) Single-instance lock: a private _InstanceLock in sync.py takes fcntl.flock(LOCK_EX|LOCK_NB) on .lock, opened with O_CREAT|O_NOFOLLOW|O_CLOEXEC and mode 0o600. BlockingIOError raises StoreError('sync-running'); the code goes in CODES and SETUP_CODES (exit 2) and is not retried. sync_once and sync_loop hold the lock through _run, which calls lock.hold(cfg.store.path) inside the start try before _open_stores. rebuild holds it before the rebuild-store-present check (sync.py:754) and passes it to _run. Forget does not take it. (2) Re-read: sync_loop/_run get reload: Callable[[], tuple[Config, Secrets] | int] | None. The _run start loop (sync.py:691-708) moves the feeder/salt preamble inside the loop. After wait and the is_set check it calls reload(); an int return is returned as-is. cli.py factors the config=error/secret=error prints (cli.py:118-123) into _refused(), adds _reloader(config) wrapping startup.start(config, 'sync'), and passes reload= at cli.py:154. (3) _start_failure (sync.py:678-685) calls store.open_writer(path, key, create=False). That is a new keyword: skip create_private, connect with the mode=rw URI as _open_guarded does (store.py:281), and refuse user_version 0 with store-absent. So no Mirror is created and no deletion_slice marker is written. (4) Docs: the exit-3 Loop cells in the README code table state the launchd restart about every 60 s (the plist ThrottleInterval); a sync-running row is added. A paragraph covers: the log shows the code, /healthz/sync answers 503, the start retry re-reads config and secrets, the lock, and notes 10 and 12. The recovery steps add 'Stop the sync agent first.' while keeping 'Move the Mirror aside'. Matching edits go to SECURITY.md:41 and docs/install-single-host.md:195. (5) Tests: a module-level BoundedStop(set_at, fail_at) plus call-bounded failing stubs, so wrong loops fail rather than hang; new tests for items 2, 3, 4, 6, 7, 8a-d, 9 and 11. Update the tests/test_config_cli.py:1176 sync_loop double, the tests/test_sync_documents.py loop_column_agrees, and the tests/test_deletion.py:803-818 store-dir snapshot (exclude .lock).
Files:
src/messages_mind_mcp/sync.py·src/messages_mind_mcp/store.py·src/messages_mind_mcp/cli.py·tests/test_sync.py·tests/test_config_cli.py·tests/test_sync_documents.py·tests/test_deletion.py·tests/test_store.py·README.md·SECURITY.md·docs/install-single-host.mdDecision: accept the 5 open risk(s) above and dispatch this spec (
svd:go), or park (svd:skip) / re-spec (svd:respec)?Your call (when this issue is held at the gate via
svd:hold):svd:go— approve; Half-B dispatch accepts exactly this spec (open risks accepted)svd:firebesidesvd:go— approve AND authorise the Half-B fire from the phone; never on its ownsvd:skip— park it; dispatch refuses it and the issue stays for a humansvd:respec— discard this spec; the next Half-A run re-produces it with this record as prior-attempt contextSpec:
/Users/piers/.local/state/exhaust/groupthink/specs/2026-11-16-sync-start-retry-launchd-restarts-after-exit-3-config-re-rea.md— next:codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-16-sync-start-retry-launchd-restarts-after-exit-3-config-re-rea.mdspec-verify-dispatch Half B for dev/messages-mind-mcp#78 sync-start-retry-launchd-restarts-after-exit-3-config-re-rea completed integration verify.
70992f3f23sync --oncewhile a sync runs on each deployed store volume and expectsync-running, exit 2.codex-svd ship --run-id 20261116T010546Z-05ad1830 --confirm-merge)