release v1.3: fix crash loop (FileNotFoundError), add content chunking

ERROR FIXED:
- FileNotFoundError on deleted session files caused 2,551 restarts/24h
- Embedding token overflow for long messages (exceeded 4K token limit)

ROOT CAUSES:
1. File opened before existence check - crash when OpenClaw deletes session files
2. No content truncation for embedding - long messages failed silently

FIXES:
1. Added pre-check for file existence before open()
2. Added try/catch for FileNotFoundError
3. Added chunk_text() for long content (6000 char chunks with 200 char overlap)
4. Each chunk stored separately with metadata (chunk_index, total_chunks)

IMPACT:
- Eliminates crash loop
- No memory loss for long messages
- Graceful recovery on session rotation
This commit is contained in:
root
2026-03-10 12:11:50 -05:00
parent b71a16891d
commit af93a55a80
2 changed files with 101 additions and 1 deletions

97
CHANGELOG.md Normal file
View File

@@ -0,0 +1,97 @@
# Changelog - openclaw-true-recall-base
All notable changes to this project will be documented in this file.
## [v1.3] - 2026-03-10
### Fixed
#### Critical: Crash Loop on Deleted Session Files
**Error:** `FileNotFoundError: [Errno 2] No such file or directory: '/root/.openclaw/agents/main/sessions/daccff90-f889-44fa-ba8b-c8d7397e5241.jsonl'`
**Root Cause:**
- OpenClaw deletes session `.jsonl` files when `/new` or `/reset` is called
- The watcher opened the file before checking existence
- Between file detection and opening, the file was deleted
- This caused unhandled `FileNotFoundError` → crash → systemd restart
**Impact:** 2,551 restarts in 24 hours
**Original Code (v1.2):**
```python
# Track file handle for re-opening
f = open(session_file, 'r') # CRASH HERE if file deleted
f.seek(last_position)
try:
while running:
if not session_file.exists(): # Check happens AFTER crash
...
```
**Fix (v1.3):**
```python
# Check file exists before opening (handles deleted sessions)
if not session_file.exists():
print(f"Session file gone: {session_file.name}, looking for new session...", file=sys.stderr)
return None
# Track file handle for re-opening
try:
f = open(session_file, 'r')
f.seek(last_position)
except FileNotFoundError:
print(f"Session file removed during open: {session_file.name}", file=sys.stderr)
return None
```
#### Embedding Token Overflow
**Error:** `Ollama API error 400: {"StatusCode":400,"Status":"400 Bad Request","error":"prompt too long; exceeded max context length by 4 tokens"}`
**Root Cause:**
- The embedding model `snowflake-arctic-embed2` has a 4,096 token limit (~16K chars)
- Long messages were sent to embedding without truncation
- The watcher's `get_embedding()` call passed full `turn['content']`
**Impact:** Failed embedding generation, memory loss for long messages
**Fix:**
- Added `chunk_text()` function to split long content into 6,000 char overlapping chunks
- Each chunk gets its own Qdrant point with `chunk_index` and `total_chunks` metadata
- Overlap (200 chars) ensures search continuity
- No data loss - all content stored
### Changed
- `store_to_qdrant()` now handles multiple chunks per turn
- Each chunk stored with metadata: `chunk_index`, `total_chunks`, `full_content_length`
---
## [v1.2] - 2026-02-26
### Fixed
- Session rotation bug - added inactivity detection (30s threshold)
- Improved file scoring to properly detect new sessions on `/new` or `/reset`
---
## [v1.1] - 2026-02-25
### Added
- 1-second mtime polling for session rotation
---
## [v1.0] - 2026-02-24
### Added
- Initial release
- Real-time monitoring of OpenClaw sessions
- Automatic embedding via local Ollama (snowflake-arctic-embed2)
- Storage to Qdrant `memories_tr` collection

View File

@@ -1,11 +1,14 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
""" """
TrueRecall v1.2 - Real-time Qdrant Watcher TrueRecall v1.3 - Real-time Qdrant Watcher
Monitors OpenClaw sessions and stores to memories_tr instantly. Monitors OpenClaw sessions and stores to memories_tr instantly.
This is the CAPTURE component. For curation and injection, install v2. This is the CAPTURE component. For curation and injection, install v2.
Changelog: Changelog:
- v1.3: Fixed crash loop (2551 restarts/24h) from FileNotFoundError on deleted session files.
Added chunking for long content (6000 char chunks) to prevent embedding token overflow.
Improved error handling for session file lifecycle.
- v1.2: Fixed session rotation bug - added inactivity detection (30s threshold) - v1.2: Fixed session rotation bug - added inactivity detection (30s threshold)
and improved file scoring to properly detect new sessions on /new or /reset and improved file scoring to properly detect new sessions on /new or /reset
- v1.1: Added 1-second mtime polling for session rotation - v1.1: Added 1-second mtime polling for session rotation