Skip to content

fix(openclaw): rtk-rewrite plugin silently drops all rewrites — exit code 3 treated as error #2200

Closed

Description

@kzzalews

Summary

The rtk-rewrite OpenClaw plugin (openclaw/index.ts) silently drops all command rewrites. Every rtk rewrite call that produces a suggestion returns exit code 3, which execSync treats as an exception. The catch block returns null, so no command is ever rewritten — the plugin is effectively dead code.

The problem

rtk rewrite returns:

  • exit code 3 when it has a rewrite suggestion (known command)
  • exit code 1 when it has no rewrite (unknown command)
  • exit code 0 — never

The plugin's tryRewrite() function:

function tryRewrite(command: string): string | null {
  try {
    const result = execSync(`rtk rewrite ${JSON.stringify(command)}`, {
      encoding: "utf-8",
      timeout: 2000,
    }).trim();
    return result && result !== command ? result : null;
  } catch {
    return null; // ← always lands here for exit code 3
  }
}

execSync throws on any non-zero exit code. The catch block discards the rewrite. The command passes through unchanged.

How we found it

We discovered this while investigating why our RTK token savings weren't growing. We:

  1. Ran rtk rewrite "git log --oneline -5" → returns rtk git log --oneline -5 with exit code 3
  2. Simulated the plugin's tryRewrite() in Node.js → execSync threw, catch returned null
  3. Tested all common commands (git, kubectl, find, cat, grep) — all return exit code 3, all silently dropped

The fix

Check e.stdout in the catch handler — exit code 3 with stdout output is a valid rewrite suggestion, not an error:

} catch (e: any) {
    if (e?.stdout) {
      const result = String(e.stdout).trim();
      if (result && result !== command) return result;
    }
    return null;
  }

What we verified

Tested the fix against all common shell commands:

git log --oneline -5     → rtk git log --oneline -5     ✅
kubectl get pods -A      → rtk kubectl get pods -A      ✅
cat /tmp/test            → rtk read /tmp/test           ✅
ls -la /tmp              → rtk ls -la /tmp              ✅
find /tmp -name "*.log"  → rtk find /tmp -name "*.log"  ✅
grep -r test /tmp        → rtk grep -r test /tmp        ✅

All previously returned null (no rewrite) with the upstream code.

Environment

  • RTK: 0.42.0
  • OpenClaw: 2026.5.28
  • Node.js: v24.14.0
  • OS: Linux (Debian, k3s)

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)

Activity

  1. added
    bug
    good first issue
    on Jun 1, 2026
  2. pszymkowiak commented on Jun 1, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 97%

    Summary

    Plugin silently drops all rtk rewrites due to execSync throwing on exit code 3; PR #2202 already in progress with a verified fix.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • openclaw/index.ts

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  3. added a commit that references this issue on Jun 1, 2026
    5a914d9
  4. kzzalews commented on Jun 1, 2026

    @kzzalews
    ContributorAuthor

    Proposed fix: #2202

  5. added a commit that references this issue on Jun 2, 2026
    8e7611a
  6. added 5 commits that reference this issue on Jun 29, 2026
    3a9efaa
    c059525
    bbc694c
    f5c6eab
    97aaac8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibuggood first issuepriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions