Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

docs(eval): #6278 Phase 4.1 results on the fixed head (reporter-shape pool 10 and 3, forced lock, fence outcomes, concurrent fence_repair) + bench summarizer

garrytan76f9e9b2ecde
diff --git a/docs/eval/managed-sync-stall-repro.md b/docs/eval/managed-sync-stall-repro.md
index a5cfe26f75..64075699c8 100644
--- a/docs/eval/managed-sync-stall-repro.md
+++ b/docs/eval/managed-sync-stall-repro.md
@@ -170,3 +170,221 @@ UBI_OWNER=gbra59 scripts/ubicloud/ubi-runner.sh run -s standard-16 --setup scrip
it needs its own note on the issue because the reporter's `queued=73`
could be either the sync's own admitted window or queued adoptions, and
`writer status` does not say which without `intent->>'kind'`.
+
+## Phase 4.1: fixed head
+
+The same fixture and topology (16-vCPU `standard-16`, PgBouncer transaction
+mode with `statement_timeout` dropped, 57 ms, heavy adoption, non-TTY
+`timeout 3600 gbrain sync --source bench --no-pull --no-embed` looped until
+the source reports synced) against the complete PR 1 head (14962f947 plus the
+Phase 4.1 bench captures, `capy/6278-phase41` 846bea44, VERSION 0.60.108.0
+with the 0.60.109.0 changelog). The bench now records, per pass, the hold
+records by code and reason, writer status, `preparation_stalled` receipts and
+the drain's closing lines (`post-pass-N.json`); one `gbrain dream --phase
+fence_repair` run 20 minutes into pass 1 (`fence-repair.json`); the fate of
+every seeded legacy row by shape (`legacy_outcome`); `gbrain doctor --only
+fence_integrity --json`; and `gbrain sources retry-held` plus the sync it
+prints after the passes (`retry-held.json`). `scripts/bench/stall-repro-summarize.py
+<dir>` prints the figures below from `report.json` and `samples.jsonl`
+(steady pages/min is the middle 80% of a pass by time; the longest no-commit
+window is the largest `committed_stale_ms` the 30 s sampler saw).
+
+### Before/after
+
+| run | gbrain | pool | passes to synced | pages per pass | pages/min per pass (wall; steady) | longest window with no committed page | `sync_deadline_stop` | failed receipts | holds at end |
+|---|---|---|---|---|---|---|---|---|---|
+| A heavy (Phase 0) | 0.60.105.0 | 10 | never (stopped after 48 min) | 102 | 2.6 → 16 → 0 | 888 s (queued adoptions) | none | 471 `repeated_marker` + 276 round-trip refusals on the comparable head run; 0.60.105 killed before the tail | 20 `invalid_fence` |
+| C heavy (Phase 0) | 0.60.105.0 | 3 | never (stopped after 44 min) | 62 | 1.4 → 0 | 668 s (same) | none | — | 20 |
+| B heavy (Phase 0) | GBRA-45 head d99e2b43 | 10 | 3 | 3,900 / 7,538 / 3,542 | 65 / 126 / 75 | 285 s (tail) | none | 471 `repeated_marker` + 276 "does not render its legacy fact" | 20 |
+| D heavy (Phase 0) | GBRA-45 head d99e2b43 | 3 | not reached in 170 min | 3,425 / 4,747 | 57 / 79 | 33 s | none | same classes | 20 |
+| **4.1 pool 10** | this head | 10 | **2** (91 min) | 7,719 / 7,261 | 128.7 (119.8) / 231.1 (262.5) | 605 s (pass 1, queued adoptions); 285 s (pass 2 tail: 20 holds + links pass, queue empty) | none (pass 1 ended rc 124 from the outer `timeout 3600`; pass 2 `Managed sync synced`) | **0** | 20 `invalid_fence` / `repeated_marker` |
+| **4.1 pool 3** | this head | 3 | 3 passes committed every page; the third was cut by the outer `timeout` at 14,996/15,000 processed and the `retry-held` sync closed it `synced` | 3,076 / 6,355 / 5,545 | 51.3 (46.5) / 106 (104.8) / 92.5 (93.5) | 544 s (pass 1, queued adoptions); 0 s; 64 s | none (every pass rc 124 from the outer `timeout`) | **0** | 20 `invalid_fence` / `repeated_marker` |
+
+Every pass ended at the outer `timeout 3600` (rc 124, SIGTERM from the
+reporter's loop) or `synced`; no pass stopped on the non-TTY watchdog
+(`sync_deadline_stop`, rc 143) or on a drain stop reason, and no pass
+printed `restart_required`. Each pass checkpointed and the next resumed at
+the cursor without re-walking entries (pass 2 of the pool-10 run started at
+7,719, pass 3 of the pool-3 run at 9,435). The 15,000-entry fixture does not
+drain in one 3600 s pass on this topology at 120-260 pages/min, which is a
+throughput ceiling, not a stall: the reporter's own loop ran under `timeout
+14400`.
+
+The one zero-progress window that remains is Phase 0's second mode, not a
+stuck preparation: after the first `extract_facts` run of the heavy load
+(killed by the harness at 20 minutes, as on every build), 70-100
+`managed_maintenance_adopt_fact_fence` requests sit queued on the worktree
+root ahead of the sync's admitted imports and publish one at a time. In the
+pool-10 run the sync committed nothing from 09:59:12 to 10:09:51 (605 s)
+while 22 different adoption requests ran and committed (every sample shows a
+different `running` request, `claim_phase` ages of seconds, `writer status`
+`assessment: pending`); the pool-3 run's 544 s window is the same shape (34
+different running requests). 0.60.105 took 888 s and 668 s here and never
+recovered its rate; the GBRA-45 head took 285 s; this head's windows are
+longer than GBRA-45's because every adoption now succeeds (255-285 committed
+adoption writes per run, 0 refusals), so more of them publish. Nothing in the
+window is a single request holding the root.
+
+### Writer status during the runs (G2)
+
+Across the two reporter-shape runs the deep samples saw 3,676 `preparing`
+blockers in `writer status --json`; none was past its budget (oldest phase
+age 29.6 s), so `claim.stall` was null on all of them, as it should be. 58 of
+them carried `diagnostic.reason: cause_unknown`: that field is computed from
+the request's `created_at` (older than 120 s, mostly time spent queued) and
+not from the claim, so a request that waited in the queue and is now a few
+seconds into preparing reads `cause_unknown` next to a `claim` block that
+says `phase: preparing`, `phase_age_ms: 3000`. In the lock run (below) all 39
+overdue observations carried `claim.stall = { reason: preparation_overdue,
+step, step_age_ms, waiting_on: db, budget_ms: 120000 }` and, at the same
+time, `diagnostic.reason: cause_unknown` and `diagnostic.assessment:
+stalled`. The step is always named once a preparer has entered one; the two
+fields disagree in wording on the same row.
+
+### Forced stall inside the real run (lock run, `--chaos-kind lock`, 2 × 300 s)
+
+Same topology and load on a 3,000-entry backlog (so one pass completes),
+pool 10, `LOCK TABLE pages IN ACCESS EXCLUSIVE MODE` held through the pooler
+from 09:41:26 to 09:46:26 and from 09:51:26 to 09:56:26. Captures:
+`chaos.jsonl`, `stall-1.json`, `samples.jsonl`, `post-pass-1.json`,
+`retry-held.json`.
+
+- **Budget fires at 120 s; the group members are not released while the
+ lock is held.** 18 `managed_sync_import` members of six lane groups entered
+ `preparing` at 09:41:25 (steps `canonical_projections` ×4,
+ `page_snapshot` ×4, `origin_check` ×8, `knowledge_publication` ×1, all
+ `waiting_on: db`); 14 later members sat `running` without a stamp. The
+ consumer logged `[persistence] phase=preparation reason=deadline_exceeded`
+ between the 300 s and 360 s watchdog ticks (09:43:25-09:44:25, the budget
+ after a 09:41:25 claim) and `writer status` showed `claim.stall: preparation_overdue`
+ with the step from the 09:43:41 sample on. But the members stayed
+ `running` / `preparing` with `preparation_attempts: 0` and no
+ `blocked_reason` until the lock dropped: `pg_stat_activity` had 9 of the
+ sync's 10 pool connections in `Lock` / `relation` on the blocked statements
+ for the whole hold, and the only statements the sync completed between
+ 09:43:30 and 09:46:20 were 51 claim renewals on the one free connection
+ plus two `UPDATE persistence_requests SET state='queued'` releases. The
+ release of member k needs a connection and the lock-blocked statements
+ (the zombies) pinned them. Releases that did land took five members off
+ the running set (18 → 12 preparing by 09:44:17). This is the condition
+ lane A9 is changing (the budget cancels the blocked statement, which frees
+ its connection); on this head the deadline is observed and named but the
+ root stays held by the zombies.
+- **Root release and resumption:** 300 s after the lock was taken (the lock
+ duration, 2.5× the budget), not at 120 s. First committed page after
+ release 1: 09:46:54 (28 s after the lock dropped, 176 → 196). No
+ `preparation_abandoned` (the 300 s hold is inside the 600 s ceiling, so the
+ ceiling path and `restart_required` never engaged), no `preparation_stalled`
+ receipt for any sync member (each member was charged at most once per
+ episode and committed on its next claim, which resets the count), so no
+ `preparation_stalled` hold was written and that hold path was not exercised
+ by a 300 s lock. A lock held past the ceiling would be the test for it.
+- **The single path did complete the budget contract.** The adoption write
+ for `companies/scale-0-582` was claimed as the second lock began, cut off
+ at 120 s at step `page_snapshot` (`waiting_on: db`), reclaimed, cut off
+ again and finished `failed` / `preparation_stalled` at 09:55:29 (about 240
+ s after its first claim, inside budget × attempts + slack), with the
+ receipt naming the step, the wait cause, the attempt limit and the
+ writer-status route. `preparation_attempts` on the row: 2.
+- **Progress line:** zero `stalled <N>s on <step>` lines in either hold.
+ The pass stderr went silent between `160/3000` and `179/3000` for the
+ first hold (five watchdog ticks) and between `256/3000` and the next line
+ for the second. The drain's stall ticker reads `stall`, which is set only
+ when `performManagedSync` returns `writer_pending` and the drain
+ fingerprints the head between passes; a stall inside the group publish
+ (the drain's own consumer holding the preparation) never reaches it. The
+ drain-level `drain_stalled` / `preparation_abandoned` stops therefore did
+ not fire either; the run came back on its own.
+- **Second hold:** the sync had no member in flight when the lock was taken
+ (the root was serving the queued adoption writes); the lock blocked the
+ adoption write above and, through the pooler, the `extract_facts` run's own
+ reads. The pass finished `synced` (2,980 of 3,000 written, 20 held) in
+ 3,471 s at 51.5 pages/min wall; 665 s was the longest no-commit window
+ (lock 2 plus the adoption queue behind it).
+- **After the run:** `gbrain sources retry-held bench --json` scheduled 20
+ held files (all `invalid_fence` / `repeated_marker`) and printed `gbrain
+ sync --source bench --no-pull` (the backlog was done, so the resume args
+ came from the plain source command, not from a managed cursor; the
+ `--no-embed` the run used was not carried). The printed sync re-screened
+ the 20 files and held them again, as a manual-tier fence hold should.
+
+### Fence outcomes (G3)
+
+- Every seeded repeated-marker page in the backlog (20) ended held
+ `invalid_fence` / `repeated_marker` with the line, in every run, written
+ before admission (the sync's stdout lists each with `gbrain repair fences
+ --source bench --only <path>` as the next step).
+- The 20 history pages with a repeated marker were never submitted as
+ adoption writes: `extract_facts` reports them as `FACTS_FENCE_FAILED:
+ <slug> (Fence repeated_marker: in the facts fence (timeline), at line 18
+ ...)` and skips the page; the stable count per run is 23 tokens (20 marker
+ pages + 3 whitespace-only rows). Phase 0's 471 `repeated_marker` refusals
+ at preparation are gone: 0 failed receipts of any class in both
+ reporter-shape runs, 1 in the lock run (the `preparation_stalled` above).
+- The four shapes: `trailing_ws`, `leading_ws` and `crlf` adopted (3 of 3
+ each, in every run); `whitespace_only` stayed pending (3 rows, 0 adopted).
+ The 83 rows left at the end of each run are those 3 plus the 80 rows on
+ the 20 marker pages. `doctor --only fence_integrity --json` lists exactly
+ 3 `unrenderable_legacy_facts` rows on 3 pages, class `empty` / reason
+ `fence_unrenderable`, status `warn` with `next: report`. Zero "does not
+ render its legacy fact" refusals (Phase 0 head: 276).
+- Controls: 908 of 988 seeded control rows adopted (the 80 on marker pages
+ did not), plus every dripped row (100 / 220 / 60 across the runs).
+
+### Concurrent maintenance (G4, PR 2 territory)
+
+`gbrain dream --phase fence_repair --source bench --json` 20 minutes into
+pass 1 on the same host: status `ok`, `candidates: 22`, `repaired: 0`,
+`held_by_reason: { sync_in_progress: 22 }`, `owner_unavailable` absent,
+`scan_partial: true`, 9.6-9.8 s (pool 10 and pool 3 alike). As expected on
+this head: the repair kind skips the source while the sync runs; Phase 3 /
+PR 2 changes that. In the local smoke the same phase run during a `pages`
+lock blocked for the lock's duration (158 s) and reported `repeated_marker 6`
+held, manual. A `dream` holds the cycle lock, so the adoption loop's
+`extract_facts` runs that overlapped it were refused ("another cycle is
+already running"); the bench records that in `adoption.jsonl` (`json_head`).
+
+### Other observations
+
+- The first `extract_facts` run on 1,000 legacy rows still exceeds 20
+ minutes on every build and the harness kills it (exit 143); its ~100
+ accepted adoption submissions are what queue ahead of the sync. On the
+ pool-3 run, later `extract_facts` runs grew from 319 s to over 1,200 s as
+ the synced page count grew (the phase reconciles every page), and the
+ last three were killed too; with pool 10 they stayed at 450-1,160 s.
+- The pool-10 pass 2 tail: 14,980 pages committed by 11:05:00, process exit
+ 11:10:13; the queue was empty and the stdout shows the 20 holds and the
+ links pass (`Links: 2958 created across 998 page(s)`) landing in that gap.
+- Source id in these runs is `bench` (the bench's fixture source), where the
+ reporter's is `default`; nothing in the measured paths keys on the id.
+
+### Verdict per plan goal
+
+- **G1 (no catch-up stops because of one request): met for the write path
+ as specified, with one caveat recorded.** No pass stalled on a single
+ request; a cut-off single write became `preparation_stalled` with the step
+ inside 240 s; the group members' budget fired and was reported, but under
+ a lock that pins the pool their release waits for the lock (the zombie
+ bound is the 600 s ceiling, not the 120 s budget), and the
+ `preparation_stalled` sync hold was not reached by a 300 s lock. Lane A9's
+ statement cancellation is what turns the 120 s release into a real one.
+- **G2 (writer status names the step): met.** Every overdue claim carried
+ `claim.stall` with step, step age, `waiting_on: db` and the budget;
+ `diagnostic.reason` still reads `cause_unknown` on the same rows (and on
+ young claims of long-queued requests), which is a wording clash rather
+ than missing evidence.
+- **G3 (fence defects never consume the write path): met.** 0 refusals in
+ two 15k runs; marker pages held or skipped with the reason; three shapes
+ adopt, whitespace-only is counted in `fence_integrity`.
+- **G4 (fence_repair runs during the sync): not met on this head, as PR 1
+ scoped it.** 22 candidates, all `sync_in_progress`, none repaired; no
+ `owner_unavailable`. PR 2's criterion.
+- **G5 (one pass drains at ≥ the GBRA-45 head's rate, zero
+ `sync_deadline_stop`): rate and watchdog met, one pass not.** Zero
+ `sync_deadline_stop` in 6 passes; steady 120 / 263 pages/min at pool 10
+ against GBRA-45's 65 / 126 / 75 wall on the same fixture, 47 / 105 / 94 at
+ pool 3 against 57 / 79; the whole 15k drained in 2 passes (91 min) where
+ GBRA-45 took 3 (~167 min). One 3600 s pass cannot hold 15,000 entries at
+ these rates, so under the reporter's `timeout 3600` loop it is two passes
+ by arithmetic, not by a stall; under the reporter's actual `timeout 14400`
+ it would be one.
diff --git a/scripts/bench/stall-repro-summarize.py b/scripts/bench/stall-repro-summarize.py
new file mode 100644
index 0000000000..333c0b236b
--- /dev/null
+++ b/scripts/bench/stall-repro-summarize.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python3
+"""Summarize one managed-sync-stall-repro capture directory (#6278 Phase 4.1).
+
+ python3 scripts/bench/stall-repro-summarize.py .context/bench/stall-p10 [more dirs...]
+
+Reads report.json and samples.jsonl and prints, per pass: pages committed,
+wall and steady pages/min (steady = the middle 80% of the pass by time), the
+longest window without a committed sync page, the exit code, the drain's
+closing line, holds by code/reason, `preparation_stalled` receipts and the
+`stalled <N>s on <step>` progress lines; then the run-level fence, legacy-row,
+writer-status and retry-held results. Numbers only; no page content.
+"""
+import json
+import sys
+from pathlib import Path
+
+
+def summarize(out: Path) -> dict:
+ report = json.loads((out / 'report.json').read_text())
+ samples = [json.loads(line) for line in (out / 'samples.jsonl').read_text().splitlines() if line.strip()]
+ passes = []
+ for p in report.get('passes', []):
+ rows = [s for s in samples if s.get('pass') == p['pass'] and isinstance(s.get('committed'), int)]
+ steady = None
+ if len(rows) >= 5:
+ t0, t1 = rows[0]['t'], rows[-1]['t']
+ mid = [s for s in rows if t0 + (t1 - t0) * 0.1 <= s['t'] <= t0 + (t1 - t0) * 0.9]
+ if len(mid) >= 2 and mid[-1]['t'] > mid[0]['t']:
+ steady = round((mid[-1]['committed'] - mid[0]['committed']) / ((mid[-1]['t'] - mid[0]['t']) / 60000), 1)
+ passes.append({
+ 'pass': p['pass'], 'exit_code': p.get('code'), 'killed_by': p.get('killedBy'), 'status': p.get('status'), 'outcome': p.get('outcome'),
+ 'pages_committed': (p.get('committedAtEnd') or 0) - (p.get('committedAtStart') or 0), 'wall_s': p.get('wall_s'),
+ 'pages_per_min_wall': p.get('pages_per_min'), 'pages_per_min_steady': steady,
+ 'longest_no_commit_s': round(max((s.get('committed_stale_ms') or 0) for s in rows) / 1000) if rows else None,
+ 'sync_deadline_stop': p.get('sync_deadline_stop'), 'drain_lines': p.get('drain_lines'), 'stalled_progress_lines': p.get('stalled_progress_lines'),
+ 'stalled_by_step': p.get('stalled_by_step'), 'restart_required': p.get('restart_required'),
+ 'holds': p.get('holds_by_code_reason'), 'preparation_stalled_receipts': p.get('stalled_receipts'),
+ })
+ result = report.get('result', {})
+ return {
+ 'dir': str(out), 'label': report.get('label'), 'cli_commit': report.get('cli_commit'), 'cli_version': report.get('cli_version'), 'params': report.get('params'),
+ 'passes': passes, 'committed_total': result.get('committed_sync_requests'), 'backlog_entries': result.get('backlog_entries'),
+ 'failed_receipts': result.get('failed_receipts_by_kind_and_error'), 'states': result.get('states'),
+ 'preparing_claims_observed': result.get('preparing_claims_observed'), 'doctor_fence_integrity': result.get('doctor_fence_integrity'),
+ 'legacy_outcome': report.get('legacy_outcome'), 'legacy_pending_at_end': result.get('legacy_pending_at_end'),
+ 'adoption_runs': result.get('adoption_summary'), 'fence_repair': (report.get('fence_repair') or {}).get('phase'),
+ 'retry_held': report.get('retry_held'), 'chaos': result.get('chaos'), 'stalls': [{k: v for k, v in s.items() if k != 'running'} for s in result.get('stalls', [])],
+ }
+
+
+if __name__ == '__main__':
+ print(json.dumps([summarize(Path(d)) for d in sys.argv[1:]], indent=1))