Allow thread instruction providers to share updates with subagents (#46577)

## Why

Subagents inherit applied instruction snapshots, so later provider updates do not reach running descendants. Hosts need an explicit way to share current thread instructions across an agent tree.

## What changed

- Add `ThreadInstructionsProvider::share_with_subagents()`, defaulting to `false`. Opted-in descendants refresh instructions at their next model-request boundary.
- Retain shared providers across root unloads and descendant reloads. Let a resumed root replace the provider for surviving descendants, or preserve their last shared instructions when it supplies a non-sharing provider.
- Keep providers scoped to their root tree and preserve snapshot-only instructions for root forks and isolated sessions, including Guardian reviews.

## Testing

Add coverage for child and grandchild instruction updates and clearing, provider replacement after root restart, lazy descendant reloads, default snapshot inheritance, and isolation between roots and Guardian sessions.

GitOrigin-RevId: 44c9fb7fe9ae1f96156bdf3c47ab6c4a81bd65e9
This commit is contained in:
vinh-gpt
2026-09-19 02:15:20 +00:00
committed by copyberry
parent fd59b42a09
commit e24ac448b3
14 changed files with 864 additions and 45 deletions
+7 -1
View File
@@ -6,6 +6,7 @@ use crate::agent::types::AgentMetadata;
use crate::agent::types::LiveAgent;
use crate::agent::types::SpawnAgentForkMode;
use crate::agent::types::SpawnAgentOptions;
use crate::agents_md_manager::SessionInstructions;
use crate::codex_thread::CodexThread;
use crate::config::PermissionProfileSnapshot;
use crate::context::ContextualUserFragment;
@@ -576,7 +577,12 @@ impl LocalAgentControl {
{
Some(parent.session.inherited_instructions().await)
} else {
None
self.shared_thread_instructions_provider
.get()
.map(|provider| SessionInstructions {
thread_provider: Some(Arc::clone(provider)),
..Default::default()
})
};
// Reserving a slot can evict an idle nested parent. Capture its instructions
// alongside its authority so the child does not depend on a later live lookup.