Move Code Mode business logic into dispatch#72
Conversation
|
Warning Review limit reached
Your plan includes 1 review of capacity. Refill in 10 minutes and 28 seconds. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more review capacity refills, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (10)
📒 Files selected for processing (13)
📝 WalkthroughWalkthroughThis PR centralizes Code Mode logic into a dispatch-owned CodeModeBroker (search, schema, execute), rewrites the JS runner to use promise-based concurrent tool calls, exposes the broker via MCP and a new native CLI ( ChangesCode Mode Dispatch and Surface Integration
Possibly related PRs
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/lab/src/dispatch/gateway/code_mode.rs`:
- Around line 1016-1029: The write_runner_input function currently writes JSON
to the ChildStdin but never flushes, which can leave data in user-space buffers;
after calling stdin.write_all(&line).await in write_runner_input, call
stdin.flush().await and map any flush errors to the same ToolError::Sdk shape
(same sdk_kind "internal_error" and similar message text like "failed to flush
Code Mode runner stdin: {err}") so the function returns an error on flush
failure; update the async function handling to return that mapped error.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: f0b577af-2496-4182-a5b5-fadade7a9fec
📒 Files selected for processing (10)
crates/lab/src/api/services/gateway.rscrates/lab/src/cli/gateway.rscrates/lab/src/dispatch/gateway/code_mode.rscrates/lab/src/mcp/CLAUDE.mdcrates/lab/src/mcp/server.rscrates/lab/src/node/ws_client.rscrates/lab/tests/code_mode_runner.rsdocs/dev/DISPATCH.mddocs/services/GATEWAY.mddocs/superpowers/plans/2026-05-24-code-mode-dispatch-refactor.md
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: abe12d03a8
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
572663c to
3e4d479
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/lab/src/cli/gateway.rs`:
- Around line 760-771: The match arm for GatewayCodeCommand::Exec currently
enforces CODE_MODE_CLI_MAX_SOURCE_BYTES only for files; after you compute the
final code string (the local variable code in that arm), add the same guard:
check if code.as_bytes().len() > CODE_MODE_CLI_MAX_SOURCE_BYTES and, if so,
return an anyhow::bail!("Code Mode source file exceeds 20480 bytes") (or the
same message used for files). This ensures both the code branch and the file
branch share the same size validation.
In `@crates/lab/src/dispatch/gateway/code_mode.rs`:
- Around line 291-314: The schema handler currently only checks
caller.can_execute() which allows non-admin callers to fetch admin-only Lab
action schemas; modify schema to pass the caller into schema_for_lab_action
(call site: schema -> schema_for_lab_action(&parsed.raw, &service, &action,
surface, caller)) and update the schema_for_lab_action function to accept a
CodeModeCaller parameter and call caller.can_execute_action(entry, action_name)
(using the entry/service/action names available) before returning built-in
schemas; if can_execute_action returns false, return the same ToolError::Sdk
forbidden response as in schema, otherwise proceed to build and return the
schema.
In `@crates/lab/src/log_fmt.rs`:
- Line 1: Remove the module-level #![allow(dead_code)] in the log_fmt module and
instead apply item-level #[allow(dead_code)] to only the specific unused items
(e.g., helper structs/functions) so unused-warning suppression is precise; if
the blanket allow is temporary due to test harness restructuring, replace the
module attribute with a short comment explaining the temporary rationale and a
TODO to remove the suppression once the tests/binary linkage (e.g., formatter
helper types) are consolidated.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: d0679d6a-3560-4c3c-b3ef-ffec9e4f6b3f
⛔ Files ignored due to path filters (10)
docs/generated/action-catalog.jsonis excluded by!**/generated/**and included by**/*docs/generated/action-catalog.mdis excluded by!**/generated/**and included by**/*docs/generated/api-routes.jsonis excluded by!**/generated/**and included by**/*docs/generated/api-routes.mdis excluded by!**/generated/**and included by**/*docs/generated/cli-help.mdis excluded by!**/generated/**and included by**/*docs/generated/mcp-help.jsonis excluded by!**/generated/**and included by**/*docs/generated/mcp-help.mdis excluded by!**/generated/**and included by**/*docs/generated/openapi.jsonis excluded by!**/generated/**and included by**/*docs/generated/service-catalog.jsonis excluded by!**/generated/**and included by**/*docs/generated/service-catalog.mdis excluded by!**/generated/**and included by**/*
📒 Files selected for processing (14)
.cargo/config.tomlcrates/lab/Cargo.tomlcrates/lab/src/api/services/gateway.rscrates/lab/src/cli/gateway.rscrates/lab/src/dispatch/gateway/code_mode.rscrates/lab/src/lib.rscrates/lab/src/log_fmt.rscrates/lab/src/mcp/CLAUDE.mdcrates/lab/src/mcp/server.rscrates/lab/src/node/ws_client.rscrates/lab/tests/code_mode_runner.rsdocs/dev/DISPATCH.mddocs/services/GATEWAY.mddocs/superpowers/plans/2026-05-24-code-mode-dispatch-refactor.md
Resolves review thread PRRT_kwDOR8nC1M6EcO3b Resolves review thread PRRT_kwDOR8nC1M6EcO3e Resolves review thread PRRT_kwDOR8nC1M6EcO3f Resolves review thread PRRT_kwDOR8nC1M6Eb7ED Resolves review thread PRRT_kwDOR8nC1M6Eb645
b56660b to
4e7ca5d
Compare
Summary
CodeModeBrokerlabby gateway code search|schema|execCLI path using the same brokerlabbybin test harness, keepinglog_fmttests in the lib harness, and stripping repo-local debug info that triggered LLVM OOM under the global Cargo configVerification
cargo fmt --all -- --checkCARGO_BUILD_JOBS=1 cargo clippy --workspace --all-features -- -D warningsCARGO_BUILD_JOBS=1 RUST_TEST_THREADS=1 cargo test --workspace --all-features -- --test-threads=1cargo test --workspace --all-features -- --test-threads=1target/debug/labby --json gateway code execwithPromise.allover two read-onlylab::gateway.gateway.serverscalls through real configured upstream discoveryHarness Debugging Notes
labbytest harness with-C debuginfo=1from~/.cargo/config.toml.src/main.rsduplicated the app module tree, so cargo was also compiling a redundant bin test harness with nearly the same test set as the lib harness..cargo/config.tomlnow overrides debug info to0, and the bin target hastest = false; the formatter tests that were only in the bin harness are covered through the lib harness.Summary by CodeRabbit
New Features
lab gateway code search,lab gateway code schema, andlab gateway code execfor searching tools, fetching schemas, and executing sandboxed JavaScript.Bug Fixes
Documentation