feat(cli): inject codebase env vars for bash nodes#1069
feat(cli): inject codebase env vars for bash nodes#1069cburyta wants to merge 3 commits intocoleam00:devfrom
Conversation
Bash nodes in CLI workflows were not receiving codebase env vars from the database. After codebase resolution, load env vars and merge into process.env so all child processes (bash and AI nodes) inherit them.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughLoads codebase-scoped environment variables from the DB before executing the workflow, injects them into Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as CLI Command
participant DB as EnvVar DB
participant OS as process.env / Spawned Processes
participant Workflow as executeWorkflow()
CLI->>DB: getCodebaseEnvVars(codebase.id)
alt vars returned
DB-->>CLI: {KEY: value, ...}
CLI->>CLI: snapshot existing process.env keys
CLI->>OS: merge loaded vars into process.env
CLI->>CLI: log cli.codebase_env_vars_injected(codebaseId, count)
else load fails
DB-->>CLI: error
CLI->>CLI: log cli.codebase_env_vars_load_failed(...)
end
CLI->>Workflow: executeWorkflow()
Workflow->>OS: spawn child processes (inherit env)
Workflow-->>CLI: completes
CLI->>CLI: restore original process.env values (delete newly undefined)
CLI->>CLI: unsubscribe from workflow events
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/cli/src/commands/workflow.ts`:
- Around line 595-613: The code injects codebase env vars into process.env via
Object.assign(process.env, codebaseEnvVars) (using envVarDb.getCodebaseEnvVars
and getLog()) but never restores the previous process.env, causing injected keys
to leak across reuses of workflowRunCommand (resume/approve/reject flows); fix
by snapshotting the set of keys added (or the prior values) before assignment,
perform the injection as now, and ensure in a finally block after execution you
remove the added keys or restore prior values so process.env is returned to its
original state for subsequent runs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 039b9ab9-81c8-4b9f-aa0b-a82deebc82f8
📒 Files selected for processing (1)
packages/cli/src/commands/workflow.ts
Snapshot injected env var keys before mutation and restore previous values in a finally block after workflow execution completes. Prevents env var bleed if workflowRunCommand is ever called multiple times in the same process (e.g. future long-lived process reuse).
|
Closing — this feature (bash node managed env injection) is now tracked as part of #1161, which covers all execution surfaces consistently. The approach here (mutating |
Summary
process.env.source setup-env.sh && terraform validatecan't resolve credentials, making bash nodes useless against cloned codebases that rely on DB-stored env vars.process.envbeforeexecuteWorkflow(). All child processes (bash and AI) inherit them.UX Journey
Before
After
Architecture Diagram
Before
After
Connection inventory:
Label Snapshot
risk: lowsize: XSclicli:workflowChange Metadata
featurecliLinked Issue
Validation Evidence (required)
bun run validate # PASS - type-check, lint, format, tests all green (exit code 0)source setup-env.sh && terraform validate) against an Archon-cloned codebase (no.envfile on disk). Before the fix: env vars empty. After: all 8 codebase env vars injected, tools authenticated successfully.bun run test— all packages pass, 0 failures.Security Impact (required)
No— env vars are already stored in the DB and used by AI nodes. This extends the same access to bash nodes.NoYes— codebase env vars (which may contain API tokens) are now merged into process.env for the CLI process lifetime. This is the same trust boundary as the existing Claude SDK injection.NoCompatibility / Migration
Yes— if no codebase is resolved or no env vars are set, behavior is unchanged.NoNoHuman Verification (required)
.envon disk — still works (env vars from both sources merge)Side Effects / Blast Radius (required)
workflowRunCommandinpackages/cli/src/commands/workflow.ts)infolevel with count of injected vars. Failed loads logged atwarnlevel.Rollback Plan (required)
Risks and Mitigations
archon workflow runinvocation. No persistence across runs.Summary by CodeRabbit