Skip to content

fix(sessions): scope ambient transcript watermark to session id#99385

Merged
obviyus merged 1 commit into
mainfrom
fix/ambient-watermark-session-scope
Jul 3, 2026
Merged

fix(sessions): scope ambient transcript watermark to session id#99385
obviyus merged 1 commit into
mainfrom
fix/ambient-watermark-session-scope

Conversation

@obviyus

@obviyus obviyus commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #99373. The ambient transcript watermark (#99306) survives session resets, but the transcript rows it vouches for do not: after any reset (manual, daily, delete), every prompt-facing window consumer kept filtering out messages at/before the watermark while those rows existed only in the archived transcript. Confirmed in production: a new session's transcript began exactly at watermark+1, with all older group messages permanently invisible — not in the window, not in the transcript, never compactable.

Why This Change Was Made

Watermark validity is a fact about a specific transcript (sessionId), not about the chat. The fix makes that structural:

  • AmbientTranscriptWatermark now carries sessionId; writes stamp the entry's current sessionId.
  • Reads (readAmbientTranscriptWatermark) treat a watermark whose sessionId differs from the entry's current sessionId as absent — self-invalidating on every reset path, with no per-reset-flow cleanup to forget. Legacy records without sessionId are ignored the same way (cache-like state: window backfills once; no doctor migration).
  • Stale-hook guard: the room-event onMessagePersisted hook passes the prepared session id as expectedSessionId; if the session reset between the durable row write and the watermark advance, the advance is skipped instead of stamping a transcript that lacks the rows.

All consumers go through the read helper (Telegram session/prompt-context, live cache window, recovered threads, plugin-SDK facade), so they inherit the fix with no per-consumer changes.

User Impact

Ambient-mode group deployments no longer silently lose chat visibility across session resets: after a reset, the per-turn window backfills the persisted-but-archived messages (up to historyLimit) instead of hiding them forever. Steady-state dedupe behavior within a session is unchanged.

Evidence

  • Regression tests reproduce the production scenario end-to-end: watermark written under one sessionId, entry reset to a new sessionId, Telegram structured prompt context backfills all rows (extensions/telegram/src/bot-message-context.prompt-context.test.ts); core read/write/legacy/stale-hook coverage in src/config/sessions/ambient-transcript-watermark.test.ts. Both fail-confirmed against the unfixed code (window collapsed to the unpersisted gap; legacy watermark still honored).
  • Production LOC delta is 15 insertions / 2 deletions; the rest is tests.
  • node scripts/run-vitest.mjs on touched tests, pnpm tsgo, pnpm check:test-types: exit 0.
  • Blacksmith Testbox check:changed on the rebased branch: exit 0 (run tbx_01kwk866aemnttw2zjzgb8v8ek).

Diagnosis side-finding recorded on the issue: the observed intra-day daily reset is explained by process-UTC + DEFAULT_RESET_AT_HOUR=4 semantics (sessionStartedAt < resolveDailyResetAtMs), not a reset-policy bug.

Ambient transcript watermarks now carry the transcript session id, resolve only for the current session entry, and skip stale room-event hooks that no longer match the prepared transcript session.

This protects Telegram group prompt windows after reset by backfilling rows that are no longer present in the new session transcript, while preserving steady-state watermark filtering within one session.

Fixes #99373

Release-note: fixes Telegram group context loss after session reset when ambient transcript watermarks outlived the transcript they referenced.
@openclaw-barnacle openclaw-barnacle Bot added the channel: telegram Channel integration: telegram label Jul 3, 2026
@obviyus
obviyus merged commit 0bf66ab into main Jul 3, 2026
36 of 38 checks passed
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Jul 3, 2026
@obviyus
obviyus deleted the fix/ambient-watermark-session-scope branch July 3, 2026 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ambient transcript watermark survives session reset, permanently hiding archived messages

1 participant