Skip to content

hotfix: append "do not commit your changes." to sandbox prompts#142

Merged
sweetmantech merged 1 commit intomainfrom
hotfix/execute-step-no-commit
Apr 15, 2026
Merged

hotfix: append "do not commit your changes." to sandbox prompts#142
sweetmantech merged 1 commit intomainfrom
hotfix/execute-step-no-commit

Conversation

@sweetmantech
Copy link
Copy Markdown
Contributor

@sweetmantech sweetmantech commented Apr 15, 2026

Summary

  • Hotfix guardrail in `runSandboxCommandTask`: the `--message` value passed to `openclaw agent` is now always suffixed with `"do not commit your changes."`
  • Added `appendNoCommitInstruction(args)` helper — idempotent, no-op when `--message` isn't present, returns a copy (no mutation)
  • Wired the helper into the execute step just before `sandbox.runCommand`

Why

The task pushes sandbox state to GitHub after the run (`pushSandboxToGithub`). We don't want the agent itself creating commits during execution — it breaks the snapshot flow and can cause force-push / divergence issues.

Test plan

  • Unit tests for the helper (append, idempotent, no-op without `--message`, no-op when `--message` is the last arg, returns a copy)
  • Full suite: 350 tests pass
  • Verify in prod: trigger a run-sandbox-command with a plain prompt and confirm the agent does not create commits during the run

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Sandbox commands now automatically append a "do not commit your changes" instruction to message arguments, helping prevent accidental commits from the sandbox environment.
  • Tests

    • Added test coverage for automatic instruction appending, including idempotency verification and edge case handling.

Summary by cubic

Hotfix guardrail: sandbox commands now always append "do not commit your changes." to --message prompts so the agent doesn’t create commits during execution and break snapshot flow.

  • Bug Fixes
    • Added appendNoCommitInstruction(args) helper (idempotent; no-op without --message; returns a copy).
    • Wired into runSandboxCommandTask to rewrite args before sandbox.runCommand.

Written for commit a364400. Summary will update on new commits.

run-sandbox-command now rewrites the --message value passed to openclaw
so it always ends with "do not commit your changes." regardless of what
the caller sends. The helper is idempotent and a no-op when --message
isn't in the args, so other consumers of the task are unaffected.

The task pushes sandbox state to GitHub after the run; we don't want the
agent creating its own commits during execution.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 15, 2026

📝 Walkthrough

Walkthrough

A new module exports a constant NO_COMMIT_INSTRUCTION and a function that appends this instruction to command-line arguments when a --message flag is present. The function is integrated into sandbox command execution, with comprehensive test coverage validating the behavior.

Changes

Cohort / File(s) Summary
Append No Commit Instruction Module
src/sandboxes/appendNoCommitInstruction.ts
New module exporting NO_COMMIT_INSTRUCTION constant and appendNoCommitInstruction() function that clones input args, locates the --message flag, and appends the instruction to its value if not already present.
Test Suite
src/sandboxes/__tests__/appendNoCommitInstruction.test.ts
Comprehensive Vitest suite validating instruction appending, idempotency, edge cases (missing flag, no value, final argument), and array immutability.
Integration
src/tasks/runSandboxCommandTask.ts
Modified to pass command args through appendNoCommitInstruction() before invoking sandbox.runCommand().

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 A hop, skip, and a string append,
No commits shall happen by accident!
With messages checked and instructions inserted,
The sandbox stays safe and undisturbed.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely describes the main change: appending a specific instruction to sandbox prompts via a guardrail in sandbox command execution.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hotfix/execute-step-no-commit

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/sandboxes/__tests__/appendNoCommitInstruction.test.ts (1)

23-31: Add a regression test for “instruction present but not suffixed”.

Current coverage doesn’t catch cases where the phrase exists mid-message. Add one test to enforce true suffix behavior.

Suggested test addition
+  it("appends when instruction appears in the middle but is not the suffix", () => {
+    const original = [
+      "agent",
+      "--message",
+      `${NO_COMMIT_INSTRUCTION} and then continue`,
+    ];
+
+    expect(appendNoCommitInstruction(original)).toEqual([
+      "agent",
+      "--message",
+      `${NO_COMMIT_INSTRUCTION} and then continue ${NO_COMMIT_INSTRUCTION}`,
+    ]);
+  });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/sandboxes/__tests__/appendNoCommitInstruction.test.ts` around lines 23 -
31, Add a new unit test to cover the case where NO_COMMIT_INSTRUCTION appears
inside a message but is not the trailing suffix: create an original args array
whose last string contains `${NO_COMMIT_INSTRUCTION}` in the middle (e.g., "do
something ${NO_COMMIT_INSTRUCTION} please"), call
appendNoCommitInstruction(original) and assert that the returned array has the
instruction appended (i.e., the function treats the mid-message occurrence as
not-suffixed and adds the NO_COMMIT_INSTRUCTION as the proper trailing element).
This ensures appendNoCommitInstruction correctly checks for a true suffix rather
than any substring match.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/sandboxes/appendNoCommitInstruction.ts`:
- Around line 24-26: The early return uses
current.includes(NO_COMMIT_INSTRUCTION) which matches substrings anywhere;
change the check to ensure the message actually ends with the instruction (e.g.,
use current.trim().endsWith(NO_COMMIT_INSTRUCTION) or an anchored regex) so you
only skip when the instruction is the suffix. Keep the append logic that sets
out[valueIdx] = `${current} ${NO_COMMIT_INSTRUCTION}` but ensure you trim/trail
whitespace appropriately so you don't introduce double spaces when adding the
suffix.

In `@src/tasks/runSandboxCommandTask.ts`:
- Around line 78-80: The code currently applies appendNoCommitInstruction to
every sandbox.runCommand invocation, which can mutate unrelated commands; change
the args passed to sandbox.runCommand so appendNoCommitInstruction is only
applied when invoking the OpenClaw agent (check the command and first arg).
Concretely, compute finalArgs = (command === 'openclaw' && Array.isArray(args)
&& args[0] === 'agent') ? appendNoCommitInstruction(args) : (args || []), then
pass finalArgs into sandbox.runCommand instead of always calling
appendNoCommitInstruction(args || []).

---

Nitpick comments:
In `@src/sandboxes/__tests__/appendNoCommitInstruction.test.ts`:
- Around line 23-31: Add a new unit test to cover the case where
NO_COMMIT_INSTRUCTION appears inside a message but is not the trailing suffix:
create an original args array whose last string contains
`${NO_COMMIT_INSTRUCTION}` in the middle (e.g., "do something
${NO_COMMIT_INSTRUCTION} please"), call appendNoCommitInstruction(original) and
assert that the returned array has the instruction appended (i.e., the function
treats the mid-message occurrence as not-suffixed and adds the
NO_COMMIT_INSTRUCTION as the proper trailing element). This ensures
appendNoCommitInstruction correctly checks for a true suffix rather than any
substring match.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: a2da7669-b5d5-4a12-81cd-2567d1f84625

📥 Commits

Reviewing files that changed from the base of the PR and between ddf9404 and a364400.

📒 Files selected for processing (3)
  • src/sandboxes/__tests__/appendNoCommitInstruction.test.ts
  • src/sandboxes/appendNoCommitInstruction.ts
  • src/tasks/runSandboxCommandTask.ts

Comment on lines +24 to +26
if (current.includes(NO_COMMIT_INSTRUCTION)) return out;

out[valueIdx] = `${current} ${NO_COMMIT_INSTRUCTION}`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

includes() does not enforce the required suffix behavior.

At Line [24], the early return triggers even when the instruction is only a substring, so the message may still not end with the required text.

Proposed fix
-  const current = out[valueIdx];
-  if (current.includes(NO_COMMIT_INSTRUCTION)) return out;
-
-  out[valueIdx] = `${current} ${NO_COMMIT_INSTRUCTION}`;
+  const current = out[valueIdx].trimEnd();
+  if (current.endsWith(NO_COMMIT_INSTRUCTION)) return out;
+
+  out[valueIdx] = current.length
+    ? `${current} ${NO_COMMIT_INSTRUCTION}`
+    : NO_COMMIT_INSTRUCTION;
   return out;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (current.includes(NO_COMMIT_INSTRUCTION)) return out;
out[valueIdx] = `${current} ${NO_COMMIT_INSTRUCTION}`;
const current = out[valueIdx].trimEnd();
if (current.endsWith(NO_COMMIT_INSTRUCTION)) return out;
out[valueIdx] = current.length
? `${current} ${NO_COMMIT_INSTRUCTION}`
: NO_COMMIT_INSTRUCTION;
return out;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/sandboxes/appendNoCommitInstruction.ts` around lines 24 - 26, The early
return uses current.includes(NO_COMMIT_INSTRUCTION) which matches substrings
anywhere; change the check to ensure the message actually ends with the
instruction (e.g., use current.trim().endsWith(NO_COMMIT_INSTRUCTION) or an
anchored regex) so you only skip when the instruction is the suffix. Keep the
append logic that sets out[valueIdx] = `${current} ${NO_COMMIT_INSTRUCTION}` but
ensure you trim/trail whitespace appropriately so you don't introduce double
spaces when adding the suffix.

Comment on lines 78 to +80
const commandResult = await sandbox.runCommand({
cmd: command,
args: args || [],
args: appendNoCommitInstruction(args || []),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Limit prompt mutation to OpenClaw agent invocations only.

At Line [80], appendNoCommitInstruction is applied to every command’s args, not just openclaw agent. This can unexpectedly rewrite unrelated --message flags.

Proposed fix
-      const commandResult = await sandbox.runCommand({
+      const normalizedArgs = args ?? [];
+      const shouldAppendNoCommit =
+        command === "openclaw" && normalizedArgs[0] === "agent";
+
+      const commandResult = await sandbox.runCommand({
         cmd: command,
-        args: appendNoCommitInstruction(args || []),
+        args: shouldAppendNoCommit
+          ? appendNoCommitInstruction(normalizedArgs)
+          : normalizedArgs,
         cwd,
         env: getSandboxEnv(accountId),
       });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const commandResult = await sandbox.runCommand({
cmd: command,
args: args || [],
args: appendNoCommitInstruction(args || []),
const normalizedArgs = args ?? [];
const shouldAppendNoCommit =
command === "openclaw" && normalizedArgs[0] === "agent";
const commandResult = await sandbox.runCommand({
cmd: command,
args: shouldAppendNoCommit
? appendNoCommitInstruction(normalizedArgs)
: normalizedArgs,
cwd,
env: getSandboxEnv(accountId),
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tasks/runSandboxCommandTask.ts` around lines 78 - 80, The code currently
applies appendNoCommitInstruction to every sandbox.runCommand invocation, which
can mutate unrelated commands; change the args passed to sandbox.runCommand so
appendNoCommitInstruction is only applied when invoking the OpenClaw agent
(check the command and first arg). Concretely, compute finalArgs = (command ===
'openclaw' && Array.isArray(args) && args[0] === 'agent') ?
appendNoCommitInstruction(args) : (args || []), then pass finalArgs into
sandbox.runCommand instead of always calling appendNoCommitInstruction(args ||
[]).

@sweetmantech sweetmantech merged commit 3dd5c8c into main Apr 15, 2026
2 checks passed
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.

1 participant