-
Notifications
You must be signed in to change notification settings - Fork 465
fix(openclaw): restore 2026.9 compatibility for 1.0.5 #796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // @vitest-environment node | ||
| import { beforeEach, describe, expect, it } from "vitest"; | ||
| import { evaluatePolicies } from "../../src/hooks/policy-evaluator"; | ||
| import { clearPolicies, registerPolicy } from "../../src/hooks/policy-registry"; | ||
|
|
||
| const OPERATIONS_WORKSPACE_RE = /(?:^|\/)operations(?:\/|$)/; | ||
| const REVIEW_CHECKPOINT_RE = /\brequires_manual_review\b/; | ||
| const NOTIFICATION_SEND_RE = /\bopenclaw\s+message\s+send\b[\s\S]*?(?:--channel\s+slack|-c\s+slack)[\s\S]*?(?:-t\s+C0123456789|--target\s+C0123456789)/i; | ||
| const FAILURE_STATUS_RE = /(?:needs\s+review|couldn['’]?t\s+process)/i; | ||
|
|
||
| describe("OpenClaw instruct policy", () => { | ||
| beforeEach(() => { | ||
| clearPolicies(); | ||
| registerPolicy("retry-before-action", "generic recovery", (ctx) => { | ||
| if (ctx.cli !== "openclaw") return { decision: "allow" }; | ||
| if (!OPERATIONS_WORKSPACE_RE.test(String(ctx.session?.cwd ?? ""))) return { decision: "allow" }; | ||
|
|
||
| const toolInput = JSON.stringify(ctx.toolInput ?? {}); | ||
| const isReviewCheckpoint = REVIEW_CHECKPOINT_RE.test(toolInput); | ||
| const isNotification = | ||
| ctx.toolName === "Bash" && | ||
| NOTIFICATION_SEND_RE.test(toolInput) && | ||
| FAILURE_STATUS_RE.test(toolInput); | ||
|
|
||
| if (!isReviewCheckpoint && !isNotification) return { decision: "allow" }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| return { decision: "instruct", reason: "make one more evidence-backed recovery pass" }; | ||
| }, { events: ["PreToolUse"] }); | ||
| }); | ||
|
|
||
| it("emits an OpenClaw instruct verdict for a matching escalation", async () => { | ||
| const result = await evaluatePolicies("PreToolUse", { | ||
| tool_name: "Bash", | ||
| tool_input: { | ||
| command: "openclaw message send --channel slack -t C0123456789 --message 'Needs review: couldn’t process record'", | ||
| }, | ||
| cwd: "/Users/tester/.openclaw/workspace/operations", | ||
| }, { | ||
| cli: "openclaw", | ||
| cwd: "/Users/tester/.openclaw/workspace/operations", | ||
| }); | ||
|
|
||
| expect(result.decision).toBe("instruct"); | ||
| expect(JSON.parse(result.stdout)).toMatchObject({ | ||
| permission: "instruct", | ||
| policyName: "failproofai/retry-before-action", | ||
| }); | ||
| }); | ||
|
|
||
| it("instructs on a review checkpoint without requiring a notification command", async () => { | ||
| const result = await evaluatePolicies("PreToolUse", { | ||
| tool_name: "Write", | ||
| tool_input: { path: "status.json", content: "requires_manual_review" }, | ||
| cwd: "/Users/tester/.openclaw/workspace/operations", | ||
| }, { | ||
| cli: "openclaw", | ||
| cwd: "/Users/tester/.openclaw/workspace/operations", | ||
| }); | ||
|
|
||
| expect(result.decision).toBe("instruct"); | ||
| expect(JSON.parse(result.stdout)).toMatchObject({ | ||
| permission: "instruct", | ||
| policyName: "failproofai/retry-before-action", | ||
| }); | ||
| }); | ||
|
|
||
| it("does not affect unrelated OpenClaw Slack sends", async () => { | ||
| const result = await evaluatePolicies("PreToolUse", { | ||
| tool_name: "Bash", | ||
| tool_input: { | ||
| command: "openclaw message send --channel slack -t C0123456789 --message 'Record processed successfully'", | ||
| }, | ||
| cwd: "/Users/tester/.openclaw/workspace/operations", | ||
| }, { | ||
| cli: "openclaw", | ||
| cwd: "/Users/tester/.openclaw/workspace/operations", | ||
| }); | ||
|
|
||
| expect(result.decision).toBe("allow"); | ||
| expect(result.stdout).toBe(""); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // @vitest-environment node | ||
| import { describe, expect, it } from "vitest"; | ||
| import { | ||
| createInstructRetryGate, | ||
| mapBeforeToolVerdict, | ||
| } from "../../openclaw-plugin/instruct-retry-gate.js"; | ||
|
|
||
| describe("OpenClaw instruct retry gate", () => { | ||
| it("interrupts the first instruction and permits retries during the window", () => { | ||
| let now = 1_000; | ||
| const gate = createInstructRetryGate({ windowMs: 300_000, now: () => now }); | ||
| const verdict = { | ||
| permission: "instruct", | ||
| reason: "recover once", | ||
| policyName: "failproofai/retry-before-escalation", | ||
| }; | ||
| const ctx = { sessionKey: "recovery-session" }; | ||
|
|
||
| expect(gate.shouldInterrupt(verdict, {}, ctx)).toBe(true); | ||
| expect(gate.shouldInterrupt(verdict, {}, ctx)).toBe(false); | ||
|
|
||
| now += 300_001; | ||
| expect(gate.shouldInterrupt(verdict, {}, ctx)).toBe(true); | ||
| }); | ||
|
|
||
| it("keeps sessions and policies independent", () => { | ||
| const gate = createInstructRetryGate(); | ||
| const recovery = { permission: "instruct", reason: "recover", policyName: "recovery" }; | ||
| const security = { permission: "instruct", reason: "review", policyName: "security" }; | ||
|
|
||
| expect(gate.shouldInterrupt(recovery, {}, { sessionKey: "one" })).toBe(true); | ||
| expect(gate.shouldInterrupt(recovery, {}, { sessionKey: "one" })).toBe(false); | ||
| expect(gate.shouldInterrupt(security, {}, { sessionKey: "one" })).toBe(true); | ||
| expect(gate.shouldInterrupt(recovery, {}, { sessionKey: "two" })).toBe(true); | ||
| }); | ||
|
|
||
| it("keeps separate OpenClaw runs independent within one session", () => { | ||
| const gate = createInstructRetryGate(); | ||
| const verdict = { permission: "instruct", reason: "recover", policyName: "recovery" }; | ||
|
|
||
| expect(gate.shouldInterrupt(verdict, {}, { sessionKey: "one", runId: "run-a" })).toBe(true); | ||
| expect(gate.shouldInterrupt(verdict, {}, { sessionKey: "one", runId: "run-a" })).toBe(false); | ||
| expect(gate.shouldInterrupt(verdict, {}, { sessionKey: "one", runId: "run-b" })).toBe(true); | ||
| }); | ||
|
|
||
| it("does not share a retry window between anonymous invocations", () => { | ||
| const gate = createInstructRetryGate(); | ||
| const verdict = { permission: "instruct", reason: "recover", policyName: "recovery" }; | ||
|
|
||
| expect(gate.shouldInterrupt(verdict, {}, {})).toBe(true); | ||
| expect(gate.shouldInterrupt(verdict, {}, {})).toBe(true); | ||
| }); | ||
|
|
||
| it("clears the retry window when the session ends", () => { | ||
| const gate = createInstructRetryGate(); | ||
| const verdict = { permission: "instruct", reason: "recover", policyName: "recovery" }; | ||
| const ctx = { sessionKey: "recovery-session", runId: "recovery-run" }; | ||
|
|
||
| expect(gate.shouldInterrupt(verdict, {}, ctx)).toBe(true); | ||
| expect(gate.shouldInterrupt(verdict, {}, ctx)).toBe(false); | ||
| gate.clear({}, { sessionKey: "recovery-session" }); | ||
| expect(gate.shouldInterrupt(verdict, {}, ctx)).toBe(true); | ||
| }); | ||
|
|
||
| it("maps deny permanently and instruct to a one-shot model-visible rejection", () => { | ||
| const gate = createInstructRetryGate(); | ||
| const ctx = { sessionKey: "recovery-session" }; | ||
| const deny = { permission: "deny", reason: "never send this" }; | ||
| const instruct = { | ||
| permission: "instruct", | ||
| reason: "perform one more recovery pass", | ||
| policyName: "recovery", | ||
| }; | ||
|
|
||
| expect(mapBeforeToolVerdict(deny, {}, ctx, gate)).toEqual({ | ||
| block: true, | ||
| blockReason: "never send this", | ||
| }); | ||
| expect(mapBeforeToolVerdict(deny, {}, ctx, gate)).toEqual({ | ||
| block: true, | ||
| blockReason: "never send this", | ||
| }); | ||
| expect(mapBeforeToolVerdict(instruct, {}, ctx, gate)).toEqual({ | ||
| block: true, | ||
| blockReason: "perform one more recovery pass", | ||
| }); | ||
| expect(mapBeforeToolVerdict(instruct, {}, ctx, gate)).toBeUndefined(); | ||
| expect(mapBeforeToolVerdict({ permission: "allow" }, {}, ctx, gate)).toBeUndefined(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.