Skip to content

s09: recent_user_text should slice the tail (most recent), not the head - #518

Open
siri666942 wants to merge 1 commit into
shareAI-lab:mainfrom
siri666942:fix/s09-memory-cleanup
Open

s09: recent_user_text should slice the tail (most recent), not the head#518
siri666942 wants to merge 1 commit into
shareAI-lab:mainfrom
siri666942:fix/s09-memory-cleanup

Conversation

@siri666942

Copy link
Copy Markdown

Closes #517.

s09_memory/code.py recent_user_text walks messages in reverse to collect up to max_turns=3 user 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:

  • If the latest user turn is short (e.g. "ok"), the head-4000 fills with older turns and the latest one — the most relevant signal — is dropped.
  • If the latest turn is long enough, older turns get squeezed out and the function silently degrades to "use only the latest turn", which is not what the code looks like it does.

This PR keeps the call site and signature semantically equivalent (max_chars replaces max_turns since the slice-based form no longer needs a turn cap; default 4000 preserved) but:

  1. Walks messages forward (chronological order).
  2. Joins everything into one string.
  3. Returns the tail slice (joined[-max_chars:]).

Now recent_user_text actually returns recent content.

Diff is intentionally minimal — one function, 6+/7-.

中文版本

s09_memory/code.py 里的 recent_user_text 之前是反向走 messages 收集最多 3 条 user 文本,然后再翻一次顺序,最后取头部 4000 字符。这导致:

  • 最新那条 user 消息很短时(比如 "ok"),头部 4000 字符会被更旧的消息灌满,最新那条反而被切掉
  • 最新那条够长时,老消息被挤出窗口,函数悄悄退化成"只用最新一条"——但代码看不出来

修复:正向遍历 messages,全量 join 后取尾部 -max_chars:。函数名和实现现在一致。

签名上把 max_turns: int = 3 换成 max_chars: int = 4000,默认值保留对调用方等价。Diff 只有这一个函数,6+/7-。

…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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread s09_memory/code.py
for message in reversed(messages):
def recent_user_text(messages: list, max_chars: int = 4000) -> str:
parts = []
for message in messages:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

s09: select_relevant_memories 的 "recent" 拼接顺序与切片不合理,不是真正的最近 2k 上下文

1 participant