Skip to content

Gate handoff delivery counter and consolidation trigger on source=compact (#341, #342, #344) - #379

Merged
fdaviddpt merged 1 commit into
mainfrom
fix/341
Aug 28, 2026
Merged

fdaviddpt merged 1 commit into
mainfrom
fix/341

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

What

Three issues in scripts/session-start-hook.sh, all about SessionStart firing on source=compact (auto-compaction) as though it were a new session.

Judgment call

Both #341 and #342 name clear/resume/fork as needing an actual argument rather than a guess for whether they should also be excluded. I could not construct a reason to exclude any of them — resume and fork are genuinely new entry points into a session, and clear explicitly replaces context (the issue text leans the same way). So both gates exclude only compact, the one source that is provably still the same session. Full reasoning in the branch's own notes file.

Cost of the #342 gate

A session that only ever sees compact after its initial startup will not re-trigger consolidation for staging that accumulates mid-session, until the process ends and a fresh entry point happens. Bounded: the trigger only ever acts on past-day staging (never same-day), and #342 is filed as "runs more often than it needs to," not as data loss — nothing is lost, consolidation just runs on the next real entry point instead of every mid-session fire.

Tests

Three new files, each red before the fix (or, for #344, a passing characterization from the start since no fix was made):

  • tests/test_handoff_delivery_count_source_341.py — 3 tests, including a positive control (startup refires must still inflate the count) paired with the negative (compact refires must not).
  • tests/test_consolidation_trigger_source_342.py — 3 tests, same positive/negative pairing, plus a characterization that the gate is staging-count AND source, not source alone.
  • tests/test_stdin_source_top_level_wins_344.py — 2 tests pinning the extractor's current first-occurrence behaviour in both key orderings.

All 8 pass locally (macOS, observed). Linux is reasoned via CI's existing matrix already exercising this file's POSIX [ syntax; Windows is skipped by an explicit skipif marker on all three files, consistent with the repo's existing convention for this hook (test_session_start_compact_recap_339.py does the same).

Review

Self-reviewed by an Explore agent (correctness, test vacuousness, stale prose) and an oss:auditor agent (silent-absence, guard-did-not-run, untrusted-input, platform band) against the committed diff — both returned NO FINDINGS.

Docs

README.md is held by a concurrent lane (#377) this tick, so not edited here. Two spots would benefit from a mention once that lane frees it: the line near "already delivered N times since" (README.md:296) could note that compact fires no longer inflate the count, and the source=compact paragraph (README.md:128) could note the consolidation trigger is gated the same way. Left as text for the maintainer to fold in, not an edit.

Closes #341
Closes #342
Closes #344

…urce=compact (#341, #342); pin the source extractor's first-occurrence scan (#344)

At source=compact, SessionStart fires mid-session with an unchanged handoff
fingerprint, so the delivery counter incremented as though a new session had
seen the note -- a handoff delivered once could read as "already delivered
5 times" after four auto-compactions. The consolidation trigger had the same
gap: it re-spawned run-consolidation.sh on every compact fire even though
nothing about yesterday's staging files changed, measured firing 82 times
across 50 sessions. Both are now gated on SESSION_START_SOURCE != "compact";
every other source (startup, resume, clear, fork, absent, unrecognised)
behaves exactly as before.

#344 adds a characterization test for _stdin_json_string's first-occurrence
scan of "source" -- pinning that a top-level source wins over a nested one
that follows it, and documenting (not fixing) the one direction that isn't
covered: a nested source key appearing before the top-level one. No such
payload shape exists today.

Closes #341, Closes #342, Closes #344

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt merged commit 456acd7 into main Aug 28, 2026
13 checks passed
@fdaviddpt
fdaviddpt deleted the fix/341 branch August 28, 2026 06:03
fdaviddpt added a commit that referenced this pull request Aug 28, 2026
Two paragraphs described pre-#379 behaviour of the handoff delivery
counter and the consolidation trigger without mentioning that an
auto-compaction refire (source=compact) no longer inflates the
counter or re-spawns run-consolidation.sh. startup/resume/clear/fork
are unaffected either way. (#384)
fdaviddpt added a commit that referenced this pull request Sep 1, 2026
…nd session_id (#493)

* test: generalise the #344 top-level-wins pin to the extractor across source, cwd and session_id (#447)

The #344/#379 pin only ever covered `source`, which #344 had bounded to a
five-literal whitelist. Since #444 the same first-occurrence
`_stdin_json_string`/`_stdin_cwd` extractor also resolves `cwd` (feeding
REMEMBER_HOOK_CWD/PROJECT_DIR) and `session_id` on session-start,
session-end and post-tool hooks -- none of which carry that whitelist.
Adds the same two-test shape (nested-after wins, nested-before is the
documented gap) for every (hook, key) pair the extractor actually reads,
run directly against the extracted function bodies rather than through a
full hook invocation. No JSON parser introduced and no extractor changed,
per #340/#344's standing decision.

Co-Authored-By: Max <noreply>

* fix: narrow the new #447 extractor pin's win32 skip to "no bash found" (#432)

The reviewer's audit flagged that the new test file copied the blanket
`skipif(sys.platform == "win32")` shape #432 explicitly fixed in
test_hook_cwd_leak_417.py and test_transcript_path_leak_424.py -- that
pattern makes the windows-latest CI leg collect and skip every test while
reporting the leg green, indistinguishable from a genuine pass. Switches
to tests/_bash_runner.py's resolve_bash() (Git-Bash discovery), the same
fix those two files already carry, so the 17 new tests actually run under
Git Bash on Windows CI instead of being silently skipped for the whole
platform.

Co-Authored-By: Max <noreply>
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