Skip to content

fix(sessions): unread advances only when a run ends with a new visible reply - #204281

Merged
obviyus merged 1 commit into
mainfrom
fix/unread-at-run-end
Nov 24, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/unread-at-run-end

Conversation

@obviyus

@obviyus obviyus commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

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.

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 fix(sessions): exclude hidden coordination and failed children from unread #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 fix(sessions): unread follows visible transcript rows, not run ends #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.

…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
@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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Nov 23, 2026
@obviyus

obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Control UI E2E (real Gateway, scripted provider). Sidebar after an agent turn with a hidden heartbeat input: "Quiet chat" got NO_REPLY, "Visible chat" got a visible reply. Base: the NO_REPLY chat shows an unread dot. Head: only the visible-reply chat does.

Base: NO_REPLY chat marked unread

Head: NO_REPLY chat stays read

Head: visible reply marks its chat unread

@obviyus

obviyus commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Rejected review findings:

  • P2 session-store.ts (CLI-backend openclaw agent --local reply is persisted after the run-end read, so it does not mark unread): accepted edge case, named in the PR body. The decision for this PR was: --local reads the newest visible row through the existing transcript read; where that needs new plumbing, record the gap instead of adding a second writer. Moving the read after persistCliTurnTranscript would add a second unread writer for one backend. Embedded --local runs and all Gateway runs (including CLI backends, through the lifecycle run end) are covered.
  • P2 session-row-transcript-backfill.ts (a visible reply whose stored event is over 64 KiB has no row preview, so it does not mark unread): accepted edge case, named in the PR body. The row preview's size bound is the reason the read is cheap enough to run at every run end; reading oversized events would put an unbounded read on every run end. Any later visible row in that chat marks it unread as usual.

@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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: needs changes before merge.

What this changes

This 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.

  • Before: Run completion lights the session’s unread dot despite adding nothing visible.
  • After: The session stays read; a visible reply still marks it unread.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong proof supports the central fix, but two source-established unread regressions block merge.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): Inspected screenshots and their accompanying scenario demonstrate the changed finalizers through a real Gateway and Control UI with a scripted provider: NO_REPLY incorrectly marks unread on base, stays read on head, and a visible reply marks unread on head.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: The sidebar directs users to sessions that contain nothing new to read.
Reason: The maintainer-authored direction addresses a demonstrated attention problem and explicitly accepts the bounded-preview limitations.

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
Reviewed head: 9fd1d40f183123424847fcdf69f1b23690464465

Before merge

  • Use content arrival time rather than the preview ordering timestamp (P2) - The returned timestamp prefers event.message.timestamp, which the model transport assigns before streaming begins, rather than the transcript append time. For example, a response starts at 1000, the user opens the still-running chat and acknowledges it at 1500, then leaves before the answer is committed at 2000. Both finalizers now write activity=1000, so deriveSessionUnread remains false despite the newly completed reply; base used the completion time. Preserve the content-arrival fact for unread without changing the preview’s separate reply-ordering contract, and cover this read-during-generation case.
  • Include visible terminal failure reports in unread activity (P2) - When a visible run fails before producing assistant text, this read finds no new assistant reply. The lifecycle owner subsequently appends a display-visible run-failed-before-reply custom report at line 269, after the activity update has already committed. Custom reports are also excluded by projectSessionDisplayMessage’s user/assistant filter, so reading again would not recover this case. A previously read background chat therefore receives a visible failure notice but stays read, whereas base marked the accepted visible terminal event unread. Carry the visible failure-report outcome through the existing lifecycle/failure owner while keeping suppressed failures quiet.

Findings

  • [P2] Use content arrival time rather than the preview ordering timestamp — src/gateway/session-row-transcript-backfill.ts:115-117
  • [P2] Include visible terminal failure reports in unread activity — src/gateway/session-lifecycle-state.ts:149-158
Agent review details

How this fits together

Agent-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]
Loading

Technical review

Best 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:

  • [P2] Use content arrival time rather than the preview ordering timestamp — src/gateway/session-row-transcript-backfill.ts:115-117
    The returned timestamp prefers event.message.timestamp, which the model transport assigns before streaming begins, rather than the transcript append time. For example, a response starts at 1000, the user opens the still-running chat and acknowledges it at 1500, then leaves before the answer is committed at 2000. Both finalizers now write activity=1000, so deriveSessionUnread remains false despite the newly completed reply; base used the completion time. Preserve the content-arrival fact for unread without changing the preview’s separate reply-ordering contract, and cover this read-during-generation case.
    Confidence: 0.98
  • [P2] Include visible terminal failure reports in unread activity — src/gateway/session-lifecycle-state.ts:149-158
    When a visible run fails before producing assistant text, this read finds no new assistant reply. The lifecycle owner subsequently appends a display-visible run-failed-before-reply custom report at line 269, after the activity update has already committed. Custom reports are also excluded by projectSessionDisplayMessage’s user/assistant filter, so reading again would not recover this case. A previously read background chat therefore receives a visible failure notice but stays read, whereas base marked the accepted visible terminal event unread. Carry the visible failure-report outcome through the existing lifecycle/failure owner while keeping suppressed failures quiet.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Visible-terminal lifecycle activity changes intended behavior with a stated reason (359a8a3: Show unread immediately when a visible session completes after its last read; the later worker refactor preserved that lifecycle responsibility.)
  • Agent-command activity and snooze settlement changes intended behavior with a stated reason (88f1ec3: Provide durable activity for unread across clients; later coordination and snooze changes excluded hidden work and woke snoozed sessions on user-facing completion.)
  • Snapshot unread recomputation keeps the original intent (359a8a3: Keep completion status, activity, and the published unread snapshot consistent; removing its event-only activity source explains removing this recomputation.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/shared/session-unread.test.ts src/gateway/session-lifecycle-state.test.ts src/gateway/session-event-payload.test.ts --maxWorkers=1
  • pnpm check:changed
  • Verify through an isolated Gateway that a reply committed after a read acknowledgment marks the inactive chat unread.
  • Verify that a visible terminal failure notice marks an inactive chat unread while suppressed failures and NO_REPLY remain quiet.

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 1ad9fe2 adds src/shared/session-unread.ts:10 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)

PR surface

Source +17, Tests -25, Docs 0. Total -8 across 14 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 44 27 +17
Tests 6 137 162 -25
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 182 190 -8

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.

Review metrics

Metric Value Why it matters
Production versus test changes Production +44/-27; tests +135/-161 The production growth connects two existing finalizers to one shared read, while transcript-backed regressions replace mocked parameter assertions.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #204164
Summary: This PR is the active repair for content-independent unread stamping.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add P2: False or missing unread indicators affect attention and navigation without preventing conversations from running.
  • add merge-risk: 🚨 session-state: The changed activity timestamps can leave newly completed replies and visible failure notices incorrectly marked read.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: False or missing unread indicators affect attention and navigation without preventing conversations from running.
  • merge-risk: 🚨 session-state: The changed activity timestamps can leave newly completed replies and visible failure notices incorrectly marked read.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.

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, 6:54 PM ET / 23:54 UTC.

@obviyus
obviyus merged commit 7986fe1 into main Nov 24, 2026
184 of 185 checks passed
@obviyus
obviyus deleted the fix/unread-at-run-end branch November 24, 2026 00:03
@obviyus

obviyus commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

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).

obviyus added a commit that referenced this pull request Nov 24, 2026
…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]>
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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 24, 2026
…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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…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]>
obviyus added a commit that referenced this pull request Nov 24, 2026
…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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 25, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 25, 2026
…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]>
obviyus added a commit that referenced this pull request Nov 29, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 30, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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.

Unread follows run visibility, not visible content (NO_REPLY and quiet wakes still mark unread)

1 participant