Skip to content

fix: reset the auto-capture watermark after valid-empty extractions#948

Draft
gorkem2020 wants to merge 2 commits into
CortexReach:masterfrom
gorkem2020:fix/autocapture-reset-on-valid-empty-extraction
Draft

fix: reset the auto-capture watermark after valid-empty extractions#948
gorkem2020 wants to merge 2 commits into
CortexReach:masterfrom
gorkem2020:fix/autocapture-reset-on-valid-empty-extraction

Conversation

@gorkem2020

Copy link
Copy Markdown
Contributor

The agent-end auto-capture watermark (autoCaptureSeenTextCount) is reset after a successful extraction, but a valid-empty extraction (the LLM legitimately returns zero candidates) returns early and skips that reset. The counter then carries a stale, too-high value into the next turn.

In ingress-fed sessions (message_received feeds the pending-texts queue and each agent end delivers only the newest messages) this makes the very next turn fire extraction prematurely on a single genuinely new message, instead of waiting for a fresh extractMinMessages-sized window. In history-carrying sessions the asymmetry happens to be a no-op (the cumulative count is recomputed from the full history each turn), which is why it went unnoticed.

What changed

The valid-empty path now applies the identical watermark reset as the successful path. Both cases represent a batch the extractor genuinely and conclusively considered; only errored extractions leave the counter untouched.

Test plan

New regression test reproduces the exact ingress-fed sequence with the real plugin harness: a three-text turn whose extraction returns valid-empty, then one new message (must defer), then a second new message (fires normally). Watched red against the pre-fix code (the one-message turn fired prematurely), green after. The existing watermark and fallback-gating suites pass unchanged.

Found while live-testing the runtime transport work; the defect predates all current feature branches and reproduces on plain master, so it ships on its own branch.

…action

A "valid-empty" extraction result (the LLM genuinely ran and confirmed the
batch had nothing worth storing, not a failure) skipped the issue CortexReach#417
Fix CortexReach#5 watermark reset that a successful (created/merged > 0) extraction
already applies. The counter was left at whatever the pre-extraction
cumulative set it to, so the very next turn re-fired on just one new
message instead of waiting for a fresh minMessages-sized window.

Live-fleet trace (transport=host, extractMinMessages=2, ingress-fed webchat
session): a valid-empty extraction at a fresh cursor, followed by turns
that either mis-fired early or produced inconsistent windowing depending on
exact message timing -- traced to this exact gap. Confirmed via
`git show master:index.ts` that this predates every fleet-2026-07-13
feature branch; not a composition artifact, so it lands on its own branch
rather than touching any live PR head.

Fix: apply the same counter reset (issue CortexReach#417 Fix CortexReach#5) on the valid-empty
path as on the successful path, since both represent a batch the extractor
genuinely and conclusively considered.

Red-first: test/autocapture-reset-on-valid-empty-extraction.test.mjs
reproduces the exact ingress-fed sequence (3-text valid-empty turn, then a
single new message, then a second new message) using the real plugin
harness (message_received + agent_end). Watched it fail (turn 2 re-fired
with extractionPrompts.length going to 2 instead of staying at 1) against
the pre-fix code, then confirmed green after the fix. No regression in
test/smart-extractor-branches.mjs or test/functional-e2e.mjs.

Registered in package.json's test chain and scripts/ci-test-manifest.mjs.
@gorkem2020
gorkem2020 force-pushed the fix/autocapture-reset-on-valid-empty-extraction branch from 19a9143 to c747bb5 Compare July 18, 2026 15:52
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.

1 participant