Skip to content

c-abi: thread_stack_size(2 MiB) is a cap, not a floor — it shrinks workers when RUST_MIN_STACK is larger (#328) - #329

Merged
vikrantpuppala merged 1 commit into
mainfrom
ai/issue-328
Sep 9, 2026
Merged

vikrantpuppala merged 1 commit into
mainfrom
ai/issue-328

Conversation

@oss-engineer-bot

Copy link
Copy Markdown

Summary

Automated fix for #328 — c-abi: thread_stack_size(2 MiB) is a cap, not a floor — it shrinks workers when RUST_MIN_STACK is larger.

The C-ABI runtime now resolves worker stack size as max(ambient RUST_MIN_STACK, 2 MiB) via the pure helper c_abi_runtime_thread_stack_size, so 2 MiB is a floor rather than a cap: a host asking for more than 2 MiB (e.g. the partner's 3194880) keeps its larger stack instead of being shrunk, while a too-small or unset RUST_MIN_STACK still clamps up to 2 MiB (preserving #326). Both unit tests pass and fmt/clippy are clean. This is an offline-only fix (client-side stack-size arithmetic anchored in the issue's stated expectation), which cannot be observed via a live-server round-trip, so unit coverage over the extracted helper is the appropriate red→green evidence.

Root cause & plan

Root cause: In src/c_abi/mod.rs, the C-ABI Tokio runtime is built with .thread_stack_size(C_ABI_RUNTIME_THREAD_STACK_SIZE) where the constant is a fixed 2 MiB. thread_stack_size is an ABSOLUTE value and makes the underlying std thread builder ignore RUST_MIN_STACK entirely, so a host whose ambient RUST_MIN_STACK exceeds 2 MiB (e.g. the databricks-odbc partner at 3194880) has its kernel-c-abi worker stacks SHRUNK to 2 MiB — the opposite of #326's stated intent to prevent a small RUST_MIN_STACK from shrinking workers. 2 MiB must act as a floor, not a cap: the effective size should be max(ambient RUST_MIN_STACK, 2 MiB).
Files: src/c_abi/mod.rs
Planned coverage:

  • Floor-not-cap (the bug): when ambient RUST_MIN_STACK is LARGER than 2 MiB (e.g. 3194880), the computed worker stack size preserves the larger value rather than clamping down to 2 MiB. Fails today because the fixed constant would yield 2 MiB. Implemented against an extracted pure helper that takes the ambient value. (RUST_MIN_STACK > 2 MiB must be preserved (not shrunk))
  • Floor preserved: when ambient RUST_MIN_STACK is smaller than 2 MiB (e.g. 16384) or unset, the computed worker stack size is clamped UP to the 2 MiB floor — the fix(c-abi): give runtime workers an explicit stack size (isolate from host RUST_MIN_STACK / ulimit -s) #326 behavior the fix must keep. Passes today; guards against regression. (RUST_MIN_STACK < 2 MiB (or unset) clamps up to the 2 MiB floor)

Files changed

  • src/c_abi/mod.rs

Test plan

  • c_abi::tests::c_abi_runtime_stack_size_preserves_larger_rust_min_stack — fails (red) against the original code, passes (green) after the fix
  • c_abi::tests::c_abi_runtime_stack_size_clamps_small_rust_min_stack_up_to_floor — fails (red) against the original code, passes (green) after the fix

🤖 Generated by engineer-bot (bug-fix flow) — review before merge.

…rkers when RUST_MIN_STACK is larger (#328)

Signed-off-by: peco-engineer-bot[bot] <3815206+peco-engineer-bot[bot]@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: 1 Nit

Looks good — correct floor-not-cap fix with matching red→green unit coverage. c_abi_runtime_thread_stack_size (ambient.unwrap_or(0).max(2 MiB)) preserves a larger RUST_MIN_STACK while still clamping small/unset values up to 2 MiB, and the existing subprocess test (RUST_MIN_STACK=16384) remains valid. One nit about a now-slightly-misleading pre-existing test name, noted inline.

Other findings

  • ⚪ Nit — The pre-existing test c_abi_runtime_ignores_ambient_rust_min_stack is now a slight misnomer: the runtime no longer ignores RUST_MIN_STACK, it treats 2 MiB as a floor and honors larger ambient values. The test itself still probes correct behavior (16384 < floor → clamps up), so it's valid; only the name/docstring reads as if the ambient value is always disregarded. Consider renaming to something like c_abi_runtime_clamps_small_rust_min_stack_up_to_floor for consistency with the new helper tests. Nit only.

@vikrantpuppala vikrantpuppala added the integration-test Maintainer-only: triggers cross-repo integration tests. Auto-removed on push for re-review. label Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

Kernel integration tests triggered. View status. Results post back here as the "Kernel Integration Tests" check.

@vikrantpuppala
vikrantpuppala added this pull request to the merge queue Sep 9, 2026
Merged via the queue into main with commit fa0b72d Sep 9, 2026
28 of 29 checks passed

This branch was previously deployed

1 inactive deployment
azure-prod — e3a630a1 Deployed Sep 9, 2026 by oss-engineer-bot[bot] via review #553
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engineer-bot Apply to an issue to trigger the engineer-bot; on a PR to enable engineer follow-up integration-test Maintainer-only: triggers cross-repo integration tests. Auto-removed on push for re-review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant