Skip to content

fix: reuse parent system prompt for background review to preserve cache bytes - #25330

Closed
NeroNarada wants to merge 4 commits into
NousResearch:mainfrom
NeroNarada:fix-25322-bg-review-prompt-cache
Closed

fix: reuse parent system prompt for background review to preserve cache bytes#25330
NeroNarada wants to merge 4 commits into
NousResearch:mainfrom
NeroNarada:fix-25322-bg-review-prompt-cache

Conversation

@NeroNarada

Copy link
Copy Markdown

Summary

Background self-improvement review currently builds a new AIAgent with a freshly
generated system prompt, which can differ from the parent agent and break prefix
cache / preprocessing tree-dedup behavior. This change reuses the parent’s
already-built system prompt when spawning the review agent, while keeping the
review toolset restricted to memory/skills.

Changes

  • Add optional cached_system_prompt: Optional[str] = None to AIAgent.__init__.
  • Seed self._cached_system_prompt from that value during initialization.
  • In _spawn_background_review, pass:
    • session_id=self.session_id
    • pass_session_id=self.pass_session_id
    • cached_system_prompt (from parent cache, or built lazily if absent)
  • Keep enabled_toolsets=["memory", "skills"] unchanged.
  • Add regression coverage in background review tests:
    • review fork receives inherited system prompt and session settings,
    • fallback to a parent-built prompt when cache is absent.

Motivation

This preserves byte-identical prompt bytes across the parent/review boundary
without relaxing the tool-restriction safety model from #15204.

Issue

@alt-glitch alt-glitch added type/perf Performance improvement or optimization P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cron Cron scheduler and job management labels May 14, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This PR appears to be superseded by #25332, which contains all changes from this PR plus additional gateway session cleanup and tool-defs cache cap fixes. Additionally, #17276 is an existing open PR addressing the same background review prompt cache issue (#25322). Consider closing in favor of #25332.

@NeroNarada

Copy link
Copy Markdown
Author

Superseded by #25332, which carries the same intent plus gateway session cleanup/tool-defs cache cap fixes. Keeping only the broader follow-up.

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

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cron Cron scheduler and job management P2 Medium — degraded but workaround exists type/perf Performance improvement or optimization

Projects

None yet

2 participants