turn metadata followups (#11782)
some trivial simplifications from #11677
This commit is contained in:
parent
26a7cd21e2
commit
a5e8e69d18
5 changed files with 26 additions and 36 deletions
|
|
@ -31,7 +31,6 @@ use crate::models_manager::manager::ModelsManager;
|
|||
use crate::parse_command::parse_command;
|
||||
use crate::parse_turn_item;
|
||||
use crate::rollout::session_index;
|
||||
use crate::sandbox_tags::sandbox_tag;
|
||||
use crate::stream_events_utils::HandleOutputCtx;
|
||||
use crate::stream_events_utils::handle_non_tool_response_item;
|
||||
use crate::stream_events_utils::handle_output_item_done;
|
||||
|
|
@ -556,7 +555,7 @@ pub(crate) struct TurnContext {
|
|||
pub(crate) truncation_policy: TruncationPolicy,
|
||||
pub(crate) js_repl: Arc<JsReplHandle>,
|
||||
pub(crate) dynamic_tools: Vec<DynamicToolSpec>,
|
||||
turn_metadata_state: Arc<TurnMetadataState>,
|
||||
pub(crate) turn_metadata_state: Arc<TurnMetadataState>,
|
||||
}
|
||||
impl TurnContext {
|
||||
pub(crate) fn model_context_window(&self) -> Option<i64> {
|
||||
|
|
@ -686,18 +685,6 @@ impl TurnContext {
|
|||
denied_domains: network.denied_domains.clone().unwrap_or_default(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn current_turn_metadata_header(&self) -> Option<String> {
|
||||
self.turn_metadata_state.current_header_value()
|
||||
}
|
||||
|
||||
pub fn spawn_turn_metadata_enrichment_task(self: &Arc<Self>) {
|
||||
self.turn_metadata_state.spawn_git_enrichment_task();
|
||||
}
|
||||
|
||||
pub fn cancel_turn_metadata_enrichment_task(&self) {
|
||||
self.turn_metadata_state.cancel_git_enrichment_task();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
@ -926,13 +913,8 @@ impl Session {
|
|||
let turn_metadata_state = Arc::new(TurnMetadataState::new(
|
||||
sub_id.clone(),
|
||||
cwd.clone(),
|
||||
Some(
|
||||
sandbox_tag(
|
||||
session_configuration.sandbox_policy.get(),
|
||||
session_configuration.windows_sandbox_level,
|
||||
)
|
||||
.to_string(),
|
||||
),
|
||||
session_configuration.sandbox_policy.get(),
|
||||
session_configuration.windows_sandbox_level,
|
||||
));
|
||||
TurnContext {
|
||||
sub_id,
|
||||
|
|
@ -1758,7 +1740,7 @@ impl Session {
|
|||
turn_context.final_output_json_schema = final_schema;
|
||||
}
|
||||
let turn_context = Arc::new(turn_context);
|
||||
turn_context.spawn_turn_metadata_enrichment_task();
|
||||
turn_context.turn_metadata_state.spawn_git_enrichment_task();
|
||||
turn_context
|
||||
}
|
||||
|
||||
|
|
@ -4009,13 +3991,8 @@ async fn spawn_review_thread(
|
|||
let turn_metadata_state = Arc::new(TurnMetadataState::new(
|
||||
review_turn_id.clone(),
|
||||
parent_turn_context.cwd.clone(),
|
||||
Some(
|
||||
sandbox_tag(
|
||||
&parent_turn_context.sandbox_policy,
|
||||
parent_turn_context.windows_sandbox_level,
|
||||
)
|
||||
.to_string(),
|
||||
),
|
||||
&parent_turn_context.sandbox_policy,
|
||||
parent_turn_context.windows_sandbox_level,
|
||||
));
|
||||
|
||||
let review_turn_context = TurnContext {
|
||||
|
|
@ -4058,7 +4035,7 @@ async fn spawn_review_thread(
|
|||
text_elements: Vec::new(),
|
||||
}];
|
||||
let tc = Arc::new(review_turn_context);
|
||||
tc.spawn_turn_metadata_enrichment_task();
|
||||
tc.turn_metadata_state.spawn_git_enrichment_task();
|
||||
sess.spawn_task(tc.clone(), input, ReviewTask::new()).await;
|
||||
|
||||
// Announce entering review mode so UIs can switch modes.
|
||||
|
|
@ -4341,7 +4318,7 @@ pub(crate) async fn run_turn(
|
|||
})
|
||||
.map(|user_message| user_message.message())
|
||||
.collect::<Vec<String>>();
|
||||
let turn_metadata_header = turn_context.current_turn_metadata_header();
|
||||
let turn_metadata_header = turn_context.turn_metadata_state.current_header_value();
|
||||
match run_sampling_request(
|
||||
Arc::clone(&sess),
|
||||
Arc::clone(&turn_context),
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ async fn run_compact_task_inner(
|
|||
personality: turn_context.personality,
|
||||
..Default::default()
|
||||
};
|
||||
let turn_metadata_header = turn_context.current_turn_metadata_header();
|
||||
let turn_metadata_header = turn_context.turn_metadata_state.current_header_value();
|
||||
let attempt_result = drain_to_completed(
|
||||
&sess,
|
||||
turn_context.as_ref(),
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ async fn build_request_context(session: &Arc<Session>, config: &Config) -> Reque
|
|||
let turn_context = session.new_default_turn().await;
|
||||
RequestContext::from_turn_context(
|
||||
turn_context.as_ref(),
|
||||
turn_context.current_turn_metadata_header(),
|
||||
turn_context.turn_metadata_state.current_header_value(),
|
||||
model,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,7 +197,9 @@ impl Session {
|
|||
turn_context: Arc<TurnContext>,
|
||||
last_agent_message: Option<String>,
|
||||
) {
|
||||
turn_context.cancel_turn_metadata_enrichment_task();
|
||||
turn_context
|
||||
.turn_metadata_state
|
||||
.cancel_git_enrichment_task();
|
||||
|
||||
let mut active = self.active_turn.lock().await;
|
||||
let mut pending_input = Vec::<ResponseInputItem>::new();
|
||||
|
|
@ -262,7 +264,9 @@ impl Session {
|
|||
|
||||
trace!(task_kind = ?task.kind, sub_id, "aborting running task");
|
||||
task.cancellation_token.cancel();
|
||||
task.turn_context.cancel_turn_metadata_enrichment_task();
|
||||
task.turn_context
|
||||
.turn_metadata_state
|
||||
.cancel_git_enrichment_task();
|
||||
let session_task = task.task;
|
||||
|
||||
select! {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,9 @@ use crate::git_info::get_git_remote_urls_assume_git_repo;
|
|||
use crate::git_info::get_git_repo_root;
|
||||
use crate::git_info::get_has_changes;
|
||||
use crate::git_info::get_head_commit_hash;
|
||||
use crate::sandbox_tags::sandbox_tag;
|
||||
use codex_protocol::config_types::WindowsSandboxLevel;
|
||||
use codex_protocol::protocol::SandboxPolicy;
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct WorkspaceGitMetadata {
|
||||
|
|
@ -124,8 +127,14 @@ pub(crate) struct TurnMetadataState {
|
|||
}
|
||||
|
||||
impl TurnMetadataState {
|
||||
pub(crate) fn new(turn_id: String, cwd: PathBuf, sandbox: Option<String>) -> Self {
|
||||
pub(crate) fn new(
|
||||
turn_id: String,
|
||||
cwd: PathBuf,
|
||||
sandbox_policy: &SandboxPolicy,
|
||||
windows_sandbox_level: WindowsSandboxLevel,
|
||||
) -> Self {
|
||||
let repo_root = get_git_repo_root(&cwd).map(|root| root.to_string_lossy().into_owned());
|
||||
let sandbox = Some(sandbox_tag(sandbox_policy, windows_sandbox_level).to_string());
|
||||
let base_metadata = build_turn_metadata_bag(Some(turn_id), sandbox, None, None);
|
||||
let base_header = base_metadata
|
||||
.to_header_value()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue