Skip to content

fix(sessions): exclude hidden coordination and failed children from unread - #204143

Merged
obviyus merged 3 commits into
mainfrom
fix/unread-follows-visible
Nov 23, 2026
Merged

obviyus merged 3 commits into
mainfrom
fix/unread-follows-visible

Conversation

@obviyus

@obviyus obviyus commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A session went unread with nothing new to read. Example (synthetic): a subagent sends its parent 15 progress messages with sessions_send. Each one starts a hidden parent turn that answers only the child. Nothing appears in the parent chat, but every turn lights the parent's unread dot.

Cause: deriveSessionUnread compared lastReadAt with max(lastInteractionAt, lastActivityAt).

  • lastInteractionAt is the idle-reset clock. Every non-system turn moves it, hidden turns included.
  • Agent-command post-run moved lastActivityAt on every non-internal-event run. Unlike the run-end lifecycle writer, it did not skip hidden subagent coordination turns.

Second problem: failed or timed-out hidden subagent runs stayed unread for good. Opening the parent acknowledged its hidden runs but skipped failed ones, and hidden runs have no row of their own to open.

Change

  • deriveSessionUnread reads only lastActivityAt (plus the manual markedUnreadAt). It no longer reads the idle clock.
  • Post-run touchActivity now also skips subagent coordination provenance (isSubagentCoordinationInputProvenance), the same check the run-end lifecycle writer already applies through controlUiVisible. A hidden coordination turn no longer stamps activity, and it no longer clears a snooze.
  • Auto-reply initSessionState stamps lastActivityAt for an inbound non-system message, with the same value as the existing lastInteractionAt stamp. Channel sessions (for example Telegram) depended on the idle clock for unread, so they still go unread when a message arrives. Internal wakes do not.
  • Background and scheduled results committed into a conversation (commitBackgroundResultToSession, used by confirmed cross-conversation messages and cron results) stamp lastActivityAt with the same message timestamp as lastInteractionAt.
  • The sidebar tree counts a hidden subagent run toward its parent's unread count only while reading the parent can acknowledge it (isAcknowledgeableHiddenRun). Failed and timed-out hidden runs no longer hold the parent dot. They are not acknowledged, so their failure stays on the child card.
  • Docs: docs/web/control-ui/sessions-and-sidebar.md.

Production line delta (excluding tests and docs): +27 / −15 (net +12).

What the user sees

  • A parent that only answers its child's sessions_send stays read.
  • A visible reply, or a channel message arriving, still marks the session unread.
  • Failed hidden child runs no longer keep a parent's dot or count lit after you open the parent.

Review notes

  • Round 2 found (both fixed): (a) background and scheduled results stamped only the idle clock, so they would stop marking the destination unread; (b) the first head acknowledged failed hidden runs when the parent opened, which stamps lastReadAt and hides the failure on the child card. Now failed runs stay unacknowledged and are left out of the parent count instead.
  • Local ClawSweeper round 1 found that openclaw agent --local has no Gateway lifecycle persister. The first head deleted the post-run lastActivityAt write, so visible replies from that path stopped marking unread. Fixed by keeping the write and gating it on coordination provenance instead.

Not done here (original scope, unfinished)

The goal was that unread follows visible content: a turn that appends nothing visible never marks the session unread. This PR covers hidden coordination turns and failed hidden children only. Unread still follows run visibility, not appended content, so a Control UI–visible run that ends in NO_REPLY or a quiet heartbeat still marks the session unread. Fixing that needs one owner that decides from transcript content (the run end has no visible-output fact today). Tracked in #204164.

Evidence

  • src/shared/session-unread.test.ts (new) drives the real run-end lifecycle patch and initSessionState through deriveSessionUnread:
    • hidden turn (idle clock moved, run not visible) → read; visible run end → unread. Red on base, green on head.
    • inbound channel message → unread; internal wake → read. Green on both (guards the auto-reply stamp).
  • src/agents/agent-command.live-model-switch.test.ts: through agentCommand, an operator turn stamps activity and a child's sessions_send to its requester does not. Red on base, green on head.
  • ui/src/components/app-sidebar-session-tree.test.ts: an unread finished hidden run counts toward its parent; failed and timed-out ones do not. Red on base, green on head.
  • src/cron/isolated-agent/destination-completion.test.ts: a delivered cron result stamps lastActivityAt on the destination. Red on base, green on head.
  • Real-Gateway Control UI E2E (throwaway; only the model provider is scripted, while Gateway, sessions_spawn, sessions_send and sidebar are real): a parent spawns a visible child; the operator moves to another session; the child sends the parent a progress message with sessions_send; the parent's hidden turn replies only to the child (the child stays running, so no completion wake). Assertion: the parent sidebar row has no unread dot.
    • Base: fails, 1 dot. Head: passes, 0 dots. Screenshots in the PR comment.

Unread reads lastActivityAt only. A parent answering its child's sessions_send no longer lights the dot.
Drop the post-run lastActivityAt write that ignored coordination provenance; the run-end lifecycle projection gated on controlUiVisible is the one run writer. The flag keeps only its snooze job (touchActivity -> clearSnooze).
Auto-reply stamps lastActivityAt for inbound non-system messages so channel sessions still go unread.
Opening a parent acknowledges failed and timed-out hidden runs too, so they no longer hold the parent's unread count.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@obviyus

obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

E2E sidebar after the child's sessions_send and the parent's hidden reply. Before (base): parent shows an unread dot. After (head): no dot.

Before: unread dot after hidden turn

After: no unread dot

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui agents Agent runtime and tooling size: S labels Nov 23, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 23, 2026
…ination

Restore the post-run lastActivityAt write: `openclaw agent --local` has no Gateway lifecycle persister, so visible replies from that path must still stamp activity.
Gate it on subagent coordination provenance, the same check the run-end lifecycle writer applies via controlUiVisible, so a child's sessions_send to its requester neither stamps activity nor clears a snooze.

Co-authored-by: obviyus <[email protected]>
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 23, 2026
@clawsweeper

clawsweeper Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR makes unread indicators follow visible activity and lets opening a parent acknowledge failed hidden runs.

Example: A child sends its parent 15 progress messages through sessions_send, with replies visible only to the child.

  • Before: The parent becomes unread despite having no new visible conversation content.
  • After: The parent stays read.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful, focused work with direct proof of the central symptom, but an incomplete visible-input cutover and remaining behavior/upgrade proof prevent a pass.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Hidden coordination lights unread indicators without new visible content, and failed hidden runs can leave parent indicators uncleared.
Reason: The reported behavior is concrete and demonstrated, and the maintainer-authored PR supplies the decision to change failed-run acknowledgment.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this maintainer-authored PR open: it addresses a real unread-state bug, but dropping the interaction-clock fallback misses accepted chat input that fails before reply initialization.

Priority: P2
Reviewed head: 31a5cc8632918325ac2d7988370426097c82a31e

Before merge

  • Record visible accepted input before removing the interaction fallback (P2) - A visible chat.send can commit its transcript and then fail during preparation before initSessionState runs. chat-send-input-dispatch.ts:415–426 stamps only lastInteractionAt, and handleChatSendSetupError persists an error event without controlUiVisible, so the lifecycle projection also leaves lastActivityAt unchanged. For an entry with lastReadAt=100, lastActivityAt=90, and accepted input at lastInteractionAt=200, the base reports unread=true while this predicate reports false despite new visible input and its failure. The new stamp in session.ts is never reached on this path. Complete the visible-input writer cutover at acceptance, or otherwise preserve this case, before removing the fallback; add a regression through the real persistence owner.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P2] Record visible accepted input before removing the interaction fallback — src/shared/session-unread.ts:15

Tests

  • Missing end-to-end proof: Provide a real Gateway trace or recording of failed hidden-run acknowledgment and an upgrade from v2026.11.7 retaining session read/manual-unread state; redact credentials, IPs, and non-public endpoints.
Agent review details

How this fits together

Session admission and run completion persist activity timestamps; shared unread derivation feeds Gateway rows and Control UI indicators, while parent-read actions acknowledge folded hidden runs.

flowchart TD
  A[Incoming chat or coordination] --> B[Session admission]
  B --> C[Agent execution]
  B --> D[Persisted session timestamps]
  C --> D
  D --> E[Shared unread derivation]
  E --> F[Gateway session rows]
  F --> G[Control UI sidebar and parent reads]
Loading

Technical review

Best possible solution:

Stamp visible accepted input through its existing persistence owner before removing the idle-clock fallback, while preserving hidden coordination suppression and standalone agent activity.

Do we have a high-confidence way to reproduce the issue?

The original hidden-turn defect is supported by source and inspected author-supplied before/after screenshots; the missed accepted-input failure path is source-reproducible, and no target code was executed during this review.

Is this the best way to solve the issue?

Separating idle activity from unread activity is sound, but the cutover must include visible input acceptance rather than relying on reply initialization to run successfully.

Full review comments:

  • [P2] Record visible accepted input before removing the interaction fallback — src/shared/session-unread.ts:15
    A visible chat.send can commit its transcript and then fail during preparation before initSessionState runs. chat-send-input-dispatch.ts:415–426 stamps only lastInteractionAt, and handleChatSendSetupError persists an error event without controlUiVisible, so the lifecycle projection also leaves lastActivityAt unchanged. For an entry with lastReadAt=100, lastActivityAt=90, and accepted input at lastInteractionAt=200, the base reports unread=true while this predicate reports false despite new visible input and its failure. The new stamp in session.ts is never reached on this path. Complete the visible-input writer cutover at acceptance, or otherwise preserve this case, before removing the fallback; add a regression through the real persistence owner.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e5dcfa009663.

Provenance checked

  • Shared unread derivation changes intended behavior with a stated reason (1ad9fe2: Centralize unread and row freshness behavior across session views; earlier predicate introduction remains unknown beyond the inspected extraction.)
  • Reply initialization activity changes intended behavior with a stated reason (10bdf2c: Reuse activity already committed with accepted input and avoid a redundant initialization rewrite.)
  • Hidden-run failure acknowledgment changes intended behavior with a stated reason (bff90d6: Acknowledge folded plain unread runs while preserving failures and active attention on their notice paths.)
  • Agent-command activity keeps the original intent (7f4cbc1: Keep ordinary and Cron activity after retiring heartbeat-specific paths while excluding internal events.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/shared/session-unread.test.ts src/auto-reply/reply/session.test.ts src/gateway/server-methods/chat-send-dispatch-errors.test.ts
  • pnpm test src/agents/agent-command.live-model-switch.test.ts ui/src/pages/chat/chat-pane.read-marker.test.ts
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 1ad9fe2 adds src/shared/session-unread.ts:11 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1ad9fe2a759d; files: src/shared/session-unread.ts)
  • Holger Gruenhagen: Raw commit bff90d6 adds ui/src/components/app-sidebar-session-parent.ts:79 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: bff90d69144c; files: ui/src/components/app-sidebar-session-parent.ts)

PR surface

Source +2, Tests +103, Docs +2. Total +107 across 8 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 4 19 17 +2
Tests 3 105 2 +103
Docs 1 3 1 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 127 20 +107

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: Incorrect unread indicators affect session attention without preventing chat execution.
  • add merge-risk: 🚨 session-state: Removing the fallback can make persisted visible input appear read when setup fails before the replacement stamp runs.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Incorrect unread indicators affect session attention without preventing chat execution.
  • merge-risk: 🚨 session-state: Removing the fallback can make persisted visible input appear read when setup fails before the replacement stamp runs.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 23, 2026, 12:02 PM ET / 17:02 UTC.

Leave failed and timed-out hidden runs unacknowledged so their failure stays on the child card, and stop counting them toward the parent's unread state instead.

Background and scheduled results committed into a conversation stamp lastActivityAt with the message timestamp, so they still mark the destination unread.

Co-authored-by: obviyus <[email protected]>

@THE-NAVVV THE-NAVVV left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

​

@obviyus obviyus changed the title fix(sessions): mark unread only for visible activity fix(sessions): exclude hidden coordination and failed children from unread Nov 23, 2026
@obviyus
obviyus merged commit 3346727 into main Nov 23, 2026
152 of 153 checks passed
@obviyus
obviyus deleted the fix/unread-follows-visible branch November 23, 2026 17:38
@obviyus

obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Landed. A parent that only answers its child's sessions_send stays read, and failed or timed-out hidden child runs no longer hold the parent's unread count; their failure stays on the child card. Proof: new unit tests (red on base, green on head) and a real-Gateway Control UI E2E (base: 1 dot, head: 0). Not covered: NO_REPLY and quiet wakes on visible runs still mark unread, tracked in #204164.

obviyus added a commit that referenced this pull request Nov 24, 2026
…e reply (#204281)

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` (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 (#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 #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 #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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 24, 2026
…nread (openclaw#204143)

## Problem

A session went unread with nothing new to read. Example (synthetic): a subagent sends its parent 15 progress messages with `sessions_send`. Each one starts a hidden parent turn that answers only the child. Nothing appears in the parent chat, but every turn lights the parent's unread dot.

Cause: `deriveSessionUnread` compared `lastReadAt` with `max(lastInteractionAt, lastActivityAt)`.
- `lastInteractionAt` is the idle-reset clock. Every non-system turn moves it, hidden turns included.
- Agent-command post-run moved `lastActivityAt` on every non-internal-event run. Unlike the run-end lifecycle writer, it did not skip hidden subagent coordination turns.

Second problem: failed or timed-out hidden subagent runs stayed unread for good. Opening the parent acknowledged its hidden runs but skipped failed ones, and hidden runs have no row of their own to open.

## Change

- `deriveSessionUnread` reads only `lastActivityAt` (plus the manual `markedUnreadAt`). It no longer reads the idle clock.
- Post-run `touchActivity` now also skips subagent coordination provenance (`isSubagentCoordinationInputProvenance`), the same check the run-end lifecycle writer already applies through `controlUiVisible`. A hidden coordination turn no longer stamps activity, and it no longer clears a snooze.
- Auto-reply `initSessionState` stamps `lastActivityAt` for an inbound non-system message, with the same value as the existing `lastInteractionAt` stamp. Channel sessions (for example Telegram) depended on the idle clock for unread, so they still go unread when a message arrives. Internal wakes do not.
- Background and scheduled results committed into a conversation (`commitBackgroundResultToSession`, used by confirmed cross-conversation messages and cron results) stamp `lastActivityAt` with the same message timestamp as `lastInteractionAt`.
- The sidebar tree counts a hidden subagent run toward its parent's unread count only while reading the parent can acknowledge it (`isAcknowledgeableHiddenRun`). Failed and timed-out hidden runs no longer hold the parent dot. They are not acknowledged, so their failure stays on the child card.
- Docs: `docs/web/control-ui/sessions-and-sidebar.md`.

Production line delta (excluding tests and docs): **+27 / −15 (net +12)**.

## What the user sees

- A parent that only answers its child's `sessions_send` stays read.
- A visible reply, or a channel message arriving, still marks the session unread.
- Failed hidden child runs no longer keep a parent's dot or count lit after you open the parent.

## Review notes

- Round 2 found (both fixed): (a) background and scheduled results stamped only the idle clock, so they would stop marking the destination unread; (b) the first head acknowledged failed hidden runs when the parent opened, which stamps `lastReadAt` and hides the failure on the child card. Now failed runs stay unacknowledged and are left out of the parent count instead.
- Local ClawSweeper round 1 found that `openclaw agent --local` has no Gateway lifecycle persister. The first head deleted the post-run `lastActivityAt` write, so visible replies from that path stopped marking unread. Fixed by keeping the write and gating it on coordination provenance instead.

## Not done here (original scope, unfinished)

The goal was that unread follows visible content: a turn that appends nothing visible never marks the session unread. This PR covers hidden coordination turns and failed hidden children only. Unread still follows run visibility, not appended content, so a Control UI–visible run that ends in `NO_REPLY` or a quiet heartbeat still marks the session unread. Fixing that needs one owner that decides from transcript content (the run end has no visible-output fact today). Tracked in openclaw#204164.

## Evidence

- `src/shared/session-unread.test.ts` (new) drives the real run-end lifecycle patch and `initSessionState` through `deriveSessionUnread`:
  - hidden turn (idle clock moved, run not visible) → read; visible run end → unread. **Red on base, green on head.**
  - inbound channel message → unread; internal wake → read. Green on both (guards the auto-reply stamp).
- `src/agents/agent-command.live-model-switch.test.ts`: through `agentCommand`, an operator turn stamps activity and a child's `sessions_send` to its requester does not. **Red on base, green on head.**
- `ui/src/components/app-sidebar-session-tree.test.ts`: an unread finished hidden run counts toward its parent; failed and timed-out ones do not. **Red on base, green on head.**
- `src/cron/isolated-agent/destination-completion.test.ts`: a delivered cron result stamps `lastActivityAt` on the destination. **Red on base, green on head.**
- Real-Gateway Control UI E2E (throwaway; only the model provider is scripted, while Gateway, `sessions_spawn`, `sessions_send` and sidebar are real): a parent spawns a visible child; the operator moves to another session; the child sends the parent a progress message with `sessions_send`; the parent's hidden turn replies only to the child (the child stays running, so no completion wake). Assertion: the parent sidebar row has no unread dot.
  - Base: **fails**, 1 dot. Head: **passes**, 0 dots. Screenshots in the PR comment.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 24, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui docs Improvements or additions to documentation merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants