Repository navigation
fix(openclaw): handle exit code 3 from rtk rewrite - #2202
Conversation
KuSh
left a comment
There was a problem hiding this comment.
Thanks for your PR! While your current solution works as a temporary workaround, it’s not yet production-ready. I’ve left some suggestions to help guide you toward a more robust, final implementation.
Let me know if you’d like further clarification or assistance!
Address KuSh review feedback on rtk-ai#2202: - tryRewrite now returns [string | null, "ask"?] tuple - Exit code 3 specifically checked (e.status === 3) - before_tool_call returns requireApproval when rewrite is a suggestion (exit 3), per OpenClaw hook docs - 60s approval timeout with deny on timeout See: rtk-ai#2202 (review) Signed-off-by: Karol Zalewski <[email protected]>
Address KuSh review feedback on rtk-ai#2202: - tryRewrite now returns [string | null, "ask"?] tuple - Exit code 3 specifically checked (e.status === 3) - before_tool_call returns requireApproval when rewrite is a suggestion (exit 3), per OpenClaw hook docs - 60s approval timeout with deny on timeout See: rtk-ai#2202 (review) Signed-off-by: Karol Zalewski <[email protected]>
1162f2d to
2256da9
Compare
Rework the plugin to respect RTK's full exit code protocol (src/hooks/rewrite_cmd.rs): Exit codes: 0 + stdout Allow — auto-apply rewrite (no approval) 1 No match — pass through unchanged 2 Deny — block the call (new) 3 + stdout Ask — rewrite with requireApproval (KuSh review) Changes: - tryRewrite returns [string | null, "ask" | "deny" | undefined] - Exit 3: requireApproval with configurable timeout (default 120s) - Exit 2: block:true (was silently passed through — security gap) - allowedDecisions: ["allow-once", "deny"] — no allow-always (plugin does not persist trust) - onResolution callback for verbose logging - approvalTimeoutMs config option in openclaw.plugin.json - Documented exit code protocol in file header Address KuSh review: rtk-ai#2202 (review) Signed-off-by: Karol Zalewski <[email protected]>
KuSh
left a comment
There was a problem hiding this comment.
Just a few remaining nitpicks and questions
…t timeoutMs - Extract RewriteVerdict type per KuSh suggestion - Remove timeoutMs from requireApproval (omit to use Gateway default) - Remove approvalTimeoutMs config option from plugin.json - allowedDecisions still excludes allow-always: OpenClaw docs confirm plugin allow-always does not auto-persist; offering it without our own persistence would mislead users Address KuSh review: rtk-ai#2202 (review-4588193872) Signed-off-by: Karol Zalewski <[email protected]>
|
Thanks for the thorough review, KuSh — really appreciate the guidance. 1. 2. 3.
The troubleshooting section reinforces this:
Since this plugin doesn't implement its own trust persistence, offering |
9827755 to
6b2851c
Compare
Address KuSh review feedback on rtk-ai#2202: - tryRewrite now returns [string | null, "ask"?] tuple - Exit code 3 specifically checked (e.status === 3) - before_tool_call returns requireApproval when rewrite is a suggestion (exit 3), per OpenClaw hook docs - 60s approval timeout with deny on timeout See: rtk-ai#2202 (review) Signed-off-by: Karol Zalewski <[email protected]>
Rework the plugin to respect RTK's full exit code protocol (src/hooks/rewrite_cmd.rs): Exit codes: 0 + stdout Allow — auto-apply rewrite (no approval) 1 No match — pass through unchanged 2 Deny — block the call (new) 3 + stdout Ask — rewrite with requireApproval (KuSh review) Changes: - tryRewrite returns [string | null, "ask" | "deny" | undefined] - Exit 3: requireApproval with configurable timeout (default 120s) - Exit 2: block:true (was silently passed through — security gap) - allowedDecisions: ["allow-once", "deny"] — no allow-always (plugin does not persist trust) - onResolution callback for verbose logging - approvalTimeoutMs config option in openclaw.plugin.json - Documented exit code protocol in file header Address KuSh review: rtk-ai#2202 (review) Signed-off-by: Karol Zalewski <[email protected]>
…t timeoutMs - Extract RewriteVerdict type per KuSh suggestion - Remove timeoutMs from requireApproval (omit to use Gateway default) - Remove approvalTimeoutMs config option from plugin.json - allowedDecisions still excludes allow-always: OpenClaw docs confirm plugin allow-always does not auto-persist; offering it without our own persistence would mislead users Address KuSh review: rtk-ai#2202 (review-4588193872) Signed-off-by: Karol Zalewski <[email protected]>
6b2851c to
c059525
Compare
f5c6eab to
97aaac8
Compare
0d50a72 to
8b632e9
Compare
Interpret all RTK rewrite exit codes and respond appropriately: - Exit 0 (Allow): auto-apply rewrite - Exit 1 (Passthrough): no RTK equivalent, pass through unchanged - Exit 2 (Deny): block the call entirely - Exit 3 (Ask): rewrite available, require user approval via requireApproval with allow-once/deny decisions Uses execFileSync (not execSync) to avoid shell injection. Returns a [string | null, RewriteVerdict?] tuple from tryRewrite so the before_tool_call hook can react to each verdict type. "allow-always" omitted from allowedDecisions because OpenClaw does not auto-persist approval for plugin hooks — see: https://docs.openclaw.ai/plugins/plugin-permission-requests#troubleshooting Closes rtk-ai#2202
8b632e9 to
776a4b1
Compare
|
Thanks KuSh! All three rounds of feedback are now addressed in a single squashed commit (776a4b1):
|
KuSh
left a comment
There was a problem hiding this comment.
LGTM, thanks for keeping up!
Interpret all RTK rewrite exit codes and respond appropriately: - Exit 0 (Allow): auto-apply rewrite - Exit 1 (Passthrough): no RTK equivalent, pass through unchanged - Exit 2 (Deny): block the call entirely - Exit 3 (Ask): rewrite available, require user approval via requireApproval with allow-once/deny decisions Uses execFileSync (not execSync) to avoid shell injection. Returns a [string | null, RewriteVerdict?] tuple from tryRewrite so the before_tool_call hook can react to each verdict type. "allow-always" omitted from allowedDecisions because OpenClaw does not auto-persist approval for plugin hooks — see: https://docs.openclaw.ai/plugins/plugin-permission-requests#troubleshooting Closes rtk-ai#2202
rtk 0.44.0 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>## [0.44.0](rtk-ai/rtk@v0.43.0...v0.44.0) (2026-07-26) ### Features * add git checkout support ([be1844c](rtk-ai/rtk@be1844c)) * add uv run support ([a5f0774](rtk-ai/rtk@a5f0774)) * **cargo:** route --message-format=json builds through explicit arg detection ([5ea03f3](rtk-ai/rtk@5ea03f3)) * **hook:** add Cargo.lock ([531bc93](rtk-ai/rtk@531bc93)) * **hook:** add support for Kimi AI agent ([7624c43](rtk-ai/rtk@7624c43)) * **hooks:** add Factory Droid integration ([8a8b356](rtk-ai/rtk@8a8b356)) * **hook:** wire TOML filters + better tee tail hint ([31f9d43](rtk-ai/rtk@31f9d43)) * **hook:** wire TOML filters into the rewrite path + reversible truncation ([73b8cb3](rtk-ai/rtk@73b8cb3)) * **php:** consolidated PHP tooling (php, artisan, phpunit, phpstan, pest, paratest, ecs, pint) ([1052c1c](rtk-ai/rtk@1052c1c)) * **pipe:** expose PHP tool filters as stdin pipe filters ([214a79a](rtk-ai/rtk@214a79a)) * **sbt:** add SBT (Scala Build Tool) support ([4f86523](rtk-ai/rtk@4f86523)) * **trust:** gate custom filters (project + user-global) + init opt-in flags ([1130a7c](rtk-ai/rtk@1130a7c)) * **trust:** rtk trust uses the same opt-in prompt as init ([e0a83ac](rtk-ai/rtk@e0a83ac)) ### Bug Fixes * **analytics:** floor prefix slices to char boundary instead of full-string fallback ([c9468ee](rtk-ai/rtk@c9468ee)) * **analytics:** truncate display strings on UTF-8 char boundaries ([47b22e0](rtk-ai/rtk@47b22e0)), closes [#2787](rtk-ai/rtk#2787) * **benchmark:** use deterministic curl and wget responses ([6c57836](rtk-ai/rtk@6c57836)) * **benchmark:** use stable indexed MockHTTP responses ([8dd5a34](rtk-ai/rtk@8dd5a34)) * **cargo:** give the json batch filter the exit code ([a3e65e9](rtk-ai/rtk@a3e65e9)) * **cargo:** honor last --message-format when the flag is repeated ([25d6a09](rtk-ai/rtk@25d6a09)) * **cargo:** keep "No issues found" wording for clean clippy json runs ([1f74614](rtk-ai/rtk@1f74614)) * **cargo:** label check output as "check" instead of "build" ([90b4f5f](rtk-ai/rtk@90b4f5f)) * **cargo:** match the human path when skipping the json warning summary ([59ed885](rtk-ai/rtk@59ed885)) * **cargo:** restore failure check before trusting reused build filter ([e4bfe35](rtk-ai/rtk@e4bfe35)) * **cargo:** skip "N warnings generated" record in json diagnostics ([9ae0872](rtk-ai/rtk@9ae0872)) * **cargo:** strip ansi from json rendered diagnostics ([b47653a](rtk-ai/rtk@b47653a)) * **cargo:** surface --message-format=json test compile errors ([f9b720c](rtk-ai/rtk@f9b720c)) * **cargo:** tee-hint dropped json diagnostics beyond the cap ([cf1caf9](rtk-ai/rtk@cf1caf9)) * **cargo:** tighten json warning-summary skip to ends_with ([6c9a60d](rtk-ai/rtk@6c9a60d)) * **ccusage:** accept `period` key from current ccusage ([d823aaf](rtk-ai/rtk@d823aaf)) * **cicd:** next release pr target fork compatibel ([6e34bba](rtk-ai/rtk@6e34bba)) * **copilot:** add missing 'get' to kubectl example in init template ([f9d8c77](rtk-ai/rtk@f9d8c77)) * **copilot:** remove unnecessary test ([b49568f](rtk-ai/rtk@b49568f)) * **copilot:** support IDE terminal hooks ([1d6798d](rtk-ai/rtk@1d6798d)) * detect absolute rtk path in Claude hook settings ([5d32d07](rtk-ai/rtk@5d32d07)) * **filter:** address review findings in the TOML filter path ([315a943](rtk-ai/rtk@315a943)) * **gain:** note untrusted custom filters so they can be re-trusted ([a4872d9](rtk-ai/rtk@a4872d9)) * **git:** compact git stash show instead of forcing -p ([1b38eec](rtk-ai/rtk@1b38eec)) * **grep:** only insert -- separator when context flags are active ([34a0f0e](rtk-ai/rtk@34a0f0e)) * **grep:** preserve -- separator between non-adjacent match blocks ([6871e55](rtk-ai/rtk@6871e55)) * **hook:** handle AskRewrite in Cursor hook when no rules configured ([ff0b9ac](rtk-ai/rtk@ff0b9ac)), closes [#2372](rtk-ai/rtk#2372) * **hook:** include ask rules in cursor_has_explicit_rules check ([3362325](rtk-ai/rtk@3362325)) * **hook:** kimi init writes AGENTS.md instead of dead .kimirules ([8fe4a40](rtk-ai/rtk@8fe4a40)) * **hooks:** distinguish explicit ask from default in AskRewrite ([0df6929](rtk-ai/rtk@0df6929)) * **hooks:** don't force-allow Droid rewrites ([9dd8211](rtk-ai/rtk@9dd8211)) * **hooks:** emit permissionDecision allow for simple Copilot CLI rewrites ([23d1e89](rtk-ai/rtk@23d1e89)) * **hooks:** source Droid verdicts from Droid's own permission lists ([70ed82a](rtk-ai/rtk@70ed82a)) * **hook:** use ask action in audit log for AskRewrite verdict ([36dd8f2](rtk-ai/rtk@36dd8f2)) * **hook:** use ask permission for AskRewrite in Cursor hook ([a0c16ef](rtk-ai/rtk@a0c16ef)) * **init:** honor RTK_TELEMETRY_DISABLED in consent prompt ([#1307](rtk-ai/rtk#1307)) ([debac0f](rtk-ai/rtk@debac0f)) * **openclaw:** handle exit code 3 from rtk rewrite ([487a2e7](rtk-ai/rtk@487a2e7)), closes [#2202](rtk-ai/rtk#2202) * **parser:** use byte offsets instead of char indices in extract_json_object ([32dda24](rtk-ai/rtk@32dda24)) * **parser:** use byte offsets instead of char indices in extract_json_object ([27f9739](rtk-ai/rtk@27f9739)), closes [#2509](rtk-ai/rtk#2509) * **permissions:** stop extra whitespace from evading deny rules ([3483786](rtk-ai/rtk@3483786)) * **permissions:** stop extra whitespace from evading deny rules ([f6b9290](rtk-ai/rtk@f6b9290)) * **php:** address phpstan review feedback (resolution, text fallback, path compaction) ([07c231e](rtk-ai/rtk@07c231e)) * **php:** anchor phpunit failure-heading detection to the "N) " format ([128d04f](rtk-ai/rtk@128d04f)) * **php:** classify php subcommands in the PASSTHROUGH list ([4a37246](rtk-ai/rtk@4a37246)) * **php:** default pint applied_fixers when key is absent ([0cc15dc](rtk-ai/rtk@0cc15dc)) * **php:** detect phpstan analyse after global flags; avoid duplicate format ([7cc46b4](rtk-ai/rtk@7cc46b4)) * **php:** drop bogus pest.php check in test-runner detection ([28366ce](rtk-ai/rtk@28366ce)) * **php:** rewrite ./vendor/bin/<tool> form for phpunit/pest/paratest/ecs/pint ([88e56ce](rtk-ai/rtk@88e56ce)) * **php:** route php_tool_command through resolved_command ([8eae6b7](rtk-ai/rtk@8eae6b7 See merge request: Harmonybrew/homebrew-core!15172
Problem
The rtk-rewrite OpenClaw plugin silently drops all command rewrites. Every
rtk rewritecall that produces a suggestion returns exit code 3, whichexecSynctreats as an exception. The catch block returnsnull, so no command is ever rewritten.See #2200 for full analysis.
Fix
Check
e.stdoutin the catch handler — exit code 3 with stdout output is a valid rewrite suggestion, not an error:Verified
All common shell commands now correctly rewritten:
All previously returned
null(no rewrite) with the upstream code.Aiko — AI assistant in OpenClaw
Running RTK on k3s with Kilo Gateway
Config: RTK 0.42.0 | OpenClaw 2026.5.28 | Node.js v24.14.0 | Model: MiMo-V2.5-Pro
Reviewed and verified by Zal (@kzzalews)