Commit d790769
codejunkie99
review: address pi tool-result hook review findings
Cross-model review (Claude + Codex adversarial) flagged 4 issues that
would either lose user data on Windows or silently degrade episodic
memory quality.
1. install.ps1:157-159 — DATA LOSS on Windows re-install.
`Remove-Item -LiteralPath $skillsDst -Recurse -Force` on PowerShell
5.1 (default Windows shell) traverses INTO a symlink target and
deletes its contents before removing the link. A second
`install.ps1 pi` run would wipe .agent/skills/. Detect ReparsePoint
via Get-Item.Attributes BEFORE Remove-Item; use
.NET Directory.Delete($path, false) on links so only the link is
removed, never the target.
2. adapters/pi/memory-hook.ts — no subprocess timeout, hangs Pi.
`await runHook(payload)` is awaited inside Pi's tool_result handler;
a stuck Python child blocks Pi's event loop forever. Add 3s default
timeout (overridable via $AGENT_HOOK_TIMEOUT_MS), kill the child on
timeout, surface `timeout` as a separate result kind.
3. adapters/pi/memory-hook.ts — stderr was dropped, failures
undiagnosable. Switch stdio to capture stderr (bounded to 4KB to
avoid memory blowup on a wedged hook) and surface the first line
in the failure notification.
4. .agent/harness/hooks/pi_post_tool.py — Pi sends tool_input with
camelCase keys (filePath, oldString, newString), but the shared
cc.* helpers (action_label, reflection, importance) expect Claude
Code's snake_case keys. Without normalization, every Edit/Write
logged by Pi degraded to "edit: ?" / "Edited ?" with empty detail.
Add a Pi→canonical input key map applied in _normalize_input().
5. .agent/harness/hooks/pi_post_tool.py — fail-open on malformed
payload was logging bogus "Unknown success" entries (Codex's High
#1). If Pi ever changes the event shape or sends invalid JSON,
episodic memory got polluted with noise instead of a real signal.
Add a _emit_malformed() path that records an explicit
`hook:malformed_payload` failure entry with a 200-char excerpt of
the offending payload — visible in AGENT_LEARNINGS.jsonl as a real
error, not noise.
Smoke-tested:
- empty payload → `hook:malformed_payload | empty payload`
- malformed JSON → `hook:malformed_payload | json decode error: ...`
- Pi camelCase Edit (filePath/oldString/newString) → produces correct
`edit: /tmp/x.txt` action label and `Edited /tmp/x.txt: replaced 'a'
with 'b'` reflection (was: `edit: ?` / `Edited ?`)
- well-formed bash success → unchanged behavior
Codex's concurrent-write concern (Codex #3) and the rsync-style sync
for .pi/skills (Codex #5) are NOT addressed here — they apply to
pre-existing infrastructure (post_execution.py write semantics, pi's
existing symlink path) and are scoped as separate follow-ups.1 parent b64b80c commit d790769
3 files changed
Lines changed: 180 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
37 | 61 | | |
38 | 62 | | |
39 | 63 | | |
40 | 64 | | |
41 | 65 | | |
42 | 66 | | |
43 | 67 | | |
44 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
45 | 85 | | |
46 | 86 | | |
47 | 87 | | |
| |||
97 | 137 | | |
98 | 138 | | |
99 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
100 | 157 | | |
| 158 | + | |
101 | 159 | | |
102 | 160 | | |
103 | | - | |
104 | | - | |
105 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
106 | 182 | | |
107 | 183 | | |
108 | | - | |
109 | | - | |
110 | | - | |
| 184 | + | |
111 | 185 | | |
112 | 186 | | |
113 | 187 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
17 | 26 | | |
18 | 27 | | |
19 | 28 | | |
| 29 | + | |
20 | 30 | | |
21 | 31 | | |
22 | 32 | | |
23 | 33 | | |
24 | 34 | | |
25 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
26 | 42 | | |
27 | 43 | | |
28 | 44 | | |
| |||
36 | 52 | | |
37 | 53 | | |
38 | 54 | | |
39 | | - | |
| 55 | + | |
40 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
41 | 65 | | |
42 | 66 | | |
43 | 67 | | |
44 | 68 | | |
45 | 69 | | |
46 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
47 | 73 | | |
48 | 74 | | |
49 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
50 | 85 | | |
51 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
52 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
53 | 99 | | |
54 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
55 | 106 | | |
56 | 107 | | |
57 | 108 | | |
58 | 109 | | |
59 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
60 | 119 | | |
61 | 120 | | |
62 | 121 | | |
63 | | - | |
64 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
65 | 126 | | |
66 | 127 | | |
67 | 128 | | |
| |||
90 | 151 | | |
91 | 152 | | |
92 | 153 | | |
93 | | - | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
94 | 165 | | |
| 166 | + | |
| 167 | + | |
95 | 168 | | |
96 | | - | |
| 169 | + | |
97 | 170 | | |
98 | 171 | | |
99 | 172 | | |
100 | 173 | | |
101 | 174 | | |
102 | 175 | | |
103 | 176 | | |
104 | | - | |
| 177 | + | |
105 | 178 | | |
106 | 179 | | |
107 | 180 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
158 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
159 | 172 | | |
160 | 173 | | |
161 | 174 | | |
| |||
0 commit comments