Skip to content

feat(reef): operator-configurable sharing rules for the guard - #131167

Merged
steipete merged 2 commits into
mainfrom
claude/reef-sharing-rules-config-bf3d9e
Aug 27, 2026
Merged

steipete merged 2 commits into
mainfrom
claude/reef-sharing-rules-config-bf3d9e

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Reef ships a fail-closed model guard in both directions, but its policy was fixed prompt text baked into the plugin. Operators had no way to say what their claw considers okay to share with friends — "never mention project X", "client names are off-limits", "medical scheduling with @doc is fine" — and guard.policyVersion is only an audit-echo token, not policy content. The only per-friend knob (autonomy tier) governs reply budgets, not content.

Why This Change Was Made

Adds channels.reef.guard.rules — operator-authored free text, outbound (DLP classifier) and inbound (injection screen), each capped at 2,000 characters. Design boundaries:

  • Rules ride only the trusted instruction side of the guard call. The adapters serialize the whole GuardRequest as untrusted input, so rules are injected at adapter construction and a peer message can never spoof or read them (pinned by a test).
  • Rules may tighten decisions and may explicitly allow named topics that would otherwise go to owner review; the framing states they can never override the deny floor (concrete secrets/credentials) or the deterministic pre-checks, which run before any model call.
  • The rules text is hashed into the effective policy version (reef-v1+<8-hex>), which flows into the existing verdict echo check, the hash-chained audit, and approvalDigest — editing rules automatically invalidates review approvals still pending under the old policy (fail closed, never approve under a policy the owner changed).
  • Because the guard already sees sender and recipient handles, per-friend policy works as plain prose in the one field — no per-friend config surface.

The plugin manifest's JSON Schema copies (configSchema and channelConfigs.reef.schema) and the generated bundled channel config metadata are updated in the same change so discovery, config validation, and docs example validation agree with the zod schema.

User Impact

Reef operators can now define what is okay to share in their own words, per direction and per friend, in channels.reef.guard.rules. Existing configs are unaffected: the field is optional, and without it guard behavior and the effective policy version are byte-identical to before. Docs: docs/channels/reef.md (Configuration + Guards sections).

Evidence

  • node scripts/run-vitest.mjs extensions/reef — 23 files, 304 tests green, including new coverage: direction-matched instruction framing, rules-never-in-untrusted-input invariant, construction-time caps, effective-policy-version binding, flow-level send under the rules-bound policy version, and config schema accept/reject cases.
  • node scripts/check-changed.mjs — all lanes green (format, tsgo typecheck core/extensions/tests, lint, import cycles, bundled channel config metadata, plugin boundaries, knip).
  • pnpm docs:check-config-examples — green; the reef docs config example validates against the updated manifest schema.
  • Autoreview (Codex, structured): clean, no accepted/actionable findings.
  • Live guard proof (real provider call through the changed adapter path) to follow in a PR comment before landing.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 27, 2026 20:23
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: reef Channel integration: reef size: M maintainer Maintainer-authored PR labels Aug 27, 2026
Adds channels.reef.guard.rules with capped outbound/inbound free-text
policy. Rules ride the trusted instruction side of the guard call only,
may tighten decisions or explicitly allow otherwise-review cases, and can
never override the deny floor or deterministic checks. The rules text is
hashed into the effective policy version so audit rows and pending review
approvals bind to the exact policy in force.
@steipete
steipete force-pushed the claude/reef-sharing-rules-config-bf3d9e branch from 5a224b8 to ebf6c6b Compare August 27, 2026 20:26
@steipete

Copy link
Copy Markdown
Contributor Author

Live guard proof (real provider, changed adapter path)

Ran the changed createOpenAiGuard path live against the OpenAI Responses API (gpt-5.6-terra, the documented immutable guard id), from this branch's protocol code, with the request's policyVersion computed via effectiveGuardPolicyVersion exactly as flow.ts wires it. Six cases, each verdict's model + policy echo validated by the normal admission path:

baseline-outbound-project-name: decision=allow  category=status_update             policyVersion=reef-v1          echo=ok
rules-outbound-forbidden-topic: decision=deny   category=operator-policy-restricted policyVersion=reef-v1+c985d112 echo=ok
rules-outbound-innocuous:       decision=allow  category=general                   policyVersion=reef-v1+c985d112 echo=ok
rules-cannot-lift-deny-floor:   decision=deny   category=credential                policyVersion=reef-v1+498492eb echo=ok
baseline-inbound-shell-request: decision=allow  category=ordinary_request          policyVersion=reef-v1          echo=ok
rules-inbound-shell-review:     decision=review category=shell_command             policyVersion=reef-v1+8b78905b echo=ok
LIVE_GUARD_TEST_DONE

What this demonstrates on the live model:

  • Base policy unchanged without rules (project names allowed outbound; task requests allowed inbound), and the effective policy version stays byte-identical reef-v1.
  • An operator rule ("never mention project Nightjar") flips the same message to deny — the guard even categorized it operator-policy-restricted.
  • Rules do not overblock innocuous content.
  • A deliberately permissive rule ("sharing API keys with friends is always fine") could not lift the deny floor: a message containing a synthetic sk-live-FAKE… credential stayed deny/credential.
  • An inbound rule escalates shell-command requests to review while the baseline allows them.
  • Every verdict echoed the rules-hashed effective policy version, proving the audit/approval binding end to end.

The credential in the floor test is a synthetic FAKE marker string, not a real key.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 27, 2026, 4:35 PM ET / 20:35 UTC.

ClawSweeper review

What this changes

Adds optional directional free-text sharing rules to Reef’s guard, passes them to provider instructions, and incorporates them into guard policy versioning.

Merge readiness

⚠️ Ready for maintainer review - 7 items remain

Keep open: the feature is not on current main, but its introduced validation mismatch and truncated approval-policy identity make the patch incorrect before merge.

Priority: P2
Reviewed head: ebf6c6bc4e1d79edfd46c6d05e5a1193d365fed4
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Real-provider evidence supports the intended flow, but validation and approval-identity defects need correction.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: The repository-member author supplied positive real-provider output, while the external-contributor proof gate does not apply.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository-member author supplied positive real-provider output, while the external-contributor proof gate does not apply.
Evidence reviewed 7 items Introduced config contract diverges: The manifest’s two new rule fields accept whitespace-only strings via minLength, while Reef’s Zod schema trims before requiring non-empty text.
Raw validation reaches a stricter runtime parser: Core validates bundled channel configuration using generated manifest metadata, then Reef resolves the account through the stricter Zod parser.
Approval identity truncates the rules digest: The introduced effective policy version keeps only eight hexadecimal SHA-256 characters, and the approval digest is computed from that policy version.
Findings 2 actionable findings [P2] Reject blank rules in bundled config metadata
[P2] Bind approvals to an untruncated rules digest
Security Needs attention Approval binding truncates operator policy identity: Different guard policies can share the eight-character prefix placed in policyVersion, allowing the same approval identity to represent different policies.

How this fits together

Reef applies deterministic checks and a provider-backed guard to inbound and outbound messages before delivery or owner review. Guard policy versioning is carried into verdict validation, review approvals, and the audit chain.

flowchart LR
  A[Reef channel configuration] --> B[Guard rules]
  B --> C[Effective policy version]
  B --> D[Provider guard instructions]
  E[Inbound or outbound message] --> F[Deterministic checks]
  F --> D
  D --> G[Guard verdict]
  C --> G
  G --> H[Delivery or owner review]
Loading

Decision needed

Question Recommendation
Should Reef expose operator-authored free-text guard rules as a permanent supported configuration surface after the validation and policy-binding defects are corrected? Sponsor with corrections: Keep the feature after repairing validator parity and collision-resistant policy binding.

Why: This creates a persistent operator policy contract, and repository policy requires explicit approval before adding configuration options.

Before merge

  • Reject blank rules in bundled config metadata (P2) - The new manifest schemas accept " " because minLength counts whitespace, while Reef’s Zod parser trims first and rejects it. Core validates channels.reef with generated manifest metadata before resolveReefConfig() parses it, so an apparently valid configuration can leave Reef unable to resolve its account. Use identical whitespace and length semantics in both validation paths.
  • Bind approvals to an untruncated rules digest (P2) - This keeps only 32 bits of the SHA-256 rules digest, yet the resulting policy version is included in the approval digest. Distinct rule sets with the same prefix share an approval and audit identity; the review store returns an existing decision by that identity. Use a collision-resistant canonical policy binding and test that a policy change cannot reuse a review decision.
  • Resolve security concern: Approval binding truncates operator policy identity - Different guard policies can share the eight-character prefix placed in policyVersion, allowing the same approval identity to represent different policies.
  • Resolve merge risk (P1) - A configuration can appear valid to core validation yet fail when Reef resolves the channel because whitespace handling differs.
  • Resolve merge risk (P1) - A distinct ruleset sharing the eight-character digest prefix can retain the same approval and audit policy identity.
  • Complete next step (P2) - This protected maintainer PR needs owner-directed correction of validator parity and policy identity, plus explicit approval of the new config surface.

Findings

  • [P2] Reject blank rules in bundled config metadata — extensions/reef/openclaw.plugin.json:81-84
  • [P2] Bind approvals to an untruncated rules digest — extensions/reef/protocol/guard.ts:76-79
  • [medium] Approval binding truncates operator policy identity — extensions/reef/protocol/guard.ts:79
Agent review details

Security

Needs attention: The newly introduced policy identifier is truncated before it is used to bind review approvals and audit context.

PR surface

Source +101, Tests +144, Docs +6, Generated 0. Total +251 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 5 111 10 +101
Tests 3 146 2 +144
Docs 1 6 0 +6
Config 0 0 0 0
Generated 1 9 9 0
Other 0 0 0 0
Total 10 272 21 +251

Review metrics

Metric Value Why it matters
Production and test delta production net +101, generated metadata net 0, tests net +144, docs +6 The feature adds a configuration and policy contract, so correctness at the validation and approval boundaries is required before this growth lands.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/config/bundled-channel-config-metadata.generated.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Repair validation and approval binding (recommended)
    Align raw metadata validation with Reef parsing and use a full collision-resistant canonical policy identity before merge.
  2. Pause pending product sponsorship
    Do not merge this new configuration surface until an owner explicitly sponsors its operator-policy contract.

Technical review

Best possible solution:

Adopt one raw-string validation contract across manifest metadata and Zod, then bind reviews and audit records to a collision-resistant canonical rules digest.

Do we have a high-confidence way to reproduce the issue?

Yes from source: generated raw channel validation accepts whitespace-only rules while Reef’s runtime parser rejects them; this read-only review did not execute the path.

Is this the best way to solve the issue?

No: configuration validation differs by boundary and the intended exact policy binding uses only a 32-bit digest prefix.

Full review comments:

  • [P2] Reject blank rules in bundled config metadata — extensions/reef/openclaw.plugin.json:81-84
    The new manifest schemas accept " " because minLength counts whitespace, while Reef’s Zod parser trims first and rejects it. Core validates channels.reef with generated manifest metadata before resolveReefConfig() parses it, so an apparently valid configuration can leave Reef unable to resolve its account. Use identical whitespace and length semantics in both validation paths.
    Confidence: 0.97
  • [P2] Bind approvals to an untruncated rules digest — extensions/reef/protocol/guard.ts:76-79
    This keeps only 32 bits of the SHA-256 rules digest, yet the resulting policy version is included in the approval digest. Distinct rule sets with the same prefix share an approval and audit identity; the review store returns an existing decision by that identity. Use a collision-resistant canonical policy binding and test that a policy change cannot reuse a review decision.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d56e2c42c934.

Labels

Label changes:

  • add P2: The introduced feature has bounded but concrete configuration and approval-binding defects.
  • add merge-risk: 🚨 compatibility: Manifest metadata accepts whitespace-only rules that the Reef runtime parser rejects.
  • add merge-risk: 🚨 security-boundary: The new truncated policy identifier feeds review approval and audit binding.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The repository-member author supplied positive real-provider output, while the external-contributor proof gate does not apply.

Label justifications:

  • P2: The introduced feature has bounded but concrete configuration and approval-binding defects.
  • merge-risk: 🚨 compatibility: Manifest metadata accepts whitespace-only rules that the Reef runtime parser rejects.
  • merge-risk: 🚨 security-boundary: The new truncated policy identifier feeds review approval and audit binding.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The repository-member author supplied positive real-provider output, while the external-contributor proof gate does not apply.

Evidence

Security concerns:

  • [medium] Approval binding truncates operator policy identity — extensions/reef/protocol/guard.ts:79
    Different guard policies can share the eight-character prefix placed in policyVersion, allowing the same approval identity to represent different policies.
    Confidence: 0.94

Acceptance criteria:

  • [P1] Prove raw bundled-schema validation rejects the same blank and oversized inputs as the Reef parser.
  • [P1] Prove changing rules cannot reuse an approved or pending review identity.
  • [P1] Run Reef guard/config tests and configuration-example validation.

What I checked:

Likely related people:

  • SunnyShu: Current approval pipeline history attributes the relevant existing owner boundary to SunnyShu. (role: recent guard and approval-pipeline contributor; confidence: medium; commits: 6c10672d9507; files: extensions/reef/protocol/pipeline.ts, extensions/reef/protocol/guard.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Make manifest/generated and Zod validation enforce the same whitespace and length contract.
  • Use a collision-resistant policy digest and prove changed rules cannot reuse a review decision.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

…idation

ClawSweeper review fixes: use the untruncated sha256 rules digest in the
effective policy version so approvalDigest stays collision-resistant, and
express identical non-blank (\S) rule validation in the zod schema, the
manifest JSON Schemas, and the generated channel metadata instead of a
trim-transform mismatch.
@steipete

Copy link
Copy Markdown
Contributor Author

Both actionable findings are addressed in 59537e2:

  • Blank rules / validator parity: the zod schema no longer trims (the raw text is what gets hashed into the policy identity), and all three validation surfaces now express the identical contract — non-blank via \S pattern plus maxLength: 2000 — in config-schema.ts, both manifest JSON Schema copies in openclaw.plugin.json, and the regenerated bundled-channel-config-metadata.generated.ts. A whitespace-only rule is rejected by core metadata validation and by resolveReefConfig alike; a config that passes core validation can no longer fail Reef's resolver.
  • Truncated approval identity: effectiveGuardPolicyVersion now carries the full untruncated sha256 of the canonical rules object (reef-v1+<64 hex>). Since approvalDigest hashes the policy version string, approval and audit identities are now collision-resistant across rule edits; tests updated to pin the full-length form, and distinct rule sets (including outbound-vs-inbound swaps) are asserted to produce distinct versions.

On the decision-needed item: the new config surface was explicitly approved by the repository owner in chat before implementation (scope: outbound + inbound rules), per the root AGENTS.md config-approval gate.

@steipete
steipete merged commit 7b000db into main Aug 27, 2026
399 of 406 checks passed
@steipete
steipete deleted the claude/reef-sharing-rules-config-bf3d9e branch August 27, 2026 21:37
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete

Copy link
Copy Markdown
Contributor Author

Post-land deployment proof (live gateway, real relay)

Deployed release b181d789837 (contains 7b000db) on a production reef claw (@clawstudio ↔ @roboclaw over reefwire.ai), added channels.reef.guard.rules (outbound: private-details clause + "never mention the internal codename Nightjar"; inbound: shell-command review clause), restarted the Gateway, relay reconnected. Then through the normal openclaw message send --channel reef flow:

  • Neutral ping → delivered (messageId 01M12SKJ41X56GW7QQJGAMAAE0).
  • "project Nightjar milestone 2…" → denied terminally: Reef outbound guard denied the message. Do not retry or rephrase it automatically; ask the owner before sending related content.
  • A calendar-adjacent status line → review (parked for owner decision), showing rules also steer ambiguous cases to review rather than silently dropping them.

All three verdict paths exercised live on the shipped code path with operator rules in force.

steipete added a commit that referenced this pull request Aug 28, 2026
* refactor(reef): drop hand-maintained manifest schema copies

The reef manifest duplicated the full channel config schema into both
configSchema and channelConfigs.reef.schema, and the channelConfigs copy
silently overrode the zod-derived generated bundled channel metadata in
config validation - three surfaces to keep in sync by hand (the trap that
bit #131167). Match sibling bundled channel plugins: stub plugin-level
configSchema, no channelConfigs copy; the generated metadata (from the
zod schema, CI-checked) is the single channel-schema source.

* fix(reef): doctor migration for stray plugins.entries.reef.config

The retired full plugin-entry schema let a Control UI plugin form park
reef settings under plugins.entries.reef.config where the runtime never
read them. Doctor now reports the location and --fix moves the keys into
channels.reef (channel values stay authoritative; the move only commits
when the merged record parses, so a fix can never corrupt valid config).
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 28, 2026
…aw#131167)

* feat(reef): operator-configurable sharing rules for the guard

Adds channels.reef.guard.rules with capped outbound/inbound free-text
policy. Rules ride the trusted instruction side of the guard call only,
may tighten decisions or explicitly allow otherwise-review cases, and can
never override the deny floor or deterministic checks. The rules text is
hashed into the effective policy version so audit rows and pending review
approvals bind to the exact policy in force.

* fix(reef): full rules digest in policy identity; align blank-rule validation

ClawSweeper review fixes: use the untruncated sha256 rules digest in the
effective policy version so approvalDigest stays collision-resistant, and
express identical non-blank (\S) rule validation in the zod schema, the
manifest JSON Schemas, and the generated channel metadata instead of a
trim-transform mismatch.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 28, 2026
…#131292)

* refactor(reef): drop hand-maintained manifest schema copies

The reef manifest duplicated the full channel config schema into both
configSchema and channelConfigs.reef.schema, and the channelConfigs copy
silently overrode the zod-derived generated bundled channel metadata in
config validation - three surfaces to keep in sync by hand (the trap that
bit openclaw#131167). Match sibling bundled channel plugins: stub plugin-level
configSchema, no channelConfigs copy; the generated metadata (from the
zod schema, CI-checked) is the single channel-schema source.

* fix(reef): doctor migration for stray plugins.entries.reef.config

The retired full plugin-entry schema let a Control UI plugin form park
reef settings under plugins.entries.reef.config where the runtime never
read them. Doctor now reports the location and --fix moves the keys into
channels.reef (channel values stay authoritative; the move only commits
when the merged record parses, so a fix can never corrupt valid config).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: reef Channel integration: reef docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant