Repository navigation
fix(sessions): unread advances only when a run ends with a new visible reply - #204281
Conversation
…e reply - Both run-end writers read the transcript's newest visible assistant row (the row preview projection) and advance lastActivityAt only when it is newer. NO_REPLY, heartbeat acks and hidden coordination replies no longer mark a session unread. - Remove the controlUiVisible run-end stamp, agent-command touchActivity and its coordination special case, and the lifecycle-event unread recompute. - Nothing is written in the transcript append path. Co-authored-by: obviyus <[email protected]> Fixes #204164
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Rejected review findings:
|
|
Codex review: needs changes before merge. What this changesThis PR makes run-end unread activity depend on the transcript’s newest visible assistant reply. Example: A read session receives a hidden wake and the model answers NO_REPLY.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 2 items remain Keep open: this maintainer-authored PR fixes false unread indicators, but two concrete regressions can leave new replies or visible failures marked read. Priority: P2 Before merge
Findings
Agent review detailsHow this fits togetherAgent-command and Gateway lifecycle finalizers update session metadata; clients derive unread indicators from that metadata and their last read acknowledgment. flowchart TD
A[Agent run] --> B[Transcript owner]
B --> C[Bounded visible reply projection]
C --> D[Run end writers]
D --> E[Session activity metadata]
E --> F[Client unread indicator]
Technical reviewBest possible solution: Keep the existing run-end owners, but derive unread activity from content arrival and include visible terminal failure reports. Do we have a high-confidence way to reproduce the issue? Current-main source establishes unconditional unread stamping for visible terminal events, and the supplied base/head screenshots demonstrate the central quiet-turn failure; no target code was executed during this read-only review. Is this the best way to solve the issue? Reusing transcript facts at run end avoids the append-path failures recorded on the superseded PR, but preview ordering timestamps and assistant-only selection do not fully represent newly visible content. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 57dd84bd1e0f. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +17, Tests -25, Docs 0. Total -8 across 14 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 23, 2026, 6:54 PM ET / 23:54 UTC. |
|
Landed. Bug: a run that ended in NO_REPLY, a quiet heartbeat or a hidden wake still marked its chat unread. Fix: both run-end writers now advance unread only when the transcript has a newer visible assistant reply. Proof: real-SQLite run-end tests (red on base), the PostgreSQL cron lifecycle suite, and a real-Gateway Control UI check (NO_REPLY chat stays read, visible reply lights the dot). |
…ct (#204316) ## Result `test/vitest-projects-config.test.ts` "covers each normal full-suite test file exactly once" passes again. `src/shared/session-unread.test.ts` runs in one project only. ## Cause #204281 (`7986fe168800`) moved `src/shared/session-unread.test.ts` into `databaseWorkerCoreTestFiles` (it now reads the transcript through the agent database worker). The infra project runs those files. The `shared-core` project (`src/shared/**/*.test.ts`) did not exclude the list, so the file ran in both `vitest.infra.config.ts` and `vitest.shared-core.config.ts`. Every other scoped project that can include a listed file already excludes `databaseWorkerCoreTestFiles`. ## Fix `vitest.shared-core.config.ts` excludes `databaseWorkerCoreTestFiles`, like the other scoped configs. ## Evidence - Ownership audit (`auditFullSuiteTestFileOwnership`) on `main`: duplicated `src/shared/session-unread.test.ts: vitest.infra.config.ts, vitest.shared-core.config.ts`. On the head: no duplicates and nothing missing. - Head: `vitest-projects-config.test.ts` (42) and `session-unread.test.ts` (5) pass. CI green on the head; local ClawSweeper: patch is correct, no findings. Co-authored-by: Ayaan Zaidi <[email protected]>
…e reply (openclaw#204281) Closes openclaw#204164. Replaces openclaw#204209. ## Problem A session went unread with nothing new to read. Example (synthetic): a heartbeat or child-end wake runs in a chat, the model answers `NO_REPLY` (or `HEARTBEAT_OK`), the chat shows no new row, and the sidebar still lights its unread dot. Cause: the run end stamped unread activity per run, not per content. - The Gateway's run-end lifecycle projection set `lastActivityAt = endedAt` for every Control UI–visible run (`controlUiVisible`). - Agent-command post-run set `lastActivityAt = now` for every run without internal events (`touchActivity`), with a special case for a child's `sessions_send` turns (openclaw#204143). Neither knew whether the run added anything a person can see. ## Change The run end now reads what the run added. Both run-end writers ask the transcript for its newest visible assistant row (`lastAssistantMessage`, the same row projection that feeds the sidebar preview) and advance `lastActivityAt` to that row's time only when it is newer. Silent replies (`NO_REPLY`), heartbeat acknowledgements and hidden coordination replies (`display: false`) are not visible rows, so a run that ends in one of them leaves unread alone. - One read: `readVisibleSessionActivityAt` (`src/gateway/session-row-transcript-backfill.ts`), a thin wrapper over the existing bounded row-transcript read (`backfillSessionRowTranscriptFields`). - Gateway run end: `persistPreparedGatewaySessionLifecycleEvent` passes the time into the lifecycle patch (`visibleActivityAt`); `projectSessionLifecyclePatch` applies it on terminal events. - Agent-command run end (Gateway `agent` runs and `openclaw agent --local`): `updateSessionStoreAfterAgentRun` reads the same fact; a visible reply also ends a snooze, as before. - Nothing is written in the transcript append path. - Channel inbound messages and background/cron results keep their existing stamping (they add a visible row themselves). Removed: - the run-end `controlUiVisible` stamp and `controlUiVisible` on lifecycle events, which only fed it; - agent-command `touchActivity`, its internal-event and coordination special cases; - the lifecycle-event unread recomputation in `buildGatewaySessionSnapshot`; - `session-store.snooze.test.ts`, which asserted the removed `touchActivity` parameter (snooze is covered in `session-unread.test.ts`). Production line delta (excluding tests, docs and test inventories): **+44 / −27 (net +17)**. The read is one helper with two call sites; the per-run special cases it replaces were smaller than the read and its plumbing. ## What the user sees - A turn that ends in `NO_REPLY`, a quiet heartbeat, an internal wake, or a parent answering its child's `sessions_send` no longer lights the unread dot. - A visible reply, a channel message, or a delivered cron/background result still does. A visible reply still wakes a snoozed session. ## Accepted edge cases - Incognito sessions: their transcripts stay in the Gateway process, so the run end has no stored row to read and their replies no longer mark them unread. You are usually in an incognito chat while it runs. - A reply that is only an image (no text) has no row preview, so it does not mark the chat unread. - CLI-backend runs (`claude-cli` and similar) persist their transcript after the agent-command run end, so `openclaw agent --local` with a CLI backend does not mark unread from that writer. I did not verify whether the Gateway lifecycle run end sees a Gateway CLI run's reply. - A visible reply whose stored event is over 64 KiB has no row preview, so it does not mark the chat unread (the preview read is size-bounded so it can run at every run end). - The run end adds one bounded transcript read per terminal run (the same read the sidebar row owner already does). ## Evidence - `src/shared/session-unread.test.ts` (rewritten) appends real rows to a SQLite transcript and runs the real agent-command run end: - stays read and snoozed after a `NO_REPLY` wake turn, a quiet heartbeat, and a parent's reply to a child's `sessions_send` (built through the run writer's display projection). **Red on base** (base stamps every run). - turns unread and ends the snooze after a visible reply; - inbound channel message unread, internal wake read (unchanged from openclaw#204143). - `src/gateway/session-lifecycle-state.test.ts`: a visible run that ends without a new visible reply leaves `lastActivityAt` alone. **Red on base.** - `src/cron/isolated-agent/destination-completion.test.ts` (unchanged): a delivered cron result still stamps the destination. - PostgreSQL conformance, full suite, locally against PostgreSQL 16 (pgvector pg16 image from CI): `server-database-engine-cron.postgres.test.ts`, which failed on openclaw#204209, passes. `client-credential-update.test.ts` and `git-backup.postgres.test.ts` fail locally the same way on the merge base (local environment, not this change). - `pnpm check:changed`: typecheck, lint and guards pass. The dead-export scan fails on three exports this PR does not touch (also on `main`). - Real-Gateway Control UI E2E (throwaway, not committed; only the model provider is scripted; dist build): two chats each get an `agent` turn with a hidden heartbeat input while the browser shows a third chat. The first reply is `NO_REPLY`, the second visible. - Base: **fails**, the `NO_REPLY` chat shows an unread dot. - Head: **passes**, the `NO_REPLY` chat stays read; the visible-reply chat shows a dot. Screenshots in a PR comment. Co-authored-by: Ayaan Zaidi <[email protected]>
…ct (openclaw#204316) ## Result `test/vitest-projects-config.test.ts` "covers each normal full-suite test file exactly once" passes again. `src/shared/session-unread.test.ts` runs in one project only. ## Cause openclaw#204281 (`1be1a08706d1`) moved `src/shared/session-unread.test.ts` into `databaseWorkerCoreTestFiles` (it now reads the transcript through the agent database worker). The infra project runs those files. The `shared-core` project (`src/shared/**/*.test.ts`) did not exclude the list, so the file ran in both `vitest.infra.config.ts` and `vitest.shared-core.config.ts`. Every other scoped project that can include a listed file already excludes `databaseWorkerCoreTestFiles`. ## Fix `vitest.shared-core.config.ts` excludes `databaseWorkerCoreTestFiles`, like the other scoped configs. ## Evidence - Ownership audit (`auditFullSuiteTestFileOwnership`) on `main`: duplicated `src/shared/session-unread.test.ts: vitest.infra.config.ts, vitest.shared-core.config.ts`. On the head: no duplicates and nothing missing. - Head: `vitest-projects-config.test.ts` (42) and `session-unread.test.ts` (5) pass. CI green on the head; local ClawSweeper: patch is correct, no findings. Co-authored-by: Ayaan Zaidi <[email protected]>
…ct (#204316) ## Result `test/vitest-projects-config.test.ts` "covers each normal full-suite test file exactly once" passes again. `src/shared/session-unread.test.ts` runs in one project only. ## Cause #204281 (`7986fe168800`) moved `src/shared/session-unread.test.ts` into `databaseWorkerCoreTestFiles` (it now reads the transcript through the agent database worker). The infra project runs those files. The `shared-core` project (`src/shared/**/*.test.ts`) did not exclude the list, so the file ran in both `vitest.infra.config.ts` and `vitest.shared-core.config.ts`. Every other scoped project that can include a listed file already excludes `databaseWorkerCoreTestFiles`. ## Fix `vitest.shared-core.config.ts` excludes `databaseWorkerCoreTestFiles`, like the other scoped configs. ## Evidence - Ownership audit (`auditFullSuiteTestFileOwnership`) on `main`: duplicated `src/shared/session-unread.test.ts: vitest.infra.config.ts, vitest.shared-core.config.ts`. On the head: no duplicates and nothing missing. - Head: `vitest-projects-config.test.ts` (42) and `session-unread.test.ts` (5) pass. CI green on the head; local ClawSweeper: patch is correct, no findings. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 60dede9) Co-authored-by: RomneyDa <[email protected]>
…r closes (#204544) ## Problem During a Gateway restart or stop, a run that ends after the agent database's clean-close receipt can reopen the sealed store. `test/gateway-restart-resume.e2e.test.ts` ("restart markers survive graceful shutdown (blocked store: false)") catches it: a `session.rowTranscript.backfill` reservation starts after the clean-close (`expected true to be false` at the `[close-backfill-proof]` check). No scheduled CI lane runs this file. Cause: #204281 added `readVisibleSessionActivityAt`. Every run end calls it, and it uses `backfillSessionRowTranscriptFields` with no signal. #188976 fenced only the session-row projection queue. Shutdown aborts the active runs, those runs end, and each run end then opens the store again. ## Solution The drain and shutdown fence moves into `backfillSessionRowTranscriptFields`, the function that opens the store. Every caller gets it, including the run-end read. The `signal` parameter is removed, because its only caller (the projection queue) passed the same two signals. ## Impact - A run that ends while the Gateway drains or closes does not advance unread. The run-end read already treats a failure as "unread unchanged". Accepted edge case: a visible reply that lands during shutdown does not light the unread dot. - No change outside shutdown. - Production: +16 / −11 lines in 2 files. ## Evidence - Base (`main`), the same filtered case: the `[close-backfill-proof]` check fails in cycle 1. - Head: cycle 1 passes the check (a run free of a local port probe that sends `GET /` to new listeners and breaks the fixture's JSON parse). Unit tests `session-row-transcript-backfill.test.ts` (16) and `session-accessor.sqlite-maintenance-read.test.ts` (8) pass. `pnpm tsgo:core` passes. - The e2e case is still red on head, at a later step: in cycle 2, a queued input is cancelled at restart (`HANDLED_QUEUED_BEFORE_RESTART_2_1`). That failure also occurs on `57dd84bd`, before #204281, so it has a separate cause. It is tracked separately. Co-authored-by: Ayaan Zaidi <[email protected]>
…r closes (#204544) ## Problem During a Gateway restart or stop, a run that ends after the agent database's clean-close receipt can reopen the sealed store. `test/gateway-restart-resume.e2e.test.ts` ("restart markers survive graceful shutdown (blocked store: false)") catches it: a `session.rowTranscript.backfill` reservation starts after the clean-close (`expected true to be false` at the `[close-backfill-proof]` check). No scheduled CI lane runs this file. Cause: #204281 added `readVisibleSessionActivityAt`. Every run end calls it, and it uses `backfillSessionRowTranscriptFields` with no signal. #188976 fenced only the session-row projection queue. Shutdown aborts the active runs, those runs end, and each run end then opens the store again. ## Solution The drain and shutdown fence moves into `backfillSessionRowTranscriptFields`, the function that opens the store. Every caller gets it, including the run-end read. The `signal` parameter is removed, because its only caller (the projection queue) passed the same two signals. ## Impact - A run that ends while the Gateway drains or closes does not advance unread. The run-end read already treats a failure as "unread unchanged". Accepted edge case: a visible reply that lands during shutdown does not light the unread dot. - No change outside shutdown. - Production: +16 / −11 lines in 2 files. ## Evidence - Base (`main`), the same filtered case: the `[close-backfill-proof]` check fails in cycle 1. - Head: cycle 1 passes the check (a run free of a local port probe that sends `GET /` to new listeners and breaks the fixture's JSON parse). Unit tests `session-row-transcript-backfill.test.ts` (16) and `session-accessor.sqlite-maintenance-read.test.ts` (8) pass. `pnpm tsgo:core` passes. - The e2e case is still red on head, at a later step: in cycle 2, a queued input is cancelled at restart (`HANDLED_QUEUED_BEFORE_RESTART_2_1`). That failure also occurs on `57dd84bd`, before #204281, so it has a separate cause. It is tracked separately. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 76e2021) Co-authored-by: RomneyDa <[email protected]>
…r closes (openclaw#204544) ## Problem During a Gateway restart or stop, a run that ends after the agent database's clean-close receipt can reopen the sealed store. `test/gateway-restart-resume.e2e.test.ts` ("restart markers survive graceful shutdown (blocked store: false)") catches it: a `session.rowTranscript.backfill` reservation starts after the clean-close (`expected true to be false` at the `[close-backfill-proof]` check). No scheduled CI lane runs this file. Cause: openclaw#204281 added `readVisibleSessionActivityAt`. Every run end calls it, and it uses `backfillSessionRowTranscriptFields` with no signal. openclaw#188976 fenced only the session-row projection queue. Shutdown aborts the active runs, those runs end, and each run end then opens the store again. ## Solution The drain and shutdown fence moves into `backfillSessionRowTranscriptFields`, the function that opens the store. Every caller gets it, including the run-end read. The `signal` parameter is removed, because its only caller (the projection queue) passed the same two signals. ## Impact - A run that ends while the Gateway drains or closes does not advance unread. The run-end read already treats a failure as "unread unchanged". Accepted edge case: a visible reply that lands during shutdown does not light the unread dot. - No change outside shutdown. - Production: +16 / −11 lines in 2 files. ## Evidence - Base (`main`), the same filtered case: the `[close-backfill-proof]` check fails in cycle 1. - Head: cycle 1 passes the check (a run free of a local port probe that sends `GET /` to new listeners and breaks the fixture's JSON parse). Unit tests `session-row-transcript-backfill.test.ts` (16) and `session-accessor.sqlite-maintenance-read.test.ts` (8) pass. `pnpm tsgo:core` passes. - The e2e case is still red on head, at a later step: in cycle 2, a queued input is cancelled at restart (`HANDLED_QUEUED_BEFORE_RESTART_2_1`). That failure also occurs on `c28cebe5`, before openclaw#204281, so it has a separate cause. It is tracked separately. Co-authored-by: Ayaan Zaidi <[email protected]>
…ional Talk timestamps persist (#207876) Related: #206321 ## What Problem This Solves When a chat's latest visible reply has a sub-millisecond timestamp, saving the session's activity time fails, so the reply never reaches the session history. iPhone Talk transcripts carry such timestamps (for example `1795914508633.935`). The run finishes and the user sees the answer live, but after a reload, or in the next call's starting history, that answer is missing. The Gateway log shows SQLite rejecting the value: a REAL written into the integer column `session_nodes.last_activity_at`. `readVisibleSessionActivityAt` (added in #204281) passes the transcript timestamp straight through. ## User Impact Talk replies can settle normally even when the transcript carries fractional milliseconds. No migration or user action is required. ## Why This Change Was Made `readVisibleSessionActivityAt` truncates the timestamp to whole milliseconds before it becomes the session row's activity time. Transcript timestamps themselves are unchanged. ## Evidence - A new test in `session-row-transcript-backfill.test.ts` uses a fractional assistant timestamp. It fails on main and passes with this change. - Found during live iPhone Talk testing for #206321: on a production build, the answer appeared live but was missing from history afterwards. The same fix is on that branch and is being removed from it in favor of this PR. #206321 depends on this fix landing first or alongside it. **Gateway integration proof (AI-assisted).** Ran the same regression cases against `origin/main` at `7e676835a57` and the patched branch. The in-process Gateway suite scripts only model execution. It runs the Talk consult, closes the call before or after the final reply, and exercises the real terminal persistence and SQLite database. The test reopens the database and queries `chat.history` through the Gateway handler. ```text origin/main — Tests 2 failed | 20 skipped (22) Caused by: Error: cannot store REAL value in INTEGER column session_nodes.last_activity_at SQLite: last_activity_at = NULL (expected whole milliseconds) patched — Tests 2 passed | 20 skipped (22) Both cases: terminal settlement succeeds; SQLite stores trunc(replyTimestamp) with typeof(last_activity_at) = 'integer'; reopened chat.history contains the reply once. ``` This fixture reproduces the terminal write failure, not the missing history: its scripted model appends the transcript before settlement, so history also contains the reply on main. The missing reply was observed separately in the original iPhone run. Its redacted Gateway log: ```text 2026-11-29T01:08:57.911Z [gateway] terminal session persistence failed session=[redacted] run=[redacted] error=Error: cannot store REAL value in INTEGER column session_nodes.last_activity_at: code=ERR_SQLITE_ERROR ``` The previous [check-lint failure](https://github.com/openclaw/openclaw/actions/runs/46211916112/job/141188208993) flagged formatting in this PR's test file, not a UI guard. The formatting is fixed and the local format check passes on all three PR files. Co-authored-by: Ayaan Zaidi <[email protected]>
…ional Talk timestamps persist (openclaw#207876) Related: openclaw#206321 ## What Problem This Solves When a chat's latest visible reply has a sub-millisecond timestamp, saving the session's activity time fails, so the reply never reaches the session history. iPhone Talk transcripts carry such timestamps (for example `1795914508633.935`). The run finishes and the user sees the answer live, but after a reload, or in the next call's starting history, that answer is missing. The Gateway log shows SQLite rejecting the value: a REAL written into the integer column `session_nodes.last_activity_at`. `readVisibleSessionActivityAt` (added in openclaw#204281) passes the transcript timestamp straight through. ## User Impact Talk replies can settle normally even when the transcript carries fractional milliseconds. No migration or user action is required. ## Why This Change Was Made `readVisibleSessionActivityAt` truncates the timestamp to whole milliseconds before it becomes the session row's activity time. Transcript timestamps themselves are unchanged. ## Evidence - A new test in `session-row-transcript-backfill.test.ts` uses a fractional assistant timestamp. It fails on main and passes with this change. - Found during live iPhone Talk testing for openclaw#206321: on a production build, the answer appeared live but was missing from history afterwards. The same fix is on that branch and is being removed from it in favor of this PR. openclaw#206321 depends on this fix landing first or alongside it. **Gateway integration proof (AI-assisted).** Ran the same regression cases against `origin/main` at `fa5df2fc8ec` and the patched branch. The in-process Gateway suite scripts only model execution. It runs the Talk consult, closes the call before or after the final reply, and exercises the real terminal persistence and SQLite database. The test reopens the database and queries `chat.history` through the Gateway handler. ```text origin/main — Tests 2 failed | 20 skipped (22) Caused by: Error: cannot store REAL value in INTEGER column session_nodes.last_activity_at SQLite: last_activity_at = NULL (expected whole milliseconds) patched — Tests 2 passed | 20 skipped (22) Both cases: terminal settlement succeeds; SQLite stores trunc(replyTimestamp) with typeof(last_activity_at) = 'integer'; reopened chat.history contains the reply once. ``` This fixture reproduces the terminal write failure, not the missing history: its scripted model appends the transcript before settlement, so history also contains the reply on main. The missing reply was observed separately in the original iPhone run. Its redacted Gateway log: ```text 2026-11-29T01:08:57.911Z [gateway] terminal session persistence failed session=[redacted] run=[redacted] error=Error: cannot store REAL value in INTEGER column session_nodes.last_activity_at: code=ERR_SQLITE_ERROR ``` The previous [check-lint failure](https://github.com/openclaw/openclaw/actions/runs/46211916112/job/141188208993) flagged formatting in this PR's test file, not a UI guard. The formatting is fixed and the local format check passes on all three PR files. Co-authored-by: Ayaan Zaidi <[email protected]>



Closes #204164. Replaces #204209.
Problem
A session went unread with nothing new to read. Example (synthetic): a heartbeat or child-end wake runs in a chat, the model answers
NO_REPLY(orHEARTBEAT_OK), the chat shows no new row, and the sidebar still lights its unread dot.Cause: the run end stamped unread activity per run, not per content.
lastActivityAt = endedAtfor every Control UI–visible run (controlUiVisible).lastActivityAt = nowfor every run without internal events (touchActivity), with a special case for a child'ssessions_sendturns (fix(sessions): exclude hidden coordination and failed children from unread #204143).Neither knew whether the run added anything a person can see.
Change
The run end now reads what the run added. Both run-end writers ask the transcript for its newest visible assistant row (
lastAssistantMessage, the same row projection that feeds the sidebar preview) and advancelastActivityAtto that row's time only when it is newer. Silent replies (NO_REPLY), heartbeat acknowledgements and hidden coordination replies (display: false) are not visible rows, so a run that ends in one of them leaves unread alone.readVisibleSessionActivityAt(src/gateway/session-row-transcript-backfill.ts), a thin wrapper over the existing bounded row-transcript read (backfillSessionRowTranscriptFields).persistPreparedGatewaySessionLifecycleEventpasses the time into the lifecycle patch (visibleActivityAt);projectSessionLifecyclePatchapplies it on terminal events.agentruns andopenclaw agent --local):updateSessionStoreAfterAgentRunreads the same fact; a visible reply also ends a snooze, as before.Removed:
controlUiVisiblestamp andcontrolUiVisibleon lifecycle events, which only fed it;touchActivity, its internal-event and coordination special cases;buildGatewaySessionSnapshot;session-store.snooze.test.ts, which asserted the removedtouchActivityparameter (snooze is covered insession-unread.test.ts).Production line delta (excluding tests, docs and test inventories): +44 / −27 (net +17). The read is one helper with two call sites; the per-run special cases it replaces were smaller than the read and its plumbing.
What the user sees
NO_REPLY, a quiet heartbeat, an internal wake, or a parent answering its child'ssessions_sendno longer lights the unread dot.Accepted edge cases
claude-cliand similar) persist their transcript after the agent-command run end, soopenclaw agent --localwith a CLI backend does not mark unread from that writer. I did not verify whether the Gateway lifecycle run end sees a Gateway CLI run's reply.Evidence
src/shared/session-unread.test.ts(rewritten) appends real rows to a SQLite transcript and runs the real agent-command run end:NO_REPLYwake turn, a quiet heartbeat, and a parent's reply to a child'ssessions_send(built through the run writer's display projection). Red on base (base stamps every run).src/gateway/session-lifecycle-state.test.ts: a visible run that ends without a new visible reply leaveslastActivityAtalone. Red on base.src/cron/isolated-agent/destination-completion.test.ts(unchanged): a delivered cron result still stamps the destination.server-database-engine-cron.postgres.test.ts, which failed on fix(sessions): unread follows visible transcript rows, not run ends #204209, passes.client-credential-update.test.tsandgit-backup.postgres.test.tsfail locally the same way on the merge base (local environment, not this change).pnpm check:changed: typecheck, lint and guards pass. The dead-export scan fails on three exports this PR does not touch (also onmain).agentturn with a hidden heartbeat input while the browser shows a third chat. The first reply isNO_REPLY, the second visible.NO_REPLYchat shows an unread dot.NO_REPLYchat stays read; the visible-reply chat shows a dot. Screenshots in a PR comment.