Skip to content

API Reference parrot.e2e.targets.redis

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.e2e.targets.redis

View source

Private, persistence-disabled Redis process provisioning (FEAT-581, M4).

Spec §2 "Target and Authentication Design" requires the botmanager minimal target to authenticate through real navigator-session Redis-backed sessions, using "a private local Redis process with persistence disabled, unique port and data directory" and never the operator's shared Redis instance. This module owns exactly that provisioning step:

  • :func:find_redis_server_binary — resolve the redis-server binary on PATH, or fail BLOCKED (spec §2: "Missing redis-server blocks required authenticated scenarios; plain MCP scenarios still execute.").
  • :func:allocate_loopback_port — allocate one free loopback port (same free-port technique as :mod:parrot.e2e.targets.mcp's own private _free_loopback_port, duplicated here rather than shared — this package's own established convention of not sharing private per-module helpers; see :mod:parrot.e2e.state's module docstring).
  • :func:build_redis_argv — the literal, never-shell redis-server argv with persistence fully disabled (--save "", --appendonly no).
  • :func:spawn_private_redis — start one private instance and block until it answers a raw-socket PING, or raise.

This module is intentionally dependency-light (standard library only, no parrot.tools/navigator_session/BotManager imports) so it can be imported both from the E2E harness's own (async, long-running) process — to verify the binary and allocate a port during :meth:parrot.e2e.targets.base. TargetAdapter.prepare — and, unmodified, from a target child's own synchronous bootstrap script (:mod:parrot.e2e.targets.botmanager's run_app_entrypoint), which spawns the private instance before importing anything navconfig/navigator_session-related, per the verified session research contract (sdd/state/FEAT-581/research/session.md §6 item 1).

Every function here only ever provisions a new, private instance bound to loopback on a caller-chosen port and data directory — nothing in this module ever inspects, connects to, or otherwise touches an already-running Redis instance (the operator's shared instance is never contacted).

Class RedisEndpoint

One private Redis instance's location — never the operator's shared instance.

Parameter Type Default Description
host str
port int
data_dir Path

Fields:

Field Type Default Description
host str Loopback host the instance is bound to.
port int Loopback port the instance is bound to.
data_dir Path This instance's own private, persistence-disabled data directory.

Function allocate_loopback_port

Allocate one currently-free loopback TCP port.

allocate_loopback_port() -> int

Returns: int — A port number free at the moment of the call (spec §2: "unique port ... per run"). A subsequent bind race is handled by redis-server's own startup failure, not by this helper.

Function build_redis_argv

Build the literal redis-server argv for one private, persistence-disabled instance.

build_redis_argv(binary: str, *, host: str, port: int, data_dir: Path) -> list[str]

Parameter Type Default Description
binary str Absolute path to the redis-server executable.
host str Loopback host to bind (never a wildcard/public address).
port int Loopback port to bind.
data_dir Path This instance's own private data directory (already created).

Returns: list[str] — The literal argv — never a shell string, matching class:parrot.e2e.targets.base.LaunchSpec's own contract. --save "" and --appendonly no disable persistence entirely (spec §2: "private local Redis process with persistence disabled"); --protected-mode no is required because loopback-only binding alone still refuses unauthenticated clients under Redis's default protected mode.

Function find_redis_server_binary

Locate the redis-server binary on PATH, or fail BLOCKED.

find_redis_server_binary() -> str

Returns: str — The resolved absolute path to the redis-server executable.

Raises:

  • E2EPrerequisiteError — If no redis-server binary is found (spec §2: "Missing redis-server blocks required authenticated scenarios; plain MCP scenarios still execute."), raised before any subprocess is spawned.

Function spawn_private_redis

Start one private, persistence-disabled redis-server and wait for it.

Runs entirely synchronously (no asyncio): intended to be called from a target child's own bootstrap script, before that process starts serving its own application (spec §2: distinct port/data directory per run, never the operator's shared Redis). Deliberately never calls start_new_session — the spawned process inherits the caller's own process group, so the supervisor's single killpg on the top-level target process also reaches this Redis child (spec §2's own owned process-group teardown model).

spawn_private_redis(*, host: str, port: int, data_dir: Path, timeout_s: float = 10.0, binary: Optional[str] = None) -> tuple['subprocess.Popen[bytes]', RedisEndpoint]

Parameter Type Default Description
host str Loopback host to bind (never a wildcard/public address).
port int Loopback port to bind — already allocated by the caller (spec §2: "unique port ... per run"), never re-allocated here.
data_dir Path This instance's own private data directory; created (mode 0700) if missing.
timeout_s float 10.0 Maximum seconds to wait for the instance to answer PING.
binary Optional[str] None Optional explicit path to redis-server; resolved via :func:find_redis_server_binary when not given.

Returns: tuple['subprocess.Popen[bytes]', RedisEndpoint] — (process, endpoint). The caller owns process's lifetime.

Raises:

  • E2EPrerequisiteError — If no redis-server binary can be found.
  • E2ETargetError — If the instance cannot be spawned, exits early, or never becomes ready.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally