Skip to content

feat(send-command): add read-only mode toggle and write command blocking - #569

Open
RajGahoi wants to merge 2 commits into
valkey-io:mainfrom
RajGahoi:feat/send-command-readonly-mode
Open

RajGahoi wants to merge 2 commits into
valkey-io:mainfrom
RajGahoi:feat/send-command-readonly-mode

Conversation

@RajGahoi

Copy link
Copy Markdown
Contributor

Fixes #402

Description

This PR introduces a Read-Only Mode for the Send Command tool, preventing accidental or unintended mutation of Valkey servers and production clusters.

Key Changes

  1. Mutation & Write Command Classification Engine (common/src/command-restrictions.ts):
    • Implemented WRITE_COMMANDS: ReadonlySet covering mutating commands across strings (SET, INCR, APPEND, etc.), hashes (HSET, HDEL, etc.), lists (LPUSH, LPOP, LMOVE, etc.), sets (SADD, SREM, etc.), sorted sets (ZADD, ZREM, etc.), streams (XADD, XDEL, XGROUP, etc.), bitmaps (SETBIT, BITOP), hyperloglog (PFADD, PFMERGE), geospatial (GEOADD), server config (CONFIG SET, FLUSHALL), cluster topologies (CLUSTER MEET, CLUSTER ADDSLOTS), and RedisJSON (JSON.SET, JSON.DEL, etc.).
    • Implemented isWriteCommand(parsedArgs) and indReadOnlyBlockedCommand(parsedArgs).
  2. Server-Side Enforcement (�pps/server/src/actions/command.ts):
    • sendRequested inspects payload.readOnly. When active, prevents write commands from reaching GlideClient/GlideClusterClient and emits VALKEY.COMMAND.sendFailed with an informative error.
  3. Frontend UI & Safety Toggle (�pps/frontend/src/components/send-command/SendCommand.tsx):
    • Added an interactive Read-Only toggle button with shield icons beside the Send button.
    • Persisted user preference in localStorage (�alkey:send-command:readonly).
    • Prevents command dispatch and displays a toast notification (Read-only mode: ) when a write command is attempted.
    • Shows a subtle, clear Read-Only Mode indicator badge in the header when active.
  4. Comprehensive Test Coverage:
    • 100+ tests verified in common test suite covering read/write command classification.
    • Added unit tests for server action read-only validation.
    • Added unit tests for frontend command slice state handling.

- Add comprehensive write commands classification engine in valkey-common (isWriteCommand, findReadOnlyBlockedCommand) covering standard Valkey mutation commands across strings, hashes, sets, zsets, lists, streams, bitmaps, hyperloglog, geospatial, JSON, cluster, and server configuration
- Enforce read-only write prevention on the server in sendRequested action before execution
- Provide read-only safety mode toggle with persisted state in Send Command UI
- Block write command dispatch on frontend with descriptive error notification
- Display active Read-Only Mode badge and status indicator
- Add extensive test coverage in common, server, and frontend command slice

Fixes valkey-io#402

Signed-off-by: Raj Gahoi <gahoiraj01@gmail.com>
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 24 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4cb5095b-9177-47dd-a68a-65094eec2271
📥 Commits

Reviewing files that changed from the base of the PR and between 0161e2a and 9ae320d.

📒 Files selected for processing: 7
  • apps/frontend/src/components/send-command/SendCommand.tsx
  • apps/frontend/src/state/valkey-features/command/commandSlice.test.ts
  • apps/frontend/src/state/valkey-features/command/commandSlice.ts
  • apps/server/src/__tests__/command-restrictions-action.test.ts
  • apps/server/src/actions/command.ts
  • common/src/__tests__/command-restrictions.test.ts
  • common/src/command-restrictions.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added area/frontend UI components, state, routing area/server Backend, WebSocket, actions labels Oct 17, 2026
…uite

Signed-off-by: Raj Gahoi <gahoiraj01@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/frontend UI components, state, routing area/server Backend, WebSocket, actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add read-only mode for Send Command

1 participant