Skip to the content.

Experimental pre-registered CLI wrapper

This repository-local experiment launches Codex or Pi with a GPTQueue identity that exists before the coding agent starts. It supplies per-launch MCP configuration and uses the installed codex and pi CLIs. Their own startup code can still write global runtime state; configuration-content and cache isolation are measured by the verifier below. The experiment does not restart the live GPTQueue HTTP server on port 8101.

Lifecycle

  1. gptqueue-experiment atomically claims the requested name, then registers it directly against an explicitly non-db0 Redis database. Every mode refuses an active same-name agent; non-destructive close mode may reuse an offline registry identity and its retained mailbox. The wrapper verifies that its new session is still the only active session before launching and atomically re-verifies that ownership in the same Redis transaction that removes a disposable session and mailbox. If another session appeared, the transaction closes only the wrapper’s session and preserves shared state.
  2. It starts an authenticated MCP bridge on an ephemeral loopback port. The bridge owns the registered GPTQueue session; the app-level session_id never enters the agent prompt, command line, or environment. Ambient REDIS_URL and live-server token variables are also removed from the child environment; the CLI receives only the per-launch bridge URL and token.
  3. Codex receives a per-launch MCP configuration override. Pi receives a one-run local extension backed by the already-installed pi-mcp-adapter.
  4. The bridge exposes exactly send_message, receive_message, list_agents, and get_queue_status. Pi disables adapter scripting and filters tool registration/activation, including the adapter’s fallback proxy. Before inference it waits for discovery and checks the actual active catalog; a missing or unexpected tool terminates the child. These are restrictions on the model’s tools, not an operating-system sandbox for trusted extensions.
  5. When the CLI exits, the bridge stops and the wrapper closes the session. --cleanup unregister additionally deletes the named test mailbox and is intended only for disposable test identities. That mode also requires the registry name to be fresh, so it cannot adopt and later delete an existing offline identity.

Bridge teardown force-closes lingering HTTP connections after a short grace period. After child termination, Redis/bridge cleanup has a 10-second budget; expiry forces the wrapper’s Redis connections closed and produces a nonzero exit while preserving the identity claim for inspection. Child termination can add up to six seconds. A second signal kills a running child, or forces cleanup connections closed when the child has already exited. Initial Redis claim acquisition is not covered by this cleanup deadline.

Child configuration and state scope:

Receive cancellation and delivery

Every bridge receive owns a separate blocking Redis connection. MCP request cancellation, transport-session termination, or bridge shutdown closes that connection without interrupting other receives or registration heartbeats. The cancelled request does not issue further pops or reconnect/replay a pop.

Delivery remains at most once: a Redis pop that has already executed when cancellation or a network failure races its response may have consumed the message without the caller receiving it. The wrapper does not requeue an uncertain result or claim acknowledgement-based delivery guarantees.

Build and run

Create a disposable workspace inside the repository and build first:

mkdir -p .gptqueue/registered-wrapper-workspace
npm run build

Codex example:

node bin/gptqueue-experiment codex \
  --agent gptqueue-experiment-codex \
  --workspace .gptqueue/registered-wrapper-workspace \
  -- 'Call list_agents and report whether gptqueue-experiment-codex is present.'

Pi example:

node bin/gptqueue-experiment pi \
  --agent gptqueue-experiment-pi \
  --workspace .gptqueue/registered-wrapper-workspace \
  -- 'Call list_agents and report whether gptqueue-experiment-pi is present.'

The wrapper defaults to Redis db14, and it refuses db0 even when explicitly requested. The REDIS_URL environment variable is not used as an implicit override; pass --redis-url when selecting another isolated database, either as redis://host[:port]/<db> or as a unix socket path /path/redis.sock?db=<1-15> (a socket path without ?db= selects db0 and is refused). The destructive --cleanup unregister mode additionally requires a fresh name starting with gptqueue-experiment-; the wrapper refuses a pre-existing name. All modes refuse a name already claimed by another wrapper or backed by an active GPTQueue session/heartbeat. Claims fail closed: an uncatchable process kill at any point while a claim is held can leave a claim key in the selected isolated database, which an operator must inspect before removing. The bridge limits receive_message to 1-60 seconds. If the claim disappears or is replaced during shutdown, the wrapper exits nonzero and closes its connections without deleting state it no longer owns.

Repeatable verification

Run the focused regression suite directly with Node/vitest:

npm run build
node node_modules/vitest/vitest.mjs run tests/experimental-wrapper*.test.ts

Vitest starts its own private, socket-only Redis for the run (docs/OPERATING_RULES.md §10); there is no Redis URL to pass.

The suite covers cancellation followed by delayed delivery, concurrent receive isolation, transport deletion, bridge shutdown, the Pi tool filter and startup gate, forged session IDs, explicitly seeded private environment variables, and connection cleanup after identity-claim loss.

With permission to use the installed CLIs/model providers, run the Linux-local live verifier. It starts its own private, socket-only Redis and uses db14 there, so it never touches a shared server:

node scripts/verify-registered-wrapper.mjs --live

It requires db14 to start empty, gates both real CLI launches on registration and loopback/catalog checks, then verifies a correlated Codex-to-Pi-to-Codex exchange and Pi’s active tools. It uses the installed default models, checks global configuration hashes and Pi cache metadata, and checks that new Pi files remain in the expected runtime directory. Both sends use explicit retry keys; the verifier checks their message IDs and deletes only those two exact keys. It requires db14 to return to empty and never flushes it. The verification shim adds Pi’s JSON output mode for tool-call evidence.

Evidence and transcripts are saved under .gptqueue/wrapper-verification/. Configuration-content changes, Pi cache metadata changes, unexpected tools, bad correlation, nonzero wrapper exits, or Redis residue fail verification. Codex configuration mtime changes with identical contents are recorded without failing. The verifier bounds live runs to four minutes plus termination time; forced termination can leave fail-closed identity residue requiring inspection.

Pi adapter provenance

The wrapper uses an existing pi-mcp-adapter installation (MIT) and never installs anything. Override the inspected local entrypoint with GPTQ_PI_MCP_ADAPTER_ENTRY when necessary.