Skip to content

fix: default task root#196

Open
darklight3it wants to merge 1 commit into
nodejs24.xfrom
fix/default-task-root
Open

fix: default task root#196
darklight3it wants to merge 1 commit into
nodejs24.xfrom
fix/default-task-root

Conversation

@darklight3it

@darklight3it darklight3it commented Jun 12, 2026

Copy link
Copy Markdown

Issue #, if available:

Description of changes:

Restore LAMBDA_TASK_ROOT fallback to process.cwd() for OCI runtime image customers.

The RIC 4.x refactoring introduced a hard requirement on the LAMBDA_TASK_ROOT environment variable, throwing a PlatformError when it's not set. This is a regression from RIC 3.x behavior where process.cwd() was used as the function root directory.

LAMBDA_TASK_ROOT is a restricted environment variable set by lambda worker environment to /var/task. Customers building custom runtime images via OCI cannot change this value, but were previously free to place their handler anywhere and rely on the working directory. The new strict check forces them to explicitly set LAMBDA_TASK_ROOT.

Changes

  • Fall back to process.cwd() when LAMBDA_TASK_ROOT is not set, restoring RIC 3.x behavior
  • Remove the now-unreachable PlatformError check for taskRoot (the fallback guarantees a value)
  • Add unit test covering the fallback behavior

Testing

  • Unit test verifying process.cwd() is used when LAMBDA_TASK_ROOT is unset
  • Existing tests continue to pass

Target (OCI, Managed Runtime, both): both

#184

Checklist

  • I have run npm install to generate the package-lock.json correctly and included it in the PR.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@darklight3it darklight3it self-assigned this Jun 12, 2026
if (!handlerString) {
throw new PlatformError("_HANDLER environment variable is not set");
}
if (!taskRoot) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should still check that it's not empty

@darklight3it darklight3it Jun 12, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes! I was super undecided for this.

You are right to be suspicious. However, I don't know if process.cwd() could ever be undefined or even string.empty, by definition a process should start somewhere on the filesystem.

And on the practical side the result would be the same as putting the handler in the wrong folder.

https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/9ab0fac53c768d6d8901dca9788c729d8eba94ec/src/function/module-loader.ts

https://nodejs.org/api/process.html#processcwd

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

process.cwd() would never be empty isn't it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

process.cwd() would never be empty isn't it?

exactly

Comment thread src/utils/runtime-setup.test.ts Outdated
Comment thread src/utils/runtime-setup.ts Outdated
@darklight3it darklight3it force-pushed the fix/default-task-root branch 3 times, most recently from d6dd716 to 731a2d8 Compare June 12, 2026 14:43
@darklight3it darklight3it force-pushed the fix/default-task-root branch from 731a2d8 to 9b9bca3 Compare June 12, 2026 14:52
@darklight3it darklight3it marked this pull request as ready for review June 12, 2026 14:52
@darklight3it darklight3it added the bug Something isn't working label Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants