Skip to content

swarm: propagate root effort to workers, allow model:inherit sentinels - #2154

Open
osmanaksu wants to merge 7 commits into
1jehuang:masterfrom
osmanaksu:fix/swarm-root-effort-propagation
Open

osmanaksu wants to merge 7 commits into
1jehuang:masterfrom
osmanaksu:fix/swarm-root-effort-propagation

Conversation

@osmanaksu

@osmanaksu osmanaksu commented Nov 12, 2026 •

Copy link
Copy Markdown

Fixes #2148. Related: #2153, #2149.

Summary

Three focused swarm-spawn fixes, each independently testable. (The context-window documentation was drafted in this branch's history but removed before review to keep the PR focused on the code fixes — it does not add a file to the diff.)

  1. Propagate root swarm effort to spawned workers (swarm: root session effort not propagated to spawned workers #2153). When the coordinator is in swarm mode, its effective reasoning effort (from agents.swarm_root_effort) now propagates to workers instead of falling back to the hardcoded "low" default. A coordinator with swarm_root_effort = "none" no longer silently re-enables thinking for its workers.

  2. Allow model: "inherit" / model: "coordinator" when swarm_model_selection is disabled (swarm: tool description advertises model/model: "inherit" but schema strips it; error does not name the config keys #2148). These are resolution sentinels handled by resolve_swarm_spawn_selection, not agent-selected model overrides. They must pass validate_swarm_model_request regardless of the flag. Previously, LLMs that always send model: "inherit" blocked every spawn in default configs, and the tool-level validation was not the only place the sentinel needed bypassing.

  3. Config-free effort-resolution test. The new effort tests no longer depend on global configuration state, so they run reliably in the lib test harness.

Commits

SHA Subject Files
ef4dc3c32 swarm: propagate root swarm effort to spawned workers 6 files, +59 −9
a9bb2cb22 fix(swarm): allow model:inherit when swarm_model_selection is disabled 1 file, +7 −1
d11910fa7 swarm: document context window auto-discovery gap (added, then removed) +248 / −248 (net 0)
4ea43ca39 fix(swarm): apply inherit sentinel bypass at tool-level validation (removes the doc) 6 files, +46 −252
4ee7e9d54 test(swarm): make effort resolution test config-free 3 files, +31 −16
0477295a3 fix(swarm): correct is_inherit_sentinel visibility to pub(crate) 2 files, +3 −2
8e2e4e43f style(swarm): rustfmt the use groups in the files this PR touches 2 files, +2 −4

The #2020 suffix in the first commit's subject is a stray carry-over from a prior branch's naming; it does not reference a tracked issue. History is left as-is rather than rebased to preserve the pushed SHAs.

Changes

1. Root effort propagation

resolve_swarm_spawn_effort in spawn_policy.rs gains a root-inherit fallback level:

requested_effort → agents.swarm_effort → root swarm effort → "low"

The root-inherit step checks is_swarm_effort(root_effort) (only the "swarm" sentinel triggers it) and resolves via the already-resolved agents.swarm_root_effort value, passed as a parameter to keep the function pure and testable without global configuration.

  • spawn_policy.rs: added root_effort / root_swarm_effort parameters + the 3rd fallback level; is_inherit_sentinel is pub(crate).
  • spawn_model_selection.rs: added reasoning_effort: Option<String> to CoordinatorSpawnIdentity.
  • comm_session.rs: passes the coordinator's reasoning effort into resolve_swarm_spawn_effort.
  • provider.rs: added session_reasoning_effort() accessor.
  • comm_session_effort_tests.rs: 5 new test cases.

2. model:inherit sentinel bypass

The inherit sentinels are filtered out before validation in both the session path (comm_session.rs) and the tool-level path (communicate.rs), so a disabled swarm_model_selection flag can no longer reject a valid model: "inherit" / model: "coordinator" request. is_inherit_sentinel matches "inherit" and "coordinator" case-insensitively.

3. Net diff contains no documentation file

The swarm_spawn_issues.md analysis (5N1K: catalog parser ignores max_input_tokens, Provider bypasses the catalog cache, stall watchdog blind to long inference) was written up on this branch to ground the fix, then removed (4ea43ca39) so the PR stays a focused code change. The analysis is preserved in the linked issue #2149 rather than merged as a repo doc.

Tests

  • comm_session_effort_tests.rs: 5 new test cases (explicit SDK effort wins over config pin; config pin wins over root sentinel; root "swarm" + no config inherits swarm_root_effort; non-swarm root effort ignored; no root/no config → "low").
  • comm_session_tests.rs: coordinator_identity helper updated with reasoning_effort: None.
  • communicate_tests/input_format.rs: tool-level sentinel-bypass coverage.

Validation

  • cargo test -p jcode-app-core --lib comm_session: 37 passed, 0 failed.
  • cargo clippy -p jcode-app-core --lib: clean.
  • cargo fmt --check: clean on the two files this PR touches (server.rs, comm_session.rs). Three other files that trip cargo fmt (reload.rs, util.rs, bash_tests.rs) are byte-identical to master and unchanged by this PR, so they are left out to keep the diff focused.

Related issues

mac added 3 commits November 12, 2026 15:16
"inherit" and "coordinator" are resolution sentinels handled by resolve_swarm_spawn_selection, not agent-selected model overrides. They must pass validate_swarm_model_request regardless of the swarm_model_selection flag so LLMs that always send model:inherit do not block every spawn in default configs.
LiteLLM's /v1/models endpoint reports max_input_tokens but Jcode's
catalog parser only checks context_window and context_length. This
means models like deepseek-reasoner (1M window) get a 200k fallback
budget, causing premature compaction.

Also documents the second layer: Provider::context_window() calls
context_limit_for_model_with_provider (static table) instead of
context_limit_for_model_with_provider_and_cache, so even correctly
parsed catalog data is bypassed.

Issue 2 now has three defects: 2a (catalog parser), 2b (Provider
bypasses cache), 2c (stall watchdog blind to long inference — the
original watchdog finding, preserved).
@osmanaksu
osmanaksu marked this pull request as ready for review November 12, 2026 14:16
@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no outstanding findings.

Summary

Workers now inherit agents.swarm_root_effort when the coordinator uses swarm effort mode. Both spawn paths allow model: "inherit" and model: "coordinator" when model selection is disabled.

  • Swarm workers inherit the root’s reasoning effort when it is in swarm mode.
  • The communicate tool lets model-inheritance sentinels reach swarm workers.

Reviews (6) · Last reviewed commit: "style(swarm): rustfmt the use groups in ..." · Reviewed by Greptile

@osmanaksu osmanaksu left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Review

Three commits, three concerns. The core logic is correct, but there are issues to address before merge:

1. Wrong issue reference (#2020)

Two doc comments reference :

  • crates/jcode-app-core/src/server/spawn_policy.rs:3 — (#1165, #2020)
  • crates/jcode-app-core/src/server/comm_session.rs:357 — (#1165, #2020)

#2020 is "reasoning_effort none does not disable thinking on OpenAI-compatible gateways" — a closed, unrelated bug. The correct reference is #2153 (root session effort not propagated to spawned workers).

2. swarm_spawn_issues.md in the repo root

248 lines of issue-analysis documentation committed to the repo root. This is working material, not product code. Options:

  • Remove it from the PR (keep it in the issue comments instead)
  • Move it to docs/swarm_spawn_issues.md if it's meant to be a permanent reference

3. Correctness of the effort propagation (verified OK)

The three-level fallback chain is correct:

requested_effort → agents.swarm_effort → root swarm effort → "low"
  • is_swarm_effort gate ensures only the "swarm" sentinel triggers root inheritance (a root at "medium" does NOT propagate).
  • swarm_root_reasoning_effort() reads agents.swarm_root_effort from config (default "low").
  • Config pin (swarm_effort) wins over root inheritance — verified by the test resolve_swarm_spawn_effort(None, Some("high"), Some("swarm")) → Some("high").
  • Non-swarm root effort is ignored — verified by resolve_swarm_spawn_effort(None, None, Some("medium")) → Some("low").

4. Inherit sentinel fix (verified OK)

validate_swarm_model_request(None) → Ok(()) — confirmed in crates/jcode-config-types/src/lib.rs:677-678. Filtering out "inherit"/"coordinator" before validation is correct: these are resolution sentinels, not model overrides.

Suggested changes before merge

  1. Replace #2020 with #2153 in both doc comments.
  2. Remove swarm_spawn_issues.md from the PR (or move to docs/).
  3. After rebase, verify CI passes (Build & Test, Format, Guardrails).

The swarm tool's CommunicateTool::execute called validate_swarm_model_request
directly on params.model, rejecting 'inherit'/'coordinator' sentinels before
they could reach resolve_swarm_spawn_selection. Only direct protocol requests
(via spawn_swarm_agent) benefited from the server-side filter.

Fix: apply the same is_inherit_sentinel filter at the tool entry point so
agent-facing spawns with model:'inherit' work regardless of
swarm_model_selection state. Also re-export is_inherit_sentinel at the
server module level for cross-module access.

Additionally:
- Replace incorrect 1jehuang#2020 issue reference with 1jehuang#2153 (2 locations)
- Remove swarm_spawn_issues.md working file from the PR
- Add regression test for inherit sentinel bypass
@osmanaksu

Copy link
Copy Markdown
Author

✅ Fixed: tool-level inherit sentinel bypass applied (commit 4ea43ca).

CommunicateTool::execute now filters inherit/coordinator before calling validate_swarm_model_request, so agent-facing spawns with model: "inherit" work regardless of swarm_model_selection state.

Also applied:

Tests pass: cargo test -p jcode-app-core -- comm_session_effort_tests communicate_tests

Comment thread crates/jcode-app-core/src/server.rs Resolved
resolve_swarm_spawn_effort now takes root_swarm_effort as an explicit
parameter instead of calling swarm_root_reasoning_effort() which reads
global configuration. This makes the function pure and the test isolated:

- Test now checks non-default values ("none", "medium") proving the
  inheritance branch actually propagates the value
- Blank/whitespace root_swarm_effort correctly falls through to default
- Test no longer fails if JCODE_SWARM_ROOT_EFFORT is set to a non-default

Addresses code review feedback: the previous assertion passed even if the
inheritance branch was removed (both paths yield "low" default).
@osmanaksu

Copy link
Copy Markdown
Author

✅ Fixed both review issues (commits 4ea43ca + 4ee7e9d):

Issue 1 (tool-level inherit bypass): Applied. CommunicateTool::execute now filters inherit/coordinator before calling validate_swarm_model_request. Regression test added.

Issue 2 (test depends on settings): Refactored. resolve_swarm_spawn_effort now takes root_swarm_effort as an explicit 4th parameter instead of calling swarm_root_reasoning_effort() (which reads global config). The test is now:

  • Config-free: passes the value directly, no dependency on JCODE_SWARM_ROOT_EFFORT
  • Strong assertion: checks "none" and "medium" (non-default values) — if the inheritance branch is removed, the test fails because it expects the param value, not the hardcoded default
  • Edge case: blank/whitespace root_swarm_effort correctly falls through to "low"

Caller in comm_session.rs passes Some(agents_config.root_effort_for_swarm()) — behavior unchanged, just the config read moved from inside the pure function to the caller.

@osmanaksu

Copy link
Copy Markdown
Author

✅ The E0364 compile error is already resolved in commit 4ee7e9d. is_inherit_sentinel in spawn_policy.rs is pub(super) (visible within comm_session), and the pub(crate) use comm_session::is_inherit_sentinel re-export in server.rs correctly widens it for the tool module. cargo check -p jcode-app-core passes clean.

The re-export chain required pub(crate) at the source (spawn_policy.rs)
for server.rs to re-export it crate-wide. pub(super) caused E0364.
@osmanaksu
osmanaksu force-pushed the fix/swarm-root-effort-propagation branch from 13d8778 to 0477295 Compare November 12, 2026 16:12
Comment thread crash_recovery_test.sh Resolved
Comment thread soak_test.sh Resolved
server.rs and comm_session.rs are in the PR diff, so normalize the
use-group ordering/rustfmt on those two files. The other three files
that trip cargo fmt (reload.rs, util.rs, bash_tests.rs) are unchanged
vs master and are left out to keep the diff focused.

This branch has not been deployed

No deployments
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.

swarm: tool description advertises model/model: "inherit" but schema strips it; error does not name the config keys Demo video upload

1 participant