Skip to content

fix: stop agentic sessions from silently never saving (#147) - #148

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/147-advance-position
Jul 25, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/147-advance-position

Conversation

@fdaviddpt

@fdaviddpt fdaviddpt commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes #147, and finishes what v0.8.5 left open on #125.

The asymmetry

save-position is only reached on a successful save (save-session.sh:211), but the cooldown marker is written before every gate (:131). So both early exits after extraction advanced the throttle and left the read cursor where it was — and the next run re-extracted the identical span and exited identically. Once per cooldown window. For the life of the session.

One asymmetry, two failures users actually hit:

0 exchanges → now advances the position. There is nothing to summarize in an empty span, so nothing is lost and the loop breaks.

Many exchanges, few human turns → this is the shape of every agentic session, and it never cleared min_human_messages, so the plugin's core function silently never ran. That is the complaint at the heart of #125, and v0.8.5 did not touch it. A span of at least thresholds.min_exchanges_without_human (default 30, 0 disables) now saves regardless of the human count — work is not only measured in human turns.

What deliberately did not change

The under-threshold skip still does not advance the cursor. My own acceptance criteria in #147 said "advance the position regardless of gate outcome" — that turned out to be wrong. Those exchanges are real content, just not enough of it yet; advancing would drop them from every future extract. Keeping the cursor lets them be summarized together with the turns that follow, and the re-read cost is bounded by the save cooldown.

Tests

tests/test_save_session_gates.py drives the real script against a stubbed pipeline.shell, so the gates are exercised without a Haiku call: empty span advances, under-threshold skip does not advance, agentic span saves, the fallback threshold is configurable and can be disabled with 0, and the ordinary path is untouched. The two new behaviours fail on main.

521 passed locally.


Post-review additions

An adversarial review after opening found two defects, both fixed here:

--dry advanced the position. The 0-exchange advance ran unconditionally, so a dry run wrote last-save.json — #147 explicitly requires it must not, and the old code was implicitly safe because no save-position call existed on that path at all. Guarded, with a test.

The claim to close #147 was inaccurate. A failing Haiku call still never advanced the position — @VictorVvdl's month-long repro, and the issue's most-cited scenario. Advancing on the first failure would silently drop memory for a transient error, so consecutive failures against the same (session, position) are counted instead: past thresholds.max_summary_failures (default 3, 0 retries forever) the span is dropped with a WARNING naming the threshold, and everything after it can still be saved. Losing one span is bad; losing every future span is worse.

Writing that test surfaced a third thing: a SKIP advances the position, so it must clear the failure count too — otherwise a stale count sits there and the next single failure trips the give-up threshold early.

Also hardened MIN_HUMAN/MIN_EXCHANGES against a non-numeric config value, which under set -e would abort the script and turn a config typo into "memory just stopped".

526 passed, 12/12 CI green.

Florian DAVID added 2 commits July 25, 2026 16:16
save-position is only reached on a successful save, but the cooldown marker is
written before every gate. Both early exits after extraction therefore left the
read cursor untouched while the throttle advanced — so the next run re-extracted
the identical span and exited identically, once per cooldown window, for the
life of the session. One asymmetry, two user-visible failures.

0 exchanges: nothing to summarize, so advance the position. Nothing is lost and
the loop breaks.

Few human turns but many exchanges: this is what every agentic session looks
like, and it never cleared min_human_messages, so the plugin's core function
silently never ran — the complaint at the heart of #125. A span of at least
thresholds.min_exchanges_without_human (default 30, 0 disables) now saves
regardless of the human count. Work is not only measured in human turns.

The under-threshold skip deliberately still does NOT advance the cursor: those
exchanges are real content, just not enough of it yet, and keeping the cursor
lets them be summarized together with the turns that follow. Re-read cost is
bounded by the save cooldown.

Tests drive the real script against a stubbed pipeline.shell, so the gates are
exercised without a Haiku call. Both new behaviours fail on main.

Co-Authored-By: Max <noreply>
… failures

Review of !148 found two defects.

1. The 0-exchange position advance ran unconditionally, so `--dry` wrote
   last-save.json — a dry run must never move the cursor. #147 says so in as
   many words, and the previous code was implicitly safe because no
   save-position call existed on that path at all. Guarded.

2. The PR claimed to close #147 while leaving its most-cited case untouched: a
   failing Haiku call never advanced the position, so the same span was
   re-extracted and failed identically forever, and no later span could ever be
   saved. That is @VictorVvdl's month-long repro.

   Advancing on the first failure would silently drop memory for a transient
   error, so instead consecutive failures against the same (session, position)
   are counted; past thresholds.max_summary_failures (default 3, 0 retries
   forever) the span is dropped with a WARNING naming the threshold, and
   everything after it can still be recorded. Losing one span is bad; losing
   every future span is worse.

   A successful save clears the count — and so does a SKIP, which a new test
   caught: SKIP advances the position, so leaving a stale count there would trip
   the give-up threshold early on the next single failure.

Also hardened MIN_HUMAN/MIN_EXCHANGES against a non-numeric config value, which
under set -e would abort the script and turn a typo into "memory just stopped".

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt merged commit 3988e51 into main Jul 25, 2026
12 checks passed
@fdaviddpt
fdaviddpt deleted the fix/147-advance-position branch July 25, 2026 14:34
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.

save-session never advances the saved position past an early exit, so a low-human-turn session re-extracts and bails forever

1 participant