Skip to content

fix(gateway): store whole-millisecond session activity times so fractional Talk timestamps persist - #207876

Merged
obviyus merged 2 commits into
openclaw:mainfrom
Marvinthebored:fix/session-activity-integer-ms
Nov 29, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
Marvinthebored:fix/session-activity-integer-ms

Conversation

@Marvinthebored

@Marvinthebored Marvinthebored commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

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

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.

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:

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

@clawsweeper

clawsweeper Bot commented Nov 29, 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.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Nov 29, 2026
Marvinthebored added a commit to Marvinthebored/openclaw that referenced this pull request Nov 29, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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 29, 2026
@clawsweeper

clawsweeper Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

This PR truncates visible-reply activity timestamps to whole milliseconds before persisting session metadata.

Example: A Talk reply has timestamp 1795914508633.935.

  • Before: Terminal persistence attempts to store fractional milliseconds in an INTEGER column and fails.
  • After: Session activity stores 1795914508633 while the transcript timestamp retains its original precision.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused shared-owner repair supported by linked live saved-history evidence and targeted persistence regression coverage.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The newer companion-PR evidence identifies an iPhone production Gateway containing this fix, shows the answer arriving after End Talk, and supplies its saved-history excerpt. The added integration cases separately report successful fractional-timestamp settlement and integer SQLite storage on the fix; their scripted model does not reproduce missing history on base. Together these address the previous review's persistence-proof gap.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A Talk reply can appear live while terminal session persistence fails on its fractional timestamp, with missing saved history reported on iPhone.
Reason: Restores the existing integer activity-time contract without adding configuration, changing cancellation policy, or expanding the companion Talk work.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current-main persistence defect with a minimal change at the shared owner. No introduced defects were found; CI remains pending.

Reviewed head: 1dafe2f899b29c0a436762daf00b722e02256765

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gateway derives session activity from the latest visible assistant message; Gateway lifecycle and agent-command completion writers consume that value to update durable session metadata.

flowchart TD
  A[Assistant transcript] --> B[Visible reply projection]
  B --> C[Whole millisecond activity]
  C --> D[Run completion writers]
  D --> E[SQLite session metadata]
Loading

Technical review

Best possible solution:

Keep timestamp normalization in the existing shared activity reader so both completion writers receive values compatible with session storage.

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

Source traces fractional transcript timestamps through both completion writers to strict INTEGER storage, matching the supplied SQLite failure log and reported red-on-main integration results; no reproduction was executed during this read-only review.

Is this the best way to solve the issue?

This is the smallest complete repair: normalize the shared activity value while preserving transcript precision, visibility rules, and existing storage contracts.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Visible-reply activity timestamps keeps the original intent (7986fe1: Advance unread activity only when a run adds a new visible assistant reply, using one shared transcript-derived value for both completion writers.)
  • Talk closure-order regression cases keeps the original intent (6485b19: The historical test consolidation retained distinct closure orderings; this PR preserves both and adds fractional-timestamp persistence observations.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 3d385d4 adds src/gateway/session-row-transcript-backfill.ts:49 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3d385d4f7423; files: src/gateway/session-row-transcript-backfill.ts)

PR surface

Source +2, Tests +32. Total +34 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 3 1 +2
Tests 2 35 3 +32
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 38 4 +34

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 proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-29T01:51:26.652Z sha 7b023b2 :: needs real behavior proof before merge. :: none

Reviewed November 29, 2026, 6:04 AM ET / 11:04 UTC (Revision 2).

@Marvinthebored

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Nov 29, 2026
@obviyus
obviyus merged commit 7c0080f into openclaw:main Nov 29, 2026
128 of 130 checks passed
@obviyus

obviyus commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Landed in 7c0080f. The session's activity time now drops sub-millisecond precision from transcript timestamps, so fractional Talk reply timestamps no longer fail the integer last_activity_at write. The Gateway Talk settlement tests fail on the old code with the same SQLite error and pass with the fix. Thanks @Marvinthebored for the precise report and fix.

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

gateway Gateway runtime impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants