Skip to content

bug(infrastructure): 99 scripts use sys.path.append("${AUTOBOT_PROJECT_ROOT...}") — Python never expands shell variable syntax #4945

@mrveiss

Description

@mrveiss

Discovery

Found while reviewing the #4305 fix. 99 infrastructure Python scripts contain:

sys.path.append("${AUTOBOT_PROJECT_ROOT:-/opt/autobot/code_source}")
# or:
sys.path.insert(0, "${AUTOBOT_PROJECT_ROOT:-/opt/autobot/code_source}")

Python treats this as a literal string${...} shell expansion never occurs inside Python string literals. The sys.path entry becomes the useless string "${AUTOBOT_PROJECT_ROOT:-/opt/autobot/code_source}" which is not a directory path and resolves nothing.

Verification

import sys
sys.path.append("${AUTOBOT_PROJECT_ROOT:-/opt/autobot/code_source}")
print(sys.path[-1])  # → "${AUTOBOT_PROJECT_ROOT:-/opt/autobot/code_source}" (literal, never a real path)

Why Scripts Still Work in Production

Ansible shell wrappers (e.g. start-coordinator.sh) run:

export PYTHONPATH="${AUTOBOT_PROJECT_ROOT:-/opt/autobot/code_source}:$PYTHONPATH"

The shell does expand this, so scripts work via PYTHONPATH in production. The broken sys.path.append lines are dead no-ops — they neither help nor hurt in production, but give a false sense that the import path is being set.

Impact

Correct Fix

# Replace:
sys.path.append("${AUTOBOT_PROJECT_ROOT:-/opt/autobot/code_source}")

# With:
import os, sys
sys.path.insert(0, os.environ.get("AUTOBOT_PROJECT_ROOT", "/opt/autobot/code_source"))

Scope

grep -rn 'sys.path.*\${' autobot-infrastructure/ | grep -v ".pyc" | wc -l
# → 99

This is a bulk fix — good candidate for sed/script across 99 files.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions