Skip to content

fix(agent-host): keep the Pi provider token out of the model's processes - #200

Merged
deymosh merged 3 commits into
masterfrom
fix/pi-provider-token-pipe
Nov 18, 2026
Merged

deymosh merged 3 commits into
masterfrom
fix/pi-provider-token-pipe

Conversation

@deymosh

@deymosh deymosh commented Nov 18, 2026

Copy link
Copy Markdown
Owner

What

A Pi session bound to a provider profile no longer exposes the profile's token to anything the model starts.

The leak (reproduced live before the fix): the driver passed the token in CODEDECK_PI_PROVIDER_TOKEN, which Pi read for every request. Pi's bash gets Pi's whole environment, so ./codedeck live pi --fake-model --prompt "/tool node -p process.env.CODEDECK_PI_PROVIDER_TOKEN" printed the token. Background shells, sub-agents and MCP servers inherited it too.

Why not just delete it inside Pi: on Linux, /proc/<pid>/environ keeps a process's starting environment even after delete process.env.X — checked in a node:22-slim container, where a child read the deleted value back from its parent. Any process of the same user (the model's bash) can read it.

The route

The token never enters Pi's environment:

  • the driver spawns Pi with a fourth stdio pipe (fd 3), writes the token and closes it (rpc.ts);
  • the extension reads fd 3 to the end as it loads, before anything can start a process, and registers the token as the profile's apiKey, escaped so Pi's config syntax ($NAME, a leading !) takes it literally (extension/provider.ts);
  • Node passes a child only the stdio it is given, so nothing Pi starts gets the pipe (checked on Windows and Linux: a grandchild has no fd 3);
  • a sub-agent's Pi gets the token on its own pipe from its parent (extension/task.ts);
  • the memory tool refused secret-named variables' values; the token is in no variable now, so it is passed in and refused explicitly;
  • LSP servers no longer need to strip the token variable (there isn't one); they still drop the profile variable.

Without a token (a wrapper that doesn't hand fd 3 on), the profile is registered keyless, the extension writes a stderr line that the driver logs, and requests fail with Pi's "No API key" error.

Tests

  • piFakeModel.test.ts (the real Pi CLI, runs in CI): the fake model now requires the profile's token (--key), and the token holds a leading ! and a $, so every turn proves Pi got the exact token through the escaping. Two new tests dump the environment of the model's shell, a background shell and a sub-agent's shell, plus Pi's own /proc environ on Linux, using shell builtins only. None holds the token.
  • Proven by breaking the code: with the token put back in Pi's env, both tests fail (Windows). With the token in the env and the extension deleting it at load, the main test fails on Linux at the /proc check.
  • Unit tests: the driver hands the token over on the pipe and nowhere in the env, with no pipe for a session without a profile; configLiteral; readProviderToken; the keyless registration; memory refusing the token; the fake model's 401.

Verified: ./codedeck check --changed green (host typecheck/test/build, Android); the Pi tests and fake-model tests on Linux (CODEDECK_ENGINE=docker), 155/155; live ./codedeck live pi --fake-model after the fix: the variable prints undefined, and the full export -p dump does not contain the token.

PowerShell (Windows) isn't tested separately. It runs with Pi's own environment, the same one as bash, and that environment no longer holds the token.

Traffic cost: none, nothing changes on the wire.
Data: nothing persisted changes.

🤖 Generated with Claude Code

deymosh and others added 3 commits November 18, 2026 20:58
With a key (--key, or the key option in process), a model request that
does not carry it as a bearer token or an x-api-key is answered 401,
without echoing what was sent. A test can then prove an agent sent the
key it was given, not just some key. Without one, any key is taken, as
before.

Co-Authored-By: Claude Code <[email protected]>
A session bound to a provider profile passed the profile's token to Pi
in CODEDECK_PI_PROVIDER_TOKEN, which the extension's registration named
($CODEDECK_PI_PROVIDER_TOKEN) so Pi read it per request. Everything Pi
starts inherits its environment, so the model could print the token
from its bash (reproduced live: `/tool node -p
process.env.CODEDECK_PI_PROVIDER_TOKEN` printed it), as could background
shells, sub-agents and MCP servers. Deleting the variable inside Pi is
not enough: on Linux /proc/<pid>/environ keeps a process's starting
environment, readable by any process of the same user.

The token now never enters Pi's environment. The driver spawns Pi with
a fourth stdio pipe (file descriptor 3), writes the token there and
closes it; the extension reads it to the end as Pi loads it, before
anything can start a process, and registers it as the profile's key,
escaped so Pi's config syntax ($NAME, a leading !) takes it literally.
Node passes a child only the stdio it is given, so no process Pi starts
inherits the pipe. A sub-agent's Pi gets the token on its own pipe the
same way. Without a token the profile is registered keyless and the
extension says so on stderr; requests then fail for want of a key. The
memory tool, which refused secret-named variables' values, now also
refuses the token, since it is in no variable.

The fake-model tests run the real Pi against a model server that
requires the profile's token, which holds a leading ! and a $, and dump
the environment of the model's shell, a background shell and a
sub-agent's shell, and on Linux Pi's own /proc environ: none holds the
token. Both tests fail with the token in Pi's environment; the
/proc check fails when the extension deletes it at load instead.

Co-Authored-By: Claude Code <[email protected]>
The token travels on its own pipe, not in Pi's environment, and why: what
Pi starts inherits that environment, and Linux exposes a process's
starting environment in /proc. An operator's own Pi wrapper must hand
the pipe on.

Co-Authored-By: Claude Code <[email protected]>
@deymosh
deymosh merged commit 1592fab into master Nov 18, 2026
6 checks passed
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.

1 participant