Skip to content

Tool call observability: input sanitization, error categorization, and context writeback #55806

Description

@laterequation

Problem

Tool call logging captures some information but lacks key observability features needed for production auditing:

  1. Input parameters are not sanitized - full arguments are logged, potentially exposing sensitive data
  2. Errors are not categorized - only raw error messages, no structured error types
  3. No context writeback tracking - when tools write to files/memory, no record of what was written

Current State

What's logged:

embedded run tool start: runId=xxx tool=exec toolCallId=xxx
embedded run tool end: runId=xxx tool=exec toolCallId=xxx

What's in JSONL:

{
  "role": "toolResult",
  "toolName": "exec",
  "isError": false,
  "content": [...]
}

What's missing:

Feature Status
Input summary (sanitized) ❌ Full args exposed
Permission decision ❌ (see #55801)
Execution duration ⚠️ Computed from timestamps
Error category ❌ Raw message only
Context writeback ❌ Not tracked

Proposed Enhancement

1. Input Sanitization Log

Add a sanitized parameter summary at INFO level:

tool call: exec args={"command": "cat ~/.openclaw/...", "_sanitized": true}
tool call: gateway args={"action": "config.schema.lookup", "path": "tools"}
tool call: message args={"action": "send", "to": "***", "_redacted": ["message"]}

Rules:

  • File paths: keep but truncate if too long
  • Commands: truncate, don't log full multi-line scripts
  • API keys/tokens: always redact
  • Message content: redact or hash

2. Error Categorization

Add structured error type to toolResult:

{
  "errorType": "ENOENT",  // or "PERMISSION", "VALIDATION", "TIMEOUT", etc.
  "errorMessage": "no such file or directory",
  "errorRecoverable": true
}

Common categories:

  • ENOENT - file not found
  • PERMISSION - access denied
  • VALIDATION - invalid input
  • TIMEOUT - operation timed out
  • RATE_LIMIT - API rate limited
  • TOOL_ERROR - tool-specific error

3. Context Writeback Tracking

When tools write to files/memory, log what was written:

tool writeback: edit file=memory/2026-03-27.md lines=+5/-2
tool writeback: write file=WRITING_CHECKLIST.md bytes=2934
tool writeback: memory key="user.timezone" value="Asia/Shanghai"

This enables:

  • Audit trail of what changed
  • Recovery from bad writes
  • Understanding agent behavior

Benefits

  1. Security: Sanitized logs don't leak secrets
  2. Debugging: Categorized errors are easier to search/monitor
  3. Observability: Writeback tracking shows what the agent actually did

Related

Environment

  • OpenClaw version: 2026.3.24
  • Node: 22.22.0
  • OS: Linux (WSL2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions