From f27b1de8ce0e6dd405433bd30d64bc77b79ad2a9 Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Sat, 14 Nov 2026 00:27:17 -0500 Subject: [PATCH 1/2] Worker: box each event's future so it never overflows the main thread'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. --- services/worker/src/main.rs | 48 +++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/services/worker/src/main.rs b/services/worker/src/main.rs index 53c4ce7b2..f3beccad5 100644 --- a/services/worker/src/main.rs +++ b/services/worker/src/main.rs @@ -102,8 +102,9 @@ async fn main() -> Result<(), Error> { }); lambda_runtime::run(service_fn(move |event: LambdaEvent| { - let state = Arc::clone(&state); - async move { handle_event(state, event).await } + // Boxed: the event's future lives on the heap, never on the main + // thread's stack (see `future_sizes` below). + Box::pin(handle_event(Arc::clone(&state), event)) })) .await } @@ -135,7 +136,7 @@ async fn handle_event( }; let call = clients::github_budget::scoped( common::github_budget::caller::CHAT, - passes::plan_chat::handle(&state, req), + Box::pin(passes::plan_chat::handle(&state, req)), ); Ok(common::usage::with_feature(feature, call).await) } else if let Some(req) = payload.get("model_check") { @@ -240,7 +241,7 @@ async fn handle_sqs(state: Arc, event: LambdaEvent) -> Re passes::run_ceiling::worked( &state, &ceiling_ref, - handle_message(Arc::clone(&state), message), + Box::pin(handle_message(Arc::clone(&state), message)), ), )) .await; @@ -339,7 +340,11 @@ async fn handle_message(state: Arc, message: models::WorkerMessage) } } let label = github_caller(&message); - github_budget::scoped(label, handle_message_inner(Arc::clone(&state), message)).await; + github_budget::scoped( + label, + Box::pin(handle_message_inner(Arc::clone(&state), message)), + ) + .await; github_budget::scoped( common::github_budget::caller::DESCRIPTION, passes::description::reconcile_moved(&state, team.as_deref()), @@ -976,3 +981,36 @@ async fn handle_message_inner(state: Arc, message: models::WorkerMe models::WorkerMessage::UsageRecord(_) => {} } } + +/// Lambda runs the worker on the main thread's 8 MB stack, and an event's +/// future is built on that stack before it is boxed by anything. Unboxed, +/// every wrapper around a pass (a task-local scope, the run ceiling, the +/// stop watch) holds its argument and its awaited copy of the pass, so each +/// layer doubles the size: v0.8.108 crashed every invocation with a stack +/// overflow (SIGSEGV) this way. Each entry point stays small by boxing what +/// it awaits. +#[cfg(test)] +mod future_sizes { + use super::*; + + /// The most an entry point's future may take on the stack. + const BUDGET: usize = 64 * 1024; + + fn size_of_future(_: &impl Fn(A, B) -> F) -> usize { + std::mem::size_of::() + } + + #[test] + fn entry_points_stay_small() { + for (name, size) in [ + ("handle_event", size_of_future(&handle_event)), + ("handle_sqs", size_of_future(&handle_sqs)), + ("handle_message", size_of_future(&handle_message)), + ] { + assert!( + size <= BUDGET, + "{name}'s future is {size} bytes, over {BUDGET}: box what it awaits" + ); + } + } +} From 4c445c51bfffbe0ac25d17309b2699a93e37bfd6 Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Sat, 14 Nov 2026 00:40:28 -0500 Subject: [PATCH 2/2] Worker: the budget incident test reads the boxed message call --- services/worker/src/passes/incidents/ax_github_budget.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/worker/src/passes/incidents/ax_github_budget.rs b/services/worker/src/passes/incidents/ax_github_budget.rs index 1225741e0..ecd90b28d 100644 --- a/services/worker/src/passes/incidents/ax_github_budget.rs +++ b/services/worker/src/passes/incidents/ax_github_budget.rs @@ -319,7 +319,9 @@ async fn one_budget_runs_first_sweeps_last() { ); // Every message's requests are labelled, written and logged. let main = include_str!("../../main.rs"); - assert!(main.contains("github_budget::scoped(label, handle_message_inner(")); + assert!(main.contains( + "github_budget::scoped(\n label,\n Box::pin(handle_message_inner(" + )); assert!(main.contains("github_budget::flush(&state).await;")); for sweep in [ "who::SWEEP_PR_WATCH",