ChatTask 0.1.5__tar.gz → 0.1.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. {chattask-0.1.5/src/ChatTask.egg-info → chattask-0.1.6}/PKG-INFO +4 -2
  2. {chattask-0.1.5 → chattask-0.1.6}/README.md +2 -1
  3. {chattask-0.1.5 → chattask-0.1.6}/pyproject.toml +1 -1
  4. {chattask-0.1.5 → chattask-0.1.6/src/ChatTask.egg-info}/PKG-INFO +4 -2
  5. {chattask-0.1.5 → chattask-0.1.6}/src/ChatTask.egg-info/requires.txt +1 -0
  6. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/__init__.py +1 -1
  7. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/codex_tasks.py +3 -6
  8. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/config.py +3 -2
  9. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/durable.py +23 -13
  10. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/executor.py +1 -2
  11. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/service.py +41 -107
  12. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/settings.py +15 -6
  13. {chattask-0.1.5 → chattask-0.1.6}/tests/test_version.py +1 -1
  14. {chattask-0.1.5 → chattask-0.1.6}/LICENSE +0 -0
  15. {chattask-0.1.5 → chattask-0.1.6}/setup.cfg +0 -0
  16. {chattask-0.1.5 → chattask-0.1.6}/src/ChatTask.egg-info/SOURCES.txt +0 -0
  17. {chattask-0.1.5 → chattask-0.1.6}/src/ChatTask.egg-info/dependency_links.txt +0 -0
  18. {chattask-0.1.5 → chattask-0.1.6}/src/ChatTask.egg-info/entry_points.txt +0 -0
  19. {chattask-0.1.5 → chattask-0.1.6}/src/ChatTask.egg-info/top_level.txt +0 -0
  20. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/agent_tasks.py +0 -0
  21. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/auth.py +0 -0
  22. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/broker.py +0 -0
  23. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/cli.py +0 -0
  24. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/durable_archive.py +0 -0
  25. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/durable_research.py +0 -0
  26. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/overleaf_native.mjs +0 -0
  27. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/package_plan.py +0 -0
  28. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/package_publication.py +0 -0
  29. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/package_service.py +0 -0
  30. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/package_template.py +0 -0
  31. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/package_validation.py +0 -0
  32. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/release.py +0 -0
  33. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/research.py +0 -0
  34. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/research_compiler.py +0 -0
  35. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/research_discovery.py +0 -0
  36. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/source.py +0 -0
  37. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/tool_client.py +0 -0
  38. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/web.py +0 -0
  39. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/web_static/app.js +0 -0
  40. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/web_static/index.html +0 -0
  41. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/web_static/style.css +0 -0
  42. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/workflow.py +0 -0
  43. {chattask-0.1.5 → chattask-0.1.6}/src/chattask/workspace_analysis.py +0 -0
  44. {chattask-0.1.5 → chattask-0.1.6}/tests/test_cli.py +0 -0
  45. {chattask-0.1.5 → chattask-0.1.6}/tests/test_docs_deployment.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ChatTask
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: ChatTask: a ChatArch Python package.
5
5
  Author-email: ChatArch <rex@chatarch.org>
6
6
  License-Expression: MIT
@@ -16,6 +16,7 @@ License-File: LICENSE
16
16
  Requires-Dist: click<9.0,>=8.0
17
17
  Requires-Dist: chatstyle<0.3.0,>=0.2.0
18
18
  Requires-Dist: chatenv<0.3.0,>=0.2.15
19
+ Requires-Dist: ChatSandbox<0.2.0,>=0.1.0
19
20
  Requires-Dist: opensandbox==1.1.0
20
21
  Requires-Dist: docker<8,>=7
21
22
  Requires-Dist: httpx<0.29,>=0.28
@@ -68,6 +69,7 @@ ChatTask 的主模型是 **任务 → Codex + Sandbox → 结果**。任务说
68
69
  从 0.1.4 起,受信 Workspace 可创建资料快照、单独确认运行,并回读真实模型生成的摘要校验报告。Task 页面「材料分析」显示任务来源与 Run 历史。这是只读材料执行器,不调用工具或读取宿主文件,也不会把报告完成标成原建议完成;配置、认证与 HTTP 合约见[材料分析接入](docs/workspace.md)。
69
70
 
70
71
  ```bash
72
+ python -m pip install -e ./packages/chatsandbox
71
73
  python -m pip install -e '.[web,dev]'
72
74
  chattask --tree
73
75
  chattask paths --json-output
@@ -75,7 +77,7 @@ chattask repository register --id demo --path /srv/managed/demo --github-repo ow
75
77
  chattask serve --env-profile site --host 127.0.0.1 --port 8000
76
78
  ```
77
79
 
78
- 必须先配置已有 OpenSandbox 控制面、站点账号和既有 PyPI ChatEnv 命名连接 `task-tools`;配置详情见[快速接入](docs/index.md)。仓库路径只可通过服务器 CLI 登记,浏览器只能选择 ID。Web、Tool、Sandbox 和 ChatGH 的真实生产验收由部署方完成;源码测试使用标明的合成依赖。
80
+ 必须先配置原 OpenSandbox Docker 连接或显式的 ChatSandbox 命名 profile、站点账号和既有 PyPI ChatEnv 命名连接 `task-tools`;见[快速接入](docs/index.md)与[公共后端](docs/sandbox-backends.md)。同仓库 `packages/chatsandbox/` 是独立发行包,先从源码安装,公开发布需先于依赖它的新版 ChatTask。仓库路径只可通过服务器 CLI 登记,浏览器只能选择 ID。Web、Tool、Sandbox 和 ChatGH 的真实生产验收由部署方完成;源码测试使用标明的合成依赖。
79
81
 
80
82
  ## 边界
81
83
 
@@ -26,6 +26,7 @@ ChatTask 的主模型是 **任务 → Codex + Sandbox → 结果**。任务说
26
26
  从 0.1.4 起,受信 Workspace 可创建资料快照、单独确认运行,并回读真实模型生成的摘要校验报告。Task 页面「材料分析」显示任务来源与 Run 历史。这是只读材料执行器,不调用工具或读取宿主文件,也不会把报告完成标成原建议完成;配置、认证与 HTTP 合约见[材料分析接入](docs/workspace.md)。
27
27
 
28
28
  ```bash
29
+ python -m pip install -e ./packages/chatsandbox
29
30
  python -m pip install -e '.[web,dev]'
30
31
  chattask --tree
31
32
  chattask paths --json-output
@@ -33,7 +34,7 @@ chattask repository register --id demo --path /srv/managed/demo --github-repo ow
33
34
  chattask serve --env-profile site --host 127.0.0.1 --port 8000
34
35
  ```
35
36
 
36
- 必须先配置已有 OpenSandbox 控制面、站点账号和既有 PyPI ChatEnv 命名连接 `task-tools`;配置详情见[快速接入](docs/index.md)。仓库路径只可通过服务器 CLI 登记,浏览器只能选择 ID。Web、Tool、Sandbox 和 ChatGH 的真实生产验收由部署方完成;源码测试使用标明的合成依赖。
37
+ 必须先配置原 OpenSandbox Docker 连接或显式的 ChatSandbox 命名 profile、站点账号和既有 PyPI ChatEnv 命名连接 `task-tools`;见[快速接入](docs/index.md)与[公共后端](docs/sandbox-backends.md)。同仓库 `packages/chatsandbox/` 是独立发行包,先从源码安装,公开发布需先于依赖它的新版 ChatTask。仓库路径只可通过服务器 CLI 登记,浏览器只能选择 ID。Web、Tool、Sandbox 和 ChatGH 的真实生产验收由部署方完成;源码测试使用标明的合成依赖。
37
38
 
38
39
  ## 边界
39
40
 
@@ -9,7 +9,7 @@ description = "ChatTask: a ChatArch Python package."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
11
11
  license = "MIT"
12
- dependencies = ["click>=8.0,<9.0", "chatstyle>=0.2.0,<0.3.0", "chatenv>=0.2.15,<0.3.0", "opensandbox==1.1.0", "docker>=7,<8", "httpx>=0.28,<0.29", "packaging>=24,<27", "tomli>=2,<3; python_version < '3.11'"]
12
+ dependencies = ["click>=8.0,<9.0", "chatstyle>=0.2.0,<0.3.0", "chatenv>=0.2.15,<0.3.0", "ChatSandbox>=0.1.0,<0.2.0", "opensandbox==1.1.0", "docker>=7,<8", "httpx>=0.28,<0.29", "packaging>=24,<27", "tomli>=2,<3; python_version < '3.11'"]
13
13
  authors = [{name = "ChatArch", email = "rex@chatarch.org"}]
14
14
  keywords = ["chattask", "chatarch", "cli"]
15
15
  classifiers = [
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ChatTask
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: ChatTask: a ChatArch Python package.
5
5
  Author-email: ChatArch <rex@chatarch.org>
6
6
  License-Expression: MIT
@@ -16,6 +16,7 @@ License-File: LICENSE
16
16
  Requires-Dist: click<9.0,>=8.0
17
17
  Requires-Dist: chatstyle<0.3.0,>=0.2.0
18
18
  Requires-Dist: chatenv<0.3.0,>=0.2.15
19
+ Requires-Dist: ChatSandbox<0.2.0,>=0.1.0
19
20
  Requires-Dist: opensandbox==1.1.0
20
21
  Requires-Dist: docker<8,>=7
21
22
  Requires-Dist: httpx<0.29,>=0.28
@@ -68,6 +69,7 @@ ChatTask 的主模型是 **任务 → Codex + Sandbox → 结果**。任务说
68
69
  从 0.1.4 起,受信 Workspace 可创建资料快照、单独确认运行,并回读真实模型生成的摘要校验报告。Task 页面「材料分析」显示任务来源与 Run 历史。这是只读材料执行器,不调用工具或读取宿主文件,也不会把报告完成标成原建议完成;配置、认证与 HTTP 合约见[材料分析接入](docs/workspace.md)。
69
70
 
70
71
  ```bash
72
+ python -m pip install -e ./packages/chatsandbox
71
73
  python -m pip install -e '.[web,dev]'
72
74
  chattask --tree
73
75
  chattask paths --json-output
@@ -75,7 +77,7 @@ chattask repository register --id demo --path /srv/managed/demo --github-repo ow
75
77
  chattask serve --env-profile site --host 127.0.0.1 --port 8000
76
78
  ```
77
79
 
78
- 必须先配置已有 OpenSandbox 控制面、站点账号和既有 PyPI ChatEnv 命名连接 `task-tools`;配置详情见[快速接入](docs/index.md)。仓库路径只可通过服务器 CLI 登记,浏览器只能选择 ID。Web、Tool、Sandbox 和 ChatGH 的真实生产验收由部署方完成;源码测试使用标明的合成依赖。
80
+ 必须先配置原 OpenSandbox Docker 连接或显式的 ChatSandbox 命名 profile、站点账号和既有 PyPI ChatEnv 命名连接 `task-tools`;见[快速接入](docs/index.md)与[公共后端](docs/sandbox-backends.md)。同仓库 `packages/chatsandbox/` 是独立发行包,先从源码安装,公开发布需先于依赖它的新版 ChatTask。仓库路径只可通过服务器 CLI 登记,浏览器只能选择 ID。Web、Tool、Sandbox 和 ChatGH 的真实生产验收由部署方完成;源码测试使用标明的合成依赖。
79
81
 
80
82
  ## 边界
81
83
 
@@ -1,6 +1,7 @@
1
1
  click<9.0,>=8.0
2
2
  chatstyle<0.3.0,>=0.2.0
3
3
  chatenv<0.3.0,>=0.2.15
4
+ ChatSandbox<0.2.0,>=0.1.0
4
5
  opensandbox==1.1.0
5
6
  docker<8,>=7
6
7
  httpx<0.29,>=0.28
@@ -1,6 +1,6 @@
1
1
  """ChatTask: explicit task execution, sessions and an optional browser adapter."""
2
2
 
3
- __version__ = "0.1.5"
3
+ __version__ = "0.1.6"
4
4
  __all__ = ["__version__", "TaskService", "TaskSettings", "create_app", "state_paths", "WorkflowService", "TaskStore"]
5
5
 
6
6
 
@@ -14,7 +14,6 @@ import tarfile
14
14
  import uuid
15
15
  from urllib.parse import urlsplit
16
16
  from opensandbox.models.execd import RunCommandOpts
17
- from .service import TaskService
18
17
 
19
18
  @dataclass(frozen=True)
20
19
  class CodexRuntime:
@@ -131,9 +130,7 @@ class CodexTaskExecutor:
131
130
  elif not sandbox_id or not isinstance(receipt,dict):
132
131
  return False
133
132
  if sandbox_id:
134
- matched=[container for container in self.task_service.docker.containers.list(all=True)
135
- if container.name=='sandbox-'+sandbox_id]
136
- if matched:return False
133
+ if not self.task_service.verify_absent(sandbox_id):return False
137
134
  if self.gateway:
138
135
  closed=await asyncio.to_thread(self.gateway.close,run['id'])
139
136
  if closed!={'closed':True}:
@@ -172,7 +169,7 @@ class CodexTaskExecutor:
172
169
  else:
173
170
  runtime=replace(runtime,base_url=lease.model_base_url,access_token=lease.model_access_token,
174
171
  tool_base_url=lease.tool_base_url,tool_access_token=lease.tool_access_token)
175
- service=TaskService(replace(self.task_service.settings,image=self.images[task['image_profile']]),docker_client=self.task_service.docker)
172
+ service=self.task_service.for_image(self.images[task['image_profile']])
176
173
  await update({'index':0,'status':'running'})
177
174
  if durable:await update({'phase':'sandbox_intent'})
178
175
  create_options={'ttl_seconds':(120 if mode=='verify' else runtime.seconds)+(hook[1] if hook else 0)+120}
@@ -341,7 +338,7 @@ class CodexTaskExecutor:
341
338
  if sandbox is not None:
342
339
  try:
343
340
  await service.dispose(sandbox,cfg)
344
- outcome['cleanup']={'requested':True,'container_absent':not any(c.name=='sandbox-'+sandbox.id for c in service.docker.containers.list(all=True))}
341
+ outcome['cleanup']={'requested':True,'container_absent':service.verify_absent(sandbox.id)}
345
342
  except Exception:outcome['cleanup']={'requested':True,'container_absent':False}
346
343
  if not outcome['cleanup']['container_absent']:outcome['ok']=False
347
344
  if lease is not None or gateway_intent:
@@ -6,8 +6,9 @@ class ChatTaskConfig(BaseEnvConfig):
6
6
  _aliases = ['chattask', 'task']
7
7
  _storage_dir = 'ChatTask'
8
8
 
9
- CHATTASK_SANDBOX_ENDPOINT = EnvField('CHATTASK_SANDBOX_ENDPOINT', desc='Trusted OpenSandbox control-plane HTTP(S) origin.')
10
- CHATTASK_SANDBOX_API_KEY = EnvField('CHATTASK_SANDBOX_API_KEY', desc='OpenSandbox control-plane API key.', is_sensitive=True)
9
+ CHATTASK_SANDBOX_PROFILE = EnvField('CHATTASK_SANDBOX_PROFILE', desc='Optional existing ChatSandbox named profile; owns its provider and connection. Mutually exclusive with legacy endpoint/key.')
10
+ CHATTASK_SANDBOX_ENDPOINT = EnvField('CHATTASK_SANDBOX_ENDPOINT', desc='Trusted legacy OpenSandbox control-plane HTTP(S) origin; empty when using a ChatSandbox profile.')
11
+ CHATTASK_SANDBOX_API_KEY = EnvField('CHATTASK_SANDBOX_API_KEY', desc='Legacy OpenSandbox control-plane key; empty when using a ChatSandbox profile.', is_sensitive=True)
11
12
  CHATTASK_TOOL_PROFILE = EnvField('CHATTASK_TOOL_PROFILE', default='task-tools', desc='Name of an existing PyPI ChatEnv connection profile; no service URL or token is stored here.')
12
13
  CHATTASK_PUBLIC_DEPS_PATH = EnvField('CHATTASK_PUBLIC_DEPS_PATH', desc='Optional trusted public Python dependency archive for offline Sandbox tests/builds.')
13
14
  CHATTASK_PUBLIC_DEPS_SHA256 = EnvField('CHATTASK_PUBLIC_DEPS_SHA256', desc='Required SHA256 digest of the trusted dependency archive.')
@@ -770,19 +770,24 @@ async def run_worker(settings, *, once=False):
770
770
  from .codex_tasks import configured_executor
771
771
  store = TaskStore(state_paths(home=settings.home)["state_dir"])
772
772
  sandbox = TaskService(settings)
773
- executor = configured_executor(settings, sandbox)
774
- if executor is None:
775
- raise ValueError("durable worker requires configured Codex gateway")
776
- publisher = None
777
- if settings.research_container and settings.research_origin:
778
- from .research import ResearchPublisher, DockerOverleafBridge
779
- from .research_compiler import IsolatedResearchCompiler
780
- publisher = ResearchPublisher(store.root / 'research',
781
- DockerOverleafBridge(settings.research_container, settings.research_origin,
782
- compiler=IsolatedResearchCompiler(sandbox.docker,
783
- store.root / 'research-compiler', settings.research_container)))
784
- tasks = DurableTaskService(store, executor, research_publisher=publisher, research_origin=settings.research_origin)
773
+ research_docker = None
785
774
  try:
775
+ executor = configured_executor(settings, sandbox)
776
+ if executor is None:
777
+ raise ValueError("durable worker requires configured Codex gateway")
778
+ publisher = None
779
+ if settings.research_container and settings.research_origin:
780
+ # Publishing to an existing Overleaf is a separate host capability;
781
+ # a remote Sandbox provider must never initialize Docker implicitly.
782
+ import docker
783
+ from .research import ResearchPublisher, DockerOverleafBridge
784
+ from .research_compiler import IsolatedResearchCompiler
785
+ research_docker = docker.from_env()
786
+ publisher = ResearchPublisher(store.root / 'research',
787
+ DockerOverleafBridge(settings.research_container, settings.research_origin,
788
+ compiler=IsolatedResearchCompiler(research_docker,
789
+ store.root / 'research-compiler', settings.research_container)))
790
+ tasks = DurableTaskService(store, executor, research_publisher=publisher, research_origin=settings.research_origin)
786
791
  with executor_lock(store):
787
792
  while True:
788
793
  result = await tasks.worker_once()
@@ -791,7 +796,12 @@ async def run_worker(settings, *, once=False):
791
796
  if result is None:
792
797
  await asyncio.sleep(2)
793
798
  finally:
794
- await sandbox.shutdown()
799
+ try:
800
+ await sandbox.shutdown()
801
+ finally:
802
+ if research_docker is not None:
803
+ research_docker.close()
804
+
795
805
 
796
806
 
797
807
  def configured_service(settings):
@@ -123,8 +123,7 @@ class SandboxExecutor:
123
123
  try:
124
124
  await self.task_service.dispose(sandbox, cfg)
125
125
  cleanup['requested'] = True
126
- cleanup['container_absent'] = not any(c.name == 'sandbox-' + sandbox_id
127
- for c in self.task_service.docker.containers.list(all=True))
126
+ cleanup['container_absent'] = self.task_service.verify_absent(sandbox_id)
128
127
  except Exception as exc:
129
128
  cleanup['error'] = type(exc).__name__
130
129
  cleanup['container_absent'] = False
@@ -4,15 +4,9 @@ import asyncio
4
4
  import json
5
5
  import time
6
6
  import uuid
7
- from dataclasses import dataclass
7
+ from dataclasses import dataclass, replace
8
8
  from datetime import timedelta
9
- from urllib.parse import urlsplit
10
- import docker
11
- import httpx
12
- from opensandbox import Sandbox
13
- from opensandbox.manager import SandboxManager
14
- from opensandbox.models.sandboxes import SandboxFilter
15
- from opensandbox.config import ConnectionConfig
9
+ from chatsandbox import create_backend_from_profile, create_docker_backend
16
10
  from opensandbox.models import WriteEntry
17
11
  from .settings import TaskSettings
18
12
 
@@ -24,114 +18,55 @@ class Session:
24
18
  expires_at: float
25
19
 
26
20
  class TaskService:
27
- def __init__(self, settings: TaskSettings, *, docker_client=None):
21
+ def __init__(self, settings: TaskSettings, *, backend=None, docker_client=None):
28
22
  self.settings = settings
29
23
  self.session: Session | None = None
30
24
  self.lock = asyncio.Lock()
31
- self.docker = docker_client if docker_client is not None else docker.from_env()
32
-
33
- def connection(self) -> ConnectionConfig:
34
- endpoint = urlsplit(self.settings.endpoint)
35
- return ConnectionConfig(
36
- domain=endpoint.netloc, api_key=self.settings.api_key,
37
- protocol=endpoint.scheme, use_server_proxy=False,
38
- transport=httpx.AsyncHTTPTransport(),
39
- request_timeout=timedelta(seconds=30), disable_metrics=True,
40
- )
41
-
42
- async def connect(self, sandbox_id: str, cfg: ConnectionConfig) -> Sandbox:
43
- return await Sandbox.connect(sandbox_id, connection_config=cfg)
25
+ if backend is not None and docker_client is not None:
26
+ raise ValueError('Choose a Sandbox backend or a legacy Docker client')
27
+ if backend is not None:
28
+ self.backend = backend
29
+ elif settings.sandbox_profile:
30
+ if docker_client is not None:
31
+ raise ValueError('A named Sandbox profile cannot use a legacy Docker client')
32
+ self.backend = create_backend_from_profile(settings.sandbox_profile, home=settings.home)
33
+ else:
34
+ self.backend = create_docker_backend(settings.endpoint, settings.api_key,
35
+ settings.image, docker_client=docker_client)
36
+
37
+ def connection(self):
38
+ return self.backend.connection()
39
+
40
+ def for_image(self, image: str):
41
+ """Keep the selected provider when a task chooses an allowed image."""
42
+ return type(self)(replace(self.settings, image=image), backend=self.backend.for_image(image))
43
+
44
+ async def connect(self, sandbox_id: str, cfg):
45
+ return await self.backend.connect(sandbox_id, cfg)
44
46
 
45
47
  def inspect_owned(self, sandbox_id: str) -> dict:
46
- matched = [c for c in self.docker.containers.list(all=True)
47
- if c.name == 'sandbox-' + sandbox_id]
48
- if len(matched) != 1:
49
- raise RuntimeError('sandbox container identity missing or ambiguous')
50
- matched[0].reload()
51
- attrs = matched[0].attrs
52
- h = attrs['HostConfig']
53
- ports = attrs['NetworkSettings']['Ports']
54
- published = [entry for group in ports.values() if group for entry in group]
55
- if not published or any(entry['HostIp'] != '127.0.0.1' for entry in published):
56
- raise RuntimeError('sandbox port unexpectedly exposed off loopback')
57
- if h['Privileged'] or h['Memory'] != 512 * 1024 * 1024 or h['NanoCpus'] != 1_000_000_000 or h['PidsLimit'] != 128 or attrs['Mounts']:
58
- raise RuntimeError('sandbox resource or mount contract mismatch')
59
- return {'container_id': attrs['Id'][:12], 'host_ports': [int(e['HostPort']) for e in published],
60
- 'image_id': attrs['Image'], 'runtime': h.get('Runtime') or 'runc',
61
- 'memory_bytes': h['Memory'], 'nano_cpus': h['NanoCpus'],
62
- 'pids_limit': h['PidsLimit'], 'privileged': h['Privileged'],
63
- 'mount_count': len(attrs['Mounts'])}
48
+ return self.backend.inspect_owned(sandbox_id)
49
+
50
+ def verify_absent(self, sandbox_id: str) -> bool:
51
+ """Provider inventory must positively establish absence; errors propagate."""
52
+ return self.backend.verify_absent(sandbox_id) is True
64
53
 
65
54
  async def find_run_sandboxes(self, run_id: str) -> list[str]:
66
- """Read controller metadata for a durable Run; any uncertain list fails closed."""
55
+ """Resolve task-owned metadata through the shared provider's inventory."""
67
56
  if not isinstance(run_id, str) or len(run_id) != 32 or any(c not in '0123456789abcdef' for c in run_id):
68
57
  raise ValueError('invalid durable Run id')
69
- cfg = self.connection()
70
- manager = None
71
- try:
72
- manager = await SandboxManager.create(connection_config=cfg)
73
- found = []
74
- inventory = {}
75
- total = None
76
- for page in range(1, 101):
77
- result = await manager.list_sandbox_infos(SandboxFilter(page=page, page_size=100))
78
- if total is None:
79
- total = result.pagination.total_items
80
- if result.pagination.page != page or result.pagination.total_items != total or total > 10000 or (result.pagination.has_next_page and not result.sandbox_infos):
81
- raise RuntimeError('sandbox inventory ambiguous')
82
- for info in result.sandbox_infos:
83
- if info.id in inventory:
84
- raise RuntimeError('duplicate sandbox inventory identity')
85
- inventory[info.id] = info.metadata or {}
86
- if info.metadata and info.metadata.get('purpose') == 'chattask' and info.metadata.get('durable_run_id') == run_id:
87
- found.append(info.id)
88
- if not result.pagination.has_next_page:
89
- if not found:
90
- # A controller that drops metadata cannot prove absence when a
91
- # Docker Sandbox remains. Keep the fence until it is resolved.
92
- for container in self.docker.containers.list(all=True):
93
- if container.name.startswith('sandbox-'):
94
- metadata = inventory.get(container.name.removeprefix('sandbox-'))
95
- if metadata is None or not metadata.get('durable_run_id'):
96
- raise RuntimeError('sandbox ownership metadata unavailable')
97
- return found
98
- raise RuntimeError('sandbox inventory too large')
99
- finally:
100
- if manager is not None:
101
- await manager.close()
102
- await cfg.transport.aclose()
58
+ return await self.backend.find_owned({'purpose': 'chattask', 'durable_run_id': run_id})
103
59
 
104
- async def create(self, *, ttl_seconds: int = 600, durable_run_id: str | None = None) -> tuple[Sandbox, ConnectionConfig, dict]:
60
+ async def create(self, *, ttl_seconds: int = 600, durable_run_id: str | None = None):
105
61
  if type(ttl_seconds) is not int or not 60 <= ttl_seconds <= 7200:
106
62
  raise ValueError('sandbox lifetime must be 60–7200 seconds')
107
63
  if durable_run_id is not None and (not isinstance(durable_run_id, str) or len(durable_run_id) != 32 or any(c not in '0123456789abcdef' for c in durable_run_id)):
108
64
  raise ValueError('invalid durable Run id')
109
- cfg = self.connection()
110
- sandbox = None
111
- try:
112
- sandbox = await Sandbox.create(
113
- self.settings.image, entrypoint=['/bin/sh', '-c', 'sleep '+str(ttl_seconds)],
114
- timeout=timedelta(seconds=ttl_seconds), ready_timeout=timedelta(seconds=35),
115
- resource={'cpu': '1', 'memory': '512Mi'},
116
- metadata={'purpose': 'chattask', **({'durable_run_id': durable_run_id} if durable_run_id else {})},
117
- connection_config=cfg,
118
- )
119
- details = self.inspect_owned(sandbox.id)
120
- return sandbox, cfg, details
121
- except BaseException:
122
- if sandbox is not None:
123
- try:
124
- await asyncio.wait_for(sandbox.destroy(), timeout=15)
125
- except Exception:
126
- pass
127
- await cfg.transport.aclose()
128
- raise
65
+ return await self.backend.create(ttl_seconds=ttl_seconds,
66
+ metadata={'purpose': 'chattask', **({'durable_run_id': durable_run_id} if durable_run_id else {})})
129
67
 
130
- async def dispose(self, sandbox: Sandbox, cfg: ConnectionConfig) -> None:
131
- try:
132
- await asyncio.wait_for(sandbox.destroy(), timeout=15)
133
- finally:
134
- await cfg.transport.aclose()
68
+ async def dispose(self, sandbox, cfg) -> None:
69
+ await self.backend.dispose(sandbox, cfg)
135
70
 
136
71
  @staticmethod
137
72
  def output(execution) -> dict:
@@ -191,7 +126,7 @@ class TaskService:
191
126
  try:
192
127
  await self.dispose(sandbox, cfg)
193
128
  cleanup['requested'] = True
194
- cleanup['container_absent'] = not any(c.name == 'sandbox-' + sandbox_id for c in self.docker.containers.list(all=True))
129
+ cleanup['container_absent'] = self.verify_absent(sandbox_id)
195
130
  except Exception as exc:
196
131
  cleanup['error'] = type(exc).__name__
197
132
  if result is None:
@@ -254,9 +189,8 @@ class TaskService:
254
189
  await asyncio.wait_for(sandbox.commands.delete_session(s.shell_id), timeout=8)
255
190
  except Exception:
256
191
  pass
257
- await asyncio.wait_for(sandbox.destroy(), timeout=15)
258
- deleted = not any(c.name == 'sandbox-' + s.sandbox_id
259
- for c in self.docker.containers.list(all=True))
192
+ await self.dispose(sandbox, cfg)
193
+ deleted = self.verify_absent(s.sandbox_id)
260
194
  finally:
261
195
  await sandbox.close()
262
196
  finally:
@@ -283,10 +217,10 @@ class TaskService:
283
217
  pass
284
218
 
285
219
  async def shutdown(self):
286
- """Explicitly retire this service's owned session and Docker client."""
220
+ """Explicitly retire this service's owned session and shared backend."""
287
221
  try:
288
222
  if self.session:
289
223
  await self.close_session(self.session.id)
290
224
  finally:
291
- self.docker.close()
225
+ await self.backend.close()
292
226
 
@@ -52,11 +52,18 @@ class TaskSettings:
52
52
  codex_hosts: str='{}'
53
53
  workspace_key: str=field(default='',repr=False)
54
54
  analysis_profile: str=''
55
+ sandbox_profile: str=''
55
56
 
56
57
  def __post_init__(self):
57
- object.__setattr__(self,'endpoint',_origin(self.endpoint))
58
+ if not isinstance(self.sandbox_profile,str) or self.sandbox_profile and not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9_-]{0,127}',self.sandbox_profile):
59
+ raise ValueError('Sandbox requires an explicit existing profile name')
60
+ if self.sandbox_profile:
61
+ if self.endpoint or self.api_key:
62
+ raise ValueError('A Sandbox profile cannot be combined with legacy endpoint/key settings')
63
+ else:
64
+ object.__setattr__(self,'endpoint',_origin(self.endpoint))
58
65
  object.__setattr__(self,'origin',_origin(self.origin))
59
- if not isinstance(self.api_key,str) or not self.api_key:
66
+ if not isinstance(self.api_key,str) or not self.sandbox_profile and not self.api_key:
60
67
  raise ValueError('OpenSandbox API key is required')
61
68
  if not isinstance(self.image,str) or not self.image or len(self.image)>256:
62
69
  raise ValueError('Invalid workload image')
@@ -149,9 +156,10 @@ def load_settings(*,profile: str | None=None,home: str | Path | None=None,overri
149
156
  unknown=set(overrides)-set(fields)
150
157
  if unknown:raise ValueError('Unknown ChatTask configuration keys: '+', '.join(sorted(unknown)))
151
158
  resolved.update(overrides)
152
- for key in ('CHATTASK_SANDBOX_ENDPOINT','CHATTASK_SANDBOX_API_KEY'):
153
- if not resolved.get(key):raise ValueError('Missing ChatTask configuration: '+key)
154
- return TaskSettings(endpoint=resolved['CHATTASK_SANDBOX_ENDPOINT'],api_key=resolved['CHATTASK_SANDBOX_API_KEY'],
159
+ if not resolved.get('CHATTASK_SANDBOX_PROFILE'):
160
+ for key in ('CHATTASK_SANDBOX_ENDPOINT','CHATTASK_SANDBOX_API_KEY'):
161
+ if not resolved.get(key):raise ValueError('Missing ChatTask configuration: '+key)
162
+ return TaskSettings(endpoint=resolved.get('CHATTASK_SANDBOX_ENDPOINT') or '',api_key=resolved.get('CHATTASK_SANDBOX_API_KEY') or '',
155
163
  origin=resolved['CHATTASK_WEB_ORIGIN'],username=resolved.get('CHATTASK_LOGIN_USERNAME') or '',
156
164
  password=resolved.get('CHATTASK_LOGIN_PASSWORD') or '',
157
165
  login_users_json=resolved.get('CHATTASK_LOGIN_USERS_JSON') or '',
@@ -172,4 +180,5 @@ def load_settings(*,profile: str | None=None,home: str | Path | None=None,overri
172
180
  gateway_ca_file=resolved.get('CHATTASK_GATEWAY_CA_FILE') or '',
173
181
  codex_hosts=resolved.get('CHATTASK_CODEX_HOSTS') or '{}',
174
182
  workspace_key=resolved.get('CHATTASK_WORKSPACE_KEY') or '',
175
- analysis_profile=resolved.get('CHATTASK_ANALYSIS_PROFILE') or '')
183
+ analysis_profile=resolved.get('CHATTASK_ANALYSIS_PROFILE') or '',
184
+ sandbox_profile=resolved.get('CHATTASK_SANDBOX_PROFILE') or '')
@@ -2,4 +2,4 @@ from chattask import __version__
2
2
 
3
3
 
4
4
  def test_version_present():
5
- assert __version__ == "0.1.5"
5
+ assert __version__ == "0.1.6"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes