Skip to content

feat: add honcho capture hygiene controls#82

Open
de1tydev wants to merge 2 commits into
plastic-labs:mainfrom
de1tydev:feat/honcho-capture-hygiene
Open

feat: add honcho capture hygiene controls#82
de1tydev wants to merge 2 commits into
plastic-labs:mainfrom
de1tydev:feat/honcho-capture-hygiene

Conversation

@de1tydev
Copy link
Copy Markdown

@de1tydev de1tydev commented May 2, 2026

Summary

  • strip OpenClaw startup/reset/runtime scaffolding before persisting messages to Honcho
  • add configurable session isolation patterns for capture, defaulting to cron/heartbeat/temp utility sessions only
  • add NO_REPLY to default noise patterns and keep subagent sessions captured by default

This is split out from #78 and intentionally excludes prompt-injection controls and dedupe/flush-lock behavior.

Notes

  • inferProviderFromSessionKey is intentionally not included here to avoid relying on OpenClaw session-key heuristics.
  • Subagent sessions are not skipped by default; users can opt in with a custom isolatedSessionPatterns entry if needed.

Validation

  • pnpm exec vitest run test/helpers.test.ts
  • pnpm build

Summary by CodeRabbit

  • New Features

    • Added stripRuntimeScaffolding configuration option (enabled by default) to clean up system scaffolding from captured messages.
    • Introduced isolatedSessionPatterns configuration to exclude specified session types from message capture.
    • Enhanced message cleaning with support for filtering runtime metadata and system envelope content.
  • Tests

    • Added comprehensive test coverage for message cleaning and session isolation logic.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 2, 2026

Walkthrough

The PR extends message capture configuration with two features: conditional removal of runtime scaffolding before saving messages, and session isolation to exclude cron/heartbeat/temp-slug sessions from capture. It adds type fields, schema validation, message cleaning logic, session matching helpers, hook integration, and test coverage.

Changes

Message Capture Filtering & Runtime Scaffolding Cleanup

Layer / File(s) Summary
Config Schema & Type Extensions
config.ts
HonchoConfig gains stripRuntimeScaffolding and isolatedSessionPatterns fields. New DEFAULT_ISOLATED_SESSION_PATTERNS constant provides default cron/heartbeat/temp-slug regex patterns. Schema parser uses parseStringArray helper to normalize and deduplicate both noise and isolated-session patterns, returning computed values in the config object.
Plugin Configuration Schema & UI
openclaw.plugin.json
Plugin schema defines stripRuntimeScaffolding (boolean, default true) and isolatedSessionPatterns (string array with defaults) as user-configurable properties. Corresponding UI hints provide labels, help text, and advanced flags for each option.
Message Cleaning & Session Isolation Logic
helpers.ts
CleanMessageOptions type enables optional scaffolding stripping. shouldIsolateSession matches session keys against literal strings or /regex/flags patterns. cleanMessageContent strips runtime tags, metadata, and optionally startup context when scaffolding removal is enabled. extractMessages accepts clean options and passes them through to message content cleaning.
Capture Hook Integration
hooks/capture.ts
flushMessages now imports and checks shouldIsolateSession against configured patterns, returning early without saving if isolation criteria match. Message extraction call passes through the stripRuntimeScaffolding config flag to control cleanup behavior.
Test Coverage for Cleaning & Isolation
test/helpers.test.ts
Tests verify cleanMessageContent strips runtime scaffolding by default, removes system envelopes, preserves user text, and cleans reply tags. Tests verify shouldIsolateSession isolates cron/heartbeat/temp-slug patterns, treats invalid regex-like strings as literals, and passes through normal sessions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A fuzzy hop through code so clean,
Runtime scaffolding falls unseen,
Sessions isolated, patterns aligned,
Message capture refined in mind,
Tests confirm our changes true!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding configurable controls for cleaning and isolating message captures to Honcho.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

…-hygiene

# Conflicts:
#	hooks/capture.ts
#	test/helpers.test.ts
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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@hooks/capture.ts`:
- Around line 29-32: Resolve the agentId and sessionKey before calling
shouldIsolateSession to ensure the same agent fallback is used for isolation
checks and later flushing; specifically, move the agentId resolution (const
agentId = ctx.agentId ?? state.resolveDefaultAgentId()) and sessionKey creation
(const sessionKey = buildSessionKey({ sessionKey: ctx.sessionKey, agentId })) so
they occur prior to the shouldIsolateSession(...) call, and then call
shouldIsolateSession(ctx, state.cfg.isolatedSessionPatterns, sessionKey) or
otherwise pass the computed sessionKey/agentId into
shouldIsolateSession/flushMessages so both use the same resolved agentId and
built session key.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4fa7e2a0-0690-4fd1-95ed-85904a292f84

📥 Commits

Reviewing files that changed from the base of the PR and between bb546c2 and 480be6c.

📒 Files selected for processing (5)
  • config.ts
  • helpers.ts
  • hooks/capture.ts
  • openclaw.plugin.json
  • test/helpers.test.ts

Comment thread hooks/capture.ts
Comment on lines +29 to 32
if (shouldIsolateSession(ctx, state.cfg.isolatedSessionPatterns)) return 0;

const agentId = ctx.agentId ?? state.resolveDefaultAgentId();
const sessionKey = buildSessionKey({ sessionKey: ctx.sessionKey, agentId });
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 | 🟡 Minor | ⚡ Quick win

Resolve agentId before evaluating session isolation.

Isolation currently runs before default agentId resolution. If ctx.agentId is absent, built-key matching inside shouldIsolateSession can use a different agent fallback than the one used later in flushMessages, so custom built-key patterns may not match.

Suggested fix
-  if (!messages?.length) return 0;
-  if (shouldIsolateSession(ctx, state.cfg.isolatedSessionPatterns)) return 0;
-
-  const agentId = ctx.agentId ?? state.resolveDefaultAgentId();
+  if (!messages?.length) return 0;
+  const agentId = ctx.agentId ?? state.resolveDefaultAgentId();
+  if (shouldIsolateSession({ ...ctx, agentId }, state.cfg.isolatedSessionPatterns)) return 0;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@hooks/capture.ts` around lines 29 - 32, Resolve the agentId and sessionKey
before calling shouldIsolateSession to ensure the same agent fallback is used
for isolation checks and later flushing; specifically, move the agentId
resolution (const agentId = ctx.agentId ?? state.resolveDefaultAgentId()) and
sessionKey creation (const sessionKey = buildSessionKey({ sessionKey:
ctx.sessionKey, agentId })) so they occur prior to the shouldIsolateSession(...)
call, and then call shouldIsolateSession(ctx, state.cfg.isolatedSessionPatterns,
sessionKey) or otherwise pass the computed sessionKey/agentId into
shouldIsolateSession/flushMessages so both use the same resolved agentId and
built session key.

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