fix(memory): prevent autosave key collisions across runtime flows

Fixes #221 - SQLite Memory Override bug.

This PR resolves memory overwrite behavior in autosave paths by replacing fixed memory keys with unique keys, and improves short-horizon recall quality in channel runtime.

**Root Cause**
SQLite memory uses a unique constraint on `memories.key` and writes with `ON CONFLICT(key) DO UPDATE`.
Several autosave paths reused fixed keys (or sender-stable keys), so newer messages overwrote earlier conversation entries.

**Changes**
- Channel runtime: autosave key changed from `channel_sender` to `channel_sender_messageId`
- Added memory-context injection before provider calls (aligned with agent loop behavior)
- Agent loop: autosave keys changed from fixed `user_msg`/`assistant_resp` to UUID-suffixed keys
- Gateway: Webhook/WhatsApp autosave keys changed to UUID-suffixed keys

All CI checks passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Chummy 2026-02-16 11:55:52 +08:00 committed by GitHub
parent 7b9ba5be6c
commit b442a07530
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 381 additions and 61 deletions

View file

@ -163,7 +163,9 @@ impl Tool for ImageInfoTool {
return Ok(ToolResult {
success: false,
output: String::new(),
error: Some(format!("Path not allowed: {path_str} (must be within workspace)")),
error: Some(format!(
"Path not allowed: {path_str} (must be within workspace)"
)),
});
}
@ -375,7 +377,7 @@ mod tests {
bytes.extend_from_slice(&[
0xFF, 0xC0, // SOF0 marker
0x00, 0x11, // SOF0 length
0x08, // precision
0x08, // precision
0x01, 0xE0, // height: 480
0x02, 0x80, // width: 640
]);