Skip to content

Allow opt-in raw Redis responses in Python agent - #1295

Open
Amygos wants to merge 1 commit into
mainfrom
feat-agent-raw-redis-responses
Open

Allow opt-in raw Redis responses in Python agent#1295
Amygos wants to merge 1 commit into
mainfrom
feat-agent-raw-redis-responses

Conversation

@Amygos

@Amygos Amygos commented Sep 4, 2026

Copy link
Copy Markdown
Member

Summary

The ns8-metrics module needs to validate publisher-controlled Redis
hashes one key, field, and value at a time.

Previously, agent.redis_connect() always enabled automatic UTF-8
response decoding. A malformed value such as b"\xff" therefore raised
UnicodeDecodeError inside SCAN or HGETALL, before ns8-metrics could
identify and reject only the invalid publisher entry. This could abort
Prometheus provisioning for all publishers.

This PR adds the keyword-only decode_responses argument:

  • decode_responses=True remains the default, preserving existing
    behavior for all callers.
  • decode_responses=False creates a genuinely raw Redis connection and
    returns unchanged bytes from scan_iter() and hgetall().
  • Primary/replica selection, credentials, connection options, and
    existing positional arguments remain unchanged.

The API remains generic and contains no metrics-specific validation.

Related issue

No issue linked yet.

How to test

Run the agent test suite:

cd core/agent
bash test-agent.sh

On an installed node, verify that the default client returns strings and
that a client created with decode_responses=False returns bytes from
scan_iter() and hgetall().

During development, the behavior was verified against a real Redis
server with malformed UTF-8 in keys, hash fields, and hash values. The
complete existing agent suite passed 32 tests.

Compatibility

Existing modules remain compatible because decoded string responses are
still the default. Consumers must explicitly pass
decode_responses=False to receive bytes.

A module relying on the new public argument must require an ns8-core
release containing this change or provide a compatibility fallback.

Dependencies

No dependency is required for merging this PR.

@Amygos Amygos self-assigned this Sep 4, 2026
@Amygos Amygos added testing Start test suite and removed testing Start test suite labels Sep 4, 2026
Opt-in byte responses let consumers perform strict per-entry decoding
without changing existing decoded clients.

Assisted-by: Codex:GPT-5
@Amygos
Amygos force-pushed the feat-agent-raw-redis-responses branch from d498e63 to 661cfea Compare September 4, 2026 11:40
@Amygos
Amygos marked this pull request as ready for review September 4, 2026 11:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-04T11:43:14.894536Z 661cfea Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Amygos

Amygos commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

The autogenerated tests have been removed before marking the PR ready to review.

@DavidePrincipi DavidePrincipi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This PR leaves the previous behavior unchanged. Even if it improves code readability, It is actually a no-op.

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