feat(cloud): pass env vars to scheduled workflows#935
Conversation
📝 WalkthroughWalkthroughThis PR extends workflow scheduling to support environment secrets. A new ChangesEnvironment secrets support for scheduled workflows
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.
🧹 Nitpick comments (1)
packages/cloud/src/workflows.ts (1)
688-690: ⚡ Quick winValidate
envSecretsin the SDK entrypoint for non-CLI callers.
Line 688forwardsenvSecretsas-is. SincescheduleWorkflowis public, callers can bypass CLI parsing and send invalid keys, which shifts failures to the API layer. Adding the same key validation here gives deterministic client-side errors and keeps CLI/SDK behavior aligned.Suggested patch
+const ENV_SECRET_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/; + +function validateEnvSecrets(envSecrets?: Record<string, string>): void { + if (!envSecrets) return; + for (const [key, value] of Object.entries(envSecrets)) { + if (!ENV_SECRET_KEY_RE.test(key)) { + throw new Error(`Invalid environment variable name: ${key || '(empty)'}`); + } + if (typeof value !== 'string') { + throw new Error(`Invalid environment variable value for ${key}.`); + } + } +} + export async function scheduleWorkflow( workflowArg: string, options: ScheduleWorkflowOptions = {} ): Promise<WorkflowSchedule> { + validateEnvSecrets(options.envSecrets); const hasCron = typeof options.cron === 'string' && options.cron.trim().length > 0;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/cloud/src/workflows.ts` around lines 688 - 690, scheduleWorkflow currently forwards options.envSecrets directly; add client-side validation of envSecrets keys (same rules the CLI uses) before including them in the payload so invalid keys are rejected early. Inside scheduleWorkflow (or a small helper like validateEnvSecretsKey/validateEnvSecrets), check options.envSecrets exists and iterate its keys, enforcing the allowed pattern/whitelist used by the CLI (reject empty keys, disallowed characters, or reserved names) and throw a clear synchronous error if any key is invalid; only include envSecrets in the forwarded object when validation passes. This keeps SDK and CLI behavior aligned and prevents malformed keys from being sent to the API.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/cloud/src/workflows.ts`:
- Around line 688-690: scheduleWorkflow currently forwards options.envSecrets
directly; add client-side validation of envSecrets keys (same rules the CLI
uses) before including them in the payload so invalid keys are rejected early.
Inside scheduleWorkflow (or a small helper like
validateEnvSecretsKey/validateEnvSecrets), check options.envSecrets exists and
iterate its keys, enforcing the allowed pattern/whitelist used by the CLI
(reject empty keys, disallowed characters, or reserved names) and throw a clear
synchronous error if any key is invalid; only include envSecrets in the
forwarded object when validation passes. This keeps SDK and CLI behavior aligned
and prevents malformed keys from being sent to the API.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 172a413a-6f7e-4305-a65e-8b6a171a2c87
📒 Files selected for processing (5)
packages/cloud/src/types.tspackages/cloud/src/workflows.test.tspackages/cloud/src/workflows.tssrc/cli/commands/cloud.test.tssrc/cli/commands/cloud.ts
Summary
--env KEY=VALUEsupport toagent-relay cloud scheduleworkflowRequest.envSecretsfor the Cloud schedule APITest plan
npx vitest run src/cli/commands/cloud.test.ts packages/cloud/src/workflows.test.tsNotes
.trajectories/index.json,package-lock.json.