feat(gateway): add audit logging for gateway tool calls#63557
feat(gateway): add audit logging for gateway tool calls#63557HOYALIM wants to merge 12 commits intoopenclaw:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a centralized, append-only gateway audit trail for tool execution that works across both direct POST /tools/invoke and OpenResponses (POST /v1/responses) ingress, with tool-argument redaction and propagation through embedded tool execution.
Changes:
- Introduces a
gateway-tool-audit.jsonlwriter + redaction helper and unit tests. - Wires
/tools/invoketo append an audit record per tool call. - Threads
gatewayToolAuditcontext from OpenResponses ingress into embedded runner/tool execution so wrapped tools can emit audit records.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/gateway/tools-invoke-http.ts | Appends a gateway tool-call audit record for direct /tools/invoke executions. |
| src/gateway/tools-invoke-http.test.ts | Mocks/assersts audit append behavior for /tools/invoke. |
| src/gateway/tool-audit.ts | New audit JSONL path resolution, argument sanitization/redaction, and append helper. |
| src/gateway/tool-audit.test.ts | Verifies JSONL write location and that secrets are redacted. |
| src/gateway/openresponses-http.ts | Propagates gateway audit context (incl. effective model) into agent command opts. |
| src/gateway/openresponses-http.test.ts | Asserts OpenResponses ingress sets gatewayToolAudit fields. |
| src/agents/pi-tools.ts | Threads gatewayToolAudit option into tool hook context construction. |
| src/agents/pi-tools.before-tool-call.ts | Emits audit records from the tool wrapper when gatewayToolAudit context is present. |
| src/agents/pi-embedded-runner/run/params.ts | Adds gatewayToolAudit to embedded runner params type. |
| src/agents/pi-embedded-runner/run/attempt.ts | Forwards gatewayToolAudit into embedded attempt execution. |
| src/agents/command/types.ts | Adds gatewayToolAudit to AgentCommandOpts. |
| src/agents/command/attempt-execution.ts | Forwards gatewayToolAudit from command opts into embedded runner invocation. |
Greptile SummaryAdds a centralized append-only JSONL audit sink ( Confidence Score: 5/5Safe to merge; all findings are P2 style/hardening suggestions with no correctness or data-loss impact. Core audit logic (redaction, record shape, path resolution, error swallowing) is correct and consistent across both ingress surfaces. Four P2 findings: file-mode enforcement gap for pre-existing files, non-serializable-args fallback losing structure, duplicated context object in tools-invoke-http.ts, and a misleading test assertion due to a passthrough mock. None affect correctness or produce wrong audit records under normal conditions. src/gateway/tool-audit.ts (file-mode and args-fallback), src/gateway/tools-invoke-http.ts (context duplication)
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6d58001930
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
6d58001 to
0cebea1
Compare
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a7aec1d9e3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
|
Codex review: found issues before merge. Summary Reproducibility: yes. The skipped-audit behavior is reproducible by static diff inspection: both proposed append sites are after blocked-call exits, and current main shows those denied branches return before execution. Next step before merge Security Review findings
Review detailsBest possible solution: Land a gateway-owned audit implementation on the current shared tool invocation and hook paths that records allowed and denied attempts with redacted args, status/reason metadata, focused tests, and a changelog entry. Do we have a high-confidence way to reproduce the issue? Yes. The skipped-audit behavior is reproducible by static diff inspection: both proposed append sites are after blocked-call exits, and current main shows those denied branches return before execution. Is this the best way to solve the issue? No. The direction is right, but the implementation should audit denied outcomes before returning and should be retargeted to current Full review comments:
Overall correctness: patch is incorrect Security concerns:
Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 5b2a0fbac198. |
Summary
Describe the problem and fix in 2–5 bullets:
/tools/invokerequests and OpenResponses ingress runs.gateway-tool-audit.jsonlhelper with tool-argument redaction, threaded gateway audit context through ingress → embedded tool execution, and wired both/tools/invokeand/v1/responsesinto the same centralized JSONL audit sink.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause (if applicable)
For bug fixes or regressions, explain why this happened, not just what changed. Otherwise write
N/A. If the cause is unclear, writeUnknown./tools/invokeand OpenResponses-originated tool calls lacked a centralized append-only record.Regression Test Plan (if applicable)
For bug fixes or regressions, name the smallest reliable test coverage that should catch this. Otherwise write
N/A.src/gateway/tool-audit.test.tssrc/gateway/tools-invoke-http.test.tssrc/gateway/openresponses-http.test.ts/tools/invokeingress, and OpenResponses ingress without needing broad runtime E2E.User-visible / Behavior Changes
Gateway-originated tool calls now append structured audit records to
~/.openclaw/logs/gateway-tool-audit.jsonlwith redacted tool args and metadata including surface, session, channel, model, runId, and toolCallId.Diagram (if applicable)
For UI changes or non-trivial logic flows, include a small ASCII diagram reviewers can scan quickly. Otherwise write
N/A.Security Impact (required)
No)Yes)No)No)Yes)Yes, explain risk + mitigation:logging.redactSensitive="tools"behavior before write, and records are written under the existing state/logs path with explicit file-mode restrictions.Repro + Verification
Environment
model: openclaw; direct/tools/invokehas no model/tools/invokeand/v1/responseslogging.redactSensitive="tools")Steps
/tools/invokerequest for an allowed tool.~/.openclaw/logs/gateway-tool-audit.jsonl.Expected
surface,tool,session,channel,model,runId, andtoolCallIdwhen available.Actual
Evidence
Attach at least one:
Trace/log snippets:
{"ts":"2026-04-08T20:00:00.000Z","source":"gateway","event":"tool.call","surface":"tools-invoke","tool":"exec","args":{"command":"OPENAI_API_KEY=sk-sec…7890"},"session":"agent:main:main","channel":"discord","model":null,"runId":"run-1","toolCallId":"call-1"}Human Verification (required)
What you personally verified (not just CI), and how:
pnpm test -- src/gateway/tool-audit.test.ts src/gateway/tools-invoke-http.test.ts src/gateway/openresponses-http.test.ts/tools/invokepath actually emits an audit record (not just context propagation)pnpm check/pnpm buildas a branch-local clean gate, because latestorigin/mainstill has unrelated pre-existing failures inextensions/msteamsandsrc/agents/skills*Review Conversations
If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.
Compatibility / Migration
Yes)No)No)Risks and Mitigations
List only real risks for this PR. Add/remove entries as needed. If none, write
None.logging.redactPatternsconfiguration is honored by the shared redaction helper.