Repository navigation
fix(pi-permission-system): keep the forwarding directory with a relocated session store - #1107
Open
georgeharker wants to merge 1 commit into
Open
georgeharker wants to merge 1 commit into
georgeharker wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PI_CODING_AGENT_SESSION_DIRmoves 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
~/.configis 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/*.jsonand its temp files, even though I'd moved sessions to~/.local/share/pispecifically to keep runtime state out of the synced tree.Change
computeExtensionPaths(agentDir, piPackageDir?, sessionDir?): whensessionDiris set, it becomessessionsDir(with~expanded viaexpandHomePath), andforwardingDirfollows it.subagentSessionsDiris unchanged.index.tspassesprocess.env.PI_CODING_AGENT_SESSION_DIRand reads it once at the composition root.subagent-integration.mdnow 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-scopedsessionDirsetting, 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,subagentSessionsDirunaffected.test/composition-root.test.ts: a new out-of-process test publishes a heartbeat under a relocatedPI_CODING_AGENT_SESSION_DIRand 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.beforeEachincomposition-root.test.tsnow stubsPI_CODING_AGENT_SESSION_DIRto 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 checkpasses, and the package'spnpm run testpasses (184 files, 6433 tests).ESLint and Biome are clean on the changed files.
Full-repo
pnpm run linthit 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.