Skip to content

feat(runtime): add waitUntil to finish background work after the response - #20

Merged
ivanbarlog merged 2 commits into
mainfrom
feat/wait-until
Nov 27, 2026
Merged

ivanbarlog merged 2 commits into
mainfrom
feat/wait-until

Conversation

@kiro-agent

@kiro-agent kiro-agent Bot commented Nov 27, 2026

Copy link
Copy Markdown

Summary

Adds context.waitUntil(promise) and awslambda.waitUntil(promise). The runtime waits for registered promises after the response is posted (plain, streaming and error paths) and before polling /invocation/next.

  • Drain is bounded by the invocation deadline minus BUN_LAMBDA_WAIT_UNTIL_MARGIN_MS (default 1000 ms). On timeout it logs a warning with the pending count and continues.
  • Rejected promises are logged with console.error and do not change the invocation result.
  • Promises registered during the drain are also awaited. The pending set is per invocation.
  • Handlers that never call waitUntil behave as before.
  • Docs: docs/how-to/wait-until.md, README and DOCS.md.

Limitation

Opt-in only. A floating promise that is neither awaited nor registered is still frozen by Lambda; the runtime cannot detect it (Bun's process.getActiveResourcesInfo() is a stub). Use @typescript-eslint/no-floating-promises in CI.

Testing

  • bun test: 75 pass, 10 skipped integration tests, 0 fail
  • tsc --noEmit and bun run check clean
  • New unit tests cover ordering, global API, promises added during drain, deadline cutoff, error path, rejections, streaming path, no leak between invocations and no change when unused.

Not verified

No integration test was added (existing ones deploy to AWS). The timing where Lambda returns the response at POST but ends the invocation at the next /next call should be confirmed on real Lambda.

@ivanbarlog
ivanbarlog merged commit 18978d9 into main Nov 27, 2026
3 checks passed
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.

2 participants