Skip to content

feat: add user input blocking lifecycle gates - #75035

Merged
clawsweeper[bot] merged 21 commits into
mainfrom
feat/input-blocking-hooks
May 6, 2026
Merged

clawsweeper[bot] merged 21 commits into
mainfrom
feat/input-blocking-hooks

Conversation

@jesse-merhi

@jesse-merhi jesse-merhi commented Apr 30, 2026 •

Copy link
Copy Markdown
Member

Summary

image
  • Adds a pass/block-only before_agent_run lifecycle hook before provider submission.
  • Treats the hook as raw conversation access and requires non-bundled plugins to opt in with hooks.allowConversationAccess=true.
  • When blocked, persists only a redacted user transcript stub plus non-sensitive block metadata.
  • Prevents blocked prompts from reaching image loading, model submission, llm_input, llm_output, future turn context, and visible agent fallback replies.
  • Removes the over-broad original blocked prompt retention/reveal plumbing from history, SSE, web, Android, iOS, macOS, and generated client models.

Validation

  • pnpm test src/plugins/hook-lifecycle-gates.test.ts src/plugins/loader.test.ts src/agents/pi-embedded-runner/run.incomplete-turn.test.ts src/agents/pi-embedded-runner/run/attempt.test.ts src/agents/cli-runner.reliability.test.ts src/gateway/server-methods/chat.directive-tags.test.ts src/gateway/session-utils.fs.test.ts src/gateway/session-history-state.test.ts src/gateway/sessions-history-http.revocation.test.ts src/gateway/session-message-events.test.ts ui/src/ui/chat/message-normalizer.test.ts
  • pnpm test src/agents/model-fallback.test.ts src/agents/pi-embedded-runner/run.incomplete-turn.test.ts src/agents/pi-embedded-runner/run/attempt.test.ts
  • pnpm test src/agents/pi-embedded-runner/run/attempt.spawn-workspace.context-engine.test.ts src/agents/pi-embedded-runner/run/attempt.test.ts src/plugins/hook-lifecycle-gates.test.ts
  • pnpm tsgo:prod
  • pnpm check:test-types
  • pnpm protocol:check
  • pnpm config:docs:check
  • git diff --check

Real behavior proof

Behavior or issue addressed: before_agent_run hooks can block user input before model submission while keeping the transcript redacted and avoiding downstream hook/model leakage.

Real environment tested: Local OpenClaw dev gateway from this PR branch on macOS, Control UI webchat, temporary local hitl-test plugin with hooks.allowConversationAccess=true, configured to block prompts containing hitl, block, or secret.

Exact steps or command run after this patch: Built runtime and Control UI, launched node dist/entry.js --dev gateway run --force --verbose, opened node dist/entry.js --dev dashboard, sent blocked webchat prompts containing the HITL trigger text, and inspected /tmp/openclaw/openclaw-2026-05-05.log.

Evidence after fix: Redacted live gateway log excerpt from the local run:

[plugins] [hooks] running before_agent_run (1 handlers, sequential)
[plugins] [hooks] before_agent_run gate-decision decided by hitl-test (priority=0); skipping remaining handlers
[agent/embedded] before_agent_run hook blocked by hitl-test: HITL test policy matched trigger text
[agent/embedded] embedded run prompt end: runId=... durationMs=15
[ws] → event session.message ...
[ws] → event agent ... phase=end

Observed result after fix: The blocked turn completed without provider/model submission, did not emit llm_input/llm_output, persisted only the redacted user message, and after the final patch did not show a duplicate agent bubble or Agent failed before reply fallback.

What was not tested: Full Testbox pnpm check:changed was not rerun locally during this follow-up; focused tests and local live gateway proof above covered the changed behavior.

@clawsweeper

clawsweeper Bot commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: passed.

Summary
The PR adds a before_agent_run plugin hook with pass/block decisions, redacted blocked-turn persistence, diagnostics/docs/changelog updates, and focused runner, gateway, session, and plugin tests.

Reproducibility: not applicable. as a feature PR rather than a current-main bug report. Current main lacks before_agent_run, while the PR head adds source coverage and copied live Gateway/WebChat log proof for the new behavior.

Real behavior proof
Not applicable: The external-contributor proof gate does not apply to this MEMBER PR, though the PR body includes copied redacted local Gateway/WebChat log proof for the changed behavior.

Next step before merge
No repair lane is needed; the remaining action is exact-head branch-protection/automerge handling, not a narrow code defect.

Security
Cleared: No concrete security or supply-chain regression found; the diff avoids workflow/dependency changes, gates raw conversation access for non-bundled plugins, and keeps blocked-run diagnostics to safe blocker metadata.

Review details

Best possible solution:

Land the exact reviewed head through the existing maintainer/automerge path once branch protection accepts it.

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

Not applicable as a feature PR rather than a current-main bug report. Current main lacks before_agent_run, while the PR head adds source coverage and copied live Gateway/WebChat log proof for the new behavior.

Is this the best way to solve the issue?

Yes. Placing the gate after prompt construction but before image loading, llm_input, and provider submission is the narrow maintainable boundary, with raw conversation access gated and blocked turns persisted as redacted user messages.

What I checked:

Likely related people:

  • vincentkoc: Recent main history added adjacent plugin hook contracts, model-call hooks, and hook type documentation; this PR is also assigned to this maintainer. (role: plugin hook owner and assigned reviewer; confidence: high; commits: f3accc753cf2, 275c128e99bc, 1b25dcf57a9f; files: src/plugins/hook-types.ts, src/plugins/hooks.ts, docs/plugins/hooks.md)
  • 100yenadmin: Recent main history changed generic plugin host-hook contracts, finalize retry behavior, and session extension slots adjacent to this public hook/API surface. (role: plugin SDK contract maintainer; confidence: medium; commits: 1adaa28dc86b, 8afc9ef73cb5, cb3853587576; files: src/plugins/hook-types.ts, src/plugins/hooks.ts, src/plugins/types.ts)
  • steipete: Recent main history heavily touches embedded runner flow, WebChat transcript persistence, outbound lifecycle, and session IO paths that this PR updates. (role: embedded runner and WebChat maintainer; confidence: high; commits: 2ead1502c9bf, 6147e1b91d3e, 35da7d2c992c; files: src/agents/pi-embedded-runner/run/attempt.ts, src/gateway/server-methods/chat.ts, src/auto-reply/reply/agent-runner.ts)

Remaining risk / open question:

  • GitHub currently reports mergeable_state=unstable for head 767e46fde8d5, so final automerge should still wait for branch protection on that exact head even though the queried check runs are successful.

Codex review notes: model gpt-5.5, reasoning high; reviewed against c4537fa6c3ca.

@openclaw-barnacle openclaw-barnacle Bot added app: macos App: macos app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Apr 30, 2026
@vincentkoc vincentkoc self-assigned this Apr 30, 2026
@jesse-merhi jesse-merhi self-assigned this May 1, 2026
Copilot AI review requested due to automatic review settings May 4, 2026 07:03
@jesse-merhi
jesse-merhi requested review from a team as code owners May 4, 2026 07:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: bluebubbles Channel integration: bluebubbles channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: nostr Channel integration: nostr channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: voice-call Channel integration: voice-call and removed app: web-ui App: web-ui labels May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge docs Improvements or additions to documentation extensions: diagnostics-otel Extension: diagnostics-otel extensions: diagnostics-prometheus gateway Gateway runtime maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants