Skip to content

fix: save-session.sh --force races the lock instead of skipping it, and staging_append warns before an append-only file grows forever - #382

Merged
fdaviddpt merged 3 commits into
mainfrom
fix/369
Aug 28, 2026
Merged

fdaviddpt merged 3 commits into
mainfrom
fix/369

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

#369 -- a forced flush that lost the lock race exited 0 having saved nothing

save-session.sh acquired save.lock with a hardcoded 0-second timeout before the argument parse that would have seen --force -- so --force bypassed the cooldown and the min-human-message gate, but never the mutex. A forced call that lost the race exited 0, indistinguishable from a genuine "nothing new to flush" no-op, on exactly the save (session-end-hook.sh's SessionEnd flush) whose whole purpose is that there is no next chance.

Fix: argument parsing moved ahead of lock acquisition (no side effects to reorder around). A plain call is unchanged -- timeout 0, exit 0 on contention, a legitimate skip. A forced call now retries the same mutex, bounded (REMEMBER_FORCE_LOCK_TIMEOUT, default 30s) -- not a second writer, just a longer wait for the one lock that already exists. If the holder still has not released after that wait, the call now exits 1 instead of 0. session-end-hook.sh already checks that exit code and calls report_error() on nonzero, so this makes an existing check see the real failure instead of a false all-clear.

Closes #369

#349 -- an append-only staging file could grow for weeks with nothing noticing

staging_append() (scripts/lib-staging-lock.sh) is a bare >> with no size check, and five branches append a span and deliberately never roll it back on failure -- a visible duplicate over an invisible erasure, and that trade is correct and unchanged here. What nobody had costed: a persistent cause (sustained lock contention, a full disk, a stalled consolidation round) leaves the same kind of span landing there every round, forever, with nothing to notice.

Fix: staging_append now logs a one-time WARNING (report_error(), reaching the daily log and hook-errors.log) the first time a staging file's byte size crosses a new thresholds.staging_warn_bytes (default 2000000 bytes, documented in config.example.json). Nothing is capped or truncated -- the append itself is unchanged. hook-errors.log is already tailed by /remember:doctor's existing "Recent errors" section, confirmed by reading scripts/doctor.sh:497-506, so no diagnostic edit was needed or made.

Closes #349

README.md -- documented, once the coordinator unblocked this lane

The gap noted above (thresholds.staging_warn_bytes undocumented in README.md, README.md held by lane fix/377) is now closed: the coordinator confirmed fix/377 landed its own PR and released the file, and commit 8bed68b (after this worktree's README.md was verified unmodified against origin/main) adds the config-table row and updates the SessionEnd flush-failure paragraph to note that a --force lock-race loss is now reportable through hook-errors.log -- which it was not before #369. Scoped to exactly those two spots; the marketplace-install paragraph and CLAUDE.md (lane 377's own territory) are untouched. tests/test_config_contract.py: 11/11 passing. Full suite: 1655 passed, 43 skipped, 0 failed.

Below-bar finding from self-review, not fixed

The auditor flagged that staging_append's own size measurement (wc -c) silently collapses to 0 on any read failure (the same digit-only guard the rest of this file already uses for corrupt/unreadable values), so a wc -c failure while the cat >> append itself still succeeds would suppress the new growth warning without a trace -- the one failure mode this diagnostic was added to catch, appearing in the diagnostic itself. Judged below-bar and not fixed: the scenario needs write access without read access to the same file, which is not a configuration this plugin's own deployment model (writes as the invoking user's own uid) produces, and no reachable trigger for it exists in this diff's own callers.

Test plan

  • tests/test_save_session_force_lock_race.py -- new, real two-process lock race (positive + negative control), red before the fix / green after
  • tests/test_staging_growth_warning_349.py -- new, drives staging_append directly (positive + negative control), red before the fix / green after
  • Full suite (after README follow-up, commit 8bed68b): 0 failed, 1655 passed, 43 skipped
  • python3 .oss/assemble_changelog.py --check -- both fragments pass

fdaviddpt and others added 2 commits August 27, 2026 19:56
…nd staging_append warns before an append-only file grows forever

--force used to acquire save.lock with a 0-second timeout before the
argument parse that would have seen --force at all, so a forced flush that
lost the race exited 0 having saved nothing -- indistinguishable from a
genuine no-op, on exactly the save whose whole purpose is that there is no
next chance (#369). A forced call now retries the same mutex, bounded
(REMEMBER_FORCE_LOCK_TIMEOUT, default 30s), and exits 1 -- not 0 -- if the
holder still has not released, which session-end-hook.sh's existing
nonzero-exit check already surfaces via report_error().

staging_append's five append-only callers were each individually correct
(a visible duplicate over an invisible erasure), but nothing noticed a
staging file growing without bound under a persistent cause -- sustained
lock contention, a full disk, or a stalled consolidation (#349). It now
logs a one-time WARNING past thresholds.staging_warn_bytes, surfaced by
the existing hook-errors.log tail in /remember:doctor. Nothing is capped
or truncated.

Closes #369
Closes #349

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FLHVEH4aeVK93939UYnfFP
…ting change in README

The README config gap noted in the previous commit's report is unblocked --
the coordinator confirmed lane fix/377 (README.md) has landed its own PR and
released the file. Confirmed this worktree's README.md was still unmodified
(matched origin/main) before touching it.

Adds the thresholds.staging_warn_bytes row to the config table, matching the
neighbouring rows' convention (default, units, what 0 does). Also updates the
SessionEnd section's flush-failure paragraph: #369 made a lock-race loss on
--force reportable through the same hook-errors.log channel that paragraph
already documents for every other flush failure -- before this fix, that one
case reported nothing at all, which is user-visible behaviour worth stating
explicitly rather than leaving implied.

Scoped to exactly these two spots -- the marketplace install paragraph and
CLAUDE.md (lane 377's own territory) are untouched.

tests/test_config_contract.py now passes in full (11/11); full suite:
1655 passed, 43 skipped, 0 failed.

Closes #369
Closes #349

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FLHVEH4aeVK93939UYnfFP
@fdaviddpt
fdaviddpt merged commit 7e8ee3a into main Aug 28, 2026
13 checks passed
@fdaviddpt
fdaviddpt deleted the fix/369 branch August 28, 2026 06:46
fdaviddpt added a commit that referenced this pull request Aug 28, 2026
…ss check (#390) (#391)

PR #387 (closing #370) gave scripts/doctor.sh a second liveness check, for
SessionEnd, alongside the existing PostToolUse one. README.md's Diagnostics
section still described only the PostToolUse check, drafted before #387
landed and blocked at the time because #382 held README.md. Both PRs have
since merged; verified the wording against the merged doctor.sh (three
states, and "has ever fired" correctly describes the log-presence check
rather than a transcript count) before applying it unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant