Skip to content

fix(memory): recall runtime prompts - #653

Merged
delete-cloud merged 1 commit into
mainfrom
fix/semantic-runtime-prompt
Jun 29, 2026
Merged

delete-cloud merged 1 commit into
mainfrom
fix/semantic-runtime-prompt

Conversation

@delete-cloud

@delete-cloud delete-cloud commented Jun 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • use runtime USER_STEER / SUBAGENT_MESSAGE payloads as semantic recall query before falling back to tape user messages
  • keep SYSTEM_NOTICE, approval decisions, and interrupts out of semantic query selection so runtime controls do not shadow the user's prompt
  • add regression coverage for remote prompt recall, runtime-over-tape precedence, subagent prompts, non-query runtime messages, and authoritative rehydration without rendering backend hit text

Root Cause

Live o6n semantic memory dogfood showed rebuild/index/planner worked, but remote prompt turns did not recall indexed topic summaries. The remote prompt path supplies the current prompt through PipelineContext.runtime_messages; it is not necessarily persisted as a tape role=user message before build_context. SemanticMemoryPlugin only read the latest user message from tape, so it returned before semantic search.

Verification

  • uv run pytest tests/coding_agent/plugins/test_semantic_memory.py -k "runtime_prompt or subagent_prompt" -v
  • uv run pytest tests/coding_agent/plugins/test_semantic_memory.py -v
  • uv run pytest tests/agentkit/runtime/test_pipeline.py -k "runtime_context_and_messages_are_injected_into_prompt or runtime_message_consumed_after_build_context_reaches_prompt" -v
  • uv run pytest tests/ui/test_session_manager_runtime.py -k semantic -v
  • uv run pytest tests/coding_agent/test_semantic_maintenance.py -v
  • uv run pytest tests/coding_agent/test_memory_switch.py -k semantic -v
  • uv run ruff format --check src/coding_agent/plugins/semantic_memory.py tests/coding_agent/plugins/test_semantic_memory.py
  • uv run ruff check src/coding_agent/plugins/semantic_memory.py tests/coding_agent/plugins/test_semantic_memory.py
  • local subagent review round 1: found P2 test gaps, fixed
  • local subagent review round 2: no P1/P2

Summary by CodeRabbit

  • Bug Fixes
    • Improved semantic memory recall so it uses the most relevant runtime prompt context when available.
    • Added safer fallback behavior when runtime prompt context is unavailable, helping avoid stale or incorrect recall results.
    • Refined which runtime message types are considered for recall, preventing unrelated messages from affecting context selection.

Use runtime USER_STEER and SUBAGENT_MESSAGE payloads as the semantic recall query before falling back to tape user messages.

Keep system notices, approvals, and interrupts out of semantic query selection so operational runtime controls do not shadow the user's prompt.

Verification:

- uv run pytest tests/coding_agent/plugins/test_semantic_memory.py -v

- uv run pytest tests/agentkit/runtime/test_pipeline.py -k 'runtime_context_and_messages_are_injected_into_prompt or runtime_message_consumed_after_build_context_reaches_prompt' -v

- uv run pytest tests/ui/test_session_manager_runtime.py -k semantic -v

- uv run pytest tests/coding_agent/test_semantic_maintenance.py -v

- uv run pytest tests/coding_agent/test_memory_switch.py -k semantic -v

- uv run ruff format --check src/coding_agent/plugins/semantic_memory.py tests/coding_agent/plugins/test_semantic_memory.py

- uv run ruff check src/coding_agent/plugins/semantic_memory.py tests/coding_agent/plugins/test_semantic_memory.py
@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e02b98e6-f243-448c-818f-f939fed74f54

📥 Commits

Reviewing files that changed from the base of the PR and between 085c82f and 68c74d9.

📒 Files selected for processing (2)
  • coding-agent/src/coding_agent/plugins/semantic_memory.py
  • coding-agent/tests/coding_agent/plugins/test_semantic_memory.py

📝 Walkthrough

Walkthrough

SemanticMemoryPlugin.build_context now extracts the semantic-recall query from PipelineContext.runtime_messages (filtered by a new _RUNTIME_QUERY_KINDS allowlist) before falling back to the tape's latest user message. Two helper functions handle the scanning and payload text extraction. Tests cover the new precedence logic, kind filtering, and parametrized ignored-kind cases.

Changes

Runtime Prompt Recall Query Extraction

Layer / File(s) Summary
Runtime query allowlist, helpers, and build_context wiring
coding-agent/src/coding_agent/plugins/semantic_memory.py
Adds _RUNTIME_QUERY_KINDS constant, _latest_runtime_prompt_message and _runtime_payload_text helpers, updates build_context to call the runtime helper first with tape fallback, and extends imports with RuntimeMessageKind and PipelineContext.
Runtime recall precedence and kind-filtering tests
coding-agent/tests/coding_agent/plugins/test_semantic_memory.py
Adds four async test cases: USER_STEER runtime recall, runtime prompt overriding stale tape content, SYSTEM_NOTICE exclusion after USER_STEER, and a parametrized test for ignored post-SUBAGENT_MESSAGE runtime kinds.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • delete-cloud/Coding-Agent-Loop#623: Modifies SemanticMemoryPlugin's context building and recall query path in the same semantic_memory.py file, intersecting directly with the updated build_context logic.

Poem

🐇 Hop, hop through the runtime queue,
A stale old tape won't do!
I sniff the freshest message kind,
Leave SYSTEM_NOTICE far behind.
The right recall blooms anew~ ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: semantic memory now recalls runtime prompts before tape messages.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/semantic-runtime-prompt

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@delete-cloud
delete-cloud deleted the fix/semantic-runtime-prompt branch June 29, 2026 06:00
@delete-cloud
delete-cloud restored the fix/semantic-runtime-prompt branch June 29, 2026 06:13
@delete-cloud delete-cloud reopened this Jun 29, 2026
@delete-cloud
delete-cloud merged commit 685d8ba into main Jun 29, 2026
3 checks passed
@delete-cloud
delete-cloud deleted the fix/semantic-runtime-prompt branch June 29, 2026 06:54
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.

1 participant