rtk-ai/rtk

bug(openclaw): plugin discards rewrite stdout on non-zero exit

Aberta

#1.388 aberto em 18 de abr. de 2026

 (1 comentário) (0 reação) (0 responsável)Rust (2.914 forks)batch import
area:clibugeffort-smallgood first issuepriority:low

Métricas do repositório

Stars
 (48.085 estrelas)
Métricas de merge de PR
 (Mesclagem média 11d 1h) (45 fundiu PRs em 30d)

Description

Summary

The OpenClaw plugin currently discards any successful rtk rewrite output if the child process exits non-zero.

The plugin uses execSync(...), so Node throws on any non-zero exit code and the plugin returns null. That means if rtk rewrite ever emits a valid rewritten command on stdout while exiting non-zero, the rewrite is silently lost.

Current plugin logic

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;
  }
}

Why this is a bug

The plugin assumes that a useful rewrite can only come back on exit 0.

That is brittle. If RTK emits a rewritten command on stdout together with a non-zero status for any classification or environment-specific reason, the OpenClaw plugin will drop the rewrite entirely.

Expected behavior

If rtk rewrite emits a rewritten command on stdout, the OpenClaw plugin should preserve and use that rewrite even when the subprocess exits non-zero.

Suggested fix direction

Handle non-zero exits without discarding stdout. For example:

  • inspect error.stdout in the catch, or
  • switch to a subprocess API that always exposes stdout/status together

Notes

I originally observed a case where rtk rewrite returned rewritten stdout with a non-zero exit, but I have not re-confirmed that exact exit behavior on every environment / version combination.

So the most precise framing is:

  • this is definitely a robustness hole in the OpenClaw plugin
  • whether it is a currently reproducible regression on latest RTK may be environment/version dependent

Guia do colaborador