[Bug]: Failed memory extraction leaves archived sessions uncompactable
Issue Origin
Observed or reproduced in a real environment
Bug Description
When a session commit successfully archives messages but Phase 2 long-term-memory extraction fails, the session becomes impossible to compact afterward.
The first compaction archives the messages, but the OpenClaw integration treats the commit as fully failed and does not restore the archived context. A subsequent compaction reports commit_no_archive, because there are no longer new messages to archive. The live session context remains unchanged indefinitely.
Steps to Reproduce
Run OpenViking with an OpenAI-compatible model backend. Connect it through the OpenClaw OpenViking context-engine plugin. Start a session with a substantial message history. Issue /compact. Cause or encounter an HTTP 500 from the model backend during Phase 2 long-term-memory extraction. Confirm that the server archives the messages but the extraction task fails. Issue /compact again after the model backend is healthy.
Expected Behavior
Either:
- The archive and extraction should be atomic, leaving the session retryable if extraction fails; or
- If the archive already exists, OpenViking/OpenClaw should restore the archived context and reduce the live context even if memory extraction failed. A subsequent compaction should retry the failed extraction or otherwise provide a recovery path.
Actual Behavior
The first commit archives the session successfully, but Phase 2 extraction fails. The integration reports compaction failure and does not reduce the live context.
The next /compact reports:
Compaction skipped: commit_no_archive The live context remains unchanged.
Observed values:
Before compaction: approximately 352k tokens After first compaction attempt: approximately 352k tokens After second compaction attempt: approximately 352k tokens Completed compactions: 1
Minimal Reproducible Example
This was reproduced through the OpenClaw integration:
/compact
# Phase 2 memory extraction receives HTTP 500
/compact
# Compaction skipped: commit_no_archive
The OpenClaw adapter calls:
commitSession(sessionId, {
wait: true,
keepRecentCount: 0,
});
The first commit archives the messages, but the extraction task fails. The second commit sees no new archiveable messages
Error Logs
OpenViking server logs:
Archived: 95 messages → history/archive_003/
OpenAI VLM async completion failed with retryable error:
Error code: 500 - {'type': 'error',
'error': {'type': 'error',
'message': 'Internal server error'}}
long_term_memory_extraction failed with retryable error
(retry 3/3)
Phase 2 step long_term failed:
Error code: 500 - Internal server error
Memory extraction failed for session ...
Task ... failed
OpenClaw plugin log:
openviking: compact commit Phase 2 failed for session=...
Error code: 500 - Internal server error
On the next compaction:
Compaction skipped: commit_no_archive
OpenViking Version
0.4.16
Python Version
3.12.x
Operating System
Linux
Model Backend
Other
Additional Context
The triggering HTTP 500 came from the configured model backend, but the recovery failure appears to be in the commit/compaction lifecycle:
The archive is created before extraction fails. The failed commit is not treated as partially recoverable. Subsequent commits cannot find new messages to archive. The archived session is therefore stranded from the perspective of live-context compaction. The OpenClaw integration version was 2026.8.13, with OpenClaw 2026.8.1-beta.3
I traced the recovery path on current main and found the failure boundary that makes this unrecoverable:
Session._run_memory_extraction()catches the Phase 2 exception, writesarchive/.failed.jsonwithstage="memory_extraction", and marks the task failed.- On a later queue replay,
resume_queued_commit()checks.failed.jsonbefore attempting Phase 2 and immediately callstracker.fail(...)again. - That means an archive containing valid
messages.jsonland a transient model failure is treated as terminal even when the queue item is still available.
The existing completed_memory_steps metadata already provides a useful resume boundary for sibling-step failures. A narrowly scoped recovery change could distinguish retryable Phase 2 failures from terminal archive/validation failures: keep the failed marker and completed-step map for observability, but allow a later replay to re-enter _run_memory_extraction() for stage="memory_extraction" (with the completed steps excluded), while retaining the current terminal behavior for corrupt/missing archives and explicit cancellation.
A regression test should fail the first extraction attempt, assert .failed.json is written and the live context is still archived, then replay the same queue message with a healthy extractor and assert .done is published and the task becomes completed. This would cover the stranded-archive case without making malformed archives retry forever.
I traced the current lifecycle on main and this needs a contract decision before a patch. Phase 1 durably writes messages.jsonl, rewrites the live root, and returns archived=true; a Phase 2 exception then writes .failed.json. However, the existing regression test_commit_failed_after_long_term_extraction_failure_does_not_block explicitly documents a binary outcome with no partial state, and _prepare_phase2_archive_messages() currently prepares only the current archive, so a later empty commit cannot retry or roll forward the failed archive. get_session_context() also treats failed archives as raw messages to merge back into context and deliberately excludes their overview. Therefore changing only the OpenClaw status === failed branch to accept archived=true can hide the extraction failure without guaranteeing any token reduction. The maintainable choices appear to be: (1) add a server-side retry/requeue contract for the existing archive/task, preserving completed-step metadata; or (2) define an explicit partial-success state where a successfully generated overview is authoritative even if long-term extraction failed, then expose that state through get_session_context(). I recommend deciding this boundary before implementation; I have not opened a competing PR.
Correction to my earlier analysis: the current context read path does not replay a failed archive raw payload. It stops at the newest failed terminal and returns only newer pending archives plus the live tail, excluding the failed archive and older history. That makes the contract decision more urgent: treating failed + archived=true as compacted success can silently omit the archived conversation when no authoritative overview exists. The server-retry option must establish an actual requeue path before QueueFS ack; the partial-success option must require a durable, readable overview before any client reports compaction success. I have added the corrected evidence to the reviews on #4437 and #4441.
Thanks for the detailed report.
This is the expected behavior under the current design. If Phase 2 memory extraction still fails after its configured retries, the archive is marked as a failed/skipped terminal archive. Failed archives are intentionally not replayed or retried, so that they do not block subsequent archive jobs.
Since Phase 1 has already archived the live messages, a subsequent commit with no new messages has nothing to archive and therefore returns no_messages / commit_no_archive. The current commit lifecycle is intentionally non-atomic across Phase 1 and Phase 2 and does not provide a retry path for Phase 2 on the same archive.
Thank you for the feedback and for documenting the behavior so clearly.
I would disagree with closing the issue.
The problem of the issue is not on the openviking server side, it is on the openclaw plugin side (maybe other plugins only).
The failed memory extraction informed openclaw plugin that compaction failed, and therefore, the session context did not compact at all. Then next time a compaction is tried in openclaw, the plugin recognizes no session archive and refuses to compact. The consequence is that one single memory extract failure would prevent the session to be compacted forever.
In other word, one failed compaction renders the current session useless.