@shumkov/orchestra 0.10.19 → 0.10.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/2026-08-17-001-u23-hook-trust-characterization-findings.md +964 -0
- package/docs/FOLDED_REPLY_ATTRIBUTION_SPEC.md +317 -0
- package/lib/codex/app-server-client.js +444 -125
- package/lib/codex/preflight.js +43 -0
- package/lib/codex/protocol-schema.json +8 -0
- package/lib/process/cli-process.js +134 -40
- package/lib/process/codex-process.js +34 -0
- package/lib/process/factory.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,964 @@
|
|
|
1
|
+
# U23 S0 — Codex hook trust characterization findings
|
|
2
|
+
|
|
3
|
+
Date: 2026-08-17
|
|
4
|
+
Repository: Orchestra, branch `spike/codex-hook-trust-characterization`, based on
|
|
5
|
+
`origin/main` = `3b0587a` ("feat(codex): tolerate hook lifecycle notifications", #52).
|
|
6
|
+
Scope: characterization spike, focused tests, and this sanitized artifact only.
|
|
7
|
+
|
|
8
|
+
**Recommendation: `CONTINUE`** — every S0 decision was measured, the highest-risk
|
|
9
|
+
unknown resolved favourably, and no measurement invalidates the amendment plan's
|
|
10
|
+
approach. **Twelve** statements in the plan are contradicted by evidence and must
|
|
11
|
+
be corrected before the production design is written (section 4); one of them
|
|
12
|
+
(4.10) changes a security conclusion, so section 4 is not optional polish.
|
|
13
|
+
|
|
14
|
+
No production request was added, no protocol schema was changed, no production
|
|
15
|
+
app-server API was touched, no package version moved, no release worktree was
|
|
16
|
+
touched, and nothing was committed, published, or deployed.
|
|
17
|
+
|
|
18
|
+
## 1. Containment and provenance
|
|
19
|
+
|
|
20
|
+
| Property | Value |
|
|
21
|
+
| --- | --- |
|
|
22
|
+
| Codex under test | pinned 0.145.0, `aarch64-apple-darwin` |
|
|
23
|
+
| Binary attestation | `attestPinnedCodexBinary` against `resolveCodexTargetPin()` — **passed**, `pinnedBinaryAttested: true` |
|
|
24
|
+
| Protocol pin | unchanged; `lib/codex/protocol-schema.json` not edited |
|
|
25
|
+
| Homes | per-run isolated `CODEX_HOME`, `mkdir` 0700 + explicit `chmod 0700`, verified `isolatedHomeMode0700: true` |
|
|
26
|
+
| Credentials | none. `auth.json` absent in every lane; the loopback Responses provider declares `requires_openai_auth = false`, read back from the config actually written (`providerRequiresAuth: false`) |
|
|
27
|
+
| Network | loopback only. No hosted provider, no egress, no credential created, copied, read, or printed |
|
|
28
|
+
| Scratch | per-run root under a caller-supplied non-temporary probe root, removed in a `finally`; `probeRootRemoved: true`, root verified empty after every run |
|
|
29
|
+
| Process cleanup | owned process group enumerated and drained per raw session; `strayProcessCount: 0` after every run |
|
|
30
|
+
| Output | booleans, closed enums, counts, digests. **Nothing else leaves the run.** Host paths, rendered hook commands and config keys necessarily *exist* on disk — they are the manifest and config the app-server has to read — but only inside the per-run mode-0700 scratch root, which is removed in a `finally`. They are never emitted, never retained past the frame that projects them, and never written anywhere outside that root. Hook stdin is parsed in place: the prompt, workspace and transcript path reach no file at all |
|
|
31
|
+
|
|
32
|
+
The generated-schema facts below were read from the pinned binary's own
|
|
33
|
+
`app-server generate-json-schema --experimental` bundle, produced into a
|
|
34
|
+
disposable home. They are marked **[schema]**; everything else is **[observed]**
|
|
35
|
+
on a live turn.
|
|
36
|
+
|
|
37
|
+
## 2. What ran
|
|
38
|
+
|
|
39
|
+
Three new/edited spike surfaces, driven from a checkout:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
node scripts/spikes/codex-hook-trust-s0.mjs \
|
|
43
|
+
--binary /absolute/versioned/path/to/codex \
|
|
44
|
+
--probe-root /absolute/non-temporary/probe-root \
|
|
45
|
+
[--runtime /absolute/path/to/node] # defaults to the invoking runtime
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`--runtime` exists because the runtime is itself an attested artifact and must
|
|
49
|
+
be a canonical, owner-or-root, non-group-writable file under an equally tight
|
|
50
|
+
parent chain. A package-manager-installed Node frequently sits under a
|
|
51
|
+
group-writable prefix and is correctly refused, which would otherwise make the
|
|
52
|
+
documented command non-reproducible depending on which `node` happened to be
|
|
53
|
+
first on `PATH`.
|
|
54
|
+
|
|
55
|
+
Lanes, all against the pinned binary and the loopback provider:
|
|
56
|
+
|
|
57
|
+
- **Lane A** — three-event manifest (`SessionStart`, `UserPromptSubmit`, `Stop`),
|
|
58
|
+
`[features] hooks = true`. Wire-param matrix → untrusted inventory → user-layer
|
|
59
|
+
read → trust render → trusted inventory (twice, separate sessions) → user-layer
|
|
60
|
+
read (twice) → a real turn on the production `CodexAppServerClient` → mid-session
|
|
61
|
+
manifest mutation → a second turn in the same session → a third turn in a fresh
|
|
62
|
+
session.
|
|
63
|
+
- **Lane B** — structurally equivalent to Lane A, differing only in that
|
|
64
|
+
`[features] hooks = true` is absent. It is deliberately *not* byte-identical:
|
|
65
|
+
each lane has its own root, so its capture directory, rendered commands, hook
|
|
66
|
+
hashes and trust stanzas all differ. What is held constant is the manifest's
|
|
67
|
+
shape and event set, not its bytes.
|
|
68
|
+
- **Three boundary lanes** — `preSpawn`, `postStart`, `postThread`. Each starts
|
|
69
|
+
with manifest content A on disk while the trust stanza pins content B, and
|
|
70
|
+
swaps A→B at one point in the startup sequence (section 3, E6c).
|
|
71
|
+
- **Render check lane** — a second lane root, used only to prove the command
|
|
72
|
+
renderer is a pure function of its descriptor.
|
|
73
|
+
|
|
74
|
+
Nineteen app-server launches per run, each preceded by a fresh artifact
|
|
75
|
+
attestation. The final tree was run three times end to end at ~11s each; every
|
|
76
|
+
verdict, including the duration buckets, was identical across them.
|
|
77
|
+
|
|
78
|
+
### Deviation from the plan's section 5, stated plainly
|
|
79
|
+
|
|
80
|
+
The plan says S0 "is a reviewed extension of that file" — the checked-in release
|
|
81
|
+
gate `scripts/spikes/codex-app-server-hook-probe.mjs`. It is instead a **sibling
|
|
82
|
+
module that imports every hardened primitive from that file**: bounded raw
|
|
83
|
+
framing, the owned-process-group teardown, the loopback provider, the closed-enum
|
|
84
|
+
discipline, and the failure taxonomy.
|
|
85
|
+
|
|
86
|
+
The reason is concrete, not stylistic. The release gate's `EXPECTED_HOOK_EVENTS`
|
|
87
|
+
is a frozen two-event set threaded through its evidence shape, its
|
|
88
|
+
CONTINUE/STOP contract, and twenty of its tests. S0 characterizes three events.
|
|
89
|
+
Widening that constant would have silently redefined the gate that certifies
|
|
90
|
+
PR #52. The gate's contract is asserted unchanged by a test in the new suite, and
|
|
91
|
+
the gate was re-run live after the two additive edits below and still returns
|
|
92
|
+
`CONTINUE` with zero failed checks.
|
|
93
|
+
|
|
94
|
+
Two additive edits were made to the shared file, both covered by new tests:
|
|
95
|
+
|
|
96
|
+
1. `startLoopbackProvider` is exported.
|
|
97
|
+
2. A rejected JSON-RPC response now carries its **numeric** `error.code` on the
|
|
98
|
+
rejection. Without it, "the method is not allowed" and "the params shape was
|
|
99
|
+
refused" are indistinguishable, which is exactly what E2 has to separate. The
|
|
100
|
+
peer's `message` and `data` are still discarded with the frame.
|
|
101
|
+
|
|
102
|
+
## 3. Verified facts
|
|
103
|
+
|
|
104
|
+
### E1 — the user-layer config object with trust state present · **RESOLVED, favourable**
|
|
105
|
+
|
|
106
|
+
This was the plan's "single highest-risk unknown". It resolves in favour of the
|
|
107
|
+
design.
|
|
108
|
+
|
|
109
|
+
- **[observed]** With trust state written, the `config/read` **user layer** config
|
|
110
|
+
object is *exactly* the parse of what was written. The probe builds its owned
|
|
111
|
+
config as a JS object model, renders TOML from that same model, and compares the
|
|
112
|
+
canonical-JSON digest of the model against the digest of the returned layer:
|
|
113
|
+
`userLayerEqualsWrittenObjectModel: true`, both with and without trust state.
|
|
114
|
+
- **[observed]** No defaults are injected into the layer. Top-level key count is 12
|
|
115
|
+
without trust and 13 with it (`hooks` added); `userLayerUnexpectedTopLevelKeyCount: 0`.
|
|
116
|
+
- **[observed]** The layer's `hooks` table contains exactly one key, `state`
|
|
117
|
+
(`userLayerHooksUnexpectedTableKeyCount: 0`). It holds exactly the three
|
|
118
|
+
predeclared entries (`userLayerHooksStateKeysEqualPredeclared: true`), each with
|
|
119
|
+
exactly `{enabled, trusted_hash}` and nothing else.
|
|
120
|
+
- **[observed]** The **eleven event arrays** U21 VF5 saw appear only in the
|
|
121
|
+
**effective** config, not in the layer: `effectiveHooksTableKeyCount: 12`
|
|
122
|
+
(`state` plus eleven event arrays) with trust present, `effectiveHooksPresent: false`
|
|
123
|
+
without it. VF5's observation was about the effective config and does not
|
|
124
|
+
threaten the layer digest.
|
|
125
|
+
- **[observed]** `userLayerDigestStableAcrossSessions: true` — two independent
|
|
126
|
+
app-server sessions over identical bytes produce the identical layer digest.
|
|
127
|
+
- **[observed]** Two layers are returned, of types `user` and `system`
|
|
128
|
+
(`unrecognizedLayerCount: 0`). A consumer comparing "the layer" must select the
|
|
129
|
+
`user` layer by type, not by position.
|
|
130
|
+
- **[observed]** Writing the trust stanza changes the owned config file digest
|
|
131
|
+
(`configDigestChangedByTrustRender: true`), confirming U21 VF8's re-pin
|
|
132
|
+
requirement.
|
|
133
|
+
|
|
134
|
+
**Consequence:** `validateProjectedLayers` comparing the user layer's
|
|
135
|
+
`configSha256` against a digest of Polygram's own object model is sound, provided
|
|
136
|
+
`buildOwnedConfig` mirrors the rendered TOML exactly. The trusted-rendering
|
|
137
|
+
approach is not invalidated.
|
|
138
|
+
|
|
139
|
+
### E2 — wire params · **RESOLVED**
|
|
140
|
+
|
|
141
|
+
**[schema]** `HooksListParams` declares one optional property, `cwds: string[]`,
|
|
142
|
+
documented as "When empty, defaults to the current session working directory".
|
|
143
|
+
There is no required field and no cursor.
|
|
144
|
+
|
|
145
|
+
**[observed]** Six forms issued against one live session:
|
|
146
|
+
|
|
147
|
+
| Form sent | Verdict | Entries | Hooks | Entry cwd |
|
|
148
|
+
| --- | --- | --- | --- | --- |
|
|
149
|
+
| params key **omitted** | **rejected**, JSON-RPC `-32600` (invalid request) | – | – | – |
|
|
150
|
+
| `{}` | accepted | 1 | 3 | equals the session cwd |
|
|
151
|
+
| `{cwds: []}` | accepted | 1 | 3 | equals the session cwd |
|
|
152
|
+
| `{cwds: [ownedCwd]}` | accepted | 1 | 3 | equals the owned cwd |
|
|
153
|
+
| `{cwds: [foreignCwd]}` | accepted | 1 | 3 | equals the **requested foreign** cwd |
|
|
154
|
+
| `{cwds: [ownedCwd, foreignCwd]}` | accepted | 2 | 6 | one entry per requested cwd |
|
|
155
|
+
|
|
156
|
+
- Every accepted response's top-level key set is exactly `{data}`
|
|
157
|
+
(`responseKeysAreDataOnly: true`).
|
|
158
|
+
- `errors` and `warnings` were empty on every entry in every form.
|
|
159
|
+
|
|
160
|
+
**Freeze the exact-single-owned-cwd form**, `{"required": ["cwds"], "optional": [],
|
|
161
|
+
"stateChanging": false}` with params pinned to `{cwds: [ownedCwd]}`. It is
|
|
162
|
+
accepted, it yields exactly one entry, and the omitted form is rejected outright
|
|
163
|
+
so the `"params": "omitted"` schema variant is dead.
|
|
164
|
+
|
|
165
|
+
**One caveat the plan should absorb.** `cwds` does **not** filter which hooks are
|
|
166
|
+
returned — the same three user-level hooks came back for a foreign cwd. What it
|
|
167
|
+
does is select which cwd each entry is *reported against*, and the response
|
|
168
|
+
**echoes the requested cwd back**. So "the projector requires the returned `cwd`
|
|
169
|
+
to equal the owned cwd" is a correct pin against a malformed or reordered
|
|
170
|
+
response, but it is a tautology when the request named that cwd, and it is not
|
|
171
|
+
independent evidence that the response was scoped. Say so in the spec rather than
|
|
172
|
+
implying the check proves scoping.
|
|
173
|
+
|
|
174
|
+
### E3 — cardinality and paging · **NOT CLAIMED**
|
|
175
|
+
|
|
176
|
+
No paging or cardinality bound is asserted. What was observed: one entry per
|
|
177
|
+
requested cwd, three hooks per entry, and a response envelope carrying only
|
|
178
|
+
`data`. **[schema]** `HooksListResponse` declares only `data` and no cursor.
|
|
179
|
+
Neither observation bounds behaviour at a larger hook count, and this run does not
|
|
180
|
+
attempt to.
|
|
181
|
+
|
|
182
|
+
### E4 — is `[features] hooks = true` required? · **RESOLVED: no**
|
|
183
|
+
|
|
184
|
+
A/B with the manifest's shape, event set and trust state **structurally**
|
|
185
|
+
constant. The two lanes are not byte-identical and cannot be: each lane root
|
|
186
|
+
produces its own capture directory, so its commands, hashes and stanzas differ.
|
|
187
|
+
What varies deliberately is one table.
|
|
188
|
+
|
|
189
|
+
| Lane | Hooks listed | All `trusted` after render | Distinct events fired on a turn |
|
|
190
|
+
| --- | --- | --- | --- |
|
|
191
|
+
| `[features] hooks = true` present | 3 | yes | 3 |
|
|
192
|
+
| flag absent | 3 | yes | 3 |
|
|
193
|
+
|
|
194
|
+
`requiredForDiscovery: false`, `requiredForExecution: false`. This confirms U21
|
|
195
|
+
VF1 (`hooks` is a stable, default-on feature) and shows the memsearch installer's
|
|
196
|
+
write of that flag is unnecessary.
|
|
197
|
+
|
|
198
|
+
**Do not render `[features] hooks = true`.** Every stanza rendered has to be
|
|
199
|
+
mirrored in `buildOwnedConfig` and moves the owned-config digest; this one buys
|
|
200
|
+
nothing.
|
|
201
|
+
|
|
202
|
+
### E5 — exact `key` derivation · **RESOLVED**
|
|
203
|
+
|
|
204
|
+
**[observed]** For all three events the key is exactly
|
|
205
|
+
`<sourcePath>:<snake_case_event>:<i>:<j>` with `i = j = 0`:
|
|
206
|
+
|
|
207
|
+
| Event | Snake token | `i` | `j` | Template match |
|
|
208
|
+
| --- | --- | --- | --- | --- |
|
|
209
|
+
| `SessionStart` | `session_start` | 0 | 0 | yes |
|
|
210
|
+
| `UserPromptSubmit` | `user_prompt_submit` | 0 | 0 | yes |
|
|
211
|
+
| `Stop` | `stop` | 0 | 0 | yes |
|
|
212
|
+
|
|
213
|
+
`sourcePath` equalled the manifest path on every entry. `displayOrder` was 0, 1, 2
|
|
214
|
+
in manifest declaration order — it is a display ordinal, **not** either key index,
|
|
215
|
+
and must not be confused with them. Polygram can predeclare these keys.
|
|
216
|
+
|
|
217
|
+
### E6 — fire-time vs list-time re-validation · **RESOLVED: neither, and the boundary is `thread/start`**
|
|
218
|
+
|
|
219
|
+
Three experiments. The first two answer the original question; the third — added
|
|
220
|
+
after review pointed out that the first two only bracket the boundary loosely —
|
|
221
|
+
locates it.
|
|
222
|
+
|
|
223
|
+
**(a) Mid-session mutation.** With a live session already running, the manifest
|
|
224
|
+
was rewritten so every hook command pointed at a second capture directory. The
|
|
225
|
+
next turn in that same session fired **2 hooks from the pre-mutation command**
|
|
226
|
+
(`sameSessionAfterMutationOldPathCount: 2`) and **0 from the mutated one**. The
|
|
227
|
+
turn completed normally. Verdict: `sameSessionContentSource: 'thread-start-snapshot'`.
|
|
228
|
+
(This experiment alone only shows the content was fixed *before* the mutation;
|
|
229
|
+
(c) is what locates the fixing point, and the term is named for that result.)
|
|
230
|
+
|
|
231
|
+
**(b) Fresh session over the mutated manifest.** All three hooks reported
|
|
232
|
+
`trustStatus: 'modified'`, **no hook ran at all** (0 captures on either path),
|
|
233
|
+
and the turn still completed cleanly.
|
|
234
|
+
|
|
235
|
+
**(c) Boundary location.** Trust is content-addressed, so only one of two
|
|
236
|
+
manifest contents can ever run under a given stanza — which makes a clean
|
|
237
|
+
bisection possible. Three lanes each start with content **A** on disk while the
|
|
238
|
+
trust stanza pins content **B**, then swap A→B at one point in the startup
|
|
239
|
+
sequence. If B runs, the swap beat the snapshot; if nothing runs, A was
|
|
240
|
+
snapshotted and is `modified`.
|
|
241
|
+
|
|
242
|
+
| Swap point | Did the swapped-in content run? |
|
|
243
|
+
| --- | --- |
|
|
244
|
+
| before `client.start()` (process spawn) | **yes** — control |
|
|
245
|
+
| after `start()`/`initialize`, before `thread/start` | **yes** |
|
|
246
|
+
| after `thread/start`, before `turn/start` | **no** |
|
|
247
|
+
|
|
248
|
+
`snapshotBoundary: 'during-thread-start'`, identical across every run. The label
|
|
249
|
+
is deliberately narrow: `postStart` swaps after `initialize` and **before the
|
|
250
|
+
`thread/start` request**, `postThread` swaps **after the `thread/start`
|
|
251
|
+
response**, so the evidence brackets the fixing point *inside* `thread/start`
|
|
252
|
+
and claims nothing wider. **The manifest content a session will execute is fixed at `thread/start`,
|
|
253
|
+
not at process spawn and not at fire time.**
|
|
254
|
+
|
|
255
|
+
**This corrects a conclusion the previous revision of this document drew.** It
|
|
256
|
+
previously said the window "runs from last attestation to session start, and
|
|
257
|
+
per-session-start verification closes it". That is wrong in a way that matters:
|
|
258
|
+
|
|
259
|
+
- The plan's section 4.6 places its verification "after `initialize` and before
|
|
260
|
+
any `thread/start`" — which is **before** the snapshot, not after it. A
|
|
261
|
+
manifest replaced between the verification response and `thread/start` is the
|
|
262
|
+
copy the session goes on to use.
|
|
263
|
+
- What still bounds that window is content-addressed trust, not the
|
|
264
|
+
verification: a swap to content whose hash is not in the stanza is `modified`
|
|
265
|
+
and refuses to run, as experiment (b) shows. The verification call does not
|
|
266
|
+
add a guarantee here; the trust stanza does.
|
|
267
|
+
- The exposure that trust does **not** bound is the artifact body. The hash
|
|
268
|
+
binds the command string, which names the recorder's *path* — not the bytes
|
|
269
|
+
at that path. That window runs until the hook actually fires and is not
|
|
270
|
+
closed by anything measured here (section 6).
|
|
271
|
+
|
|
272
|
+
So: verification before `thread/start` is worth doing — it catches a manifest
|
|
273
|
+
that is already wrong — but **it must not be described as closing the race**,
|
|
274
|
+
and this document no longer does.
|
|
275
|
+
|
|
276
|
+
### E7 — real ordering · **RESOLVED; the earlier duration claim is withdrawn**
|
|
277
|
+
|
|
278
|
+
Two independent pieces of evidence, because one alone would not carry the claim.
|
|
279
|
+
|
|
280
|
+
**Code ordering (deterministic, `tests/codex-process.test.js`).** A new test drives
|
|
281
|
+
`CodexProcess` with a stub client that returns the `turn/start` response and then
|
|
282
|
+
withholds `turn/started` until the checkpoint has been observed. It proves the
|
|
283
|
+
durable `turn-accepted` checkpoint is awaited **after** the `turn/start` response
|
|
284
|
+
is validated and **before** the `turn/started` confirmation is awaited. Reordering
|
|
285
|
+
the production code makes the test deadlock rather than merely disagree — see
|
|
286
|
+
section 8 for the RED run.
|
|
287
|
+
|
|
288
|
+
**Live ordering (observed).** Wall-clock readings on one host clock, reported as
|
|
289
|
+
closed verdicts and duration buckets; no raw reading is emitted. Ties would
|
|
290
|
+
report `ambiguous`; none occurred. Ordering is derived **only** when the turn's
|
|
291
|
+
identities all agree — the `turn/start` response id, the `turn/started` id, the
|
|
292
|
+
`turn/completed` id, and the `turn_id` on every hook's stdin
|
|
293
|
+
(`turnIdentity.allConsistent: true`, gated). Each turn keeps its own record, so
|
|
294
|
+
an ordering can never be assembled from two turns' events.
|
|
295
|
+
|
|
296
|
+
```
|
|
297
|
+
thread/start response
|
|
298
|
+
→ SessionStart hook
|
|
299
|
+
→ turn/start response
|
|
300
|
+
→ turn/started notification
|
|
301
|
+
→ UserPromptSubmit hook
|
|
302
|
+
→ Stop hook
|
|
303
|
+
→ turn/completed notification
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
- `sessionStartVsThreadStartResponse: after` — `SessionStart` fires *after* the
|
|
307
|
+
`thread/start` response returns, not during it.
|
|
308
|
+
- `turnStartedNotificationVsTurnStartResponse: after`.
|
|
309
|
+
- `userPromptSubmitStrictlyBeforeTurnAccepted: false` and
|
|
310
|
+
`stopStrictlyBeforeTurnAccepted: false`. Both hooks fire after the `turn/start`
|
|
311
|
+
response, hence after the point at which the checkpoint is **initiated**.
|
|
312
|
+
- Hook stdin `turn_id` equalled the app-server turn id for both
|
|
313
|
+
`UserPromptSubmit` and `Stop`, and `SessionStart` carried **no** `turn_id`. U21
|
|
314
|
+
VF16 and the plan's section 8 negative both hold, now for the exact three-event
|
|
315
|
+
set.
|
|
316
|
+
|
|
317
|
+
**Withdrawn: the "10–100ms durable budget".** The previous revision of this
|
|
318
|
+
document reported that margin. It was measured with a recorder that stamped its
|
|
319
|
+
observation *after* draining stdin, so it timed the writer, not the hook's entry.
|
|
320
|
+
The recorder now stamps at entry, and the margin was remeasured.
|
|
321
|
+
|
|
322
|
+
The remeasured margin between the `turn/start` response and the
|
|
323
|
+
`UserPromptSubmit` hook is **`10-100ms` in three of five runs and `100ms-1s` in
|
|
324
|
+
two**, on an otherwise-idle host against a loopback provider. It is
|
|
325
|
+
load-dependent and should be read as *tens to hundreds of milliseconds*, not as
|
|
326
|
+
a bound. Do not plan against a specific figure; plan against the ordering fact.
|
|
327
|
+
|
|
328
|
+
**The ordering fact, stated at the strength the evidence supports.** The live
|
|
329
|
+
readings bound the hooks against the checkpoint's *initiation*, not its *durable
|
|
330
|
+
completion*. The checkpoint completes when the consuming sink returns, and both
|
|
331
|
+
hooks fire within a window of that order of magnitude. So the plan's section 4.8
|
|
332
|
+
clause is live rather than hypothetical: a hook **can** fire before the
|
|
333
|
+
`turn-accepted` checkpoint is durably usable if the sink is slow. Per section
|
|
334
|
+
4.8, **U15 owns it**; U23 is not blocked by it. U15 must not assume the
|
|
335
|
+
checkpoint is readable when `UserPromptSubmit` fires, and should fail closed with
|
|
336
|
+
a content-free counter, as U21 D3 anticipated.
|
|
337
|
+
|
|
338
|
+
### Decision 7 — the exact `HookMetadata` instance shape · **RESOLVED, plan is wrong**
|
|
339
|
+
|
|
340
|
+
**[schema]** Required: `currentHash`, `displayOrder`, `enabled`, `eventName`,
|
|
341
|
+
`handlerType`, `isManaged`, `key`, `source`, `sourcePath`, `timeoutSec`,
|
|
342
|
+
`trustStatus` — eleven fields. Optional/nullable: `additionalContextLimit`,
|
|
343
|
+
`command`, `matcher`, `pluginId`, `statusMessage` — **five**.
|
|
344
|
+
|
|
345
|
+
**[observed]**, identical on all three hooks in both the untrusted and trusted
|
|
346
|
+
inventories:
|
|
347
|
+
|
|
348
|
+
| Field | Value |
|
|
349
|
+
| --- | --- |
|
|
350
|
+
| `handlerType` | `command` |
|
|
351
|
+
| `source` | `user` |
|
|
352
|
+
| `isManaged` | `false` |
|
|
353
|
+
| `enabled` | **`true`, including while `trustStatus` is `untrusted`** |
|
|
354
|
+
| `timeoutSec` | `600` |
|
|
355
|
+
| `displayOrder` | 0, 1, 2 in manifest order |
|
|
356
|
+
| `currentHash` | matches `sha256:[a-f0-9]{64}` |
|
|
357
|
+
| `sourcePath` | equals the manifest path |
|
|
358
|
+
| `command` | byte-equal to the rendered command |
|
|
359
|
+
| unknown fields | 0 |
|
|
360
|
+
| optional field **keys present** | all five, on every entry |
|
|
361
|
+
| optional fields **non-null** | `command` only |
|
|
362
|
+
|
|
363
|
+
Two corrections fall out, both in section 4 below. The one to flag hardest:
|
|
364
|
+
**`enabled` is `true` while the hook is `untrusted` and will not run.** `enabled`
|
|
365
|
+
is a configuration flag, not a run predicate. A verifier that checked only
|
|
366
|
+
`enabled` would report a healthy manifest for hooks that never execute — the exact
|
|
367
|
+
silent-capture-stops failure the plan exists to prevent. Requiring
|
|
368
|
+
`trusted` **and** `enabled`, as section 4.6 already does, is correct and must not
|
|
369
|
+
be relaxed.
|
|
370
|
+
|
|
371
|
+
### Decision 8 — `system-runtime` target receipt and command byte stability · **RESOLVED**
|
|
372
|
+
|
|
373
|
+
**Target receipt, `aarch64-apple-darwin`** (this host's Node v24.4.0, arm64 darwin):
|
|
374
|
+
|
|
375
|
+
| Property | Value |
|
|
376
|
+
| --- | --- |
|
|
377
|
+
| `sha256` | `ea82308c4772253263227877abbe298205c5b5d454927300628a63dd71bcb7d5` |
|
|
378
|
+
| `nlink` | 1 |
|
|
379
|
+
| symlink | no |
|
|
380
|
+
| canonical path | yes |
|
|
381
|
+
| owner | the invoking user (not root) |
|
|
382
|
+
| group/world writable | no |
|
|
383
|
+
| owner-executable | yes |
|
|
384
|
+
| mode `0700` | **no** — and correctly not required |
|
|
385
|
+
| canonical parent chain safe | yes |
|
|
386
|
+
| satisfies the `system-runtime` rule | yes |
|
|
387
|
+
|
|
388
|
+
The `shipped-artifact` receipt for the checked-in recorder is
|
|
389
|
+
`bcb6b58c35db1bcbfae395e22f72046f81b949ec0472df84709c206630bc50d7` (nlink 1, not a
|
|
390
|
+
symlink, canonical, owner-owned, not group/world writable, safe parent chain,
|
|
391
|
+
**not** owner-executable).
|
|
392
|
+
|
|
393
|
+
Both rules now include the **canonical parent chain**: every ancestor directory
|
|
394
|
+
must be owned by root or by the invoking user and must not be group- or
|
|
395
|
+
world-writable unless it is sticky. A tight file under a loose directory is not
|
|
396
|
+
protected, because the directory permits wholesale replacement of the file. Both
|
|
397
|
+
real chains on this host pass; a deliberately `0777` intermediate directory is
|
|
398
|
+
rejected by a test.
|
|
399
|
+
|
|
400
|
+
**Command stability.** The renderer is a pure function of
|
|
401
|
+
`{runtime.path, artifacts[].path, argv}` and rendered byte-identically on repeat
|
|
402
|
+
(`commandRenderIsDeterministic: true`). A descriptor naming an unattested path
|
|
403
|
+
cannot be rendered at all. Reported `currentHash` values were identical across two
|
|
404
|
+
independent app-server sessions over unchanged content
|
|
405
|
+
(`currentHashStableAcrossSessions: true`), which is the stability property that
|
|
406
|
+
actually matters: a rendered `trusted_hash` stays valid across restarts.
|
|
407
|
+
|
|
408
|
+
Per-event command digests are **not** durable receipts — they include the capture
|
|
409
|
+
directory and so are run-scoped. The durable receipts are the two artifact digests
|
|
410
|
+
above.
|
|
411
|
+
|
|
412
|
+
**And a digest pinned once is not a guarantee.** The hook hash binds the command
|
|
413
|
+
string, which names the recorder's path rather than its contents, so an artifact
|
|
414
|
+
swapped after attestation runs with trust intact. Both pinned artifacts are
|
|
415
|
+
therefore re-read and re-compared immediately before **every** child launch
|
|
416
|
+
(`appServerLaunchesAttested === appServerLaunchesIntended`, 19 of 19 on the final
|
|
417
|
+
run, gated). That closes the window up to
|
|
418
|
+
launch and no further — see section 6.
|
|
419
|
+
|
|
420
|
+
### Decision 9 — do the trust stanza and manifest survive a turn? · **RESOLVED: yes**
|
|
421
|
+
|
|
422
|
+
Sampled immediately before and immediately after a turn that actually fired all
|
|
423
|
+
three hooks: `configDigestUnchangedAcrossTurn: true`,
|
|
424
|
+
`hooksManifestDigestUnchangedAcrossTurn: true`. Codex does not rewrite either file
|
|
425
|
+
during a turn. The claim is gated on captures existing, so a turn that fired
|
|
426
|
+
nothing cannot report vacuous stability.
|
|
427
|
+
|
|
428
|
+
### Incidental confirmations
|
|
429
|
+
|
|
430
|
+
- No `hook/*` notification reached the production delivered sink in any lane
|
|
431
|
+
(`deliveredHookMethodCount: 0`), and every turn reached `turn/completed` with an
|
|
432
|
+
assistant item and `faultCategory: 'none'`. PR #52's fix holds for the three-event
|
|
433
|
+
set, not only the gate's two.
|
|
434
|
+
- The release gate itself was re-run after the shared-file edits: `CONTINUE`,
|
|
435
|
+
zero failed checks, exit 0.
|
|
436
|
+
|
|
437
|
+
## 4. Corrections to the amendment plan
|
|
438
|
+
|
|
439
|
+
Fold these in before the second spec review. Each contradicts a specific
|
|
440
|
+
statement. **4.10 and 4.11 were added after the boundary experiment and the
|
|
441
|
+
recorder-clock fix; 4.10 replaces a security conclusion this document itself
|
|
442
|
+
previously drew.**
|
|
443
|
+
|
|
444
|
+
1. **§3.1 V5 — `command` is not a required field.** The pinned `HookMetadata`
|
|
445
|
+
lists it as optional and nullable. V5's required set must lose `command`, and
|
|
446
|
+
its optional set becomes five fields.
|
|
447
|
+
2. **§4.2.2 — "for the U23 fixture every optional field is expected absent, so the
|
|
448
|
+
map is empty" is false.** All five optional keys are *present* on every entry;
|
|
449
|
+
four are `null` and `command` is non-null. The `expectedOptional` model must
|
|
450
|
+
distinguish **key absent** from **key present with a null value**, or the U23
|
|
451
|
+
fixture fails closed on its own hooks. `command` also needs a defined position:
|
|
452
|
+
it is already covered by the descriptor's `commandSha256`, so it must be
|
|
453
|
+
excluded from `expectedOptional` rather than declared twice.
|
|
454
|
+
3. **§4.4 — do not render `[features] hooks = true`.** E4 shows it is required for
|
|
455
|
+
neither discovery nor execution. The plan already conditions it on S0; S0 says no.
|
|
456
|
+
4. **§4.1 — freeze `{cwds: [ownedCwd]}` and delete the "omitted" variant.** Omitted
|
|
457
|
+
params is rejected with `-32600`. Add the caveat from E2 that the response
|
|
458
|
+
echoes the requested cwd, so the equality check is a pin, not proof of scoping.
|
|
459
|
+
5. **§4.6 — drop `owner-executable` from the `shipped-artifact` rule** for an
|
|
460
|
+
artifact executed *through* an attested runtime. The recorder is passed to Node
|
|
461
|
+
as an argument and needs no exec bit; demanding one would force a pointless
|
|
462
|
+
permission. Keep owner match, no symlink, `nlink === 1`, not group/world
|
|
463
|
+
writable, digest match.
|
|
464
|
+
6. **§4.6 residual race — the window ends at `thread/start`, not at session
|
|
465
|
+
start.** A mid-session replacement is not executed, but the boundary sits at
|
|
466
|
+
`thread/start`: content swapped in after `initialize` and before
|
|
467
|
+
`thread/start` *is* the copy the session uses (E6c). Rewrite the window as
|
|
468
|
+
"last attestation → `thread/start`".
|
|
469
|
+
7. **§4.8 / E7 — the hook-before-checkpoint race is real; do not attach a
|
|
470
|
+
number to it.** Hooks fire after the `turn/start` response by tens to
|
|
471
|
+
hundreds of milliseconds, load-dependent, against a loopback provider.
|
|
472
|
+
Record the ordering and the race; do not record a budget figure.
|
|
473
|
+
8. **§3.1 V14 — the stale-`PATH` hazard is understated by one version.** On this
|
|
474
|
+
host `PATH` now resolves a bare `codex` to **0.147.0**, not 0.146.1. The hazard
|
|
475
|
+
is unchanged; the version in the plan is out of date.
|
|
476
|
+
9. **Add a normative statement that `enabled` is not a run predicate.** It is
|
|
477
|
+
`true` on untrusted hooks. Only `trusted` **and** `enabled` means "will run".
|
|
478
|
+
|
|
479
|
+
10. **§4.6 — verification before `thread/start` does not close the race, and the
|
|
480
|
+
plan must not imply that it does.** The plan places its trust verification
|
|
481
|
+
"after `initialize` and before any `thread/start`". E6c shows the manifest
|
|
482
|
+
snapshot happens *at* `thread/start`, so that verification runs strictly
|
|
483
|
+
inside the window it is meant to close. What actually bounds the window is
|
|
484
|
+
content-addressed trust — a swap to unstanza'd content is `modified` and
|
|
485
|
+
refuses to run. Keep the verification (it catches an already-wrong manifest)
|
|
486
|
+
and restate its guarantee honestly.
|
|
487
|
+
10a. **§4.6 — the artifact-body race must be an explicit acceptance in the
|
|
488
|
+
production spec, not an omission.** The hook hash binds the command string,
|
|
489
|
+
which names the artifact's path; the bytes at that path are bound by
|
|
490
|
+
nothing. Prelaunch attestation closes the window up to the app-server
|
|
491
|
+
launch and no further. The spec must either state that the residual
|
|
492
|
+
launch-to-fire window is accepted, or bind the artifact body by some
|
|
493
|
+
mechanism this run does not provide. Silence is not an option, because the
|
|
494
|
+
failure is silent: a swapped body runs with trust intact.
|
|
495
|
+
11. **§4.2 — a per-entry harvest of `key` and `currentHash` is unsafe; require an
|
|
496
|
+
exact whole-inventory match first.** The plan's rule 1/2 already demand exact
|
|
497
|
+
one-to-one matching, but an implementation that collects a key and hash per
|
|
498
|
+
entry as it goes will happily harvest them from a foreign, duplicated, or
|
|
499
|
+
tampered entry that carries two well-typed strings. Make it normative that
|
|
500
|
+
**no** trust value is produced unless the entire inventory matched: cardinality,
|
|
501
|
+
per-event uniqueness, key derivation, source path, handler type, source,
|
|
502
|
+
`isManaged`, command digest, hash form, required fields, and zero unknown
|
|
503
|
+
fields. This spike had that defect and it is fixed (section 8.3).
|
|
504
|
+
|
|
505
|
+
## 5. Unresolved unknowns
|
|
506
|
+
|
|
507
|
+
Explicitly not measured. None of these blocks U23, but none may be asserted.
|
|
508
|
+
|
|
509
|
+
- **The Linux target receipt.** S0 ran only on `aarch64-apple-darwin`. The
|
|
510
|
+
`x86_64-unknown-linux-musl` `system-runtime` receipt is unmeasured, so per the
|
|
511
|
+
plan's own rule that target cannot enable hooks until its gate runs.
|
|
512
|
+
- **Cardinality and paging at scale.** Section 3, E3.
|
|
513
|
+
- **User-layer exactness for config shapes this run did not write.** The object
|
|
514
|
+
model exercised strings, booleans, integers, nested tables, and one inline
|
|
515
|
+
table. Arrays, floats, datetimes, and dotted keys are untested; if
|
|
516
|
+
`buildOwnedConfig` grows one, E1 must be re-measured for that shape.
|
|
517
|
+
- **The window between child launch and the moment a hook fires.** Artifacts are
|
|
518
|
+
re-attested immediately before launch, and the manifest is fixed at
|
|
519
|
+
`thread/start`; nothing here measures whether an artifact body swapped after
|
|
520
|
+
that point still executes. It almost certainly does — the hash never bound the
|
|
521
|
+
body — but that is inference, not measurement. Section 6.
|
|
522
|
+
- **Whether a manifest can be *un*-trusted mid-session.** E6c swapped validly
|
|
523
|
+
trusted content *in* at three points. The reverse — replacing a running
|
|
524
|
+
session's manifest with content that is trusted under a different stanza — was
|
|
525
|
+
not exercised.
|
|
526
|
+
- **Non-`command` handler types.** `prompt` and `agent` exist in the pinned type
|
|
527
|
+
and were not exercised.
|
|
528
|
+
- **Populated `matcher` / `pluginId` / `statusMessage`.** All null here, so the
|
|
529
|
+
digest-comparison branch of `expectedOptional` has no live coverage.
|
|
530
|
+
- **Whether `hooks/list` requires `initialize` first.** Every session initialized
|
|
531
|
+
before calling it.
|
|
532
|
+
- **Any hosted-provider behaviour.** Loopback only, by construction.
|
|
533
|
+
- **Hook stdout semantics.** The recorder writes nothing to stdout. Whether a hook
|
|
534
|
+
that *does* write stdout can influence the turn was not probed.
|
|
535
|
+
|
|
536
|
+
## 6. Residual risks carried forward
|
|
537
|
+
|
|
538
|
+
- **The checkpoint-durability race** of section 3, E7 — owned by U15.
|
|
539
|
+
- **The artifact-body window, which trust does not bind at all.** The hook hash
|
|
540
|
+
binds the command string, and the command string names the recorder's *path*.
|
|
541
|
+
Replacing the bytes at that path leaves the hash, the trust stanza and the
|
|
542
|
+
manifest all valid and changes what executes. This spike closes the window up
|
|
543
|
+
to child launch by re-attesting every pinned artifact immediately beforehand
|
|
544
|
+
(section 8.3), but **nothing measured here closes the window between launch and
|
|
545
|
+
the moment a hook fires**. Any production design must either accept this
|
|
546
|
+
explicitly or bind the artifact body some other way.
|
|
547
|
+
- **The manifest window ends at `thread/start`** (E6c), not at spawn and not at
|
|
548
|
+
verification. Bounded by content-addressed trust, not by the verification call.
|
|
549
|
+
- Trust is content-addressed over the rendered command string, which embeds
|
|
550
|
+
absolute paths. Any path change (deploy layout, runtime upgrade, capture root)
|
|
551
|
+
invalidates every hash and lands the home in S-drift. This is the plan's
|
|
552
|
+
section 11 operator reprovision, and E5/E6 confirm there is no self-healing path.
|
|
553
|
+
- A Codex pin bump may move the key derivation, the hash, or the metadata shape.
|
|
554
|
+
E5's derivation is confirmed for 0.145.0 only.
|
|
555
|
+
|
|
556
|
+
## 7. Recommendation
|
|
557
|
+
|
|
558
|
+
**`CONTINUE`.** Proceed to fold these findings into the amendment plan and run the
|
|
559
|
+
second multi-agent spec review, with the **twelve** corrections in section 4
|
|
560
|
+
applied first. Specifically:
|
|
561
|
+
|
|
562
|
+
- E1 clears the blocking risk: the trusted-rendering approach survives, and
|
|
563
|
+
`buildOwnedConfig` can mirror the rendered TOML exactly.
|
|
564
|
+
- E2 freezes the schema entry as `{cwds: [ownedCwd]}`.
|
|
565
|
+
- E4 removes a stanza from both renderings.
|
|
566
|
+
- E5 lets Polygram predeclare all three keys.
|
|
567
|
+
- E6 **relocates** the residual race: the manifest is fixed at `thread/start`, so
|
|
568
|
+
the verification the plan places before `thread/start` sits inside the window
|
|
569
|
+
rather than closing it. What bounds the window is content-addressed trust.
|
|
570
|
+
- E7 confirms the ordering and hands the checkpoint-durability race to U15. It
|
|
571
|
+
does **not** quantify that race: the duration figure from the previous
|
|
572
|
+
revision was a measurement artefact and is withdrawn, and the remeasured
|
|
573
|
+
margin is reported as a load-dependent range, not a budget.
|
|
574
|
+
|
|
575
|
+
Nothing measured invalidates the design, and E1 — the one unknown that could
|
|
576
|
+
have — resolves in its favour. But the corrections are not all cosmetic: 4.10
|
|
577
|
+
replaces a security conclusion, and 4.6/4.7 change what the plan may claim about
|
|
578
|
+
the residual race.
|
|
579
|
+
|
|
580
|
+
## 8. Verification evidence
|
|
581
|
+
|
|
582
|
+
### 8.0 What "CONTINUE" now means, and what it meant before
|
|
583
|
+
|
|
584
|
+
The probe's gate originally derived `CONTINUE` from one predicate: that no
|
|
585
|
+
decision label remained in `unmeasured`. That is a completeness-of-*attempt*
|
|
586
|
+
check, not a completeness-of-*evidence* check, and it let an unattested binary,
|
|
587
|
+
a credential-free failure, a faulted turn, missing captures, a null enum, a
|
|
588
|
+
surviving process or an unremoved scratch root all exit 0.
|
|
589
|
+
|
|
590
|
+
The gate is now **28 named closed predicates** evaluated over the *projected*
|
|
591
|
+
evidence, so a value that collapsed to null in projection fails rather than
|
|
592
|
+
reading as a clean absence. `CONTINUE` requires `unmeasured` empty **and**
|
|
593
|
+
`failedChecks` empty; both conditions are reported in the envelope, along with
|
|
594
|
+
the full `checks` map. Every check name is drawn from a frozen list, so
|
|
595
|
+
`failedChecks` cannot carry peer-derived text.
|
|
596
|
+
|
|
597
|
+
Three of the predicates exist because "the decision was attempted" hid three
|
|
598
|
+
different failures: an **unrecognized decision label** used to be filtered out
|
|
599
|
+
of `unmeasured` and vanish; **auxiliary lanes** (the fresh session, the
|
|
600
|
+
feature-flag control, each boundary lane) used to contribute conclusions without
|
|
601
|
+
being held to the characterization lane's bar; and **launch attestation** used
|
|
602
|
+
to report success if a single guard had ever run. All three now fail closed.
|
|
603
|
+
|
|
604
|
+
**Consequence for anything read from an earlier revision of this document:** the
|
|
605
|
+
`CONTINUE` results reported before this change were produced under the weaker
|
|
606
|
+
gate. They are not evidence that the safety and completeness properties held —
|
|
607
|
+
they were simply never tested. Every result quoted in this revision comes from
|
|
608
|
+
runs under the 28-check gate, and each is re-stated from those runs rather than
|
|
609
|
+
carried over.
|
|
610
|
+
|
|
611
|
+
### 8.1 Baseline
|
|
612
|
+
|
|
613
|
+
An initial `npm test` in this worktree failed 8 suites with `EPERM mkdtemp` on
|
|
614
|
+
paths under `$HOME`. That run was **invalid setup**, not a failure: the worktree
|
|
615
|
+
had no `node_modules`, and the run was additionally sandboxed. Recorded here so it
|
|
616
|
+
is not mistaken for a regression.
|
|
617
|
+
|
|
618
|
+
Valid baseline, after `npm ci` (106 packages), unsandboxed:
|
|
619
|
+
|
|
620
|
+
```
|
|
621
|
+
ℹ tests 1265 ℹ pass 1246 ℹ fail 0 ℹ skipped 19
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
The 19 skips are pre-existing capability gates in `tests/process-contract.test.js`
|
|
625
|
+
(`# SKIP channels-protocol N/A`, `# SKIP codex-capability N/A`). The count is
|
|
626
|
+
unchanged after this work.
|
|
627
|
+
|
|
628
|
+
### 8.2 RED → GREEN
|
|
629
|
+
|
|
630
|
+
Every behaviour change below was driven by a test written first and observed
|
|
631
|
+
failing against the unfixed code.
|
|
632
|
+
|
|
633
|
+
**(a) The `turn-accepted` ordering test.** Characterizing existing production
|
|
634
|
+
behaviour, then proven non-tautological by reordering the production code: a
|
|
635
|
+
single `await pending.turnReady.promise;` inserted before the checkpoint in
|
|
636
|
+
`lib/process/codex-process.js`.
|
|
637
|
+
|
|
638
|
+
```
|
|
639
|
+
RED ✖ turn-accepted is checkpointed after the turn/start response and before the turn/started await
|
|
640
|
+
AssertionError: turn-accepted must be durable before turn/started is awaited
|
|
641
|
+
+ actual 'not-checkpointed' - expected 'checkpointed'
|
|
642
|
+
GREEN ✔ same test (3.9ms)
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
`lib/process/codex-process.js` was restored byte-for-byte (`git diff` empty)
|
|
646
|
+
before the green run and is unmodified in the final tree.
|
|
647
|
+
|
|
648
|
+
**(b) The JSON-RPC error-code carry.** Test-first against the pristine shared probe:
|
|
649
|
+
|
|
650
|
+
```
|
|
651
|
+
RED ✖ a rejected request carries its numeric code and none of the peer text
|
|
652
|
+
✖ a rejection without a usable numeric code reports no code rather than a guess
|
|
653
|
+
ℹ pass 0 ℹ fail 2
|
|
654
|
+
GREEN ✔ both ℹ pass 2 ℹ fail 0
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
**(c) The envelope-leakage tests**, proven non-tautological by two mutations of
|
|
658
|
+
the projector, each reverted:
|
|
659
|
+
|
|
660
|
+
```
|
|
661
|
+
projectShape made to spread its source →
|
|
662
|
+
RED ✖ the envelope drops unapproved keys at every nesting level
|
|
663
|
+
asEnum / asDigest made to pass values through →
|
|
664
|
+
RED ✖ an out-of-enum value becomes null instead of being echoed into the envelope
|
|
665
|
+
RED ✖ a content-bearing envelope is refused rather than printed
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
**(d) The gate, and every hardening below it.** 18 adverse tests were written
|
|
669
|
+
against the unfixed spike and observed failing together:
|
|
670
|
+
|
|
671
|
+
```
|
|
672
|
+
ℹ tests 53 ℹ pass 35 ℹ fail 18
|
|
673
|
+
✖ a complete, safe measurement is the only thing that reaches CONTINUE
|
|
674
|
+
✖ adverse evidence stops the gate instead of exiting clean
|
|
675
|
+
✖ every declared gate check is exercised by at least one adverse case
|
|
676
|
+
✖ an unmeasured decision and a failed check both stop the gate independently
|
|
677
|
+
✖ an exactly matching inventory is trustable and yields one hash per descriptor
|
|
678
|
+
✖ an inventory that is not an exact match yields no trustable hash at all
|
|
679
|
+
✖ rendering trust from an untrustable inventory is refused before any turn
|
|
680
|
+
✖ an unsafe artifact is refused, not merely reported
|
|
681
|
+
✖ an artifact under a group-writable parent is unsafe however safe the file is
|
|
682
|
+
✖ an artifact swapped after attestation is caught by re-attestation before launch
|
|
683
|
+
✖ capture ingestion validates each file before it reads a byte of it
|
|
684
|
+
✖ capture ingestion bounds file count and bytes before parsing
|
|
685
|
+
✖ a turn whose started id disagrees with its response is reported inconsistent
|
|
686
|
+
✖ each turn keeps its own outcome instead of being overwritten by the next
|
|
687
|
+
✖ a failed client close fails the lane rather than being absorbed
|
|
688
|
+
✖ a child that cannot be proved retired fails the lane
|
|
689
|
+
✖ the recorder stamps its observation before it drains stdin
|
|
690
|
+
✖ the manifest snapshot boundary is classified from where new content stops running
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
After the fixes: `ℹ tests 65 ℹ pass 65 ℹ fail 0`.
|
|
694
|
+
|
|
695
|
+
Twenty-one further tests were added across the review rounds that followed, of
|
|
696
|
+
which **twenty were observed failing before their fix**: boundary-lane health
|
|
697
|
+
and monotonic classification, lane-health predicates, per-turn typed assistant
|
|
698
|
+
correlation, the required launch guard, launch-count parity and the frozen
|
|
699
|
+
launch count, unrecognized decision labels, fixture-field pinning, the exact
|
|
700
|
+
fixture timeout, the exact modified-inventory predicate, the discovery-envelope
|
|
701
|
+
validator, the second same-session turn's own record, the fresh-session
|
|
702
|
+
inventory, the boundary label, the completion-deadline leak,
|
|
703
|
+
absence-vs-observed-false in the ordering booleans, the injected
|
|
704
|
+
prevalidation-to-open capture swap, and recorder overflow. The twenty-first — a
|
|
705
|
+
symlinked capture — passed on arrival because the pre-existing name check
|
|
706
|
+
already caught it; it is kept, and the injected-swap regression that did **not**
|
|
707
|
+
pass on arrival is what covers the actual race.
|
|
708
|
+
|
|
709
|
+
**38 adverse tests in total were written before their fix and observed
|
|
710
|
+
failing** (18 in the first round, 20 across the later ones).
|
|
711
|
+
|
|
712
|
+
The adverse table drives **67 distinct evidence mutations** through the gate, each
|
|
713
|
+
asserting both `gate === 'STOP'` and the specific named check. A further test
|
|
714
|
+
asserts that **every** declared check is covered by at least one adverse case, so
|
|
715
|
+
a check that could never fire cannot be added silently.
|
|
716
|
+
|
|
717
|
+
Two tests changed meaning as a result and were updated deliberately, not
|
|
718
|
+
loosened: the single-entry inventory case now asserts `trustable: false` and an
|
|
719
|
+
empty trust list (it previously asserted a harvested hash), and the
|
|
720
|
+
unapproved-key leakage case now injects its sentinel into an otherwise-complete
|
|
721
|
+
entry so it tests leakage rather than incidentally tripping completeness.
|
|
722
|
+
|
|
723
|
+
### 8.3 Defects found and fixed
|
|
724
|
+
|
|
725
|
+
Thirteen, all in this spike's own code, all found by review or by the new gate.
|
|
726
|
+
|
|
727
|
+
1. **E7 compared two different turns.** `runTurn` reused one set of timing slots,
|
|
728
|
+
so the second turn overwrote the first turn's readings. Fixed by keeping a
|
|
729
|
+
record per turn; the reported ordering changed as a result.
|
|
730
|
+
2. **The response id was compared against the wrong notification.**
|
|
731
|
+
`turnStartResponseMatchesStarted` was computed from the `turn/completed` id, so
|
|
732
|
+
a turn whose `turn/started` disagreed with its response reported as consistent.
|
|
733
|
+
Now the response is compared against `turn/started` and `turn/completed`
|
|
734
|
+
separately, and ordering is only derived when both agree and every hook's
|
|
735
|
+
`turn_id` matches.
|
|
736
|
+
3. **The recorder stamped its observation after draining stdin**, timing the
|
|
737
|
+
writer rather than the hook's entry and inflating every derived margin. The
|
|
738
|
+
stamp moved to process entry; the margin was remeasured and the earlier
|
|
739
|
+
"10–100ms" claim withdrawn (E7).
|
|
740
|
+
4. **Trust values were harvested per entry.** `splitHookInventory` collected a key
|
|
741
|
+
and hash from any entry carrying two well-typed strings, so a foreign,
|
|
742
|
+
duplicated or tampered hook could contribute a trust stanza. It now produces
|
|
743
|
+
trust values **only** when the whole inventory is an exact one-to-one match,
|
|
744
|
+
and `trustStateFromInventory` is the single path from inventory to stanza —
|
|
745
|
+
it throws otherwise, before any turn runs.
|
|
746
|
+
5. **Attestation described rather than enforced.** `attestArtifact` reported
|
|
747
|
+
`satisfiesKindRule` and no caller checked it. There is now an enforcing
|
|
748
|
+
`attestArtifactStrict`, the rule includes the canonical **parent chain**
|
|
749
|
+
(every ancestor owned by root or self and not group/world-writable unless
|
|
750
|
+
sticky), and `verifyPinnedArtifacts` re-reads both artifacts immediately
|
|
751
|
+
before every **app-server** launch — because the hook hash binds the
|
|
752
|
+
command's *path*, not the bytes at it. This is prelaunch attestation of the
|
|
753
|
+
app-server, not of the hook subprocess: the artifact-body window between
|
|
754
|
+
launch and hook fire stays open (section 6).
|
|
755
|
+
6. **Cleanup and capture ingestion were weak.** Client-close failure is now a
|
|
756
|
+
lane failure with its own `closeClean` fact; child retirement is proved
|
|
757
|
+
against the client's **pid and process group** with SIGKILL escalation rather
|
|
758
|
+
than a command-text match; and capture files are validated for name pattern,
|
|
759
|
+
regular-file type, no symlink, `nlink === 1`, owner, mode `0600`, file count,
|
|
760
|
+
per-file bytes and aggregate bytes **before** any byte is read.
|
|
761
|
+
|
|
762
|
+
7. **Auxiliary lanes voted without being checked.** The boundary lanes, the
|
|
763
|
+
fresh session and the feature-flag control fed conclusions on the strength of
|
|
764
|
+
"it did not throw". A lane that faulted also produces no captures, which is
|
|
765
|
+
indistinguishable from "the swapped-in content did not run" — so the boundary
|
|
766
|
+
could have been mis-located by a broken lane. Every production lane now has
|
|
767
|
+
to clear the same bar (completed, identity-consistent, assistant-producing,
|
|
768
|
+
fault-free, clean close, child retired), and a boundary lane that fails it
|
|
769
|
+
abstains rather than voting.
|
|
770
|
+
8. **Launch attestation reported presence, not parity.** The fact was
|
|
771
|
+
`reattestations > 0`, and one helper (`measureParamForms`) was never guarded
|
|
772
|
+
at all. Every app-server launch helper now requires its guard as an argument
|
|
773
|
+
— an unguarded call throws rather than launching — and the emitted fact is
|
|
774
|
+
`intended === attested` with both counted centrally. On the final run that is
|
|
775
|
+
**19 of 19**. The name was also narrowed: this is *app-server prelaunch*
|
|
776
|
+
attestation, and it says nothing about the window between launch and the
|
|
777
|
+
moment a hook fires.
|
|
778
|
+
9. **The whitelist pinned identity but not the fields that decide execution.**
|
|
779
|
+
Nonzero key indices, an unexpected `trustStatus`, `enabled: false`, a wrong
|
|
780
|
+
`displayOrder`, a non-integer timeout, or a populated `matcher` /
|
|
781
|
+
`pluginId` / `statusMessage` / `additionalContextLimit` all passed. A hook
|
|
782
|
+
that will not run is not a hook whose hash should be rendered into a trust
|
|
783
|
+
stanza, so every fixture-defining field — including the exact
|
|
784
|
+
present-but-null optional shape — is now pinned before an inventory is
|
|
785
|
+
trustable.
|
|
786
|
+
10. **Capture validation re-resolved the path it had checked.** An `lstat`
|
|
787
|
+
followed by `readFileSync` of the same name is a race. Each capture is now
|
|
788
|
+
opened once with `O_NOFOLLOW`, validated by `fstat` **on that descriptor**
|
|
789
|
+
(type, `nlink`, owner, mode, size) and read from it. A regression injects a
|
|
790
|
+
swap between the name check and the open.
|
|
791
|
+
11. **The recorder accepted a valid prefix of an oversized payload.** On
|
|
792
|
+
exceeding its 256 KiB bound it destroyed stdin and returned what it had
|
|
793
|
+
already buffered, so a well-formed opening object followed by an arbitrary
|
|
794
|
+
tail parsed cleanly and yielded a turn id. Overflow is now tracked and the
|
|
795
|
+
payload rejected whole.
|
|
796
|
+
12. **A completed turn left its 45-second deadline armed.** `wait(...).then(throw)`
|
|
797
|
+
cannot be cancelled, so every successful turn held a live timer that kept
|
|
798
|
+
the event loop alive until it fired. Natural exit was *delayed* by roughly
|
|
799
|
+
the deadline, not prevented. The deadline is now cancellable and cancelled
|
|
800
|
+
in a `finally`; a regression drives a stub session in a child process and
|
|
801
|
+
asserts prompt natural exit. Wall clock per live run went from ~52s to ~11s.
|
|
802
|
+
13. **Absence read as an observed `false`.** The two
|
|
803
|
+
`…StrictlyBeforeTurnAccepted` booleans projected through `asBool`, so a
|
|
804
|
+
missing value became `false` and passed the completeness check. They are
|
|
805
|
+
nullable now, and the check demands an actual boolean.
|
|
806
|
+
|
|
807
|
+
The credential-free reader defect from the previous revision also stands: the
|
|
808
|
+
release gate's reader matches a bare TOML key while this rendering quotes every
|
|
809
|
+
key, so `providerRequiresAuth` silently returned `null`. A quoted-key-tolerant
|
|
810
|
+
reader was added, and the gate now **fails** on a null rather than reporting it.
|
|
811
|
+
|
|
812
|
+
**The new gate immediately earned its keep.** The first live run under it
|
|
813
|
+
returned `STOP` with `failedChecks: ['snapshotBoundaryLocated']` — the boundary
|
|
814
|
+
experiment's control lane had not run, because `manifestB` was read *after*
|
|
815
|
+
re-provisioning had already overwritten it, making the swap a no-op. Under the
|
|
816
|
+
old gate that run would have exited 0 with a null boundary.
|
|
817
|
+
|
|
818
|
+
### 8.4 Focused test runs
|
|
819
|
+
|
|
820
|
+
```
|
|
821
|
+
<node> --test --test-concurrency=1 tests/codex-hook-trust-s0.test.js
|
|
822
|
+
ℹ tests 75 ℹ pass 75 ℹ fail 0 ℹ skipped 0
|
|
823
|
+
```
|
|
824
|
+
|
|
825
|
+
Run under **two different runtimes** — the repo shell's ordinary `node` (26.5,
|
|
826
|
+
installed under a group-writable prefix) and the pinned safe runtime (24.4.0
|
|
827
|
+
under an owner-only chain) — and the TAP output was compared line for line:
|
|
828
|
+
**identical results line for line, 0 `not ok` in either.**
|
|
829
|
+
|
|
830
|
+
That comparison exists because an earlier revision of this suite asserted that
|
|
831
|
+
the *ambient* `process.execPath` satisfies the `system-runtime` rule. It does
|
|
832
|
+
not, on a machine whose `node` sits under a group-writable prefix — and it
|
|
833
|
+
should not; the rule is working. The suite now attests controlled fixtures
|
|
834
|
+
(a root-owned shared binary, an owner-owned one under a verified-safe chain, and
|
|
835
|
+
one under a deliberately group-writable prefix) instead of whatever runtime
|
|
836
|
+
happens to be executing it. **The strict ambient check stays where it belongs:
|
|
837
|
+
the live probe, via `--runtime`.**
|
|
838
|
+
|
|
839
|
+
Run **without** `--test-force-exit`. `tests/codex-hook-trust-s0.test.js`,
|
|
840
|
+
`tests/codex-process.test.js` and `tests/codex-hook-probe.test.js` each exit 0
|
|
841
|
+
without it, so no new handle leak was introduced and none is being concealed.
|
|
842
|
+
The whole-repo `npm test` in 8.5 retains the repository's standard force-exit;
|
|
843
|
+
these focused runs are what make the leak claim testable.
|
|
844
|
+
|
|
845
|
+
### 8.5 Full suite
|
|
846
|
+
|
|
847
|
+
```
|
|
848
|
+
npm test (node --test --test-force-exit --test-concurrency=1 tests/*.test.js)
|
|
849
|
+
ℹ tests 1343 ℹ suites 69 ℹ pass 1324 ℹ fail 0 ℹ skipped 19
|
|
850
|
+
```
|
|
851
|
+
|
|
852
|
+
Run under both runtimes — the repo shell's ordinary `node` and the pinned safe
|
|
853
|
+
one — with identical totals. Net change from baseline: +78 tests, +78 passing,
|
|
854
|
+
skips unchanged at 19. This invocation keeps the repository's standard
|
|
855
|
+
`--test-force-exit`; the changed suites are additionally run without it (8.7).
|
|
856
|
+
|
|
857
|
+
**One flake, pre-existing, not introduced here.** `tests/codex-hook-probe.test.js`
|
|
858
|
+
→ "the raw session fails closed on malformed bytes that arrive during teardown"
|
|
859
|
+
failed once during an intermediate run
|
|
860
|
+
(`assert.ok(error, 'teardown-time garbage must fail the session')`, actual `null`).
|
|
861
|
+
It is a load-dependent timing test: it spawns a grandchild that writes to an
|
|
862
|
+
inherited stdout ~250ms after its parent exits. Characterized deliberately:
|
|
863
|
+
|
|
864
|
+
- current tree, 20 sequential repetitions → **0 failures**
|
|
865
|
+
- **pristine** shared probe (edits stashed), 20 repetitions in parallel → **1 failure**
|
|
866
|
+
- pristine, 10 sequential repetitions → 0 failures
|
|
867
|
+
|
|
868
|
+
It reproduces without these changes and only under parallel load, so it is a
|
|
869
|
+
pre-existing flake in that test's timing assumption, not a regression. It is not
|
|
870
|
+
fixed here — out of S0's scope — but it is on the record, and it is the reason
|
|
871
|
+
the suite figure above is quoted from two clean consecutive runs rather than one.
|
|
872
|
+
|
|
873
|
+
### 8.6 Live probe
|
|
874
|
+
|
|
875
|
+
Under the 28-check gate, against the pinned 0.145.0 binary on Darwin:
|
|
876
|
+
|
|
877
|
+
```
|
|
878
|
+
gate: CONTINUE unmeasured: [] failedChecks: [] exit 0 stderr empty
|
|
879
|
+
```
|
|
880
|
+
|
|
881
|
+
Invoked with an explicitly pinned safe runtime:
|
|
882
|
+
|
|
883
|
+
```sh
|
|
884
|
+
/absolute/safe/node scripts/spikes/codex-hook-trust-s0.mjs \
|
|
885
|
+
--binary /absolute/versioned/path/to/codex \
|
|
886
|
+
--probe-root /absolute/non-temporary/probe-root \
|
|
887
|
+
--runtime /absolute/safe/node
|
|
888
|
+
```
|
|
889
|
+
|
|
890
|
+
Three consecutive passing runs on the final tree, each **~11s** wall clock, with
|
|
891
|
+
**19 of 19** app-server launches prelaunch-attested against a frozen expected
|
|
892
|
+
count. Every verdict identical
|
|
893
|
+
across them, including the duration buckets. Digests differ by construction,
|
|
894
|
+
since the rendered command embeds a per-run capture directory.
|
|
895
|
+
|
|
896
|
+
Earlier revisions of this run took ~52s. The difference was a leaked 45-second
|
|
897
|
+
completion deadline (8.3), not measurement: a successful turn left its timer
|
|
898
|
+
armed, so the event loop stayed alive until that timer fired. The run still
|
|
899
|
+
exited naturally — it was delayed by roughly the deadline, not prevented from
|
|
900
|
+
exiting.
|
|
901
|
+
|
|
902
|
+
The release gate `scripts/spikes/codex-app-server-hook-probe.mjs` was re-run after
|
|
903
|
+
the shared-file edits: `gate: CONTINUE`, `failedChecks: []`, exit 0.
|
|
904
|
+
|
|
905
|
+
### 8.7 Process cleanup
|
|
906
|
+
|
|
907
|
+
Three independent facts, all gated:
|
|
908
|
+
|
|
909
|
+
- `closeClean: true` — the production client's `close()` returned without error;
|
|
910
|
+
a failure now fails the lane rather than being absorbed.
|
|
911
|
+
- `childRetired: true` — the client's own child **pid** was probed with
|
|
912
|
+
`kill(pid, 0)` and its **process group** enumerated until empty, with a
|
|
913
|
+
`SIGKILL` escalation to the group. This is structural, not a command-text match.
|
|
914
|
+
- `strayProcessCount: 0` — a final sweep of the process table found nothing
|
|
915
|
+
referencing the probe root.
|
|
916
|
+
|
|
917
|
+
`probeRootRemoved: true`, and the supplied probe root was verified empty by
|
|
918
|
+
directory listing after every run.
|
|
919
|
+
|
|
920
|
+
**Where force-exit is and is not used.** The live probe uses none: it exits on
|
|
921
|
+
its own once its deadlines are cancelled and its children are retired. Neither
|
|
922
|
+
do the changed suites — `tests/codex-hook-trust-s0.test.js`,
|
|
923
|
+
`tests/codex-process.test.js` and `tests/codex-hook-probe.test.js` each exit 0
|
|
924
|
+
when run **without** `--test-force-exit`, which is what makes the leak claim
|
|
925
|
+
mean anything. The whole-repo `npm test` keeps the repository's standard
|
|
926
|
+
`--test-force-exit`; that predates this work and is unchanged by it, which is
|
|
927
|
+
precisely why the changed suites are also run without it.
|
|
928
|
+
|
|
929
|
+
## 9. Changed paths
|
|
930
|
+
|
|
931
|
+
| Path | Change |
|
|
932
|
+
| --- | --- |
|
|
933
|
+
| `scripts/spikes/codex-hook-trust-s0.mjs` | **new** — the S0 characterization, its 28-check gate, and the hardening in 8.3 |
|
|
934
|
+
| `scripts/spikes/u23-hook-recorder.mjs` | **new** — checked-in content-free Node hook recorder |
|
|
935
|
+
| `tests/codex-hook-trust-s0.test.js` | **new** — 75 focused tests, including 67 adverse gate mutations |
|
|
936
|
+
| `scripts/spikes/codex-app-server-hook-probe.mjs` | modified — export `startLoopbackProvider`; carry the numeric JSON-RPC error code on a rejection (+11 / −3) |
|
|
937
|
+
| `tests/codex-hook-probe.test.js` | modified — 2 tests for the error-code carry |
|
|
938
|
+
| `tests/codex-process.test.js` | modified — 1 test pinning the `turn-accepted` ordering |
|
|
939
|
+
| `docs/2026-08-17-001-u23-hook-trust-characterization-findings.md` | **new** — this document |
|
|
940
|
+
|
|
941
|
+
The runtime is itself an attested artifact, so the documented invocation accepts
|
|
942
|
+
`--runtime /absolute/path/to/node`. A package-manager-installed Node commonly
|
|
943
|
+
sits under a group-writable prefix and is correctly refused by the strict
|
|
944
|
+
attestation; pass a runtime whose canonical parent chain is owned by root or the
|
|
945
|
+
invoking user and is not group- or world-writable. The invoking runtime is the
|
|
946
|
+
default, never a requirement.
|
|
947
|
+
|
|
948
|
+
Not touched: `lib/codex/protocol-schema.json`, any production `lib/` source,
|
|
949
|
+
`package.json`, `package-lock.json`, any release worktree. Nothing committed,
|
|
950
|
+
tagged, pushed, published, or deployed. `node_modules/` was installed via `npm ci`
|
|
951
|
+
and is untracked. `lib/process/codex-process.js` was temporarily edited to
|
|
952
|
+
demonstrate a RED and restored byte-for-byte; it carries no change in the final
|
|
953
|
+
tree.
|
|
954
|
+
|
|
955
|
+
Receipts from the final run (`aarch64-apple-darwin`, Node v24.4.0):
|
|
956
|
+
`system-runtime` `ea82308c4772253263227877abbe298205c5b5d454927300628a63dd71bcb7d5`,
|
|
957
|
+
`shipped-artifact` `bcb6b58c35db1bcbfae395e22f72046f81b949ec0472df84709c206630bc50d7`.
|
|
958
|
+
|
|
959
|
+
---
|
|
960
|
+
|
|
961
|
+
STATUS: DONE
|
|
962
|
+
WHAT: Ran the bounded U23 S0 characterization on pinned Codex 0.145.0 (Darwin, credential-free, loopback-only) and repaired it across five independent review rounds. CONTINUE is now 28 closed completeness/safety predicates rather than "no decision left unattempted"; trust values come only from an exact whole-inventory match that pins every fixture-defining field; artifact attestation is enforcing, covers the canonical parent chain, and re-runs before every one of the 19 app-server launches (parity-counted, not presence-counted); client-close failure, pid/pgid retirement and auxiliary-lane health all fail the lane; capture files are opened O_NOFOLLOW and validated on the descriptor they are read from; the recorder stamps its clock at entry and rejects an overflowed payload whole; per-turn identity and a typed, turn-correlated agentMessage gate the ordering; a completed turn cancels its deadline (run wall clock 52s → 11s); and a bounded three-lane experiment locates the manifest snapshot at thread/start. 38 adverse tests were written first and observed failing; 67 evidence mutations drive the gate. Full suite 1343 tests / 1324 pass / 0 fail / 19 pre-existing skips under both the ordinary repo runtime and a pinned safe one; focused 75/75 identical across both; three consecutive live runs CONTINUE with 28/28 checks and 19/19 prelaunch-attested launches.
|
|
963
|
+
NEED: Nothing to unblock S0. Two conclusions changed from earlier revisions and must be read before the design is written: verification before thread/start does NOT close the manifest race (section 4.10), and the "10-100ms durable budget" figure is withdrawn as a measurement artefact (section 3, E7). Twelve plan corrections in section 4 still need folding in. The x86_64-unknown-linux-musl runtime receipt still has to be measured on the VPS. The window between child launch and hook fire remains open and unmeasured (section 6) — the hook hash never bound the artifact body.
|
|
964
|
+
NEXT: Fold sections 3-6 into `docs/plans/2026-08-16-002-feat-codex-hook-trust-discovery-plan.md`, re-run the multi-agent spec review, then open the Orchestra PR for the local-manifest hook verification request with the frozen `{cwds: [ownedCwd]}` params form.
|