feat(session): 持久化 archive finalization 任务#2075
Conversation
Move session archive finalization into a SQLite-backed task queue so archive recovery survives process restarts and terminal failures can be retried explicitly.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
# Conflicts: # openviking/service/session_service.py # openviking/session/session.py
…finalize-recovery # Conflicts: # openviking/session/session.py # tests/session/test_session_commit.py # tests/session/test_session_context.py # tests/test_session_task_tracking.py # tests/test_task_tracker.py
…finalize-recovery # Conflicts: # openviking/session/session.py # tests/session/test_session_commit.py
Description
This PR makes session archive finalization durable and recoverable.
commit_async()now persists the archive payload, live tail, session metadata, and a SQLite-backed finalize task inside the session lock; a background worker then claims those tasks, finalizes archives in session order, and writes.doneonly after summary artifacts are complete.The latest update reconciles this flow with recent
mainchanges: large externalized tool outputs are hydrated before archive summary and memory extraction, archive finalization is split intoSessionArchiveFinalizer, session context now handles rapid consecutive commits by advancing the latest overview only when the earlier archive has a.donemarker, the conflict resolution adapts archive finalization to the asyncTaskTrackerAPI frommain, and the new session-skill extraction result fields are surfaced from durable archive finalization.Related Issue
N/A
Type of Change
Changes Made
ArchiveFinalizeTaskStorewithpreparing,pending,running,completed,retry, andterminal_failedstates, leases, ordered claiming, retry accounting, and manual recovery support..done, and task completion now run in the service worker.SessionArchiveFinalizerto own archive summary files,.donemarkers, failure markers, token metadata, and best-effort post-finalize side effects.POST /api/v1/sessions/{session_id}/archives/{archive_id}/retry..doneboundary advances, including rapid multi-commit cases.main's async task tracker API and session-skill extraction after resolving merge conflicts.Testing
Commit hooks passed:
ruff (legacy alias)andruff format..venv/bin/python -m py_compile openviking/session/session.py openviking/session/archive_finalizer.py tests/session/test_session_commit.pyEarlier validation before the latest
mainmerge:.venv/bin/python -m pytest tests/session/test_archive_finalize_tasks.py tests/session/test_session_commit.py tests/session/test_session_context.py tests/session/test_tool_result_externalization.py tests/server/test_api_sessions.py tests/test_session_task_tracking.py tests/test_task_tracker.py113 passed, with existing dependency/deprecation warnings.Latest
mainconflict merge unit tests were not rerun per maintainer request.I have added tests that prove my fix is effective or that my feature works
New and existing unit tests pass locally with my changes
I have tested this on the following platforms:
Checklist
Screenshots (if applicable)
N/A
Additional Notes
origin/mainin merge commitse58b7f6bandc3d039f5.origin/mainat982b4cda.terminal_failed; later commits for the same session are blocked until the archive is retried successfully..doneas best-effort side effects, so those failures no longer prevent archive completion.messages.jsonlexists but no finalize task was recorded.