Skip to content

Commit 3d43ef8

Browse files
committed
telegram: save user message before agent loop for session recall
session_search inside the agent loop could never find the current turn's data. The user message was appended to an in-memory slice but only persisted to disk AFTER RunWithMessages completed. This meant the vector index never had the current conversation's content, and deepSearch read a stale session file from disk. Now the user message is saved to the Store immediately after being appended, using a Store.Save call that bypasses the TurnCount increment (which happens once at the normal end-of-turn save).
1 parent 43ba6de commit 3d43ef8

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

cmd/odek/telegram.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,24 @@ func handleChatMessage(
998998
cs.Messages = append(cs.Messages, llm.Message{Role: "user", Content: text})
999999
cs.LastActive = time.Now()
10001000

1001+
// Persist the user message immediately so session_search can find it
1002+
// inside the agent loop. Without this, the current turn is only in
1003+
// memory and invisible to both vector search and deepSearch.
1004+
// Build a session.Snapshot directly to avoid incrementing TurnCount
1005+
// (that happens once at the end in the normal Save path).
1006+
sess := &session.Session{
1007+
ID: cs.SessionID,
1008+
CreatedAt: cs.CreatedAt,
1009+
UpdatedAt: time.Now(),
1010+
Model: "",
1011+
Turns: cs.TurnCount,
1012+
Task: fmt.Sprintf("tg-%d", chatID),
1013+
Messages: cs.Messages,
1014+
}
1015+
if err := sessionManager.Store.Save(sess); err != nil {
1016+
log.Error("save session before agent run", "chat_id", chatID, "error", err)
1017+
}
1018+
10011019
// Build the agent with Telegram approver.
10021020
tools := builtinTools(resolved.Dangerous, nil, approver, resolved.MaxConcurrency, resolved.APIKey, resolved.Transcription, sessionManager.Store)
10031021

0 commit comments

Comments
 (0)