Skip to content

Worker: box each event's future so it never overflows the main thread's stack - #678

Merged
nambok merged 2 commits into
mainfrom
fix/worker-future-size
Nov 14, 2026
Merged

nambok merged 2 commits into
mainfrom
fix/worker-future-size

Conversation

@nambok

@nambok nambok commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Since v0.8.108 every worker invocation dies about 360 ms in with signal: segmentation fault: a stack overflow on the main thread. The event's future was never boxed, and each wrapper around a pass (a task-local scope, the run ceiling, the stop watch) held the pass's future inline, so the future handle_event returns was about 3 MB (3,060,784 bytes at v0.8.107, 3,169,840 at v0.8.108) and was built and moved on Lambda's 8 MB main thread stack. v0.8.107 fit with little room; the passes #671 and #672 added pushed it over.

Changes

  • services/worker/src/main.rs: the handler's future, the plan chat call, the SQS message's handle_message and its handle_message_inner are boxed where they are awaited. Each entry point's future is now small; the passes run from the heap.
  • A test, future_sizes::entry_points_stay_small, holds handle_event, handle_sqs and handle_message under 64 KiB. It fails on main (about 3 MB). The budget incident test reads the boxed call.

Verification

  • Release builds of the worker run against a local fake Lambda runtime API and AWS endpoint, one model_check event, with the main thread stack set by ulimit -s:
    • v0.8.107: overflows at 8.5 MB, handles the event at 9 MB.
    • v0.8.108: fetches the event, then overflows ("thread 'main' has overflowed its stack") at 8 to 12 MB, the same order as on Lambda; handles it at 16 MB.
    • This branch: handles the event at 8 MB, 2 MB, 1 MB and 512 KB.
  • cargo fmt --check --all, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace.

…'s stack

Every wrapper around a pass (a task-local scope, the run ceiling, the stop
watch) held the pass's future inline, so the event future was about 3 MB
and was built on Lambda's 8 MB main thread stack before anything boxed it.
v0.8.108's few extra kilobytes per layer pushed it over: every invocation
died with SIGSEGV. The handler, the SQS message and the message's pass are
now boxed, and a test holds each entry point's future under 64 KiB.
@nambok
nambok merged commit 125831c into main Nov 14, 2026
10 checks passed
@nambok
nambok deleted the fix/worker-future-size branch November 14, 2026 05:51
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