Skip to content

refactor(agents): split message-tool into concept modules - #121901

Merged
steipete merged 3 commits into
mainfrom
steipete/split-message-tool
Aug 11, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/split-message-tool

Conversation

@steipete

@steipete steipete commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

src/agents/tools/message-tool.ts had grown to 2,037 lines and required a grandfathered max-lines suppression, making the model-facing message tool harder to navigate and maintain safely.

Why This Change Was Made

The monolith is split at its existing concept seams, with no behavior, tool name, schema, description, or action-flow changes:

  • message-tool-execution.ts — factory, dispatch, idempotency, and poll-echo lifecycle (696 lines)
  • message-tool-schema.ts — TypeBox action and payload schemas (498 lines)
  • message-tool-visible-content.ts — outbound visible-text sanitization (393 lines)
  • message-tool-discovery.ts — channel capability/action discovery and descriptions (308 lines)
  • message-tool-source-policy.ts — current-source reply authority and validation (197 lines)

The five manageable modules replace the original file directly; five importer files now target the execution module, with no re-export wrapper. The obsolete max-lines suppression and baseline entry are removed, and the critical CodeQL boundary follows the new concept-module prefix.

AI-assisted; implementation and proof reviewed by the author.

User Impact

None. This is a behavior-neutral source organization change; the model-visible tool contract remains unchanged.

Evidence

  • node scripts/run-vitest.mjs src/agents/tools/message-tool — 230 tests passed
  • node scripts/run-vitest.mjs src/agents/openclaw-tools.tts-config.test.ts src/agents/openclaw-tools.sessions.test.ts — 48 tests passed
  • pnpm build — passed; no [INEFFECTIVE_DYNAMIC_IMPORT] warning
  • node --import tsx scripts/check-export-name-collisions.mts — passed
  • pnpm check:wrapper-shadowing — passed, 64 current / 64 baselined
  • pnpm check:import-cycles — passed, 0 runtime value cycles
  • pnpm check:max-lines-ratchet --base origin/main — passed; baseline reduced by one
  • git diff --check — passed
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main — clean; no accepted/actionable findings

LOC classification: production +2,093/-2,038 (net +55, split-boundary imports/exports only); tests/test support +5/-5 (net 0); max-lines baseline +0/-1.

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Aug 11, 2026
@steipete
steipete marked this pull request as ready for review August 11, 2026 06:31
@clawsweeper clawsweeper Bot added 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 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 11, 2026, 2:59 AM ET / 06:59 UTC.

ClawSweeper review

What this changes

The PR replaces the monolithic message tool with five concept-focused modules and redirects agent-tool importers to the new execution module.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep this maintainer PR open: the split leaves the critical CodeQL boundary configured for the deleted monolith, so its replacement modules would no longer receive that security analysis.

Priority: P2
Reviewed head: dfd120bc626ad51b2984176723e9fb72122a69a8

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The split is focused, but the missing security-boundary configuration update is a merge-blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored, behavior-neutral refactor is not subject to the external contributor real-behavior-proof gate; the PR body supplies focused automated validation claims.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored, behavior-neutral refactor is not subject to the external contributor real-behavior-proof gate; the PR body supplies focused automated validation claims.
Evidence reviewed 5 items Moved runtime entry point: The PR-head execution module now owns the message-tool factory and imports the split source-reply policy and visible-content sanitization modules.
Stale critical-security path: The CodeQL boundary still names only src/agents/tools/message-tool.ts, which this PR deletes; the PR does not change this configuration.
Security workflow contract: The repository CodeQL workflow selects this critical MCP/process tool-boundary configuration, so its paths are the scan boundary rather than inert metadata.
Findings 1 actionable finding [P1] Keep the split modules inside the CodeQL boundary
Security Needs attention Critical CodeQL scope no longer follows the message tool: The critical security configuration retains the removed monolithic path and does not include any of the five replacement modules that now implement message delivery and source-reply policy.

How this fits together

The agent message tool turns model requests into channel actions, applying schema discovery, source-reply restrictions, and visible-content sanitization before dispatching through outbound delivery. Its security-sensitive paths feed configured channel plugins and Gateway-backed message delivery.

flowchart LR
  A[Agent tool request] --> B[Message tool entry]
  B --> C[Schema and channel discovery]
  B --> D[Source reply and content policy]
  C --> E[Outbound action runner]
  D --> E
  E --> F[Channel plugins]
  F --> G[Delivered message]
Loading

Before merge

  • Keep the split modules inside the CodeQL boundary (P1) - The critical CodeQL configuration still scans only message-tool.ts, which this PR deletes. The new tool entry point and its source-reply/content-policy modules therefore fall outside the configured security scan; update the path list for the replacement modules before merging.
  • Resolve security concern: Critical CodeQL scope no longer follows the message tool - The critical security configuration retains the removed monolithic path and does not include any of the five replacement modules that now implement message delivery and source-reply policy.
  • Resolve merge risk (P1) - Merging unchanged would leave the critical CodeQL boundary pointing at a deleted file and exclude the new message execution, source-policy, schema, discovery, and visible-content modules from that scan.
  • Complete next step (P2) - This protected maintainer PR needs its security-boundary configuration corrected before ordinary merge review can resume.

Findings

  • [P1] Keep the split modules inside the CodeQL boundary — src/agents/tools/message-tool-execution.ts:236
  • [medium] Critical CodeQL scope no longer follows the message tool — .github/codeql/codeql-mcp-process-tool-boundary-critical-security.yml:37
Agent review details

Security

Needs attention: The refactor creates a concrete security-analysis blind spot by leaving CodeQL scoped to the deleted message-tool file.

PR surface

Source +55, Tests 0, Other -1. Total +54 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 8 2094 2039 +55
Tests 3 4 4 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 12 2098 2044 +54

Review metrics

Metric Value Why it matters
Production versus test LOC production +55; tests/test support 0 net; max-lines baseline -1 The source relocation is nearly net-neutral, but its security-analysis path must move with the production entry point.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/agents/tools/message-tool-source-policy.ts, migration/backfill/repair: src/agents/tools/message-tool.ts, unknown-data-model-change: src/agents/tools/message-tool-schema.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Restore CodeQL coverage before merge (recommended)
    Update the critical security configuration to cover each replacement message-tool module and verify the corresponding analysis still runs on them.

Technical review

Best possible solution:

Replace the deleted CodeQL path with coverage for all five split message-tool modules, then rerun the relevant security analysis before merge.

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

Yes: at the PR head, the tool factory is in a new module while the configured CodeQL boundary still names only the deleted original path.

Is this the best way to solve the issue?

No: the source split is coherent, but it must preserve the existing critical security scan coverage by updating the CodeQL path list.

Full review comments:

  • [P1] Keep the split modules inside the CodeQL boundary — src/agents/tools/message-tool-execution.ts:236
    The critical CodeQL configuration still scans only message-tool.ts, which this PR deletes. The new tool entry point and its source-reply/content-policy modules therefore fall outside the configured security scan; update the path list for the replacement modules before merging.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded merge-blocking security-analysis coverage regression in a refactor, without evidence of an active runtime exploit.
  • add merge-risk: 🚨 security-boundary: The refactor removes the only message-tool path selected by the critical CodeQL boundary and does not add replacement paths.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool 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: This maintainer-authored, behavior-neutral refactor is not subject to the external contributor real-behavior-proof gate; the PR body supplies focused automated validation claims.

Label justifications:

  • P2: This is a bounded merge-blocking security-analysis coverage regression in a refactor, without evidence of an active runtime exploit.
  • merge-risk: 🚨 security-boundary: The refactor removes the only message-tool path selected by the critical CodeQL boundary and does not add replacement paths.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored, behavior-neutral refactor is not subject to the external contributor real-behavior-proof gate; the PR body supplies focused automated validation claims.

Evidence

Security concerns:

  • [medium] Critical CodeQL scope no longer follows the message tool — .github/codeql/codeql-mcp-process-tool-boundary-critical-security.yml:37
    The critical security configuration retains the removed monolithic path and does not include any of the five replacement modules that now implement message delivery and source-reply policy.
    Confidence: 0.99

What I checked:

Likely related people:

  • steipete: Current-main history for the message-tool path identifies Peter Steinberger's recent agent-tool refactor. (role: recent agent-tool refactor author; confidence: high; commits: 36fbd869eda1; files: src/agents/tools/message-tool.ts, src/agents/openclaw-tools.ts)
  • Paul Campbell: Blame attributes the CodeQL path selection that needs updating to this author. (role: security-boundary path author; confidence: high; commits: 6bd83561ad50; files: .github/codeql/codeql-mcp-process-tool-boundary-critical-security.yml)

Rank-up moves

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

  • Update the critical CodeQL paths for the split modules and verify that scan against the repaired head.

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.

@steipete
steipete requested a review from a team as a code owner August 11, 2026 07:16
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready at 3306e6375cbf214b2df5b15f31c499d3b85d42b4.

ClawSweeper's CodeQL-boundary finding is addressed by 3306e6375cb: the critical security scope now follows src/agents/tools/message-tool-*.ts.

Local proof:

  • node scripts/run-vitest.mjs src/agents/tools/message-tool — 230 passed
  • node scripts/run-vitest.mjs src/agents/openclaw-tools.tts-config.test.ts src/agents/openclaw-tools.sessions.test.ts — 48 passed
  • pnpm build — passed; no [INEFFECTIVE_DYNAMIC_IMPORT]
  • node --import tsx scripts/check-export-name-collisions.mts — passed
  • pnpm check:wrapper-shadowing — passed (64 current / 64 baselined)
  • pnpm check:import-cycles — passed (0 runtime value cycles)
  • pnpm check:max-lines-ratchet --base origin/main — passed; baseline reduced by one
  • git diff --check — passed
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main — clean, no actionable findings

Hosted proof:

Known proof gaps: none. No user-visible behavior, schema, description, docs, or changelog change.

@steipete
steipete merged commit 2b8dbc3 into main Aug 11, 2026
123 of 125 checks passed
@steipete
steipete deleted the steipete/split-message-tool branch August 11, 2026 07:31
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 12, 2026
…21901)

* refactor(agents): split message-tool into concept modules

* fix(agents): restore message-tool split imports

* ci: preserve message-tool CodeQL boundary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR 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: XL 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