Isolate plan and task runtime per session
This commit is contained in:
+68
-6
@@ -245,9 +245,9 @@ class LocalCodingAgent:
|
||||
tuple(str(path) for path in self.runtime_config.additional_working_directories),
|
||||
)
|
||||
if self.plan_runtime is None:
|
||||
self.plan_runtime = PlanRuntime.from_workspace(self.runtime_config.cwd)
|
||||
self.plan_runtime = PlanRuntime()
|
||||
if self.task_runtime is None:
|
||||
self.task_runtime = TaskRuntime.from_workspace(self.runtime_config.cwd)
|
||||
self.task_runtime = TaskRuntime()
|
||||
if self.team_runtime is None:
|
||||
self.team_runtime = TeamRuntime.from_workspace(
|
||||
self.runtime_config.cwd,
|
||||
@@ -424,6 +424,7 @@ class LocalCodingAgent:
|
||||
self.plugin_runtime.restore_session_state({})
|
||||
session_id = session_id or uuid4().hex
|
||||
scratchpad_directory = self._ensure_scratchpad_directory(session_id)
|
||||
self._bind_session_plan_task_runtime(scratchpad_directory)
|
||||
result = self._run_prompt(
|
||||
prompt,
|
||||
base_session=None,
|
||||
@@ -472,6 +473,7 @@ class LocalCodingAgent:
|
||||
if stored_session.scratchpad_directory
|
||||
else self._ensure_scratchpad_directory(stored_session.session_id)
|
||||
)
|
||||
self._bind_session_plan_task_runtime(scratchpad_directory)
|
||||
result = self._run_prompt(
|
||||
prompt,
|
||||
base_session=session,
|
||||
@@ -544,6 +546,8 @@ class LocalCodingAgent:
|
||||
self.tool_context = replace(
|
||||
self.tool_context,
|
||||
scratchpad_directory=scratchpad_directory,
|
||||
plan_runtime=self.plan_runtime,
|
||||
task_runtime=self.task_runtime,
|
||||
)
|
||||
tool_specs = [tool.to_openai_tool() for tool in self.tool_registry.values()]
|
||||
starting_usage = UsageStats()
|
||||
@@ -3560,6 +3564,36 @@ class LocalCodingAgent:
|
||||
scratchpad_directory.mkdir(parents=True, exist_ok=True)
|
||||
return scratchpad_directory
|
||||
|
||||
def _bind_session_plan_task_runtime(self, scratchpad_directory: Path | None) -> None:
|
||||
if scratchpad_directory is None:
|
||||
self.plan_runtime = PlanRuntime()
|
||||
self.task_runtime = TaskRuntime()
|
||||
else:
|
||||
self.plan_runtime = PlanRuntime.from_storage_path(
|
||||
scratchpad_directory / 'plan_runtime.json'
|
||||
)
|
||||
self.task_runtime = TaskRuntime.from_storage_path(
|
||||
scratchpad_directory / 'task_runtime.json'
|
||||
)
|
||||
self.tool_context = replace(
|
||||
self.tool_context,
|
||||
plan_runtime=self.plan_runtime,
|
||||
task_runtime=self.task_runtime,
|
||||
scratchpad_directory=scratchpad_directory,
|
||||
)
|
||||
|
||||
def _session_plan_runtime_path(self) -> Path:
|
||||
scratchpad_directory = self.tool_context.scratchpad_directory
|
||||
if scratchpad_directory is None:
|
||||
return PlanRuntime().storage_path
|
||||
return scratchpad_directory / 'plan_runtime.json'
|
||||
|
||||
def _session_task_runtime_path(self) -> Path:
|
||||
scratchpad_directory = self.tool_context.scratchpad_directory
|
||||
if scratchpad_directory is None:
|
||||
return TaskRuntime().storage_path
|
||||
return scratchpad_directory / 'task_runtime.json'
|
||||
|
||||
def _append_file_history_replay_if_needed(
|
||||
self,
|
||||
session: AgentSessionState,
|
||||
@@ -4833,9 +4867,25 @@ class LocalCodingAgent:
|
||||
if tool_name == 'config_set':
|
||||
self.config_runtime = ConfigRuntime.from_workspace(self.runtime_config.cwd)
|
||||
if tool_name.startswith('task_') or tool_name == 'todo_write':
|
||||
self.task_runtime = TaskRuntime.from_workspace(self.runtime_config.cwd)
|
||||
self.task_runtime = TaskRuntime.from_storage_path(
|
||||
(
|
||||
self.task_runtime.storage_path
|
||||
if self.task_runtime is not None
|
||||
else self._session_task_runtime_path()
|
||||
)
|
||||
)
|
||||
if tool_name.startswith('plan_') or tool_name == 'update_plan':
|
||||
self.plan_runtime = PlanRuntime.from_workspace(self.runtime_config.cwd)
|
||||
self.plan_runtime = PlanRuntime.from_storage_path(
|
||||
(
|
||||
self.plan_runtime.storage_path
|
||||
if self.plan_runtime is not None
|
||||
else self._session_plan_runtime_path()
|
||||
)
|
||||
)
|
||||
if self.task_runtime is not None:
|
||||
self.task_runtime = TaskRuntime.from_storage_path(
|
||||
self.task_runtime.storage_path
|
||||
)
|
||||
if tool_name.startswith('team_') or tool_name == 'send_message':
|
||||
self.team_runtime = TeamRuntime.from_workspace(
|
||||
self.runtime_config.cwd,
|
||||
@@ -4911,8 +4961,20 @@ class LocalCodingAgent:
|
||||
self.runtime_config.cwd,
|
||||
additional_dirs,
|
||||
)
|
||||
self.task_runtime = TaskRuntime.from_workspace(self.runtime_config.cwd)
|
||||
self.plan_runtime = PlanRuntime.from_workspace(self.runtime_config.cwd)
|
||||
self.task_runtime = TaskRuntime.from_storage_path(
|
||||
(
|
||||
self.task_runtime.storage_path
|
||||
if self.task_runtime is not None
|
||||
else self._session_task_runtime_path()
|
||||
)
|
||||
)
|
||||
self.plan_runtime = PlanRuntime.from_storage_path(
|
||||
(
|
||||
self.plan_runtime.storage_path
|
||||
if self.plan_runtime is not None
|
||||
else self._session_plan_runtime_path()
|
||||
)
|
||||
)
|
||||
self.team_runtime = TeamRuntime.from_workspace(
|
||||
self.runtime_config.cwd,
|
||||
additional_dirs,
|
||||
|
||||
Reference in New Issue
Block a user