{"record":{"id":"5a9a5071b988c19f","repo":"HKUDS/Vibe-Trading","slug":"invalid-swarm-agent-id-agent-id-r-artifact-path-5a9a50","errorCode":null,"errorMessage":"Invalid swarm agent id {agent_id!r}: artifact path must be one level below the run artifacts directory","messagePattern":"Invalid swarm agent id (.+?): artifact path must be one level below the run artifacts directory","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/swarm/worker.py","lineNumber":384,"sourceCode":"        or \"/\" in agent_id\n        or \"\\\\\" in agent_id\n    ):\n        raise ValueError(\n            f\"Invalid swarm agent id {agent_id!r}: expected one safe path segment\"\n        )\n\n    artifact_dir = artifact_root / agent_id\n    resolved_root = artifact_root.resolve()\n    resolved_dir = artifact_dir.resolve()\n    try:\n        relative = resolved_dir.relative_to(resolved_root)\n    except ValueError as exc:\n        raise ValueError(\n            f\"Invalid swarm agent id {agent_id!r}: artifact path escapes \"\n            \"the run artifacts directory\"\n        ) from exc\n    if len(relative.parts) != 1:\n        raise ValueError(\n            f\"Invalid swarm agent id {agent_id!r}: artifact path must be \"\n            \"one level below the run artifacts directory\"\n        )\n    return artifact_dir\n\n\ndef clear_agent_artifacts(artifact_dir: Path) -> None:\n    \"\"\"Remove *artifact_dir* and everything in it, before a retry attempt.\n\n    A retry re-invokes :func:`run_worker` against the same ``artifact_dir``.\n    Without this, a failed attempt's ``report.md`` (or any other file a tool\n    wrote) would still be sitting there when the retried attempt reads the\n    directory back via ``_resolve_summary``/``_report_written``/\n    ``_collect_artifacts``, silently substituting stale content for the new\n    attempt's real result.\n\n    Raises on failure rather than swallowing it: proceeding with a retry\n    while known-stale artifacts remain would recreate the exact bug this","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/swarm/worker.py#L366-L402","documentation":"Raised by agent_artifact_dir when the agent's artifact directory resolves correctly under the root but is nested more than one level deep. The API requires each agent to own exactly one directory directly beneath the run artifacts root, so ids like 'a/b' (even when legitimately contained) are rejected.","triggerScenarios":"Calling agent_artifact_dir with an agent_id that contains a path separator but still resolves inside the root, e.g. 'sub/agent1' or 'foo/.'; relative.parts ends up with more than one component after resolution.","commonSituations":"Agent ids composed from team/role hierarchies (e.g. 'team-a/worker-1'); ids with trailing '/.' or redundant segments that resolve to nested paths.","solutions":["Flatten the agent id to a single path component (replace '/' with '-' or '_')","Use a registry mapping hierarchical names to flat artifact directory names","Catch the ValueError and re-raise a user-facing message explaining ids must be flat"],"exampleFix":"// before\nagent_id = f'{team}/{worker}'  # 'red/team-1'\n// after\nagent_id = f'{team}__{worker}'  # 'red__team-1'","handlingStrategy":"validation","validationCode":"agent_id = agent_id.replace('/', '__').replace('\\\\', '__')\nassert '/' not in agent_id and len(Path(agent_id).parts) == 1","typeGuard":"def is_flat_id(agent_id: str) -> bool:\n    return isinstance(agent_id, str) and '/' not in agent_id and agent_id not in ('.', '..')","tryCatchPattern":"try:\n    d = agent_artifact_dir(root, agent_id)\nexcept ValueError:\n    d = agent_artifact_dir(root, slugify(agent_id))","preventionTips":["Design agent ids as flat tokens from the start","Encode hierarchy with separators like '__' not '/'"],"tags":["validation","filesystem","swarm"],"backgroundTag":"invalid-identifier-format","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}