Skip to content

fix: harden lib-agent.sh PYTHONPATH against shadow module bypass#195

Merged
fazxes merged 1 commit intomainfrom
fix/0201-lib-agent-pythonpath
Apr 8, 2026
Merged

fix: harden lib-agent.sh PYTHONPATH against shadow module bypass#195
fazxes merged 1 commit intomainfrom
fix/0201-lib-agent-pythonpath

Conversation

@fazxes
Copy link
Copy Markdown
Member

@fazxes fazxes commented Apr 8, 2026

Summary

  • Replaces all 6 PYTHONPATH="$RECURSIVE_DIR/lib:$REPO_DIR" calls in .recursive/engine/lib-agent.sh with the safer _NS_LIB env-var + sys.path.insert(0, os.environ['_NS_LIB']) pattern
  • Removes $REPO_DIR from every path assignment in lib-agent.sh — a shadow module placed in the project root could previously hijack imports
  • Matches the pattern applied to daemon.sh in PR fix: harden daemon python3 -c against module shadowing and interpolation #190
  • Call sites fixed: cleanup_old_logs, cleanup_healer_log, cleanup_orphan_branches, compact_handoffs, should_evaluate, run_evaluation

Verification

  • bash -n .recursive/engine/lib-agent.sh passes (syntax clean)
  • make check passes — 882 tests, ruff, mypy, shell syntax, ASCII checks all green
  • No PYTHONPATH assignments remain in lib-agent.sh

Safety invariants

No safety invariants modified. This change touches the import mechanism for library helpers only; circuit breaker, cost cap, selective git add, zone compliance, prompt guard, lock file, and reset-to-origin logic are all unchanged.

Test plan

  • bash -n .recursive/engine/lib-agent.sh - syntax check passes
  • make check - full CI passes (882 tests)
  • Grep confirms zero PYTHONPATH assignments remain in lib-agent.sh
  • Grep confirms 6 _NS_LIB assignments and 6 sys.path.insert calls are present

Replace PYTHONPATH="$RECURSIVE_DIR/lib:$REPO_DIR" with _NS_LIB env var
and sys.path.insert(0, os.environ['_NS_LIB']) at all 6 call sites in
lib-agent.sh (cleanup_old_logs, cleanup_healer_log, cleanup_orphan_branches,
compact_handoffs, should_evaluate, run_evaluation). Matches the pattern
applied to daemon.sh in PR #190.
@fazxes fazxes merged commit 5dd9df6 into main Apr 8, 2026
7 checks passed
fazxes added a commit that referenced this pull request Apr 8, 2026
- Mark #201 done (lib-agent.sh PYTHONPATH hardening, PR #195)
- Create #206 (AGENTS.md operator count follow-up from PR #196 review)
- Update .next-id to 207
- Write handoff #107 (first v2 brain session)
- First entries in decisions/log.md and commitments/log.md for v2 era
@fazxes fazxes deleted the fix/0201-lib-agent-pythonpath branch April 8, 2026 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant