Skip to content

fix(server): handle CancelledError during shutdown paths#848

Merged
ZaynJarvis merged 2 commits intomainfrom
fix/server-cancelled-error-handling
Mar 25, 2026
Merged

fix(server): handle CancelledError during shutdown paths#848
ZaynJarvis merged 2 commits intomainfrom
fix/server-cancelled-error-handling

Conversation

@ZaynJarvis
Copy link
Copy Markdown
Collaborator

@ZaynJarvis ZaynJarvis commented Mar 21, 2026

previous issue is Exception doesn't catch asyncio.CancelledError. so when asyncio.CancelledError happens, server crash.

import asyncio

print("MRO:", asyncio.CancelledError.__mro__)
print("issubclass(asyncio.CancelledError, Exception):", issubclass(asyncio.CancelledError, Exception))

try:
    raise asyncio.CancelledError("demo")
except Exception:
    print("caught by Exception")
except BaseException as e:
    print("not caught by Exception; caught by BaseException:", type(e).__name__, str(e))

===
MRO: (<class 'asyncio.exceptions.CancelledError'>, <class 'BaseException'>, <class 'object'>)
issubclass(asyncio.CancelledError, Exception): False
not caught by Exception; caught by BaseException: CancelledError demo

Summary

  • handle asyncio.CancelledError explicitly in shutdown-sensitive server paths
  • only downgrade dedup cancellation to a fallback when vector storage is actually closing
  • add regression tests for background commit cancellation, lifespan shutdown, and dedup/redo cancellation semantics

Testing

  • python3 -m ruff check openviking/session/memory_deduplicator.py openviking/storage/transaction/lock_manager.py openviking/server/app.py openviking/server/routers/sessions.py tests/session/test_memory_dedup_actions.py tests/transaction/test_lock_manager.py tests/test_session_task_tracking.py tests/server/test_server_health.py
  • python3 -m pytest tests/session/test_memory_dedup_actions.py tests/transaction/test_lock_manager.py tests/test_session_task_tracking.py tests/server/test_server_health.py

@github-actions
Copy link
Copy Markdown

Failed to generate code suggestions for PR

@ZaynJarvis ZaynJarvis requested a review from qin-ctx March 21, 2026 12:35
…tracking to commit_async

Remove router-level _background_commit_tracked since session.commit_async()
already manages background task creation and returns a task_id. Drop the
test that relied on the removed router-level cancellation handler.
@ZaynJarvis ZaynJarvis merged commit 659b22c into main Mar 25, 2026
5 checks passed
@ZaynJarvis ZaynJarvis deleted the fix/server-cancelled-error-handling branch March 25, 2026 12:31
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants