Skip to content

Add privacy-preserving JSONL RPC message logger#173

Merged
pelikhan merged 6 commits intomainfrom
copilot/add-rpc-message-logger
Jan 12, 2026
Merged

Add privacy-preserving JSONL RPC message logger#173
pelikhan merged 6 commits intomainfrom
copilot/add-rpc-message-logger

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 11, 2026

Implementation: Privacy-Preserving JSONL RPC Message Logger

Summary

Successfully implemented a privacy-preserving JSONL RPC message logger with simplified regex-based sanitization and strict JSONL format compliance.

Implementation Complete

  • Created jsonl_logger.go with simplified sanitization
    • Apply regex patterns directly to entire string
    • Marshal/unmarshal to ensure single-line JSON output (JSONL compliance)
    • Store sanitized string as json.RawMessage
    • Invalid JSON wrapped in error object for valid JSONL output
  • Created comprehensive unit tests (11 tests, all passing)
    • Added test for multi-line JSON compaction
  • Integrated with existing RPC logging infrastructure
  • Initialized in root.go alongside other loggers
  • All tests pass: 149 unit + 13 integration tests ✅
  • Code formatted and lint-clean

Key Changes

Simplified approach with JSONL compliance:

  • ✅ Regex the entire string in one pass, regardless of JSON structure
  • ✅ Marshal/unmarshal step compacts JSON to single line (removes newlines/whitespace)
  • ✅ JSONL format compliant (one complete JSON object per line)
  • ✅ Direct storage as json.RawMessage for efficiency
  • ✅ Maintains all security guarantees

JSONL Format Compliance

  • Single-line guarantee: Marshal/unmarshal ensures no newlines in output
  • Valid JSON per line: Each log entry is a complete, parseable JSON object
  • Standard format: Compatible with standard JSONL tools and parsers

Performance Benefits

  • Minimal parsing: Single unmarshal/marshal for compaction only
  • Single regex pass: One sanitization pass across entire payload
  • Efficient storage: Compacted JSON reduces file size

File Locations

  • JSONL logs: rpc-messages.jsonl in configured log directory
  • Default path: /tmp/gh-aw/mcp-logs/rpc-messages.jsonl
Original prompt

Create a RPC message logger that writes all messages to a .jsonl file in the log directory. Privacy preserving.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Created jsonl_logger.go with JSONLLogger implementation
- Logs all RPC messages to rpc-messages.jsonl in JSONL format
- Privacy-preserving: sanitizes secrets in JSON payloads
- Supports nested structures and arrays
- Comprehensive test coverage in jsonl_logger_test.go
- Integrated with existing RPC logging (LogRPCRequest/Response)
- Initialized in root.go alongside other loggers

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add RPC message logger to write messages to JSONL file Add privacy-preserving JSONL RPC message logger Jan 11, 2026
Copilot AI requested a review from pelikhan January 11, 2026 21:19
@pelikhan pelikhan marked this pull request as ready for review January 11, 2026 23:51
Copy link
Copy Markdown
Collaborator

@pelikhan pelikhan left a comment

Choose a reason for hiding this comment

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

@copilot just regex the entire JSON payload in one shot

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot format, lint

- Removed complex recursive sanitization logic
- Now applies regex patterns directly to the entire JSON string
- Added JSON-specific regex pattern for field:value pairs
- Simpler, more efficient implementation as suggested
- All tests pass including new JSON-specific sanitization

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 11, 2026

@copilot just regex the entire JSON payload in one shot

Done! Simplified to apply regex patterns directly to the entire JSON payload string in one shot. Removed the complex recursive traversal logic and added a JSON-specific regex pattern for "field":"value" pairs. Much cleaner implementation. (commit 0871bf8)

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 11, 2026

@copilot format, lint

Done! make format and make lint both pass with no issues. Code is already properly formatted and lint-clean.

@pelikhan
Copy link
Copy Markdown
Collaborator

- Convert if-else chain to tagged switch statement in jsonl_logger_test.go
- Addresses QF1003 staticcheck warning
- All tests pass, golangci-lint clean

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 12, 2026

Fix lint issues in https://github.com/githubnext/gh-aw-mcpg/actions/runs/20904020680/job/60054354876#step:6:1

@copilot

Fixed! Converted if-else chain to switch statement to address staticcheck QF1003 warning. golangci-lint now passes with 0 issues. (commit 44d349d)

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot regex the entire string, regardless of JSON in one run.

- Changed Payload field to json.RawMessage (stores raw sanitized bytes)
- Apply regex sanitization directly to entire string without parsing
- No intermediate JSON unmarshaling/marshaling for valid JSON
- Invalid JSON wrapped in error object for valid JSONL output
- More efficient: single regex pass on raw string
- All tests updated and passing

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 12, 2026

@copilot regex the entire string, regardless of JSON in one run.

Done! Now applying regex to the entire string in one pass without any JSON parsing/unparsing. Changed Payload to json.RawMessage to store the sanitized string directly. Much more efficient - single regex pass on raw bytes with no intermediate JSON operations. (commit 17abe01)

Comment thread internal/logger/jsonl_logger.go Outdated
return json.RawMessage(wrappedBytes)
}

return json.RawMessage(sanitized)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot Marshall, unmarshal to ensure single line JSON

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done! Added marshal/unmarshal step to compact JSON and ensure single-line output for JSONL format compliance. Multi-line JSON is now compacted by unmarshaling to interface{} and marshaling back, removing all newlines/whitespace. Added test to verify. (commit 60d4bc5)

- Added marshal/unmarshal step to compact JSON (removes newlines/whitespace)
- Ensures JSONL format compliance (one JSON object per line)
- Added test for multi-line JSON compacting
- All tests pass

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan January 12, 2026 00:28
@pelikhan pelikhan merged commit db4003e into main Jan 12, 2026
3 checks passed
@pelikhan pelikhan deleted the copilot/add-rpc-message-logger branch January 12, 2026 00:33
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.

2 participants