Skip to content

[AGE-4027] fix(api): Stop session rename from bumping the activity timestamp - #5634

Open
bekossy wants to merge 1 commit into
mainfrom
AGE-4027-/-playground-session-list-sort-order-flips-after-reload
Open

[AGE-4027] fix(api): Stop session rename from bumping the activity timestamp#5634
bekossy wants to merge 1 commit into
mainfrom
AGE-4027-/-playground-session-list-sort-order-flips-after-reload

Conversation

@bekossy

@bekossy bekossy commented Aug 1, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #5579. In the playground's Session history list, sending a message in session A then session B correctly shows B on top (most recent first) — but reloading the page can flip the order back, even though B still has the more recent message.

Root cause: the session list has one sort function on both the live and reload paths, keyed on lastMessageAt. Live updates stamp it precisely client-side when a turn settles. On reload, the value is folded in from the server's SessionStream.updated_at column — documented as "the heartbeat timestamp." But update_header() in the API also bumped that same column on every rename, including the frontend's fire-and-forget auto-title call that fires on every session's first message. That call is unawaited, so its write can land arbitrarily late — including after a different session's entire exchange has finished — silently reordering the list on the next reconcile (mount/reload/focus/60s poll).

Changes

update_header() (api/oss/src/dbs/postgres/sessions/streams/dao.py) no longer touches updated_at. That's the real heartbeat path's job (update(), a separate method) — a rename/auto-title is not activity. Checked: on the frontend, updated_at has exactly one consumer (the session-list sort), and nothing else on the backend depends on rename bumping it.

Testing

Verified locally

  • ruff format / ruff check clean.
  • Reproduced the underlying issue manually (create two sessions, message both, rename the older one, reload — order flips) to confirm the diagnosis before writing the fix.

Added or updated tests

  • api/oss/tests/pytest/unit/sessions/test_stream_header_no_activity_bump.py: a fake-engine unit test (no live DB) asserting a rename leaves updated_at untouched. Verified it fails against the pre-fix code and passes against the fix.
  • Full api/oss/tests/pytest/unit/sessions/ suite (142 tests) passes.

QA follow-up

  • Create two chat sessions on the same agent, message the older one, message the newer one — history list shows newest on top. Rename the older session, reload — order should stay the same (newest still on top).
  • Regression: the live/in-tab ordering (already correct before this fix) should be unaffected.

Demo

Screenshot 2026-08-01 at 6 39 07 PM

Checklist

  • I have included a video or screen recording for UI changes, or marked Demo as N/A
  • Relevant tests pass locally
  • Relevant linting and formatting pass locally
  • I have signed the CLA, or I will sign it when the bot prompts me

Contributor Resources

@linear-code

linear-code Bot commented Aug 1, 2026

Copy link
Copy Markdown

AGE-4027

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug report Something isn't working tests labels Aug 1, 2026
@vercel

vercel Bot commented Aug 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Ready Ready Preview Aug 1, 2026 4:37pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3ab54160-2368-42cb-acea-5eb7b3233654

📥 Commits

Reviewing files that changed from the base of the PR and between 7c395db and 5bd23d8.

📒 Files selected for processing (2)
  • api/oss/src/dbs/postgres/sessions/streams/dao.py
  • api/oss/tests/pytest/unit/sessions/test_stream_header_no_activity_bump.py

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Updating a session stream’s name no longer changes its activity timestamp.
    • Heartbeat timing now remains accurate when stream header details are edited.
  • Tests

    • Added coverage to verify session name updates preserve the existing activity timestamp.

Walkthrough

SessionStreamsDAO.update_header now preserves the existing heartbeat timestamp when changing stream header data. A database-free asynchronous unit test verifies that the session name changes without modifying updated_at.

Changes

Stream header timestamp behavior

Layer / File(s) Summary
Preserve heartbeat timestamp
api/oss/src/dbs/postgres/sessions/streams/dao.py
update_header no longer assigns the current time to updated_at when updating header data.
Validate header updates
api/oss/tests/pytest/unit/sessions/test_stream_header_no_activity_bump.py
Adds fake asynchronous transaction components and a test that verifies the session name changes while the existing heartbeat timestamp remains unchanged.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the fix: session renames no longer update the activity timestamp.
Description check ✅ Passed The description explains the reload sorting bug, root cause, code change, tests, and validation steps.
Linked Issues check ✅ Passed The change addresses issue #5579 by preserving updated_at during renames and keeping session ordering stable after reloads.
Out of Scope Changes check ✅ Passed The changes are limited to the DAO behavior and a focused regression test for the linked issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch AGE-4027-/-playground-session-list-sort-order-flips-after-reload

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5bd23d85f8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +209 to +212
# `updated_at` is the heartbeat timestamp (see SessionStreamDBE docstring), read by the
# frontend as last-activity time for sorting -- a rename must not move it, or an
# unrelated/delayed header write (e.g. the fire-and-forget auto-title call) can reorder
# the session list ahead of a session with a genuinely more recent message.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Condense the explanatory comment

This four-line block duplicates details already documented by SessionStreamDBE and the frontend, making the DAO harder to scan and creating another explanation that can become stale. Condense it to a terse invariant about preserving the heartbeat timestamp; api/AGENTS.md explicitly requires minimal comments and prohibits multi-line narration of what the code does.

AGENTS.md reference: api/AGENTS.md:L20-L22

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug report Something isn't working size:XS This PR changes 0-9 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(bug) Playground chat session list sort order flips after a page reload

1 participant