Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(swarm): redact task details in the REST API

xkam7arb7cd2c98b21a
diff --git a/agent/src/api/swarm_routes.py b/agent/src/api/swarm_routes.py
index dd8703391..6faecbd78 100644
--- a/agent/src/api/swarm_routes.py
+++ b/agent/src/api/swarm_routes.py
@@ -141,6 +141,8 @@ def register_swarm_routes(
run = runtime._store.reconcile_run(loaded, write=True)
+ from src.swarm.serialization import serialize_task
+
return {
"id": run.id,
"preset_name": run.preset_name,
@@ -148,7 +150,15 @@ def register_swarm_routes(
"is_stale": runtime._store.is_run_stale(run),
"user_vars": run.user_vars,
"agents": [a.model_dump() for a in run.agents],
- "tasks": [t.model_dump() for t in run.tasks],
+ "tasks": [
+ {
+ **serialize_task(t),
+ # Keep the existing REST field while sharing the public
+ # serializer used by the other swarm read paths.
+ "worker_iterations": getattr(t, "worker_iterations", 0),
+ }
+ for t in run.tasks
+ ],
"created_at": run.created_at,
"completed_at": run.completed_at,
"final_report": run.final_report,
diff --git a/agent/tests/test_swarm_route_contracts.py b/agent/tests/test_swarm_route_contracts.py
index 0dee9bc58..a9e2a6d00 100644
--- a/agent/tests/test_swarm_route_contracts.py
+++ b/agent/tests/test_swarm_route_contracts.py
@@ -10,7 +10,7 @@ from fastapi.testclient import TestClient
import api_server
import src.api.swarm_routes as swarm_routes
-from src.swarm.models import RunStatus, SwarmEvent, SwarmRun
+from src.swarm.models import RunStatus, SwarmEvent, SwarmRun, SwarmTask
from src.swarm.store import SwarmStore
@@ -33,6 +33,7 @@ def _create_run(
*,
run_id: str = "run-contract",
status: RunStatus = RunStatus.pending,
+ tasks: list[SwarmTask] | None = None,
) -> SwarmRun:
run = SwarmRun(
id=run_id,
@@ -42,6 +43,7 @@ def _create_run(
completed_at=(
"2026-07-16T00:00:01+00:00" if status == RunStatus.completed else None
),
+ tasks=tasks or [],
)
store.create_run(run)
return run
@@ -100,3 +102,37 @@ def test_swarm_events_keeps_last_index_query_compatibility(
assert response.status_code == 200
assert "event: query_step_1" not in response.text
assert "id: 2\nevent: query_step_2" in response.text
+
+
+def test_swarm_detail_uses_redacted_public_task_projection(
+ swarm_store: SwarmStore,
+) -> None:
+ internal_path = str(
+ Path.cwd() / "agent" / ".swarm" / "runs" / "secret" / "task.log"
+ )
+ _create_run(
+ swarm_store,
+ tasks=[
+ SwarmTask(
+ id="task-1",
+ agent_id="analyst",
+ prompt_template="internal prompt",
+ summary="Public summary",
+ artifacts=[internal_path],
+ error=f"failed while reading {internal_path}",
+ worker_iterations=3,
+ )
+ ],
+ )
+
+ response = _client().get("/swarm/runs/run-contract")
+
+ assert response.status_code == 200
+ task = response.json()["tasks"][0]
+ assert task["summary"] == "Public summary"
+ assert "<redacted>" in task["error"]
+ assert internal_path not in response.text
+ assert "artifacts" not in task
+ assert "prompt_template" not in task
+ assert task["worker_iterations"] == 3
+ assert task["iterations"] == 3