Skip to content

Commit 0c52aa1

Browse files
fix(sync-health): a new divergence episode files after a person's ending (#3254)
`sync_diverged` declared no material key, so after a person dismissed the alert, a new divergence episode inside the 7-day snooze filed nothing: the schedules froze again and the queue stayed silent. Every reading already carries the episode start, so `diverged_since` is now the kind's material key. Re-reads of the episode a person ended stay snoozed; a later episode differs and files its own row. Same fix as the flood, budget and Push markers in the sibling slices. Pre-move rows: the ent#706 emitter wrote `diverged_since` into every row's context, so a person-ended legacy row carries the marker and snoozes its own episode only. Tests: a poller-driven test (two days of same-episode re-reads snoozed, then a new episode inside the window is `created`) and a leaf test on a pre-move row shape. Both fail with the key removed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw
1 parent 4c2b9cc commit 0c52aa1

4 files changed

Lines changed: 60 additions & 4 deletions

File tree

‎src/backend/services/platform_alerts.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ def __post_init__(self):
149149
Kind("skills_reconcile_refused", "skills-reconcile-", _N, CLEARS_HOOK),
150150
Kind("skills_fleet_reinject", "skills-fleet-reinject-", _D, CLEARS_HOOK),
151151
Kind("sync_failing", "sync-failing-", _N, CLEARS_HOOK, row_type="sync_failing"),
152-
Kind("sync_diverged", "sync-diverged-", _N, CLEARS_HOOK, row_type="sync_diverged"),
152+
# #3254: the episode start is a material key, so a person's ending snoozes
153+
# re-reads of the SAME divergence episode only; a later episode files.
154+
Kind("sync_diverged", "sync-diverged-", _N, CLEARS_HOOK, row_type="sync_diverged",
155+
material_keys=("diverged_since",)),
153156
Kind("git_bloat_size", "git-bloat-", _N, CLEARS_HOOK, row_type="git_bloat"),
154157
Kind("git_bloat_maintenance", "git-bloat-", _N, CLEARS_HOOK, row_type="git_bloat"),
155158
Kind("db_backup_failure", "db-backup-", _D, CLEARS_HOOK),

‎src/backend/services/sync_health_service.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,8 +890,9 @@ def _observe_sync_diverged(self, agent_name: str, state: Dict, verdict: Dict) ->
890890
"""trinity-enterprise#706: report the divergence freeze through the seam.
891891
892892
One pending row per agent (subject `sync_diverged:<agent>`, #3254), so a
893-
repeat poll, a restart and a fail-open double leader all land on it; a
894-
new episode after the platform ended the last one files a fresh row.
893+
repeat poll, a restart and a fail-open double leader all land on it. A
894+
new episode files a fresh row whoever ended the last one: `diverged_since`
895+
is a material key, so a person's ending snoozes only its own episode.
895896
The context carries counts and the recommendation, never agent-authored
896897
error text.
897898
"""

‎tests/registry.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,7 @@
21932193
"operator-queue",
21942194
"unit"
21952195
],
2196-
"description": "#3254 S2: the git sync health alerts on the platform-alert seam, driven through the real SyncHealthService poll cycle against db_harness with a pinned clock. D2: Kind.row_type keeps sync_failing / sync_diverged / git_bloat as the row type; a kind without one keeps alert or its budgeted type; an explicit row_type that differs from budgeted_type is refused. Per kind (sync_failing, sync_diverged, git_bloat_size, git_bloat_maintenance): the row carries its subject, a re-read bumps seen_count and moves last_seen_at / expires_at, the falling edge ends it cancelled / platform / condition_cleared; a restarted poller's reading lands on the same row; a person's acknowledgement through ask_service.answer stands, a re-read inside the snooze files nothing, the recovery clear never overwrites it. R9: a poll inside 6 h touches nothing; a push-denied failure polled for 31 simulated days keeps one pending row with a moving deadline; a row whose recovery clear was lost expires 30 days after its last reading. AC 5: size and maintenance are two subjects and end separately. The divergence row survives a sync-failing precedence, is re-read under it (31 simulated days keep one row; a failed re-read is retried on the next poll; a restarted poller looks the row up and re-reads it; a worker's miss is looked up again after 6 h, so a row another worker raised is not stranded), a precedence never raises one, even across a restart, and it ends only with its diverged_since episode. R10: an unreachable agent, git switched off, a never cycle, an unknown tuple or a missing / malformed / negative measurement never ends an alert. /cso: an agent-written error past the 64 KiB context belt cannot keep the sync_failing alert out. R1: pre-move sync-failing / sync-diverged ids derive the seam subject; git-bloat ids are exempt and get a lifetime stamp only."
2196+
"description": "#3254 S2: the git sync health alerts on the platform-alert seam, driven through the real SyncHealthService poll cycle against db_harness with a pinned clock. D2: Kind.row_type keeps sync_failing / sync_diverged / git_bloat as the row type; a kind without one keeps alert or its budgeted type; an explicit row_type that differs from budgeted_type is refused. Per kind (sync_failing, sync_diverged, git_bloat_size, git_bloat_maintenance): the row carries its subject, a re-read bumps seen_count and moves last_seen_at / expires_at, the falling edge ends it cancelled / platform / condition_cleared; a restarted poller's reading lands on the same row; a person's acknowledgement through ask_service.answer stands, a re-read inside the snooze files nothing, the recovery clear never overwrites it; diverged_since is a sync_diverged material key, so after a person's ending two days of re-reads of that episode stay snoozed and a new episode inside the 7 days files its own row, and a pre-move person-ended row (its context carries diverged_since) snoozes its own episode only. R9: a poll inside 6 h touches nothing; a push-denied failure polled for 31 simulated days keeps one pending row with a moving deadline; a row whose recovery clear was lost expires 30 days after its last reading. AC 5: size and maintenance are two subjects and end separately. The divergence row survives a sync-failing precedence, is re-read under it (31 simulated days keep one row; a failed re-read is retried on the next poll; a restarted poller looks the row up and re-reads it; a worker's miss is looked up again after 6 h, so a row another worker raised is not stranded), a precedence never raises one, even across a restart, and it ends only with its diverged_since episode. R10: an unreachable agent, git switched off, a never cycle, an unknown tuple or a missing / malformed / negative measurement never ends an alert. /cso: an agent-written error past the 64 KiB context belt cannot keep the sync_failing alert out. R1: pre-move sync-failing / sync-diverged ids derive the seam subject; git-bloat ids are exempt and get a lifetime stamp only."
21972197
},
21982198
{
21992199
"file": "unit/test_1600_proactive_history.py",

‎tests/unit/test_3254_sync_health_alerts.py‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* the row keeps the `type` its readers filter on (D2: `Kind.row_type`);
99
* two readings are one row; a falling edge ends it as the platform;
1010
* a person's ending stands, and a re-reading inside the snooze files nothing;
11+
a new divergence episode is material and files (`diverged_since`);
1112
* a condition that persists is re-read at most every 6 hours (R9), so its
1213
deadline moves while it holds, and only a condition nobody re-read (a clear
1314
lost to a fault) ends on its 30-day lifetime;
@@ -367,6 +368,57 @@ async def test_a_persons_ending_stands(kind, service, seed_agent, db, clock, mon
367368
assert len(_rows(db, sc["prefix"])) == 1
368369

369370

371+
@pytest.mark.asyncio
372+
async def test_a_new_divergence_episode_files_inside_a_persons_snooze(
373+
service, seed_agent, db, clock, monkeypatch):
374+
"""A person's ending snoozes the episode they ended, not the agent. Each
375+
reading carries `diverged_since`, a material key of `sync_diverged`: re-reads
376+
of the ended episode stay quiet, and a divergence that comes back after a
377+
recovery is a new episode that files its own row, inside the 7 days."""
378+
seed_agent()
379+
await _raise(service, clock, SCENARIOS["sync_diverged"])
380+
(first,) = _pending(db, "sync-diverged-")
381+
_person_ends(db, first)
382+
ended_at = clock.now
383+
seam = type(service)._sync_agent.__globals__["platform_alerts"]
384+
real, readings = seam.observe, []
385+
monkeypatch.setattr(seam, "observe", lambda *a, **k: readings.append(
386+
(a[1], real(*a, **k))) or readings[-1][1])
387+
388+
for _ in range(8): # two days of re-reads of the SAME episode
389+
clock.advance(hours=6, minutes=1)
390+
await _poll(service, _AHEAD)
391+
assert [out for k, out in readings if k == "sync_diverged"] == ["snoozed"] * 8
392+
assert _pending(db, "sync-diverged-") == []
393+
394+
clock.advance(**_MIN)
395+
await _poll(service, _OK) # the episode ends; the person's ending stands
396+
assert db.get_sync_state("alpha")["diverged_since"] is None
397+
readings.clear()
398+
await _raise(service, clock, SCENARIOS["sync_diverged"]) # a second episode
399+
assert clock.now - ended_at < timedelta(days=7) # still inside the snooze
400+
assert [out for k, out in readings if k == "sync_diverged"] == ["created"]
401+
(second,) = _pending(db, "sync-diverged-")
402+
assert second["id"] != first["id"]
403+
assert second["context"]["diverged_since"] == db.get_sync_state("alpha")["diverged_since"]
404+
assert second["context"]["diverged_since"] != first["context"]["diverged_since"]
405+
assert db.get_operator_queue_item(first["id"])["status"] == "acknowledged"
406+
407+
408+
def test_a_pre_move_divergence_row_a_person_ended_snoozes_its_own_episode_only(pa):
409+
"""The pre-move emitter (ent#706) wrote `diverged_since` into every row's
410+
context, so a person-ended legacy row the sweep gave a subject carries the
411+
episode marker: the same episode stays snoozed, another one files."""
412+
since = "2026-10-30T07:00:00.000000Z"
413+
ended = {"priority": "high", "context": {
414+
"ahead": 7, "behind": 0, "dirty_files": 0, "diverged_since": since,
415+
"divergence_age_s": 90000, "recommendation": "push"}}
416+
kind = pa.KINDS["sync_diverged"]
417+
assert pa._snoozed_by(kind, ended, "high", {**ended["context"], "divergence_age_s": 99000})
418+
assert not pa._snoozed_by(kind, ended, "high",
419+
{**ended["context"], "diverged_since": "2026-11-02T09:00:00.000000Z"})
420+
421+
370422
# --------------------------------------------------------------------------
371423
# The other shape: the clock 30 days ahead
372424
# --------------------------------------------------------------------------

0 commit comments

Comments
 (0)