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

Closed
codex wants to merge 1 commit from codex/issues/79-prune-sessions into main
Collaborator

Canary status: rewrite — 3-iteration cap reached on d4bc98280f530193bad594c3fba742e1756a8f63; high finding remains: prune must require private agent.env before trusting PID/socket. Do not merge.

Canary Context Pack

Product story

After #93 gave the operator safe visibility into non-secret ssh-agent sessions, the next step is controlled cleanup. The operator should be able to remove old stopped/expired session directories without touching active or unknown access-bearing state.

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, and unconfirmed-agent sessions.
  • Before deleting an eligible session directory, requires the recorded PID to already be absent; if the PID is still present, the session is skipped rather than killed.
  • Documents the prune behavior in the Codex OpenClaw SSH runbook.
  • Adds tests for eligible pruning, unknown/active skip behavior, unconfirmed-agent skip, open-permission refusal, and private-key non-leakage.

Why it changed

This is the next child slice of #79 after #84/#90 startup cleanup and #93 non-secret listing. It deliberately avoids live probing and TTL-policy changes so the destructive cleanup behavior can be reviewed on its own.

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.
  • #93: non-secret --list contract merged.
  • 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 -> 16 passed
  • PYTHONPATH=control-plane pytest -q control-plane/platformctl/tests -> 174 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 agent.env are skipped rather than deleted, because the wrapper cannot confirm agent absence. --prune also fails on group/world-open sessions/ instead of repairing permissions, emits explicit SKIP_ACTIVE/SKIP_UNKNOWN/SKIP_NO_AGENT_ENV/SKIP_AGENT_ALIVE lines, and wraps deletion errors as SKIP_ERROR.

Explicit out-of-scope

  • No live socket probing.
  • No TTL policy changes.
  • No Infisical, Forgejo PAT, CI, or OpenClaw runtime changes.
  • No generic Agent Access Plane catalog/resolver work.

Requested decision

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

Merge blockers

  • Deleting active or unknown sessions.
  • Deleting a session when recorded agent shutdown cannot be confirmed.
  • 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.

Closes #95
Refs #79

Canary status: rewrite — 3-iteration cap reached on `d4bc98280f530193bad594c3fba742e1756a8f63`; high finding remains: prune must require private `agent.env` before trusting PID/socket. Do not merge. ## Canary Context Pack ### Product story After #93 gave the operator safe visibility into non-secret ssh-agent sessions, the next step is controlled cleanup. The operator should be able to remove old stopped/expired session directories without touching active or unknown access-bearing state. ### 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, and unconfirmed-agent sessions. - Before deleting an eligible session directory, requires the recorded PID to already be absent; if the PID is still present, the session is skipped rather than killed. - Documents the prune behavior in the Codex OpenClaw SSH runbook. - Adds tests for eligible pruning, unknown/active skip behavior, unconfirmed-agent skip, open-permission refusal, and private-key non-leakage. ### Why it changed This is the next child slice of #79 after #84/#90 startup cleanup and #93 non-secret listing. It deliberately avoids live probing and TTL-policy changes so the destructive cleanup behavior can be reviewed on its own. ### 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. - #93: non-secret `--list` contract merged. - 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` -> `16 passed` - `PYTHONPATH=control-plane pytest -q control-plane/platformctl/tests` -> `174 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 `agent.env` are skipped rather than deleted, because the wrapper cannot confirm agent absence. `--prune` also fails on group/world-open `sessions/` instead of repairing permissions, emits explicit SKIP_ACTIVE/SKIP_UNKNOWN/SKIP_NO_AGENT_ENV/SKIP_AGENT_ALIVE lines, and wraps deletion errors as SKIP_ERROR. ### Explicit out-of-scope - No live socket probing. - No TTL policy changes. - No Infisical, Forgejo PAT, CI, or OpenClaw runtime changes. - No generic Agent Access Plane catalog/resolver work. ### Requested decision Approve merge if canary confirms `--prune` removes only safe stopped/expired session state and preserves active/unknown/unconfirmed state. ### Merge blockers - Deleting `active` or `unknown` sessions. - Deleting a session when recorded agent shutdown cannot be confirmed. - 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. Closes #95 Refs #79
feat(agent-access): prune stopped and expired sessions
All checks were successful
canary-required / collect-diff (pull_request) Successful in 3s
pyfallow / Pyfallow gate (control-plane) (pull_request) Successful in 16s
python-ci / Python 3.11 (pull_request) Successful in 27s
python-ci / Python 3.12 (pull_request) Successful in 29s
python-ci / Python 3.13 (pull_request) Successful in 29s
canary-required / canary (pull_request) Successful in 12s
53ec756d62
codex force-pushed codex/issues/79-prune-sessions from 53ec756d62
All checks were successful
canary-required / collect-diff (pull_request) Successful in 3s
pyfallow / Pyfallow gate (control-plane) (pull_request) Successful in 16s
python-ci / Python 3.11 (pull_request) Successful in 27s
python-ci / Python 3.12 (pull_request) Successful in 29s
python-ci / Python 3.13 (pull_request) Successful in 29s
canary-required / canary (pull_request) Successful in 12s
to 7b6563cc86
All checks were successful
canary-required / collect-diff (pull_request) Successful in 4s
pyfallow / Pyfallow gate (control-plane) (pull_request) Successful in 16s
python-ci / Python 3.11 (pull_request) Successful in 33s
python-ci / Python 3.12 (pull_request) Successful in 33s
python-ci / Python 3.13 (pull_request) Successful in 33s
canary-required / canary (pull_request) Successful in 14s
2026-05-06 00:34:58 +02:00
Compare
codex force-pushed codex/issues/79-prune-sessions from 7b6563cc86
All checks were successful
canary-required / collect-diff (pull_request) Successful in 4s
pyfallow / Pyfallow gate (control-plane) (pull_request) Successful in 16s
python-ci / Python 3.11 (pull_request) Successful in 33s
python-ci / Python 3.12 (pull_request) Successful in 33s
python-ci / Python 3.13 (pull_request) Successful in 33s
canary-required / canary (pull_request) Successful in 14s
to d4bc98280f
All checks were successful
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) Successful in 30s
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 00:45:37 +02:00
Compare
Author
Collaborator

Terminal action: rewrite on d4bc98280f530193bad594c3fba742e1756a8f63. The third canary iteration still had one high security finding: --prune can trust agent.env even if that file is group/world-open.

I am not asking for merge with this gap. I will close this PR and open a clean rewrite PR with an explicit private-file check for agent.env, then rerun canary from a fresh PR budget.

Terminal action: `rewrite` on `d4bc98280f530193bad594c3fba742e1756a8f63`. The third canary iteration still had one high security finding: `--prune` can trust `agent.env` even if that file is group/world-open. I am not asking for merge with this gap. I will close this PR and open a clean rewrite PR with an explicit private-file check for `agent.env`, then rerun canary from a fresh PR budget.
codex closed this pull request 2026-05-06 00:51:18 +02:00
Some checks are pending
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) Successful in 30s
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
base-is-main / guard (pull_request)
Required
patchwarden-pr-sanity / sanity (pull_request)
Required

Pull request closed

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!96
No description provided.