Skip to content

fix(pi-permission-system): keep the forwarding directory with a relocated session store - #1107

Open
georgeharker wants to merge 1 commit into
gotgenes:mainfrom
georgeharker:fix/permission-forwarding-honours-session-dir
Open

georgeharker wants to merge 1 commit into
gotgenes:mainfrom
georgeharker:fix/permission-forwarding-honours-session-dir

Conversation

@georgeharker

Copy link
Copy Markdown
Contributor

Problem

PI_CODING_AGENT_SESSION_DIR moves Pi's session store out of the agent dir, but the forwarding directory stays at <agent dir>/sessions/permission-forwarding (computeExtensionPaths).
Every serving session rewrites its heartbeat there once a second (temp file + rename), so the config dir still sees a steady stream of writes after sessions have been relocated.

I hit this because ~/.config is synced by Synology Drive.
With about 10 Pi sessions open, the Drive daemon logged roughly 1,800 events a minute for sessions/permission-forwarding/serving/*.json and its temp files, even though I'd moved sessions to ~/.local/share/pi specifically to keep runtime state out of the synced tree.

Change

  • computeExtensionPaths(agentDir, piPackageDir?, sessionDir?): when sessionDir is set, it becomes sessionsDir (with ~ expanded via expandHomePath), and forwardingDir follows it.
    subagentSessionsDir is unchanged.
  • index.ts passes process.env.PI_CODING_AGENT_SESSION_DIR and reads it once at the composition root.
  • Docs: subagent-integration.md now names the heartbeat location as <sessions dir>/… and says when that differs from the agent dir.

The default behaviour is unchanged when the variable is unset.

Why only the env var

Pi resolves its own session dir as --session-dir > PI_CODING_AGENT_SESSION_DIR > settings.sessionDir.
The forwarding dir is a rendezvous point between a parent and a child process, so both have to compute the same path.
An inherited env var guarantees that.
A per-invocation --session-dir, or a project-scoped sessionDir setting, could split a parent from its child and break forwarding.
Pi also doesn't export ENV_SESSION_DIR, so the name is spelled out here.

Tests

  • test/config/extension-paths.test.ts: override, ~ expansion, empty string ignored, subagentSessionsDir unaffected.
  • test/composition-root.test.ts: a new out-of-process test publishes a heartbeat under a relocated PI_CODING_AGENT_SESSION_DIR and checks that the child forwards there and that nothing is created under <agent dir>/sessions.
    It fails without the src/ change and passes with it.
  • The shared beforeEach in composition-root.test.ts now stubs PI_CODING_AGENT_SESSION_DIR to undefined.
    Without that, running the suite from inside a Pi session that exports the variable failed 6 existing forwarding tests, because they look for heartbeats under the tmpdir agent dir.

pnpm run check passes, and the package's pnpm run test passes (184 files, 6433 tests).
ESLint and Biome are clean on the changed files.
Full-repo pnpm run lint hit a native abort in Node 25.2.1 here, which isn't related to this change.

I know CONTRIBUTING asks for an issue first; this one seemed small enough to go straight to a PR.
Happy to open an issue, or for you to reimplement it however fits best.

…ated session store

The forwarding directory was always <agent dir>/sessions/permission-forwarding, even when PI_CODING_AGENT_SESSION_DIR moves Pi's own session store elsewhere.
Every serving session rewrites a heartbeat there once a second (temp file + rename), so an operator who relocated sessions out of a synced or backed-up config directory still had per-second churn left behind in it.

The forwarding directory now roots at PI_CODING_AGENT_SESSION_DIR when it is set.
Only the inherited environment variable is honoured, not --session-dir or settings.sessionDir: parent and child processes rendezvous in this directory, and the environment is the one source guaranteed to agree between them.
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