Skip to content

fix(task_runner): forward ~/.ductor/.env secrets to one-shot subprocess#139

Open
ryuhaneul wants to merge 1 commit into
PleasePrompto:mainfrom
ryuhaneul:fix/task-runner-env-secrets
Open

fix(task_runner): forward ~/.ductor/.env secrets to one-shot subprocess#139
ryuhaneul wants to merge 1 commit into
PleasePrompto:mainfrom
ryuhaneul:fix/task-runner-env-secrets

Conversation

@ryuhaneul
Copy link
Copy Markdown
Contributor

Background

When I edit ~/.ductor/.env while ductor is running (e.g. adding a new API key for a new skill, or rotating a secret), interactive chat picks up the change on the very next message — cli/executor.py:_build_env re-reads the file each turn via env_secrets.load_env_secrets (mtime-cached, no override of existing process env).

Cron, webhook, and background one-shots don't see the edit until I fully restart the bot, because they only receive DUCTOR_HOME injected into OneShotCommand.env_overrides (added by rr#19 / #121). Any newly added key in .env is invisible to them until restart.

It would be more convenient if those one-shots also re-read .env so a freshly added key is usable on the next cron tick / background task without bouncing the bot.

Proposed change

In infra/task_runner.run_oneshot_task, when ductor_home is provided, also merge load_env_secrets(ductor_home / ".env") into one_shot.env_overrides, skipping keys already set in os.environ or already present in env_overrides (so the existing DUCTOR_HOME injection stays authoritative). Same low-priority merge policy as cli/executor.py:_build_env — keys already in the process environment are never overridden.

When ductor_home is None, behavior is unchanged.

Test plan

  • pytest tests/infra/test_task_runner.py tests/infra/test_env_secrets.py tests/cron tests/background tests/webhook — 317 passed
  • ruff check clean
  • ruff format --check clean
  • mypy clean

Added tests/infra/test_task_runner.py with 3 regression gates for the new merge policy:

  • .env keys absent from os.environ are forwarded into env_overrides
  • pre-existing process env wins over .env
  • DUCTOR_HOME set above the merge is never overridden by a stray DUCTOR_HOME= line in .env

Interactive CLI calls already merge ~/.ductor/.env via
cli/executor.py:_build_env (mtime-cached, hot-reload).  Cron, webhook,
and background one-shots only received DUCTOR_HOME.  Extend
run_oneshot_task to merge load_env_secrets results into
one_shot.env_overrides when ductor_home is known, skipping keys
already in os.environ or explicitly set above (DUCTOR_HOME).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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