Skip to content

fix(session): make GET /sessions/{id} reflect on-disk archives when counter is stale (#1550)#2665

Open
yeyitech wants to merge 1 commit into
volcengine:mainfrom
yeyitech:fix/1550-session-counters
Open

fix(session): make GET /sessions/{id} reflect on-disk archives when counter is stale (#1550)#2665
yeyitech wants to merge 1 commit into
volcengine:mainfrom
yeyitech:fix/1550-session-counters

Conversation

@yeyitech

Copy link
Copy Markdown
Contributor

Summary

Closes #1550. Sessions written through async / out-of-band paths (e.g. the Hermes OpenViking provider) materialize archive directories on disk but leave the in-record message_count / commit_count at zero. GET /api/v1/sessions/{id} then read those zeros verbatim, contradicting the on-disk evidence.

The read path now also computes archive_count from the on-disk archive directories. When the persisted counters are zero but archives exist, the derived value is surfaced so the API and CLI no longer report "nothing happened" for sessions that clearly did.

The persisted counters are still authoritative for the regular synchronous write path; this fallback only fires when persisted state is stale relative to disk — so the fix self-heals already-wedged sessions in the wild.

Test plan

  • pytest tests/server/test_session_counters.py -x -q passes.
  • Manual: reproduce the issue's setup (write archive dirs by hand under a fresh session UUID), call GET /api/v1/sessions/{id} → response reports archive_count > 0.
  • Existing tests/server/test_api_sessions.py still passes (no regression on the synchronous path).

Closes #1550

…ounter is stale (volcengine#1550)

Sessions written through the async Hermes provider produced archive
directories on disk but left the persisted counter record at zero.
GET /api/v1/sessions/{id} read the record verbatim and reported
message_count=0 / commit_count=0, contradicting the on-disk evidence.

The read path now derives archive_count from the actual on-disk archive
directories. When the persisted message_count or commit_count is zero
but archives exist, the derived value is surfaced so callers and the
CLI no longer see "nothing happened" for sessions that clearly did.

The persisted counters are still authoritative for the synchronous
write path; this only kicks in when they're stale relative to disk.

Closes volcengine#1550

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

1550 - Partially compliant

Compliant requirements:

  • GET /sessions/{id} now uses on-disk archive count as fallback when persisted counters are zero
  • Persisted counters remain authoritative for synchronous path
  • Added new archive_count field to response

Non-compliant requirements:

  • No fix for the root cause of why counters are not updated in the first place

Requires further human verification:

  • Manual reproduction of the original issue setup
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🏅 Score: 85
🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ Recommended focus areas for review

Possible Incorrect Archive Count

Archive counting does not verify items are directories. A file named "archive_001.txt" would be incorrectly counted as an archive directory.

return sum(
    1
    for item in items
    if isinstance(item, dict) and str(item.get("name", "")).startswith("archive_")
)
Broad Exception Catch

Broad exception catch without logging may hide real filesystem errors. Consider logging the exception at debug level.

except Exception:
    return 0

@github-actions

Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

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

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Session API reports zero message/commit counts even though archive and fallback files are written

1 participant