Skip to content

fix: avoid redundant status-log folds during home-summary refresh - #6464

Closed
luigia wants to merge 6 commits into
kunchenguid:mainfrom
luigia:home-summary-refresh-perf
Closed

luigia wants to merge 6 commits into
kunchenguid:mainfrom
luigia:home-summary-refresh-perf

Conversation

@luigia

@luigia luigia commented Oct 3, 2026 •

Copy link
Copy Markdown

Intent

Fix the home-summary refresh that keeps failing.
On this firstmate home, bin/fm-home-summary-refresh.sh has exceeded its 60-second deadline on every attempt since 2026-10-01 (318+ recorded failures in state/.home-summary-refresh.log); a manual run with a longer bound took about 2m03s wall, 84s CPU.
The bound must not simply be raised: the bootstrap-diagnostics guidance says to fix the blocked phase rather than raise this load-bearing bound.
Upstream issue #6257 reports the same failure and its measured cause: fm-fleet-snapshot.sh --secondmate-home-summary runs the full status_open_decisions fold over each task's whole status log on every refresh instead of the incremental cursor-backed status_open_decisions_incremental path, and prefetch_task_observations plus per-task JSON assembly are the other large cost (42s even with status logs cut to 60 lines).
The refresh should stay well under its deadline as status logs grow, with identical published output.

What Changed

  • Seed fleet-snapshot and crew-state decision folds from captured wake-drain cursors, reading only uncovered status tails without advancing those cursors; fall back to whole-log folding when unusable.
  • Invalidate cursors when effective decision verbs or reserved-key prefixes change, while preserving default cursor compatibility.
  • Add regression coverage for identical summary output, tail-only folding, replaced logs, failed cursor capture, and configured-cursor unread-note handling.

Risk Assessment

✅ Low: The read-only cursor optimization preserves whole-log fallback and publication ownership, and all cursor consumers consistently validate the effective fold configuration.

Testing

Targeted checks and isolated live CLI scenarios passed. Six tasks with 20× longer histories refreshed in 2.19 seconds, preserving published output and cursor bytes. Initial fixture-location and drain-setup timeout issues were corrected before successful reruns; JSON publications, timings, and comparison evidence were saved.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Refresh growing status histories without approaching the deadline ✅ pass live live-refresh-results.json: six tasks grew from 100 to 2,000 history lines each; seeded refresh took 2.19 seconds under the unchanged 60-second deadline.
Publish buried and newly appended decisions identically to a whole-log refresh ✅ pass live publication-byte-comparisons.json: seeded and whole-log publications were byte-identical at both history sizes; resolved blockers disappeared.
Refresh without advancing the wake drain's presentation cursor ✅ pass live live-refresh.py compared cursor bytes before and after every refresh; live-refresh-results.json records unchanged cursors.
Publish successfully despite missing, corrupt, directory, or symlink cursors ✅ pass live Real refreshes completed and matched whole-log publication byte-for-byte; publication-byte-comparisons.json.
Change reserved prefixes or decision verbs without reusing incompatible folded state ✅ pass live live-prefix-mismatch.json recovered secret-choice; live-custom-prefix.json excluded it; live-verb-mismatch.json recovered resolved-choice and held-choice.
Replace a status log without publishing decisions from its stale cursor ✅ pass live live-replaced-log.json contains replacement-choice and excludes the replaced log's choice-0.
Evidence: Live refresh timings and observed decisions

Source: Live refresh timings and observed decisions

[
  {
    "scenario": "live-small-seeded",
    "seconds": 3.305,
    "decision_keys": [
      "choice-0",
      "tail-0",
      "choice-1",
      "tail-1",
      "choice-2",
      "tail-2",
      "choice-3",
      "tail-3",
      "choice-4",
      "tail-4",
      "choice-5",
      "tail-5"
    ],
    "cursors_unchanged": true
  },
  {
    "scenario": "live-small-whole",
    "seconds": 1.83,
    "decision_keys": [
      "choice-0",
      "tail-0",
      "choice-1",
      "tail-1",
      "choice-2",
      "tail-2",
      "choice-3",
      "tail-3",
      "choice-4",
      "tail-4",
      "choice-5",
      "tail-5"
    ],
    "cursors_unchanged": true
  },
  {
    "scenario": "live-large-seeded",
    "seconds": 2.193,
    "decision_keys": [
      "choice-0",
      "tail-0",
      "new-0",
      "choice-1",
      "tail-1",
      "new-1",
      "choice-2",
      "tail-2",
      "new-2",
      "choice-3",
      "tail-3",
      "new-3",
      "choice-4",
      "tail-4",
      "new-4",
      "choice-5",
      "tail-5",
      "new-5"
    ],
    "cursors_unchanged": true
  },
  {
    "scenario": "live-large-whole",
    "seconds": 2.691,
    "decision_keys": [
      "choice-0",
      "tail-0",
      "new-0",
      "choice-1",
      "tail-1",
      "new-1",
      "choice-2",
      "tail-2",
      "new-2",
      "choice-3",
      "tail-3",
      "new-3",
      "choice-4",
      "tail-4",
      "new-4",
      "choice-5",
      "tail-5",
      "new-5"
    ],
    "cursors_unchanged": true
  },
  {
    "scenario": "live-corrupt-cursor",
    "seconds": 2.904,
    "decision_keys": [
      "choice-0",
      "tail-0",
      "new-0",
      "choice-1",
      "tail-1",
      "new-1",
      "choice-2",
      "tail-2",
      "new-2",
      "choice-3",
      "tail-3",
      "new-3",
      "choice-4",
      "tail-4",
      "new-4",
      "choice-5",
      "tail-5",
      "new-5"
    ],
    "cursors_unchanged": true
  },
  {
    "scenario": "live-directory-cursor",
    "seconds": 2.834,
    "decision_keys": [
      "choice-0",
      "tail-0",
      "new-0",
      "choice-1",
      "tail-1",
      "new-1",
      "choice-2",
      "tail-2",
      "new-2",
      "choice-3",
      "tail-3",
      "new-3",
      "choice-4",
      "tail-4",
      "new-4",
      "choice-5",
      "tail-5",
      "new-5"
    ],
    "cursors_unchanged": true
  },
  {
    "scenario": "live-symlink-cursor",
    "seconds": 2.369,
    "decision_keys": [
      "choice-0",
      "tail-0",
      "new-0",
      "choice-1",
      "tail-1",
      "new-1",
      "choice-2",
      "tail-2",
      "new-2",
      "choice-3",
      "tail-3",
      "new-3",
      "choice-4",
      "tail-4",
      "new-4",
      "choice-5",
      "tail-5",
      "new-5"
    ],
    "cursors_unchanged": true
  },
  {
    "scenario": "live-prefix-mismatch",
    "seconds": 1.689,
    "decision_keys": [
      "config-0",
      "secret-choice",
      "config-1",
      "config-2",
      "config-3",
      "config-4",
      "config-5"
    ],
    "cursors_unchanged": true
  },
  {
    "scenario": "live-custom-prefix",
    "seconds": 2.701,
    "decision_keys": [
      "config-0",
      "config-1",
      "config-2",
      "config-3",
      "config-4",
      "config-5"
    ],
    "cursors_unchanged": true
  },
  {
    "scenario": "live-verb-mismatch",
    "seconds": 1.462,
    "decision_keys": [
      "config-0",
      "secret-choice",
      "resolved-choice",
      "held-choice",
      "config-1",
      "config-2",
      "config-3",
      "config-4",
      "config-5"
    ],
    "cursors_unchanged": true
  },
  {
    "scenario": "live-replaced-log",
    "seconds": 1.505,
    "decision_keys": [
      "replacement-choice",
      "config-1",
      "config-2",
      "config-3",
      "config-4",
      "config-5"
    ],
    "cursors_unchanged": true
  },
  {
    "result": "All live publication assertions passed",
    "tasks": 6,
    "small_history_lines_per_task": 100,
    "large_history_lines_per_task": 2000,
    "deadline_seconds": 60,
    "dependencies": "real product executables; no stubs or live fleet endpoints"
  }
]
Evidence: Published long-history home summary

Source: Published long-history home summary

{
  "schema": "fm-secondmate-home-summary.v1",
  "hold_classifier_schema": "fm-captain-hold-buckets.v1",
  "contributions": {
    "known": 0,
    "checked": 0,
    "counts": {
      "captain": 0,
      "fleet": 0,
      "maintainer": 0,
      "nobody": 0
    },
    "unmeasured": 0,
    "complete": true,
    "proven_clear": true,
    "stale_verdicts": 0,
    "missing_verdicts": 0,
    "unreadable_records": 0,
    "valid_until": 900,
    "captain": [],
    "captain_omitted": 0
  },
  "generated": "2026-10-02T12:00:00Z",
  "generated_epoch": 1790942400,
  "home": "~/.no-mistakes/worktrees/3fecfed7f577/01M40XNNXBW3XW8EWKNWVK61ST/.test-tmp/live-home",
  "valid": false,
  "reason": "child current state unavailable: mate-0, mate-1, mate-2, mate-3, mate-4, mate-5",
  "invalidity": {
    "kind": "child_current_unavailable",
    "ids": [
      "mate-0",
      "mate-1",
      "mate-2",
      "mate-3",
      "mate-4",
      "mate-5"
    ]
  },
  "state": "unknown",
  "active_children": [],
  "decisions_open": [
    {
      "id": "mate-0",
      "key": "choice-0",
      "verb": "needs-decision",
      "summary": "choose rollout",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-0",
      "key": "tail-0",
      "verb": "needs-decision",
      "summary": "choose window",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-0",
      "key": "new-0",
      "verb": "needs-decision",
      "summary": "choose final window",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-1",
      "key": "choice-1",
      "verb": "needs-decision",
      "summary": "choose rollout",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-1",
      "key": "tail-1",
      "verb": "needs-decision",
      "summary": "choose window",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-1",
      "key": "new-1",
      "verb": "needs-decision",
      "summary": "choose final window",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-2",
      "key": "choice-2",
      "verb": "needs-decision",
      "summary": "choose rollout",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-2",
      "key": "tail-2",
      "verb": "needs-decision",
      "summary": "choose window",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-2",
      "key": "new-2",
      "verb": "needs-decision",
      "summary": "choose final window",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-3",
      "key": "choice-3",
      "verb": "needs-decision",
      "summary": "choose rollout",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-3",
      "key": "tail-3",
      "verb": "needs-decision",
      "summary": "choose window",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-3",
      "key": "new-3",
      "verb": "needs-decision",
      "summary": "choose final window",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-4",
      "key": "choice-4",
      "verb": "needs-decision",
      "summary": "choose rollout",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-4",
      "key": "tail-4",
      "verb": "needs-decision",
      "summary": "choose window",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-4",
      "key": "new-4",
      "verb": "needs-decision",
      "summary": "choose final window",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-5",
      "key": "choice-5",
      "verb": "needs-decision",
      "summary": "choose rollout",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-5",
      "key": "tail-5",
      "verb": "needs-decision",
      "summary": "choose window",
      "reason": null,
      "source": "status"
    },
    {
      "id": "mate-5",
      "key": "new-5",
      "verb": "needs-decision",
      "summary": "choose final window",
      "reason": null,
      "source": "status"
    }
  ],
  "holds": [],
  "queued": [],
  "landed": [],
  "endpoints": [
    {
      "id": "mate-0",
      "state": "unknown",
      "source": "none",
      "endpoint": {
        "target": "fm-lab-summary:missing-0",
        "exists": false,
        "agent_alive": "unknown",
        "status": "absent",
        "observed_at": "2026-10-02T12:00:00Z",
        "freshness": "fresh"
      }
    },
    {
      "id": "mate-1",
      "state": "unknown",
      "source": "none",
      "endpoint": {
        "target": "fm-lab-summary:missing-1",
        "exists": false,
        "agent_alive": "unknown",
        "status": "absent",
        "observed_at": "2026-10-02T12:00:00Z",
        "freshness": "fresh"
      }
    },
    {
      "id": "mate-2",
      "state": "unknown",
      "source": "none",
      "endpoint": {
        "target": "fm-lab-summary:missing-2",
        "exists": false,
        "agent_alive": "unknown",
        "status": "absent",
        "observed_at": "2026-10-02T12:00:00Z",
        "freshness": "fresh"
      }
    },
    {
      "id": "mate-3",
      "state": "unknown",
      "source": "none",
      "endpoint": {
        "target": "fm-lab-summary:missing-3",
        "exists": false,
        "agent_alive": "unknown",
        "status": "absent",
        "observed_at": "2026-10-02T12:00:00Z",
        "freshness": "fresh"
      }
    },
    {
      "id": "mate-4",
      "state": "unknown",
      "source": "none",
      "endpoint": {
        "target": "fm-lab-summary:missing-4",
        "exists": false,
        "agent_alive": "unknown",
        "status": "absent",
        "observed_at": "2026-10-02T12:00:00Z",
        "freshness": "fresh"
      }
    },
    {
      "id": "mate-5",
      "state": "unknown",
      "source": "none",
      "endpoint": {
        "target": "fm-lab-summary:missing-5",
        "exists": false,
        "agent_alive": "unknown",
        "status": "absent",
        "observed_at": "2026-10-02T12:00:00Z",
        "freshness": "fresh"
      }
    }
  ],
  "counts": {
    "active_children": 0,
    "decisions_open": 18,
    "holds": 0,
    "queued": 0,
    "landed": 0,
    "endpoints": 6
  },
  "omitted": []
}
Evidence: Publication byte comparisons

Source: Publication byte comparisons

{
  "live-small-seeded == live-small-whole": true,
  "live-large-seeded == live-large-whole": true,
  "live-large-seeded == live-corrupt-cursor": true,
  "live-large-seeded == live-directory-cursor": true,
  "live-large-seeded == live-symlink-cursor": true
}
Evidence: Reproducible live scenario driver

Source: Reproducible live scenario driver

import os, pathlib, subprocess, time, json, shutil
root = pathlib.Path.cwd()
evidence = pathlib.Path('~/.no-mistakes/evidence/01M40XNNXBW3XW8EWKNWVK61ST')
home = root / '.test-tmp/live-home'
home.mkdir()
for d in ['state','data','config','projects']:
    (home/d).mkdir()
(home/'AGENTS.md').write_text('# Isolated summary validation home\n')
(home/'.fm-secondmate-home').write_text('summary-validation\n')
(home/'data/backlog.md').write_text('## In flight\n\n## Queued\n\n## Done\n')
env = {k:v for k,v in os.environ.items() if k not in ['FM_STATE_OVERRIDE','FM_CONFIG_OVERRIDE','FM_DATA_OVERRIDE','FM_PROJECTS_OVERRIDE','FM_CLASSIFY_RESERVED_KEY_PREFIXES','FM_CLASSIFY_RESOLVE_VERB','FM_CLASSIFY_CAPTAIN_HELD_VERB','FM_HOME_SUMMARY_TIMEOUT']}
env.update(FM_HOME=str(home), FM_ROOT_OVERRIDE=str(root), FM_STATE_OVERRIDE=str(home/'state'), FM_CONFIG_OVERRIDE=str(home/'config'), FM_DATA_OVERRIDE=str(home/'data'), FM_PROJECTS_OVERRIDE=str(home/'projects'), TMPDIR=str(root/'.test-tmp'), FM_SNAPSHOT_NOW='2026-10-02T12:00:00Z', FM_SNAPSHOT_NOW_EPOCH='1790942400')
log = []
def run(script, args=(), extra=None, artifact=None, timeout=180):
    start=time.monotonic()
    proc=subprocess.run([str(root/'bin'/script), *args], env=env | (extra or {}), capture_output=True, timeout=timeout)
    elapsed=time.monotonic()-start
    if artifact:
        (evidence/artifact).write_bytes(proc.stdout)
    assert proc.returncode == 0, (script, proc.returncode, proc.stderr.decode())
    return proc.stdout, elapsed

def refresh(label, extra=None):
    before={p.name:(p.read_bytes() if p.is_file() else b'<directory>') for p in (home/'state').glob('*.open-decisions-cursor')}
    _,elapsed=run('fm-home-summary-refresh.sh',extra=extra,timeout=65)
    after={p.name:(p.read_bytes() if p.is_file() else b'<directory>') for p in (home/'state').glob('*.open-decisions-cursor')}
    assert before == after, 'refresh mutated wake-drain cursor'
    data=(home/'state/home-summary.json').read_bytes()
    (evidence/(label+'.json')).write_bytes(data)
    parsed=json.loads(data)
    keys=[d['key'] for d in parsed['decisions_open'] if d.get('source')=='status']
    log.append(dict(scenario=label,seconds=round(elapsed,3),decision_keys=keys,cursors_unchanged=True))
    return data,keys

try:
    for i in range(6):
        (home/f'state/mate-{i}.meta').write_text(f'kind=secondmate\nmode=secondmate\nharness=claude\nwindow=fm-lab-summary:missing-{i}\nhome={home}/projects/mate-{i}\n')
        (home/f'state/mate-{i}.status').write_text(f'needs-decision [key=choice-{i}]: choose rollout\nblocked [key=old-{i}]: credentials\n'+'working: routine long-history progress\n'*100)
    run('fm-wake-drain.sh',artifact='live-drain-small.txt')
    for i in range(6):
        with (home/f'state/mate-{i}.status').open('a') as f:
            f.write(f'resolved [key=old-{i}]: received\nneeds-decision [key=tail-{i}]: choose window\n')
    small, keys = refresh('live-small-seeded')
    assert set(keys)=={f'{prefix}-{i}' for prefix in ['choice','tail'] for i in range(6)}
    cursors={p:p.read_bytes() for p in (home/'state').glob('*.open-decisions-cursor')}
    for p in cursors: p.unlink()
    whole,_=refresh('live-small-whole')
    assert whole==small,'seeded publication differs from whole-log publication'
    for p,b in cursors.items(): p.write_bytes(b)
    for i in range(6):
        with (home/f'state/mate-{i}.status').open('a') as f: f.write('working: routine long-history progress\n'*1900)
    run('fm-wake-drain.sh',artifact='live-drain-large.txt',timeout=300)
    for i in range(6):
        with (home/f'state/mate-{i}.status').open('a') as f: f.write(f'needs-decision [key=new-{i}]: choose final window\n')
    large,keys=refresh('live-large-seeded')
    assert set(keys)=={f'{prefix}-{i}' for prefix in ['choice','tail','new'] for i in range(6)}
    cursors={p:p.read_bytes() for p in (home/'state').glob('*.open-decisions-cursor')}
    for p in cursors: p.unlink()
    large_whole,_=refresh('live-large-whole')
    assert large_whole==large
    for p,b in cursors.items(): p.write_bytes(b)
    # Force invalid captures without intercepting cp or any product dependency.
    for kind in ['corrupt','directory','symlink']:
        for p,b in cursors.items():
            p.unlink()
            if kind=='corrupt': p.write_text('version=invalid\noffset=99999999\nident=wrong\n')
            elif kind=='directory': p.mkdir()
            else: p.symlink_to(home/'AGENTS.md')
        actual,_=refresh('live-'+kind+'-cursor')
        assert actual==large
        for p in cursors:
            if p.is_dir() and not p.is_symlink(): p.rmdir()
            else: p.unlink()
            p.write_bytes(cursors[p])
    # Configuration adversaries use short, new logs to avoid expensive drain setup.
    for i in range(6):
        (home/f'state/mate-{i}.status').write_text(f'needs-decision [key=config-{i}]: choose configuration\n')
    # Prefix mismatch must recover the decision previously excluded by the drain.
    f=home/'state/mate-0.status'
    with f.open('a') as out: out.write('needs-decision [key=secret-choice]: choose transport\n')
    run('fm-wake-drain.sh',extra={'FM_CLASSIFY_RESERVED_KEY_PREFIXES':'pending-reply- secret-'},artifact='live-custom-prefix-drain.txt',timeout=300)
    _,keys=refresh('live-prefix-mismatch')
    assert 'secret-choice' in keys
    _,keys=refresh('live-custom-prefix',{'FM_CLASSIFY_RESERVED_KEY_PREFIXES':'pending-reply- secret-'})
    assert 'secret-choice' not in keys
    # Resolve/held changes must recover open decisions from a differently configured cursor.
    with f.open('a') as out: out.write('needs-decision [key=resolved-choice]: choose\nresolved [key=resolved-choice]: closed\nneeds-decision [key=held-choice]: choose\ncaptain-held [key=held-choice]: retained\n')
    run('fm-wake-drain.sh',artifact='live-default-verbs-drain.txt',timeout=300)
    _,keys=refresh('live-verb-mismatch',{'FM_CLASSIFY_RESOLVE_VERB':'settled','FM_CLASSIFY_CAPTAIN_HELD_VERB':'parked'})
    assert 'resolved-choice' in keys and 'held-choice' in keys
    # Replace one log at the same path; the old cursor must not seed it.
    replaced=f.with_suffix('.new')
    replaced.write_text('needs-decision [key=replacement-choice]: new log\n')
    replaced.replace(f)
    _,keys=refresh('live-replaced-log')
    assert 'replacement-choice' in keys and 'choice-0' not in keys
    log.append({'result':'All live publication assertions passed','tasks':6,'small_history_lines_per_task':100,'large_history_lines_per_task':2000,'deadline_seconds':60,'dependencies':'real product executables; no stubs or live fleet endpoints'})
finally:
    (evidence/'live-refresh-results.json').write_text(json.dumps(log,indent=2)+'\n')
    shutil.rmtree(home)
print(json.dumps(log,indent=2))

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ bin/fm-classify-lib.sh:1217 - Cursor validity omits FM_CLASSIFY_RESERVED_KEY_PREFIXES, although _fm_decision_key_transition_allowed uses it to determine the folded set. For example, drain a secondmate log containing needs-decision [key=secret-choice]: choose with prefixes pending-reply- secret-: the cursor excludes that decision. Refresh with default prefixes and no new appends: the seeded fold accepts the same version and publishes no decision, whereas the previous whole-log fold includes secret-choice. Include the effective reserved-prefix configuration in the shared cursor version so differing configurations fall back to the whole-log fold.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Refresh growing status histories without approaching the deadline ✅ pass live live-refresh-results.json: six tasks grew from 100 to 2,000 history lines each; seeded refresh took 2.19 seconds under the unchanged 60-second deadline.
Publish buried and newly appended decisions identically to a whole-log refresh ✅ pass live publication-byte-comparisons.json: seeded and whole-log publications were byte-identical at both history sizes; resolved blockers disappeared.
Refresh without advancing the wake drain's presentation cursor ✅ pass live live-refresh.py compared cursor bytes before and after every refresh; live-refresh-results.json records unchanged cursors.
Publish successfully despite missing, corrupt, directory, or symlink cursors ✅ pass live Real refreshes completed and matched whole-log publication byte-for-byte; publication-byte-comparisons.json.
Change reserved prefixes or decision verbs without reusing incompatible folded state ✅ pass live live-prefix-mismatch.json recovered secret-choice; live-custom-prefix.json excluded it; live-verb-mismatch.json recovered resolved-choice and held-choice.
Replace a status log without publishing decisions from its stale cursor ✅ pass live live-replaced-log.json contains replacement-choice and excludes the replaced log's choice-0.
  • bash tests/fm-open-decisions-prefix-cursor.test.sh
  • bash tests/fm-home-summary-refresh.test.sh — passed after correcting the temporary fixture location
  • bash tests/fm-wake-drain-unread-status.test.sh
  • python3 ~/.no-mistakes/evidence/01M40XNNXBW3XW8EWKNWVK61ST/live-refresh.py — real wake-drain and refresh executables, without stubs
  • Compared saved published JSON byte-for-byte across seeded, whole-log, and invalid-cursor refreshes; removed transient worktree fixtures
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Adds incremental cursor optimization to status log folding.

The PR appears safe to merge, with a non-blocking risk of duplicate status presentation after a reserved-prefix change in a manifestless home.

Reviews (3) · Last reviewed commit: "no-mistakes(document): Clarify configura..."

Comment thread bin/fm-classify-lib.sh Resolved
Comment thread bin/fm-fleet-snapshot.sh Resolved
Comment thread tests/fm-home-summary-refresh.test.sh Resolved
Comment thread bin/fm-classify-lib.sh Resolved
luigia added 6 commits October 3, 2026 09:01
…rsor

The secondmate home-summary refresh re-folded every task's whole status log
twice per refresh - once in fm-fleet-snapshot.sh's task assembly and once in
fm-crew-state.sh's status_current_line - so a home with long secondmate logs
blew the 60-second refresh deadline on every attempt, and crew-state reads
that hit their own bound published those secondmates as unknown.

status_open_decisions now accepts the live log (and an optional captured
copy of its cursor) and starts from the wake drain's persisted
open-decisions cursor when that cursor provably covers a line-aligned prefix
of the same file, folding only the bytes after it. The cursor is read, never
written, so the drain keeps sole ownership of its advancement. Any version,
kind, identity, size, or boundary mismatch falls back to the whole-stream
fold, so the published summary is unchanged for the same inputs.

The snapshot captures each cursor before the status copy it covers, so the
cursor can never run past the captured end, and passes both to crew-state
and to its own fold. The cursor parser is shared with the incremental fold.

Fixes kunchenguid#6257
…fault effective verbs while preserving default cursors; failed cursor copies fall back without blocking publication; tests assert byte-identical cursor preservation. Reproduced the verb mismatch before fixing it. Home-summary, wake-drain cursor, and decision-key suites pass, along with syntax checks and ShellCheck excluding source-resolution notices. Left ci-1/ci-2 unchanged
…r version

The previous fix appended non-default resolution and captain-held verbs to
the open-decisions cursor version, but status_open_decisions_cursor_offset
still built the bare `<n>:<kind>` string. A home with no presentation
manifest reads that cursor as its presented offset, so with configured verbs
the version never matched, the offset reset to zero, and the wake drain
replayed already-presented status. The legacy reader now builds its version
through _fm_open_decisions_fold_version with the effective verbs, the same
owner every cursor writer and reader uses.
@luigia
luigia force-pushed the home-summary-refresh-perf branch from ac12f39 to 671d922 Compare October 3, 2026 13:24
@luigia luigia changed the title fix: avoid refolding status history during home-summary refresh fix: avoid redundant status-log folds during home-summary refresh Oct 3, 2026
Comment thread bin/fm-classify-lib.sh
Comment on lines +1951 to +1953
fold_version=$(_fm_open_decisions_fold_version "$(_fm_status_kind "$f")" \
"${FM_CLASSIFY_RESOLVE_VERB:-$FM_CLASSIFY_RESOLVE_VERB_DEFAULT}" \
"${FM_CLASSIFY_CAPTAIN_HELD_VERB:-$FM_CLASSIFY_CAPTAIN_HELD_VERB_DEFAULT}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Presented status gets replayed If a home has an open-decisions cursor but no .status-presentation-cursor, changing FM_CLASSIFY_RESERVED_KEY_PREFIXES makes this reader reject the old cursor version and return offset zero. The next wake drain then presents notes and pending-reply resolutions that were already delivered. Refolding decisions under the new prefixes should not also rewind the presentation offset.

Knowledge Base Used: Watch and wake workflows

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @luigia for this, and for the detailed cursor work and live evidence.

#6257 was fixed by #7376, which landed on main today as ed7fbb84. It keeps the home-summary refresh inside its unchanged 60-second deadline a different way: each task's open-decision fold and row are built inside that task's own bounded observation worker, and the whole-file fold no longer forks per status line. The problem this PR set out to fix is solved on main, so I'm closing this as superseded by #7376.

If your change covers something #7376 does not, please reopen it and say what that is. One possible case: #7376 notes that collection cost still grows with status-log history, which is what your cursor-seeded tail fold targets. If you can show that cost on current main, I'll look again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants