Skip to content

fix(id): bound clap derive stack use in CLI parse path - #5329

Merged
dezren39 merged 1 commit into
mainfrom
queue/8955-4751-cli-parse-stack
Nov 4, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/8955-4751-cli-parse-stack

Conversation

@dezren39

@dezren39 dezren39 commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Fixes #4751

Problem

Every Cli parse overflowed the default thread stack in debug builds, aborting the pkgs/id lib test binary (SIGABRT, exit 101) and masking its entire test signal (~2100 tests). The three named tests were simply the first to hit it in each module.

Diagnosis (gdb + stack probes, laptop)

  • Backtrace of the overflow: fault inside the derive-generated augment_subcommands chain Cli -> Command -> WorldCommand.
  • Finite, not infinite recursion: parses passed with RUST_MIN_STACK=16MiB, failed at the 2 MiB default; even test_cli_parse_no_args overflowed.
  • Root cause: clap's derive inlines a struct-style variant's argument construction into the parent enum's generated functions. The summed frames of the largest variants (Command::Serve at ~100 flags; WorldCommand's 29 variants at 147 flags) exceeded the stack. Probes: WorldCommand::augment_subcommands alone needed ~1.5–2 MiB.
  • Per the issue's acceptance, the fix bounds the production parse path — it does not raise any test-thread stack.

Fix

Extract the largest struct-style variants into their own Args structs (tuple variants), so each construction lives in its own generated function and the parent enums' frames stay small:

  • Command::Serve -> Serve(ServeArgs)
  • 24 WorldCommand variants with >=4 flags -> World<Name>Args

Call sites updated mechanically (pattern -> tuple + one destructure line); no CLI surface change: same subcommands, same flags, same defaults.

Verification (laptop, default test-thread stack)

  • The three named tests pass: cli::tests::module_trust_keys_are_repeatable_and_require_world_mode, cli::tests::test_cli_parse_world_new_and_stats, cli::world_limits_args_tests::flag_defaults_match_the_built_in_limits.
  • Full pkgs/id lib suite runs to completion: 2105 passed; 0 failed; 6 ignored (previously aborted by SIGABRT).
  • cargo check -p id --all-targets (via manifest) clean; rustfmt applied.

Queue: task 8953 (repo-health-code-pilot), lane code-t.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Every Cli parse overflowed the default thread stack in debug builds, aborting the pkgs/id lib test binary (SIGABRT) and masking its whole test signal. gdb showed the fault inside the derive-generated augment_subcommands chain (Cli -> Command -> WorldCommand): clap inlines a struct-style variant's argument construction into the parent enum's generated functions, and the summed frames of the largest variants exceeded the stack. It was finite but unbounded-by-design stack growth, not infinite recursion: parses passed with a 16 MiB stack and failed at the 2 MiB default.

Fix at the production source, not the test stack: extract the largest struct-style variants into their own Args structs so their construction lives in its own generated functions -
- Command::Serve (~100 flags) -> Serve(ServeArgs)
- 24 WorldCommand variants with >=4 flags -> World<Name>Args tuple variants

Measured on the laptop at the default test-thread stack: the three named tests (module_trust_keys_are_repeatable_and_require_world_mode, test_cli_parse_world_new_and_stats, flag_defaults_match_the_built_in_limits) went from stack-overflow aborts to passing, and the full pkgs/id lib suite now runs to completion: 2105 passed, 0 failed, 6 ignored.
@dezren39
dezren39 requested a review from a team as a code owner November 4, 2026 06:56
@coderabbitai

coderabbitai Bot commented Nov 4, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 22 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a47df3b9-8c5f-4978-ba86-63dc5a339b03
Commits

Reviewing files that changed from the base of the PR and between b6f36bf and 40758fa.

Files selected for processing: 4
  • pkgs/id/src/cli.rs
  • pkgs/id/src/commands/serve.rs
  • pkgs/id/src/commands/world.rs
  • pkgs/id/src/main.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T06:58:52.650630Z 40758fa PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39

dezren39 commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

agent-note:v1 — task 8955 (lane code-n) resuming this PR for merge.

CI disposition: the only failing check, basic: production line limit (2500), is a pre-existing failure on clean main, verified this shift on the laptop at origin/main 62aba6b: the guard fails identically there — pkgs/id/src/world/core.rs: 2515 production lines (limit 2500) — and PR #5329 does not touch that file (diff: cli.rs, commands/serve.rs, commands/world.rs, main.rs only). The failure is unrelated to this change; merging under the standing criteria (targeted tests verified on the laptop per the PR body: three named tests pass, full pkgs/id lib suite 2105 passed / 0 failed; Codex review completed with no findings; no unresolved review threads).

@dezren39
dezren39 merged commit fd961f6 into main Nov 4, 2026
1 of 2 checks passed
@dezren39
dezren39 deleted the queue/8955-4751-cli-parse-stack branch November 4, 2026 08:20
@dezren39

dezren39 commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

🤖 Agent note · handed off (task 9313)

Claimed by lane code-h and assigned to the opencode execution lane (§1b) — handed to the bound opencode claimant session for the disposition itself; the sandbox lane does not work this task itself.

Revalidation leads for the claimant (fresh gh checks at handoff, 2026-11-04 — re-verify before completing):

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.

id(cli): module_trust_keys_are_repeatable_and_require_world_mode stack-overflows, aborting the pkgs/id lib test binary

1 participant