Skip to content

fix(sdk): resolve undefined name variable in updateEnvVar overload - #4494

Closed
okxint wants to merge 2 commits into
triggerdotdev:mainfrom
okxint:fix/update-env-var-name-scope
Closed

fix(sdk): resolve undefined name variable in updateEnvVar overload#4494
okxint wants to merge 2 commits into
triggerdotdev:mainfrom
okxint:fix/update-env-var-name-scope

Conversation

@okxint

@okxint okxint commented Aug 3, 2026

Copy link
Copy Markdown

Closes #

✅ Checklist

  • I have followed every step in the contributing guide
  • The PR title follows the convention.
  • I ran and tested the code works

Testing

The update function in envvars.ts has three overloads:

  1. (projectRef, slug, name, params, requestOptions?)
  2. (projectRef, slug, params, requestOptions?)
  3. (projectRef, slugOrParams, nameOrRequestOptions?, params?, requestOptions?)

In the implementation body, when overload 1 is matched (four args where the third is a string), the variable name is never declared as a parameter — the implementation signature uses nameOrRequestOptions as its third positional. The code then writes:

$name = name!;  // 'name' is undefined here

This resolves to undefined, silently sending an undefined env var name to the API.

Fix: read nameOrRequestOptions (which correctly holds the name in this branch):

$name = nameOrRequestOptions as string;

To verify: call updateEnvVar(projectRef, slug, "MY_VAR", { value: "x" }) — before this fix, $name is undefined and the API call targets the wrong endpoint; after, it correctly targets /${projectRef}/${slug}/MY_VAR.


Changelog

Fixed updateEnvVar silently using undefined as the env var name when called with the (projectRef, slug, name, params) overload. The implementation was reading from the wrong variable in scope.


Screenshots

N/A

@changeset-bot

changeset-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 19c99f2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 26 packages
Name Type
@trigger.dev/sdk Patch
@trigger.dev/python Patch
@internal/dashboard-agent Patch
@internal/sdk-compat-tests Patch
@trigger.dev/build Patch
@trigger.dev/core Patch
@trigger.dev/react-hooks Patch
@trigger.dev/redis-worker Patch
@trigger.dev/rsc Patch
@trigger.dev/schema-to-json Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch
@trigger.dev/rbac Patch
@trigger.dev/sso Patch
trigger.dev Patch
@internal/cache Patch
@internal/clickhouse Patch
@internal/llm-model-catalog Patch
@internal/redis Patch
@internal/replication Patch
@internal/run-engine Patch
@internal/run-store Patch
@internal/schedule-engine Patch
@internal/testcontainers Patch
@internal/tracing Patch
@internal/tsql Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Hi @okxint, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this Aug 3, 2026

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 3 potential issues.

Open in Devin Review

$projectRef = projectRefOrName;
$slug = slugOrParams;
$name = name!;
$name = nameOrRequestOptions as string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Updating an environment variable from inside a running task still targets the wrong project

When the four-argument form is used from inside a running task, the project identifier is taken from the slug argument instead of the project argument ($projectRef = slugOrParams at packages/trigger-sdk/src/v3/envvars.ts:308), so the update is sent to a non-existent project and fails.
Impact: Users calling the update helper with an explicit project and slug from within a task get a failed/incorrect update instead of the variable being changed.

Why the fix is incomplete: only the no-task-context branch was corrected

The implementation signature is (projectRefOrName, slugOrParams, nameOrRequestOptions, params, requestOptions). The PR fixed the else branch (no task context) at packages/trigger-sdk/src/v3/envvars.ts:339-342, which now correctly maps projectRefOrName -> $projectRef, slugOrParams -> $slug, nameOrRequestOptions -> $name.

But inside a task (taskContext.ctx truthy) the very same overload takes packages/trigger-sdk/src/v3/envvars.ts:307-319, where:

  • $projectRef = slugOrParams (the slug, not the project ref)
  • $slug = slugOrParams ?? ... (the ?? is dead since slugOrParams is a string here)
  • $name falls back to taskContext.ctx.environment.slug when the name is missing, which would silently update a variable named after the environment.

Compare with retrieve (packages/trigger-sdk/src/v3/envvars.ts:208-219) and del (packages/trigger-sdk/src/v3/envvars.ts:255-266) which correctly use projectRefOrName for $projectRef.

Prompt for agents
In packages/trigger-sdk/src/v3/envvars.ts, the `update` implementation resolves its arguments differently depending on whether `taskContext.ctx` exists. The PR fixed the no-context branch so that `$name` comes from `nameOrRequestOptions`, but the in-task branch (the `if (taskContext.ctx)` / `typeof slugOrParams === 'string'` path) still assigns `$projectRef = slugOrParams`, i.e. it uses the slug as the project reference, and it defaults `$name` to the environment slug when no name is supplied. For the `(projectRef, slug, name, params)` overload the mapping should be identical in both branches: `$projectRef = projectRefOrName`, `$slug = slugOrParams`, `$name = nameOrRequestOptions`. Consider unifying the argument resolution for the two branches (see how `retrieve` and `del` in the same file do it) so the in-task path is not broken.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

"@trigger.dev/sdk": patch
---

Fix `updateEnvVar` incorrectly reading from an out-of-scope variable when called with the `(projectRef, slug, name, params)` overload. The `name` parameter was undefined in the implementation body; it now correctly reads from `nameOrRequestOptions`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Release note text describes internals instead of user-facing behavior

The release note text added for this change describes internal implementation details (.changeset/fix-update-env-var-name-scope.md:5) rather than the user-visible behavior, which the repository guidelines require.
Impact: Users reading the published release notes see internal variable names instead of a plain description of what was fixed.

Repository rule from AGENTS.md on changeset wording

AGENTS.md states: "Write the description for users, not maintainers. Both changesets and .server-changes/ notes ship verbatim in user-visible release notes. Lead with what changed for the user - one plain sentence describing behavior, not implementation, and never naming internal tools or infra." The current text mentions "out-of-scope variable", "the implementation body" and the internal parameter name nameOrRequestOptions.

Suggested change
Fix `updateEnvVar` incorrectly reading from an out-of-scope variable when called with the `(projectRef, slug, name, params)` overload. The `name` parameter was undefined in the implementation body; it now correctly reads from `nameOrRequestOptions`.
Fixed updating an environment variable with an explicit project ref, slug and name sending an empty name, so the update now applies to the variable you specified.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

$projectRef = projectRefOrName;
$slug = slugOrParams;
$name = name!;
$name = nameOrRequestOptions as string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Second overload (name, params) still unusable outside a task context

Overload 2 declares update(name, params, requestOptions?). Outside a task context that call lands in the else branch at packages/trigger-sdk/src/v3/envvars.ts:327-329, where slugOrParams is the params object, so it throws "slug is required" — arguably correct (no project/env known), but the thrown message is misleading for that call shape. Worth confirming the intended error message/behaviour while touching this function.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3d25aa9e-27ef-471c-aaa2-d392fd326b49

📥 Commits

Reviewing files that changed from the base of the PR and between 57254b5 and 19c99f2.

📒 Files selected for processing (2)
  • .changeset/fix-update-env-var-name-scope.md
  • packages/trigger-sdk/src/v3/envvars.ts

Walkthrough

The updateEnvVar implementation now derives $name from nameOrRequestOptions in the non-context overload branch. A patch changeset documents this correction for @trigger.dev/sdk.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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