feat(agent-access): prune stopped and expired sessions #108

Merged
pdurlej merged 1 commit from codex/issues/95-prune-sessions-rewrite into main 2026-05-06 01:11:30 +02:00
Collaborator

Canary status: approve_merge — 6/6 reviewers OK on f269673274c23f3db54ab3ea432c7536b93f9382.

Canary Context Pack

Product story

After #93 gave safe visibility into non-secret ssh-agent sessions, the operator needs controlled cleanup without risking active or unknown access-bearing state. This rewrite keeps the friction high: prune only removes directories when metadata is validated, the agent handle is private, and the recorded PID is already absent.

What changed

  • Added --prune to scripts/agent-access/codex-openclaw-ssh-agent.
  • Prunes only validated expired and stopped sessions.
  • Skips active, unknown, malformed, invalid, unsafe, missing-agent-env, non-private-agent-env, and still-live-PID sessions.
  • Does not kill a present PID during prune; if PID is present, it emits SKIP_AGENT_ALIVE and keeps the directory.
  • Requires agent.env to be a regular 0600 file before trusting its socket/PID values.
  • Documents the prune behavior in the Codex OpenClaw SSH runbook.
  • Adds tests for eligible pruning, skip behavior, unconfirmed PID, open agent.env, open sessions/, reaped PID fixtures, and private-key non-leakage.

Why it changed

#96 hit its 3-iteration cap with one remaining high finding: prune trusted agent.env without verifying private file mode. This PR is a clean rewrite with that finding fixed and a fresh canary budget.

Files touched

  • scripts/agent-access/codex-openclaw-ssh-agent
  • control-plane/platformctl/tests/test_agent_access_ssh_agent.py
  • docs/agent-access/codex-openclaw-ssh.md

Relevant context

  • Parent #79: session lifecycle hardening.
  • Child #95: prune stopped and expired sessions.
  • PR #93: non-secret --list contract merged.
  • PR #96: closed as rewrite after 3-iteration cap.
  • Security-sensitive lane from #82 applies: smallest PR, explicit evidence, canary before merge.

Runtime evidence

  • PYTHONPATH=control-plane pytest -q control-plane/platformctl/tests/test_agent_access_ssh_agent.py -> 17 passed
  • PYTHONPATH=control-plane pytest -q control-plane/platformctl/tests -> 175 passed
  • git diff --check origin/main -> pass
  • Current diff secret-pattern scan -> pass

Known constraints

--prune depends on persisted, validated metadata from --list. active still means metadata-unexpired, not live-socket verified. Sessions with missing/bad/open agent.env are skipped rather than deleted, because the wrapper cannot safely confirm agent absence. Persistent SKIP_AGENT_ALIVE or SKIP_NO_AGENT_ENV requires manual inspection or a future explicitly-scoped force command. The runbook now includes a compact prune output legend for the emitted SKIP_* prefixes.

Explicit out-of-scope

  • No live socket probing.
  • No PID killing during prune.
  • No force-prune for missing/bad agent env.
  • No TTL policy changes.
  • No Infisical, Forgejo PAT, CI, or OpenClaw runtime changes.

Requested decision

Approve merge if canary confirms --prune removes only safe stopped/expired session state and preserves active/unknown/unconfirmed/non-private state.

Merge blockers

  • Deleting active or unknown sessions.
  • Deleting a session when recorded PID is still present.
  • Deleting a session with missing, unreadable, symlinked, malformed, or non-0600 agent.env.
  • Mutating group/world-open sessions/ permissions instead of failing.
  • Any private-key material in stdout/stderr/session files.
  • Requiring the OpenClaw private-key env to prune.

Spec sources read

  • Issue #79 — parent lifecycle hardening scope.
  • Issue #95 — child scope and acceptance criteria.
  • scripts/agent-access/codex-openclaw-ssh-agent — implementation target.
  • control-plane/platformctl/tests/test_agent_access_ssh_agent.py — wrapper test harness.
  • docs/agent-access/codex-openclaw-ssh.md — operator runbook update.
  • PR #93 body/diff — current --list contract this prune slice builds on.
  • PR #96 canary output — rewrite trigger and high finding addressed here.

Closes #95
Refs #79
Supersedes #96

Canary status: approve_merge — 6/6 reviewers OK on `f269673274c23f3db54ab3ea432c7536b93f9382`. ## Canary Context Pack ### Product story After #93 gave safe visibility into non-secret ssh-agent sessions, the operator needs controlled cleanup without risking active or unknown access-bearing state. This rewrite keeps the friction high: prune only removes directories when metadata is validated, the agent handle is private, and the recorded PID is already absent. ### What changed - Added `--prune` to `scripts/agent-access/codex-openclaw-ssh-agent`. - Prunes only validated `expired` and `stopped` sessions. - Skips `active`, `unknown`, malformed, invalid, unsafe, missing-agent-env, non-private-agent-env, and still-live-PID sessions. - Does not kill a present PID during prune; if PID is present, it emits `SKIP_AGENT_ALIVE` and keeps the directory. - Requires `agent.env` to be a regular `0600` file before trusting its socket/PID values. - Documents the prune behavior in the Codex OpenClaw SSH runbook. - Adds tests for eligible pruning, skip behavior, unconfirmed PID, open `agent.env`, open `sessions/`, reaped PID fixtures, and private-key non-leakage. ### Why it changed #96 hit its 3-iteration cap with one remaining high finding: prune trusted `agent.env` without verifying private file mode. This PR is a clean rewrite with that finding fixed and a fresh canary budget. ### Files touched - `scripts/agent-access/codex-openclaw-ssh-agent` - `control-plane/platformctl/tests/test_agent_access_ssh_agent.py` - `docs/agent-access/codex-openclaw-ssh.md` ### Relevant context - Parent #79: session lifecycle hardening. - Child #95: prune stopped and expired sessions. - PR #93: non-secret `--list` contract merged. - PR #96: closed as `rewrite` after 3-iteration cap. - Security-sensitive lane from #82 applies: smallest PR, explicit evidence, canary before merge. ### Runtime evidence - `PYTHONPATH=control-plane pytest -q control-plane/platformctl/tests/test_agent_access_ssh_agent.py` -> `17 passed` - `PYTHONPATH=control-plane pytest -q control-plane/platformctl/tests` -> `175 passed` - `git diff --check origin/main` -> pass - Current diff secret-pattern scan -> pass ### Known constraints `--prune` depends on persisted, validated metadata from `--list`. `active` still means metadata-unexpired, not live-socket verified. Sessions with missing/bad/open `agent.env` are skipped rather than deleted, because the wrapper cannot safely confirm agent absence. Persistent `SKIP_AGENT_ALIVE` or `SKIP_NO_AGENT_ENV` requires manual inspection or a future explicitly-scoped force command. The runbook now includes a compact prune output legend for the emitted `SKIP_*` prefixes. ### Explicit out-of-scope - No live socket probing. - No PID killing during prune. - No force-prune for missing/bad agent env. - No TTL policy changes. - No Infisical, Forgejo PAT, CI, or OpenClaw runtime changes. ### Requested decision Approve merge if canary confirms `--prune` removes only safe stopped/expired session state and preserves active/unknown/unconfirmed/non-private state. ### Merge blockers - Deleting `active` or `unknown` sessions. - Deleting a session when recorded PID is still present. - Deleting a session with missing, unreadable, symlinked, malformed, or non-0600 `agent.env`. - Mutating group/world-open `sessions/` permissions instead of failing. - Any private-key material in stdout/stderr/session files. - Requiring the OpenClaw private-key env to prune. ## Spec sources read - Issue #79 — parent lifecycle hardening scope. - Issue #95 — child scope and acceptance criteria. - `scripts/agent-access/codex-openclaw-ssh-agent` — implementation target. - `control-plane/platformctl/tests/test_agent_access_ssh_agent.py` — wrapper test harness. - `docs/agent-access/codex-openclaw-ssh.md` — operator runbook update. - PR #93 body/diff — current `--list` contract this prune slice builds on. - PR #96 canary output — rewrite trigger and high finding addressed here. Closes #95 Refs #79 Supersedes #96
feat(agent-access): prune stopped and expired sessions
Some checks failed
canary-required / collect-diff (pull_request) Successful in 3s
pyfallow / Pyfallow gate (control-plane) (pull_request) Successful in 14s
python-ci / Python 3.11 (pull_request) Failing after 31s
python-ci / Python 3.12 (pull_request) Successful in 32s
python-ci / Python 3.13 (pull_request) Successful in 32s
canary-required / canary (pull_request) Successful in 12s
71528fc410
codex force-pushed codex/issues/95-prune-sessions-rewrite from 71528fc410
Some checks failed
canary-required / collect-diff (pull_request) Successful in 3s
pyfallow / Pyfallow gate (control-plane) (pull_request) Successful in 14s
python-ci / Python 3.11 (pull_request) Failing after 31s
python-ci / Python 3.12 (pull_request) Successful in 32s
python-ci / Python 3.13 (pull_request) Successful in 32s
canary-required / canary (pull_request) Successful in 12s
to f269673274
All checks were successful
canary-required / collect-diff (pull_request) Successful in 3s
pyfallow / Pyfallow gate (control-plane) (pull_request) Successful in 15s
python-ci / Python 3.11 (pull_request) Successful in 31s
python-ci / Python 3.12 (pull_request) Successful in 31s
python-ci / Python 3.13 (pull_request) Successful in 31s
canary-required / canary (pull_request) Successful in 12s
2026-05-06 01:02:57 +02:00
Compare
Author
Collaborator

Canary iteration 2: approve_merge on f269673274c23f3db54ab3ea432c7536b93f9382. 6/6 reviewers OK.

Local evidence before rerun: focused test 17 passed, full platformctl/tests 175 passed, git diff --check pass, current diff secret-pattern scan pass.

Accepted weak signals for this slice: prune is intentionally conservative and may leave clutter when PID/state cannot be positively confirmed; SKIP_* outputs are expected safety behavior, not automatic failure.

Canary iteration 2: `approve_merge` on `f269673274c23f3db54ab3ea432c7536b93f9382`. 6/6 reviewers OK. Local evidence before rerun: focused test `17 passed`, full `platformctl/tests` `175 passed`, `git diff --check` pass, current diff secret-pattern scan pass. Accepted weak signals for this slice: prune is intentionally conservative and may leave clutter when PID/state cannot be positively confirmed; `SKIP_*` outputs are expected safety behavior, not automatic failure.
Sign in to join this conversation.
No reviewers
No labels
W6d-automerge-calibration
agent/claude-code
agent/codex
agent/hermes
agent/iskra
agent/ollama
agent/patchwarden
automerge-candidate
class/security-sensitive
cutover-gate
dependency/blocked
dependency/blocks-others
dependency/cross-repo
dependency/needs-confirmation
domain:agents
domain:ci
domain:docs
domain:forgejo
domain:infra
domain:memory
domain:runtime
domain:signal
domain:ux
flow/architecture
flow/blocked
flow/deployed
flow/done
flow/implementation
flow/intake
flow/maintained
flow/observed
flow/ready
flow/refining
flow/retired
flow/review
iterating
judge/codex-candidate
judge/hermes-candidate
judge/low-confidence
judge/needs-refinement
judge/operator-needed
judge/p0
judge/p1
judge/p2
judge/p3
judge/park
judge/patchwarden-candidate
judge/stale-priority
kind/adr
kind/bug
kind/chore
kind/feature
kind/infra
kind/ops
kind/refactor
kind/research
large-impact
merge/auto
merge/manual
merge/manual-dependency-conflict
merge/manual-failing-tests
merge/manual-merge-conflict
merge/manual-missing-review
merge/manual-operator-preference
merge/manual-red-zone
merge/manual-security-sensitive
merge/manual-unclear-scope
merge/manual-unknown
meta
mode:operator-only
mode:patchwarden-iskra-approved
mode:safe-auto
needs-operator-decision
needs-triage
not-ready
observed/erroring
observed/needs-followup
observed/pending
observed/retire-candidate
observed/unused
observed/used
operator-emotional
owner-attention
phase/02
phase/03
priority:p0
priority:p1
priority:p2
priority:p3
proposed
ready-for-agent
ready-for-operator
recovery
review:claude-reviewed
review:codex-reviewed
review:dziadek-reviewed
review:needs-human
risk/exposure
risk/process
risk/product
risk/runtime
safety:external-write
safety:no-prod-mutation
safety:prod-impact
safety:secret-touch
size/large
size/medium
size/small
size/tiny
size/unknown
source/adr
source/agent-generated
source/manual
source/operator-chat
source/voice-note
status:blocked
status:codex-ready
status:merged:pending-evidence
status:needs-evidence
status:operator-needed
status:parked
tier/full
tier/lite
tier/stacked
tier:0-platform-substrate
tier:1-iskra-value-layer
tier:2-tools-products-modules
type:bug
type:chore
type:docs
type:feat
type:policy
type:research
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pdurlej/platform!108
No description provided.