From d0d4ed744dbe72da30f2b42b3df679460cb5fcae Mon Sep 17 00:00:00 2001 From: ilonagaja509-glitch Date: Fri, 22 May 2026 23:53:31 +0800 Subject: [PATCH] fix(agent): re-anchor before session_search for ambiguous continuations SESSION_SEARCH_GUIDANCE previously encouraged session_search whenever cross-session context might exist, but did not distinguish between: - explicit historical recall (session_search appropriate) - ambiguous continuation requests in gateway threads ('continue', 'remaining work') For ambiguous continuations, the agent should first re-anchor on the current session/thread/project state before reaching for session_search. This prevents cross-thread retrieval from being treated as the active task context. Updates SESSION_SEARCH_GUIDANCE to include re-anchoring rule while preserving cross-session recall capability. Adds test asserting the new guidance includes re-anchoring and ambiguous continuation handling. Fixes #30498 --- agent/prompt_builder.py | 7 ++++++- tests/agent/test_prompt_builder.py | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/agent/prompt_builder.py b/agent/prompt_builder.py index 9c36d205ac5b..702c0f1d1569 100644 --- a/agent/prompt_builder.py +++ b/agent/prompt_builder.py @@ -173,7 +173,12 @@ def _strip_yaml_frontmatter(content: str) -> str: SESSION_SEARCH_GUIDANCE = ( "When the user references something from a past conversation or you suspect " "relevant cross-session context exists, use session_search to recall it before " - "asking them to repeat themselves." + "asking them to repeat themselves. Treat session_search as cross-session " + "history lookup, not as the source of truth for ambiguous continuations in " + "the current active session/thread. For requests like 'continue', 'remaining " + "work', or 'what were we doing' inside a gateway thread, first re-anchor on " + "the active session/thread and inspect current project or board state; only " + "use session_search afterward for explicitly historical context." ) SKILLS_GUIDANCE = ( diff --git a/tests/agent/test_prompt_builder.py b/tests/agent/test_prompt_builder.py index 76d13f5d22c0..a50d80795d48 100644 --- a/tests/agent/test_prompt_builder.py +++ b/tests/agent/test_prompt_builder.py @@ -49,6 +49,15 @@ def test_session_search_guidance_is_simple_cross_session_recall(self): assert "relevant cross-session context exists" in SESSION_SEARCH_GUIDANCE assert "recent turns of the current session" not in SESSION_SEARCH_GUIDANCE + def test_session_search_guidance_requires_reanchoring_for_ambiguous_continuations(self): + # For ambiguous continuations ('continue', 'remaining work'), the agent + # should re-anchor on the current session/thread before session_search. + assert "re-anchor" in SESSION_SEARCH_GUIDANCE + assert "current active session" in SESSION_SEARCH_GUIDANCE + assert "ambiguous continuations" in SESSION_SEARCH_GUIDANCE + # Cross-session recall is still supported + assert "cross-session" in SESSION_SEARCH_GUIDANCE + # ========================================================================= # Context injection scanning