MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / process_pending_subtasks

Method process_pending_subtasks

crates/opencode-session/src/prompt.rs:1984–2101  ·  view source on GitHub ↗
(
        session: &mut Session,
        provider: Arc<dyn Provider>,
        model_id: &str,
        provider_id: &str,
    )

Source from the content-addressed store, hash-verified

1982 }
1983
1984 async fn process_pending_subtasks(
1985 session: &mut Session,
1986 provider: Arc<dyn Provider>,
1987 model_id: &str,
1988 provider_id: &str,
1989 ) -> anyhow::Result<bool> {
1990 let last_user_idx = session
1991 .messages
1992 .iter()
1993 .rposition(|m| matches!(m.role, MessageRole::User));
1994 let Some(last_user_idx) = last_user_idx else {
1995 return Ok(false);
1996 };
1997
1998 let pending = Self::collect_pending_subtasks(&session.messages[last_user_idx]);
1999 if pending.is_empty() {
2000 return Ok(false);
2001 }
2002
2003 let mut results: Vec<(usize, String, bool, String, String)> = Vec::new();
2004 let tool_registry = Arc::new(opencode_tool::create_default_registry().await);
2005 let mut persisted = Self::load_persisted_subsessions(session);
2006 let default_model = format!("{}:{}", provider_id, model_id);
2007 let user_text = session.messages[last_user_idx].get_text();
2008
2009 for subtask in &pending {
2010 let combined_prompt = if user_text.trim().is_empty() {
2011 subtask.prompt.clone()
2012 } else {
2013 format!("{}\n\nSubtask: {}", user_text, subtask.prompt)
2014 };
2015 let subsession_id = format!("task_subtask_{}", subtask.subtask_id);
2016 persisted
2017 .entry(subsession_id.clone())
2018 .or_insert_with(|| PersistedSubsession {
2019 agent: subtask.agent.clone(),
2020 model: Some(default_model.clone()),
2021 disabled_tools: Vec::new(),
2022 history: Vec::new(),
2023 });
2024 let state_snapshot =
2025 persisted
2026 .get(&subsession_id)
2027 .cloned()
2028 .unwrap_or(PersistedSubsession {
2029 agent: subtask.agent.clone(),
2030 model: Some(default_model.clone()),
2031 disabled_tools: Vec::new(),
2032 history: Vec::new(),
2033 });
2034
2035 match Self::execute_persisted_subsession_prompt(
2036 &state_snapshot,
2037 &combined_prompt,
2038 provider.clone(),
2039 tool_registry.clone(),
2040 &default_model,
2041 )

Callers

nothing calls this directly

Calls 9

newFunction · 0.85
is_emptyMethod · 0.80
add_textMethod · 0.80
create_default_registryFunction · 0.50
get_textMethod · 0.45
cloneMethod · 0.45
getMethod · 0.45
get_mutMethod · 0.45
add_assistant_messageMethod · 0.45

Tested by

no test coverage detected