s09: recent_user_text should slice the tail (most recent), not the head - #518
s09: recent_user_text should slice the tail (most recent), not the head#518siri666942 wants to merge 1 commit into
Conversation
…ally Walk messages forward (chronological), join, then slice the tail — so the function name matches its behavior. Previously, the function reversed the collection and head-sliced, which dropped the latest (and most relevant) user turn whenever it was short.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d81d5a141d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for message in reversed(messages): | ||
| def recent_user_text(messages: list, max_chars: int = 4000) -> str: | ||
| parts = [] | ||
| for message in messages: |
There was a problem hiding this comment.
Keep recall scoped to recent turns
When a session has more than a few short user turns, iterating over every historical user message means the text passed as Current request can still include old topics as long as the total is under 4 KB. That makes both the model selector and the deterministic keyword fallback consider stale words from earlier tasks, so an unrelated later request can recall memories because of something the user asked many turns ago; retaining a small recent-turn window while tail-slicing would fix the truncation issue without letting old topics keep influencing recall.
Useful? React with 👍 / 👎.
Closes #517.
s09_memory/code.pyrecent_user_textwalksmessagesin reverse to collect up tomax_turns=3user texts, then re-reverses them and head-slices the join to 4000 chars. The naming promises "the most recent user context" but the implementation actually returns the oldest of the recent few, head-truncated:This PR keeps the call site and signature semantically equivalent (
max_charsreplacesmax_turnssince the slice-based form no longer needs a turn cap; default 4000 preserved) but:messagesforward (chronological order).joined[-max_chars:]).Now
recent_user_textactually returns recent content.Diff is intentionally minimal — one function, 6+/7-.
中文版本
s09_memory/code.py里的recent_user_text之前是反向走messages收集最多 3 条 user 文本,然后再翻一次顺序,最后取头部 4000 字符。这导致:修复:正向遍历 messages,全量 join 后取尾部
-max_chars:。函数名和实现现在一致。签名上把
max_turns: int = 3换成max_chars: int = 4000,默认值保留对调用方等价。Diff 只有这一个函数,6+/7-。