Repository navigation
fix(capture): one cooldown truth across setups + captureOnCompact docs (#108) - #113
Conversation
…s; captureOnCompact gets its docs
…share # Conflicts: # README.md
|
Isolating the red
Happy to send the same one-line pin (#105's shape: one test-level 20 s on the heavy test, everything else keeps the default) as a tiny separate PR if you want it - or fold it in here, your call. A re-run of the leg would very likely go green; it comes out clean on every quiet run we have measured on two Buns and two OSes. |
abogartz
left a comment
There was a problem hiding this comment.
Verdict: APPROVED_WITH_NITS
Core fix reproduced independently. I reverted only src/index.ts to main (with a no-op resetCaptureCooldowns shim) and ran your two new tests: both red with exactly Expected: 1, Received: 2 — compaction and idle broadcast each double-paying on one transcript. Post-fix: full suite on macOS 490 pass / 8 skip / 0 fail, tsc + biome lint clean. The double-pay was real, the shared trigger:sid map is the right shape, check-and-set is synchronous (no await between get and set, so the shared map is race-free single-threaded), and the eviction bound matches the ledger throttle's existing rule.
Scope claim held: the diff touches nothing around setCurrent/gateContext — the sid-binding race stays open, now tracked properly in #116 (filed today; Fixes #108 must not swallow it).
README: captureOnCompact row + separate-cooldown sentence + the cited bench/capture-trigger-results.md link all render and resolve; the bullet now states the honest worst case instead of "one pass".
Nits (small, worth fixing here or immediately after)
- Cross-file cooldown bleed is real and one file is unprotected. I verified empirically that Bun runs all test files in one process sharing module state (map written in file A is visible in file B).
capture.test.tsfires idle forses-cap;injection-framing.test.tsfires idle for the same sidses-cap(line 362) and does not callresetCaptureCooldowns(). It passes today only because capture.test.ts's last cooldown-firing test uses a different sid and each subsequentbeforeEachclears the map. One reordered/added test in capture.test.ts turns injection-framing red with a mystifying symptom. One line in itsbeforeEachremoves the order dependency. - The reset comment — "a fresh test is a fresh process" — is factually wrong (module state demonstrably survives file boundaries in a
bun testrun; the reset is needed precisely because of that). Fix the sentence so the next person doesn't reason off it. - Style: the rewritten Auto-capture bullet uses
-while every sibling bullet uses—(em-dash).
CI note (not your fault, but relevant): test-windows failed twice on this branch — attempt 1 on the import-concurrency race (5016 ms timeout), my rerun on supersede racing appends > a concurrent reader never sees a half-written file, a different member of the known Windows torn-read family (#110's own baseline names it). #114's identical-family failure passed a clean rerun. Treat as the documented suite flake, not this PR — but it reinforces that the deterministic pins #110 is trying to build are the real fix.
…n-sharing file, honest reset comment, README on main's dash
|
All three nits taken, in
Re-verified after the changes: the three files that share the cooldown map ( |
abogartz
left a comment
There was a problem hiding this comment.
Re-verified at acd265c (macOS, Bun 1.4.3) — all three nits confirmed fixed, APPROVED.
- Nit 1 (cooldown reset seam):
injection-framing.test.ts:39-42now callsresetCaptureCooldowns()inbeforeEach, and the comment names theses-capoverlap explicitly — the order-luck dependency is gone by construction, not just papered over. - Nit 2 (honest comment): the false 'a fresh test is a fresh process' sentence is replaced in both
capture.test.ts:41andcapture-compaction.test.ts:48with the true statement (module state survives file boundaries, hence the explicit clear). - Nit 3 (README): diffed the branch's bullet against
origin/main— line 36 differs from main's text only by the two added facts ('per trigger', the cooldown bound + bench cite); the em-dash is main's. The table row adds the separate-cooldown fact. Claim verified mechanically, not by eye.
Re-runs after the changes: the three cooldown-sharing files in one process → 55 pass / 0 fail; full suite → 490 pass / 8 skip / 0 fail; bun run typecheck clean.
|
🎉 This PR is included in version 0.14.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Fixes #108 - both parts, plus the related cleanup, and one deliberate non-part.
1. Cooldown state is module truth now, not setup-closure state
lastRun/lastCompactRunwere closures insidesetup()- and the file's ownbunFloorCheckedcomment already recorded that setup runs for more than one location. Two live registrations meant one event could pay twice:session.idleis a BROADCAST - every live subscription'sfor awaitloop sees it and each passed its own private cooldown check.onCompactCaptureseam (both hook instances reach a capture path whose map is fresh).The fix is the issue's prescription: one module-level
Mapkeyed`${trigger}:${sid}`(theturnsshape fromsrc/lock.ts, plus the ledger throttle's oldest-first bound so a long-lived server can't grow it per-session forever).resetCaptureCooldowns()exported for tests, exactly likeresetHitThrottle.Red-first, both vectors: two
loadPluginregistrations sharing one module (how the harness runs), one event driven through both seams, asserta.generate.calls + b.generate.calls === 1. Pre-fix: 2/2 red - compaction and idle broadcast each ran the model twice on one transcript. Post-fix 1/1; the gate would have collapsed the duplicate ROWS either way - this was always about the spend, invisible in the store, on a trigger that defaults on.2. Documented, honestly
captureOnCompact(default on underautoCapture, own cooldown, warn-not-spend when master is off).3. Bench evidence cited
bench/capture-trigger-results.mdnow ships cited from the auto-capture bullet instead of uncited (grep-able evidence, RESULTS.md pattern) - publish, not drop.Deliberately NOT here
The "Also open" item -
setCurrent+ await-before-write racinggateContext()- is a seam decision (thread sid into the write path vs mutate module state), not a bug fix. Per #68 it deserves its own thread; this PR neither worsens nor touches it.Verified
bun run test)tsc --noEmit+biome lintclean; capture neighborhood 37/37. The two new tests are red on pre-fixsrc(verified by reverting onlysrc/index.ts, shimmed reset) - the pre-fix leg fails withExpected: 1, Received: 2in both.assisted by Qwen3-flash-next