feat(memory): register lifecycle hooks #681

Merged
pdurlej merged 1 commit from codex/662-memory-lifecycle-hooks into main 2026-06-02 08:03:32 +02:00
Collaborator

Canary status: missing — fire canary 3+3 manually before merge

Summary

Adds the Memory Control Plane lifecycle hook registration layer for #662.

What changed

  • Adds platformctl memory hook register for explicit settings files.
  • Registers SessionStart, PreCompact, PostCompact, and PreToolUse commands additively.
  • Preserves existing hook entries such as RTK PreToolUse and codexbar SessionStart.
  • Makes pre-compact usable by lifecycle hooks without hand-fed task metadata by adding safe task/objective defaults.
  • Lets pre-tool-use read common harness JSON payloads from stdin, including tool_name=Write style payloads.
  • Updates hook documentation and regression tests.

Canary Context Pack

Product story

Memory Control Plane hooks should be executable by harnesses instead of relying on agents remembering lifecycle instructions. This PR gives Claude/Codex surfaces a deterministic, repo-owned way to register those hooks without clobbering existing harness controls.

What changed

A small hook registration helper and CLI command were added under platformctl. Existing hook endpoints were made safer for automatic lifecycle execution.

Why it changed

Issue #662 requires hook registration for claude and codex surfaces, preserving existing hooks including RTK PreToolUse and codexbar SessionStart.

Files touched

  • control-plane/platformctl/cli.py
  • control-plane/platformctl/memory.py
  • control-plane/platformctl/memory_hooks.py
  • control-plane/platformctl/tests/test_memory_control_plane.py
  • state/memory/hooks/README.md

Relevant context

  • decisions/0025-memory-control-plane.md §4
  • state/memory/hooks/README.md
  • Forgejo issue #662

Runtime evidence

No runtime config was changed. No live Claude/Codex $HOME settings were edited. No live Postgres migration was applied.

Validation run locally:

python3 -m py_compile control-plane/platformctl/memory.py control-plane/platformctl/memory_hooks.py control-plane/platformctl/cli.py
cd control-plane && uv run pytest platformctl/tests/test_memory_control_plane.py
PYTHONPATH=control-plane uv run --project control-plane python -m platformctl.cli validate all --json

Results:

  • py_compile: pass
  • test_memory_control_plane.py: 16 passed
  • platformctl validate all --json: exitCode 0

Known constraints

memory hook register only mutates the explicit --settings file when --write is passed. It does not discover live harness config paths.

Explicit out-of-scope

  • No live DB/table apply.
  • No live Claude/Codex config mutation.
  • No runtime apply.
  • No closure of #460/#461; those remain docs/spec verification items.

Requested decision

Review and merge if the additive registration contract and tests look correct.

Merge blockers

  • Any evidence that registration clobbers existing hooks.
  • Any secret leakage in hook payload handling or test fixtures.
  • Any hidden live runtime mutation.

Spec sources read

  • decisions/0025-memory-control-plane.md — ADR lifecycle hook contract.
  • state/memory/hooks/README.md — existing hook endpoint docs.
  • control-plane/platformctl/memory.py — existing memory helpers and hook endpoints.
  • control-plane/platformctl/cli.py — existing platformctl command conventions.
  • control-plane/platformctl/tests/test_memory_control_plane.py — local regression test conventions.
  • Forgejo issue #662 — task packet and done criteria.

Closes #662

Canary status: missing — fire canary 3+3 manually before merge ## Summary Adds the Memory Control Plane lifecycle hook registration layer for #662. ## What changed - Adds `platformctl memory hook register` for explicit settings files. - Registers `SessionStart`, `PreCompact`, `PostCompact`, and `PreToolUse` commands additively. - Preserves existing hook entries such as RTK `PreToolUse` and codexbar `SessionStart`. - Makes `pre-compact` usable by lifecycle hooks without hand-fed task metadata by adding safe task/objective defaults. - Lets `pre-tool-use` read common harness JSON payloads from stdin, including `tool_name=Write` style payloads. - Updates hook documentation and regression tests. ## Canary Context Pack ### Product story Memory Control Plane hooks should be executable by harnesses instead of relying on agents remembering lifecycle instructions. This PR gives Claude/Codex surfaces a deterministic, repo-owned way to register those hooks without clobbering existing harness controls. ### What changed A small hook registration helper and CLI command were added under `platformctl`. Existing hook endpoints were made safer for automatic lifecycle execution. ### Why it changed Issue #662 requires hook registration for `claude` and `codex` surfaces, preserving existing hooks including RTK `PreToolUse` and codexbar `SessionStart`. ### Files touched - `control-plane/platformctl/cli.py` - `control-plane/platformctl/memory.py` - `control-plane/platformctl/memory_hooks.py` - `control-plane/platformctl/tests/test_memory_control_plane.py` - `state/memory/hooks/README.md` ### Relevant context - `decisions/0025-memory-control-plane.md` §4 - `state/memory/hooks/README.md` - Forgejo issue #662 ### Runtime evidence No runtime config was changed. No live Claude/Codex `$HOME` settings were edited. No live Postgres migration was applied. Validation run locally: ```bash python3 -m py_compile control-plane/platformctl/memory.py control-plane/platformctl/memory_hooks.py control-plane/platformctl/cli.py cd control-plane && uv run pytest platformctl/tests/test_memory_control_plane.py PYTHONPATH=control-plane uv run --project control-plane python -m platformctl.cli validate all --json ``` Results: - `py_compile`: pass - `test_memory_control_plane.py`: 16 passed - `platformctl validate all --json`: exitCode 0 ### Known constraints `memory hook register` only mutates the explicit `--settings` file when `--write` is passed. It does not discover live harness config paths. ### Explicit out-of-scope - No live DB/table apply. - No live Claude/Codex config mutation. - No runtime apply. - No closure of #460/#461; those remain docs/spec verification items. ### Requested decision Review and merge if the additive registration contract and tests look correct. ### Merge blockers - Any evidence that registration clobbers existing hooks. - Any secret leakage in hook payload handling or test fixtures. - Any hidden live runtime mutation. ## Spec sources read - `decisions/0025-memory-control-plane.md` — ADR lifecycle hook contract. - `state/memory/hooks/README.md` — existing hook endpoint docs. - `control-plane/platformctl/memory.py` — existing memory helpers and hook endpoints. - `control-plane/platformctl/cli.py` — existing platformctl command conventions. - `control-plane/platformctl/tests/test_memory_control_plane.py` — local regression test conventions. - Forgejo issue #662 — task packet and done criteria. Closes #662
feat(memory): register lifecycle hooks
All checks were successful
canary-required / collect-diff (pull_request) Successful in 4s
platformctl plan / auto-apply scope (pull_request) Successful in 18s
pyfallow / Pyfallow gate (control-plane) (pull_request) Successful in 16s
python-ci / Python 3.11 (pull_request) Successful in 38s
python-ci / Python 3.12 (pull_request) Successful in 40s
python-ci / Python 3.13 (pull_request) Successful in 38s
canary-required / canary (pull_request) Successful in 12s
base-is-main / guard (pull_request) Successful in 1s
patchwarden-pr-sanity / collect-diff (pull_request) Successful in 4s
patchwarden-client-dry-run / dry-run (pull_request) Successful in 16s
patchwarden-client-dry-run / collect-diff (pull_request) Successful in 3s
patchwarden-pr-sanity / sanity (pull_request) Successful in 2m33s
9c0cd952c4
Author
Collaborator

Patchwarden PR sanity

  • Status: advisory_findings
  • PR: 681
  • Commit: 9c0cd952c49eb9b8e0f4bac60a70bdeece2cf37c
  • Security-sensitive label: present
  • Authority: advisory model review plus deterministic blockers only
  • 3+3 canary: still alive; this does not replace it

Deterministic findings

No deterministic findings.

Model reviewers

global-glm / glm-5.1:cloud

  • Status: ok

  • Verdict: OK

  • medium stdin read will hang if pre-tool-use called without piped input

    • Evidence: control-plane/platformctl/cli.py lines 618-626: raw = click.get_text_stream('stdin').read() blocks indefinitely on TTY stdin when neither --operation nor --path is provided
    • Next: Consider adding a timeout or checking sys.stdin.isatty() to provide a clear error message instead of hanging. Document this behavior prominently if intentional.
  • low Same-day default task_id collisions possible

    • Evidence: control-plane/platformctl/memory.py lines 51-54: default_task_id()returnstask_YYYY_MM_DD_session_lifecycle - multiple sessions on the same day share the same task_id
    • Next: Consider appending a short timestamp or session identifier if checkpoint overwrites are a concern. Current behavior may be acceptable for lifecycle hooks.

global-deepseek / deepseek-v4-pro:cloud

  • Status: ok

  • Verdict: NOT_OK

  • high pre_tool_guard_from_payload defaults to permissive operation/path when payload keys are missing

    • Evidence: control-plane/platformctl/memory.py: new function pre_tool_guard_from_payload defaults operation to 'read' and path to '.' if no recognizable keys are present in the harness payload. This means a harness that sends an unexpected payload for
    • Next: Change the default to a safe blocked state (e.g., operation='write', path='~/.ssh/id_ed25519' or raise an error) when the payload cannot be parsed, or at minimum log a warning and block. Add a test for a payload with no recognizable fields to verify the guard fails closed.
  • low pre-tool-use command may hang if invoked without arguments and without stdin

    • Evidence: control-plane/platformctl/cli.py: cmd_memory_hook_pre_tool_use now reads from stdin when --operation/--path are omitted. If the command is run interactively without piping input, it will block waiting for stdin, which could cause harness ti
    • Next: Add a timeout or a check for a terminal stdin, and print a usage message instead of blocking. Alternatively, require explicit --operation/--path when not in a pipe.

redteam / kimi-k2.6:cloud

  • Status: ok

  • Verdict: NOT_OK

  • high pre-tool-use guard bypass via empty string arguments

    • Evidence: control-plane/platformctl/cli.py cmd_memory_hook_pre_tool_use: @click.option("--operation", default=None)and@click.option("--path", default=None)allow empty strings. The branchif operation and target_path:treats""as falsy,
    • Next: Use explicit is not None checks (and reject empty strings) so that partial or empty explicit arguments raise an error instead of falling back to stdin defaults.

Policy notes

  • GLM 5.1 + DeepSeek V4 Pro are the operator-required model mix for this bot.
  • Optional red-team model is enabled only when PLATFORMCTL_PR_SANITY_REDTEAM_MODEL is configured.
  • Auto-merge is not enabled here.
<!-- patchwarden-pr-sanity:pdurlej/platform:PR-681 --> # Patchwarden PR sanity - Status: `advisory_findings` - PR: `681` - Commit: `9c0cd952c49eb9b8e0f4bac60a70bdeece2cf37c` - Security-sensitive label: `present` - Authority: advisory model review plus deterministic blockers only - 3+3 canary: still alive; this does not replace it ## Deterministic findings No deterministic findings. ## Model reviewers ### `global-glm` / `glm-5.1:cloud` - Status: `ok` - Verdict: `OK` - **`medium`** stdin read will hang if pre-tool-use called without piped input - Evidence: `control-plane/platformctl/cli.py lines 618-626: `raw = click.get_text_stream('stdin').read()` blocks indefinitely on TTY stdin when neither --operation nor --path is provided` - Next: Consider adding a timeout or checking `sys.stdin.isatty()` to provide a clear error message instead of hanging. Document this behavior prominently if intentional. - **`low`** Same-day default task_id collisions possible - Evidence: `control-plane/platformctl/memory.py lines 51-54: `default_task_id()` returns `task_YYYY_MM_DD_session_lifecycle` - multiple sessions on the same day share the same task_id` - Next: Consider appending a short timestamp or session identifier if checkpoint overwrites are a concern. Current behavior may be acceptable for lifecycle hooks. ### `global-deepseek` / `deepseek-v4-pro:cloud` - Status: `ok` - Verdict: `NOT_OK` - **`high`** pre_tool_guard_from_payload defaults to permissive operation/path when payload keys are missing - Evidence: `control-plane/platformctl/memory.py: new function pre_tool_guard_from_payload defaults operation to 'read' and path to '.' if no recognizable keys are present in the harness payload. This means a harness that sends an unexpected payload for` - Next: Change the default to a safe blocked state (e.g., operation='write', path='~/.ssh/id_ed25519' or raise an error) when the payload cannot be parsed, or at minimum log a warning and block. Add a test for a payload with no recognizable fields to verify the guard fails closed. - **`low`** pre-tool-use command may hang if invoked without arguments and without stdin - Evidence: `control-plane/platformctl/cli.py: cmd_memory_hook_pre_tool_use now reads from stdin when --operation/--path are omitted. If the command is run interactively without piping input, it will block waiting for stdin, which could cause harness ti` - Next: Add a timeout or a check for a terminal stdin, and print a usage message instead of blocking. Alternatively, require explicit --operation/--path when not in a pipe. ### `redteam` / `kimi-k2.6:cloud` - Status: `ok` - Verdict: `NOT_OK` - **`high`** pre-tool-use guard bypass via empty string arguments - Evidence: `control-plane/platformctl/cli.py `cmd_memory_hook_pre_tool_use`: `@click.option("--operation", default=None)` and `@click.option("--path", default=None)` allow empty strings. The branch `if operation and target_path:` treats `""` as falsy, ` - Next: Use explicit `is not None` checks (and reject empty strings) so that partial or empty explicit arguments raise an error instead of falling back to stdin defaults. ## Policy notes - GLM 5.1 + DeepSeek V4 Pro are the operator-required model mix for this bot. - Optional red-team model is enabled only when `PLATFORMCTL_PR_SANITY_REDTEAM_MODEL` is configured. - Auto-merge is not enabled here.
pdurlej deleted branch codex/662-memory-lifecycle-hooks 2026-06-02 08:03:33 +02:00
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 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!681
No description provided.