@shumkov/orchestra 0.9.0 → 0.10.1
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/CODEX_DASH_FILE_DENIAL_PROBE_SPEC.md +58 -0
- package/docs/CODEX_LINUX_TRACKED_TERMINAL_PID_SPEC.md +112 -0
- package/docs/CODEX_OPTIONAL_ATTACHMENT_EFFORT_SPEC.md +509 -0
- package/docs/codex-app-server-compatibility.md +89 -9
- package/index.js +2 -1
- package/lib/codex/app-server-client.js +65 -12
- package/lib/codex/preflight.js +8 -2
- package/lib/codex/protocol-schema.json +4 -0
- package/lib/codex/thread-attachment-settings.js +48 -0
- package/lib/process/codex-process.js +116 -20
- package/package.json +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Portable file-denial probe
|
|
2
|
+
|
|
3
|
+
## Problem
|
|
4
|
+
|
|
5
|
+
The U1a file-enforcement script tests protected files with the special builtin
|
|
6
|
+
redirection `exec 3<path`. Ubuntu `/bin/sh` is dash, which exits a
|
|
7
|
+
non-interactive shell with status 2 when that redirection is denied. The script
|
|
8
|
+
therefore never reaches its later CODEX_HOME and daemon-root checks, and the
|
|
9
|
+
checker cannot distinguish correct denial from probe failure.
|
|
10
|
+
|
|
11
|
+
The workspace marker uses the other special builtin `:` with redirection, so a
|
|
12
|
+
marker-write denial has the same dash behavior and cannot retain exit code 11.
|
|
13
|
+
|
|
14
|
+
## Chosen approach
|
|
15
|
+
|
|
16
|
+
Use the already required `/usr/bin/head -c 1 path` command for every protected
|
|
17
|
+
file probe. The script first uses the same executable to read the workspace
|
|
18
|
+
positive-control file, so a missing or unusable helper still fails with the
|
|
19
|
+
existing workspace-read exit code. A protected file is a failure only when
|
|
20
|
+
`head` can open it; denied or absent optional files let the script continue.
|
|
21
|
+
Create the workspace marker with regular `printf` redirection so a write denial
|
|
22
|
+
reaches the existing `|| exit 11` classification.
|
|
23
|
+
|
|
24
|
+
This keeps the existing arguments and exit-code contract:
|
|
25
|
+
|
|
26
|
+
- `10` and `11` remain workspace read/write failures;
|
|
27
|
+
- `12` and `13` remain readable CODEX_HOME config/auth failures;
|
|
28
|
+
- `30` remains a readable daemon-root sentinel;
|
|
29
|
+
- `0` means every required protected file was denied.
|
|
30
|
+
|
|
31
|
+
Darwin uses the same script and retains the same open/read enforcement
|
|
32
|
+
semantics. No package runtime or production client code changes.
|
|
33
|
+
|
|
34
|
+
## Alternatives rejected
|
|
35
|
+
|
|
36
|
+
- Wrapping `exec 3<path` in a subshell contains dash's fatal exit, but preserves
|
|
37
|
+
the special-builtin portability trap and adds a second shell execution path.
|
|
38
|
+
- Shell permission predicates such as `[ -r path ]` do not prove the sandboxed
|
|
39
|
+
command can actually open the file.
|
|
40
|
+
- Adding another helper such as `cat` or `dd` is unnecessary because `head` is
|
|
41
|
+
already positively controlled and used for daemon-root probes.
|
|
42
|
+
|
|
43
|
+
## Failure modes and verification
|
|
44
|
+
|
|
45
|
+
Unreadable protected files continue to classify as denied. Readable protected
|
|
46
|
+
files retain their exact failure codes. An unavailable `head`, unreadable
|
|
47
|
+
workspace control, or unwritable workspace marker still fails closed before
|
|
48
|
+
protected-file classification.
|
|
49
|
+
|
|
50
|
+
The focused regression executes the generated script with `/bin/dash` against
|
|
51
|
+
a readable workspace control, writable marker, and denied/missing protected
|
|
52
|
+
paths. It must be red on the current `exec` form with exit 2 and green with exit
|
|
53
|
+
0 after the change. Companion cases verify readable CODEX_HOME and daemon-root
|
|
54
|
+
files retain exit 12/13/30, the generated script contains no descriptor `exec`,
|
|
55
|
+
and Darwin-facing command construction remains unchanged.
|
|
56
|
+
|
|
57
|
+
After the focused test passes, run the complete spike test and the full Node
|
|
58
|
+
24.4.0 suite, then obtain independent correctness/security/simplicity review.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Linux tracked-terminal host PID resolution
|
|
2
|
+
|
|
3
|
+
## Problem
|
|
4
|
+
|
|
5
|
+
The Codex U1a checker asks a sandboxed command to write `$$` before it becomes
|
|
6
|
+
`/bin/sleep 120`. On Linux that value belongs to the sandbox PID namespace. It
|
|
7
|
+
is not safe to pass to host-side `kill(pid, 0)`: namespace PID 3 can identify an
|
|
8
|
+
unrelated host process and produce `EPERM`, or give a misleading liveness
|
|
9
|
+
result.
|
|
10
|
+
|
|
11
|
+
The app-server process spawned by `AppServerConnection` has a known host PID.
|
|
12
|
+
The tracked sleep must be identified only inside that process's descendant
|
|
13
|
+
tree.
|
|
14
|
+
|
|
15
|
+
## Chosen approach
|
|
16
|
+
|
|
17
|
+
Darwin continues to treat the marker as the host PID and uses the existing
|
|
18
|
+
`kill(pid, 0)` liveness behavior.
|
|
19
|
+
|
|
20
|
+
On Linux, the checker:
|
|
21
|
+
|
|
22
|
+
1. Before starting the turn, records the `AppServerConnection` child host PID
|
|
23
|
+
and its `/proc/<pid>/stat` start time, and records `/bin/sleep` device and
|
|
24
|
+
inode identity. It also generates a per-invocation random token which the
|
|
25
|
+
synthetic shell exports before executing sleep.
|
|
26
|
+
2. Enumerates at most 65,536 numeric `/proc` entries. PIDs are canonical
|
|
27
|
+
decimal values from 2 through 2,147,483,647.
|
|
28
|
+
3. Reads at most 4,096 bytes from each `/proc/<pid>/stat`, parsing around the
|
|
29
|
+
final `") "` delimiter. The directory PID must equal stat field 1; parent
|
|
30
|
+
PID and start time must be canonical decimal strings. Duplicate records,
|
|
31
|
+
cycles, more than 65,536 graph nodes, or ancestry deeper than 256 stop the
|
|
32
|
+
checker.
|
|
33
|
+
4. Builds the host parent tree rooted at the fingerprinted app-server PID,
|
|
34
|
+
whose start time must remain unchanged.
|
|
35
|
+
5. Reads at most 65,536 bytes each of NUL-delimited
|
|
36
|
+
`/proc/<pid>/cmdline` and `/proc/<pid>/environ` evidence without trimming or
|
|
37
|
+
text normalization. A candidate must have argv exactly equal to
|
|
38
|
+
`["/bin/sleep", "120"]` and exactly one environment entry carrying the
|
|
39
|
+
current invocation token. This prevents an older matching sleep in the same
|
|
40
|
+
app-server tree from satisfying the new command's gate.
|
|
41
|
+
6. Requires `/proc/<pid>/exe` for that candidate to have the same device and
|
|
42
|
+
inode as the pre-attested `/bin/sleep`.
|
|
43
|
+
7. Re-reads stat for the candidate and every ancestor through the app-server
|
|
44
|
+
root after command-line and executable inspection. Every PID, parent PID,
|
|
45
|
+
and start time must match the snapshot.
|
|
46
|
+
8. Records the selected host PID and its stat start time as the tracked process
|
|
47
|
+
identity. Every later liveness check re-reads stat. A missing process or
|
|
48
|
+
state `Z`, `X`, or `x` is dead; a matching non-dead start time is alive; PID
|
|
49
|
+
reuse, malformed data, or unreadable required evidence is an error.
|
|
50
|
+
|
|
51
|
+
The initial resolution is retried only for a bounded interval because the
|
|
52
|
+
marker write immediately precedes `exec /bin/sleep`. Each attempt receives the
|
|
53
|
+
same absolute monotonic deadline and a cumulative proc-evidence byte budget;
|
|
54
|
+
both are checked throughout enumeration and after every required read.
|
|
55
|
+
Ambiguity, an exhausted work bound, or invalid proc evidence fails immediately.
|
|
56
|
+
Zero matches or an owned process disappearing during inspection retries from a
|
|
57
|
+
fresh snapshot every 100 ms for at most 5 seconds. A numeric proc entry that
|
|
58
|
+
disappears before its initial stat can be omitted from that point-in-time
|
|
59
|
+
snapshot; permission errors and malformed records fail immediately.
|
|
60
|
+
|
|
61
|
+
The proc enumerator and readers are injected into the exported selection
|
|
62
|
+
helpers so the Linux contract is unit-testable without a live Linux procfs.
|
|
63
|
+
Linux never calls `kill(0)` with either the namespace marker or the resolved
|
|
64
|
+
host PID. Cleanup remains the app-server background-terminal clean request and
|
|
65
|
+
the command's bounded self-expiry.
|
|
66
|
+
|
|
67
|
+
## Alternatives rejected
|
|
68
|
+
|
|
69
|
+
- Mapping the namespace marker globally through `NSpid` is broader than needed
|
|
70
|
+
and can match processes outside the owned app-server tree. `NSpid` alone also
|
|
71
|
+
cannot distinguish separate sandbox namespaces that reuse the same inner
|
|
72
|
+
PID.
|
|
73
|
+
- Using the app-server process group does not prove which descendant is the
|
|
74
|
+
exact synthetic sleep.
|
|
75
|
+
- Changing the sandbox command to expose a host PID crosses the isolation
|
|
76
|
+
boundary and changes the live-verified probe instead of correcting the
|
|
77
|
+
host-side checker.
|
|
78
|
+
- Treating `EPERM` as alive would preserve the namespace/host identity bug and
|
|
79
|
+
could observe an unrelated process.
|
|
80
|
+
|
|
81
|
+
## Failure modes
|
|
82
|
+
|
|
83
|
+
The checker stops on a missing app-server root, zero or multiple matching sleep
|
|
84
|
+
descendants, duplicate or malformed proc records, a process-scan bound breach,
|
|
85
|
+
an aggregate evidence-budget or deadline breach, unreadable required stat,
|
|
86
|
+
command-line, environment, or executable evidence, invocation-token mismatch,
|
|
87
|
+
executable identity drift, an inconsistent ancestry chain, or a start-time
|
|
88
|
+
mismatch that indicates PID reuse. Processes that disappear before their
|
|
89
|
+
initial stat record can be read are omitted from that point-in-time snapshot;
|
|
90
|
+
the known root and every selected descendant remain mandatory. Cleanup is
|
|
91
|
+
still attempted when resolution fails, but no Linux error path signals a
|
|
92
|
+
process directly.
|
|
93
|
+
|
|
94
|
+
## Verification
|
|
95
|
+
|
|
96
|
+
Focused unit coverage must reproduce namespace PID 3 causing legacy host
|
|
97
|
+
`kill(0)` to throw `EPERM`, then prove:
|
|
98
|
+
|
|
99
|
+
- Linux selects the unique exact sleep beneath the app-server host PID and
|
|
100
|
+
ignores unrelated host processes, including host PID 3.
|
|
101
|
+
- An older exact sleep beneath the same app-server cannot match a new
|
|
102
|
+
invocation's token.
|
|
103
|
+
- Cleanup/death detection uses the selected host PID and matching start time.
|
|
104
|
+
- Zero and multiple matches fail closed.
|
|
105
|
+
- A reused PID, zombie state, changed ancestry, executable mismatch, malformed
|
|
106
|
+
stat, or unreadable required proc file fails closed.
|
|
107
|
+
- Per-file, process-count, aggregate-byte, and absolute-deadline bounds are
|
|
108
|
+
enforced.
|
|
109
|
+
- Darwin still uses the marker PID and existing `kill(0)` semantics.
|
|
110
|
+
|
|
111
|
+
The complete Codex spike test and full package suite must pass after the
|
|
112
|
+
focused regression turns green.
|
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
# Optional Codex attachment effort
|
|
2
|
+
|
|
3
|
+
Status: reviewed implementation specification accompanying this change
|
|
4
|
+
|
|
5
|
+
Baseline: `origin/main` at
|
|
6
|
+
`f4224778a6c2c932ff1f171a867ba97bd66ab16a`
|
|
7
|
+
|
|
8
|
+
## Problem
|
|
9
|
+
|
|
10
|
+
Pinned `codex-cli 0.145.0` accepted `thread/start` and returned the required
|
|
11
|
+
thread, model, provider, and static policy fields, but omitted the optional
|
|
12
|
+
top-level `reasoningEffort`. `CodexAppServerClient` preserved that valid shape.
|
|
13
|
+
`CodexProcess` then passed the attachment response to `dynamicSettings`, which
|
|
14
|
+
requires both model and effort, and raised:
|
|
15
|
+
|
|
16
|
+
```text
|
|
17
|
+
Codex thread omitted its dynamic settings
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The response had already been observed for a state-changing request, so the
|
|
21
|
+
startup failure correctly entered `ContainmentFailed`. `ProcessManager`
|
|
22
|
+
correctly converted that event into a daemon-wide Codex quarantine. No
|
|
23
|
+
`turn/start` was written.
|
|
24
|
+
|
|
25
|
+
The live direct checker did not catch the mismatch because
|
|
26
|
+
`characterizeThreadProfile` normalized a missing effort to `null` but did not
|
|
27
|
+
make the attachment dynamic shape part of the named-profile gate.
|
|
28
|
+
|
|
29
|
+
## Source-of-truth findings
|
|
30
|
+
|
|
31
|
+
A content-free local regeneration with exact `codex-cli 0.145.0` produced the
|
|
32
|
+
four deterministic Darwin hashes already recorded in
|
|
33
|
+
`tests/fixtures/codex-app-server-0.145.0/manifest.json`:
|
|
34
|
+
|
|
35
|
+
- stable `ClientRequest.json`:
|
|
36
|
+
`cc9f6e191a032bdfdc96d768f4ddaba4ced75408017af3ac0dbcc4d00c1faaa8`;
|
|
37
|
+
- stable legacy protocol:
|
|
38
|
+
`b6ec47c51bef8a6857dd9435f9919a43ba6616a5a9e3ab25087451cbc93d9f06`;
|
|
39
|
+
- experimental `ClientRequest.json`:
|
|
40
|
+
`03e30c97136d6618273e3e9197d8621bad9ac6cfd733c0cfe09dc8754ee6ac5c`;
|
|
41
|
+
- experimental legacy protocol:
|
|
42
|
+
`1f66700d1cc3de4a5004e5614a6098878b405c7e7c5f8c9be97fc900d0ad6c68`.
|
|
43
|
+
|
|
44
|
+
In both stable and experimental v2 schemas:
|
|
45
|
+
|
|
46
|
+
- `ThreadStartResponse.required` and `ThreadResumeResponse.required` include
|
|
47
|
+
`model` but not `reasoningEffort`;
|
|
48
|
+
- both responses expose `reasoningEffort` as nullable when present; and
|
|
49
|
+
- `ThreadSettings.effort` is also schema-optional and nullable.
|
|
50
|
+
|
|
51
|
+
The current app-server projection independently encodes the same response
|
|
52
|
+
contract: it always projects `model` and projects `reasoningEffort` only when
|
|
53
|
+
non-null. This projection is already correct and must not synthesize a value.
|
|
54
|
+
|
|
55
|
+
Orchestra deliberately has a stricter product contract for
|
|
56
|
+
`thread/settings/updated`: a delivered settings notification must contain a
|
|
57
|
+
complete model/effort pair. That stricter notification contract remains.
|
|
58
|
+
|
|
59
|
+
## Root cause
|
|
60
|
+
|
|
61
|
+
The valid response first becomes invalid at the process validation boundary:
|
|
62
|
+
|
|
63
|
+
1. `CodexAppServerClient.projectRpcResult` requires the attachment model and
|
|
64
|
+
conditionally projects `reasoningEffort`.
|
|
65
|
+
2. `CodexProcess._validateThreadResult` sends that projection to
|
|
66
|
+
`_validateAndObserveThreadPolicy` as an attachment.
|
|
67
|
+
3. `_validateAndObserveThreadPolicy` validates the exact static policy, then
|
|
68
|
+
calls the globally strict `dynamicSettings`.
|
|
69
|
+
4. `dynamicSettings` calls `modelSettings`, which requires a non-empty effort.
|
|
70
|
+
5. The optional response field is therefore reclassified as mandatory.
|
|
71
|
+
6. Because the attachment mutation response was already observed,
|
|
72
|
+
`CodexProcess._start` contains the generation and the manager quarantines
|
|
73
|
+
the daemon.
|
|
74
|
+
|
|
75
|
+
The bug is not in the generated schema, the client projection, static policy
|
|
76
|
+
attestation, containment, or quarantine behavior.
|
|
77
|
+
|
|
78
|
+
## Required invariants
|
|
79
|
+
|
|
80
|
+
1. Only a `thread/start` or `thread/resume` response may omit effort.
|
|
81
|
+
2. An attachment response must still contain a bounded non-empty model.
|
|
82
|
+
3. A present attachment effort must still be a bounded non-empty string.
|
|
83
|
+
4. Exact provider, approval, reviewer, sandbox, permission-profile, and runtime
|
|
84
|
+
workspace-root policy checks are unchanged and run before dynamic
|
|
85
|
+
reconciliation.
|
|
86
|
+
5. `thread/settings/updated` continues to require a complete model/effort pair,
|
|
87
|
+
including when it arrives while attachment is in progress.
|
|
88
|
+
6. Every production `turn/start` continues to carry the complete,
|
|
89
|
+
catalog-validated model and effort selected for that admission.
|
|
90
|
+
7. A missing attachment effort is unknown. It must not be replaced with the
|
|
91
|
+
selected effort, a catalog default, or a prior thread value.
|
|
92
|
+
8. Attachment model and any present attachment effort must each be a non-empty
|
|
93
|
+
string of at most 512 UTF-8 bytes. Only a `null` or omitted attachment
|
|
94
|
+
effort represents absence.
|
|
95
|
+
9. A complete observed, admitting, active, or last-accepted pair always takes
|
|
96
|
+
precedence over a provisional attachment model. An incoming complete
|
|
97
|
+
notification must exactly match one of those complete candidates.
|
|
98
|
+
10. A provisional model may authorize a first complete observation by exact
|
|
99
|
+
model only while no complete candidate exists and before the first turn
|
|
100
|
+
admission begins.
|
|
101
|
+
11. The broad `AttachingThread` state must not grant first-observation
|
|
102
|
+
authority after the attachment response has been validated.
|
|
103
|
+
12. Existing containment and response-observed non-retry behavior remains
|
|
104
|
+
unchanged.
|
|
105
|
+
|
|
106
|
+
## Chosen correction
|
|
107
|
+
|
|
108
|
+
Keep the current complete-pair contract and add a narrow shared production
|
|
109
|
+
attachment-response parser:
|
|
110
|
+
|
|
111
|
+
```text
|
|
112
|
+
attachment response -> required model + optional effort
|
|
113
|
+
settings notification -> required model + required effort
|
|
114
|
+
turn admission -> required model + required effort
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The shared parser is a small pure production module used directly by both
|
|
118
|
+
`CodexProcess` and the real checker. It validates:
|
|
119
|
+
|
|
120
|
+
- a required non-empty model of at most 512 UTF-8 bytes;
|
|
121
|
+
- an optional effort where `null` and omission both mean absent; and
|
|
122
|
+
- when effort is present, a non-empty string of at most 512 UTF-8 bytes.
|
|
123
|
+
|
|
124
|
+
It returns a discriminated partial-or-complete value without substituting an
|
|
125
|
+
effort. The complete notification and turn paths remain strict. The checker
|
|
126
|
+
must not carry a duplicate approximation of this parser.
|
|
127
|
+
|
|
128
|
+
`CodexProcess` will retain two distinct internal concepts:
|
|
129
|
+
|
|
130
|
+
- `observedThreadSettings`: a complete provider-observed model/effort pair, as
|
|
131
|
+
today; and
|
|
132
|
+
- a provisional attachment model used only when the attachment response
|
|
133
|
+
omitted effort.
|
|
134
|
+
|
|
135
|
+
It will also retain `lastAcceptedTurnSettings`, or an equivalently durable
|
|
136
|
+
complete post-admission candidate. This is set only after `turn/start` has
|
|
137
|
+
been accepted and its `turn-accepted` checkpoint has succeeded. It is not
|
|
138
|
+
cleared when the active turn finishes. The attachment provisional is
|
|
139
|
+
irrevocably retired when the first turn admission captures
|
|
140
|
+
`admittingTurnSettings`, regardless of that RPC's outcome.
|
|
141
|
+
|
|
142
|
+
No provisional value is exposed as a complete observed pair. In particular,
|
|
143
|
+
`observedThreadSettings` remains `null` while the model-only attachment is the
|
|
144
|
+
only provider evidence. The model and effort written to `thread-initialized`
|
|
145
|
+
remain the local desired selection; that checkpoint does not turn them into
|
|
146
|
+
provider-observed settings.
|
|
147
|
+
|
|
148
|
+
Attachment reconciliation follows this table:
|
|
149
|
+
|
|
150
|
+
| Earlier evidence | Attachment response | Result |
|
|
151
|
+
|---|---|---|
|
|
152
|
+
| none | model + effort | retain the complete pair |
|
|
153
|
+
| none | model only | retain only the provisional attachment model |
|
|
154
|
+
| complete notification | same model, no effort | retain the notification pair; do not downgrade it |
|
|
155
|
+
| complete notification | same complete pair | retain the complete pair |
|
|
156
|
+
| complete notification | conflicting model or present effort | fail closed |
|
|
157
|
+
|
|
158
|
+
Every complete settings notification is reconciled in this deterministic
|
|
159
|
+
order:
|
|
160
|
+
|
|
161
|
+
1. Validate its full static policy and complete bounded model/effort pair.
|
|
162
|
+
2. Collect the complete `observedThreadSettings`, `admittingTurnSettings`,
|
|
163
|
+
`activeTurnSettings`, and `lastAcceptedTurnSettings` candidates. If any
|
|
164
|
+
exist, accept only an exact pair match against at least one candidate.
|
|
165
|
+
Ignore the provisional model and attachment lifecycle state in this branch.
|
|
166
|
+
3. Otherwise, if an eligible provisional attachment model exists, accept it
|
|
167
|
+
as the first complete observation only when the notification model exactly
|
|
168
|
+
matches it. The notification's required bounded effort completes the pair.
|
|
169
|
+
4. Otherwise, allow a genuine pre-response first observation only when the
|
|
170
|
+
process is attaching and the attachment response has not yet been
|
|
171
|
+
validated. This permission is keyed by explicit response-validation state,
|
|
172
|
+
not merely `state === 'AttachingThread'`.
|
|
173
|
+
5. Fail with `CODEX_THREAD_SETTINGS_MISMATCH` in every other case.
|
|
174
|
+
|
|
175
|
+
Once that notification is accepted, the provisional observation is discarded.
|
|
176
|
+
The first turn admission also discards it permanently. The persistent
|
|
177
|
+
last-accepted pair prevents provisional authority from reappearing after
|
|
178
|
+
`admittingTurnSettings` and `activeTurnSettings` are cleared. This keeps
|
|
179
|
+
per-turn overrides safe across attachment, admission, active execution, and
|
|
180
|
+
turn completion.
|
|
181
|
+
|
|
182
|
+
The attachment response path gets the optional parser explicitly. The
|
|
183
|
+
notification path does not infer this permission from the broad
|
|
184
|
+
`AttachingThread` state, because a notification can arrive before the response
|
|
185
|
+
and must remain complete.
|
|
186
|
+
|
|
187
|
+
### Notification-before-response ordering
|
|
188
|
+
|
|
189
|
+
The app-server client delivers a notification sink before resolving a later
|
|
190
|
+
response line. A complete `thread/settings/updated` can therefore populate
|
|
191
|
+
`observedThreadSettings` while `CodexProcess` is still awaiting
|
|
192
|
+
`thread/start`. When the subsequent response omits effort, validation compares
|
|
193
|
+
the response's known model to the complete notification and retains the
|
|
194
|
+
notification pair. It must not overwrite the complete pair with a partial
|
|
195
|
+
shape.
|
|
196
|
+
|
|
197
|
+
The reverse ordering is also bounded: a later complete notification may
|
|
198
|
+
upgrade a provisional attachment model under the conditions above.
|
|
199
|
+
|
|
200
|
+
A notification delivered after the attachment response but while the
|
|
201
|
+
`thread-initialized` checkpoint is delayed is not a pre-response observation.
|
|
202
|
+
It follows the same complete-candidates-first order. This closes the interval
|
|
203
|
+
where `state` remains `AttachingThread` after the response has already been
|
|
204
|
+
validated.
|
|
205
|
+
|
|
206
|
+
## Real checker correction
|
|
207
|
+
|
|
208
|
+
The real checker will report two separately named kinds of evidence:
|
|
209
|
+
|
|
210
|
+
1. Raw schema evidence pins the generated v2 shape for both
|
|
211
|
+
`ThreadStartResponse` and
|
|
212
|
+
`ThreadResumeResponse`: model required, `reasoningEffort` optional and
|
|
213
|
+
nullable.
|
|
214
|
+
2. Production attachment-validation evidence passes each live fresh and
|
|
215
|
+
resume response through the exact shared parser used by `CodexProcess`.
|
|
216
|
+
Model and present effort must satisfy the production 512 UTF-8 byte bound.
|
|
217
|
+
Effort is classified as `omitted`, `null`, or `present`; only the first two
|
|
218
|
+
are absence, and a present value must pass the shared validator.
|
|
219
|
+
3. `evaluateNamedProfileGate` requires both fresh and resume production
|
|
220
|
+
validation booleans. Raw schema success without production validation is
|
|
221
|
+
insufficient and yields `STOP`.
|
|
222
|
+
4. Retain only booleans and presence classes in the U1a report. Do not emit
|
|
223
|
+
thread identifiers, model/effort values, or new raw response data.
|
|
224
|
+
|
|
225
|
+
The gate accepts a `null` or omitted effort because the pinned schema permits
|
|
226
|
+
both. Using the production parser is essential: the former checker could
|
|
227
|
+
correctly describe the upstream shape while the production process still
|
|
228
|
+
rejected it.
|
|
229
|
+
|
|
230
|
+
## Implementation surface
|
|
231
|
+
|
|
232
|
+
Expected implementation files:
|
|
233
|
+
|
|
234
|
+
- `lib/codex/thread-attachment-settings.js`: shared bounded production parser;
|
|
235
|
+
- `lib/process/codex-process.js`: attachment-only parsing and bounded
|
|
236
|
+
reconciliation, explicit response-validation state, and the persistent
|
|
237
|
+
last-accepted candidate;
|
|
238
|
+
- `tests/codex-process.test.js`: production-shape and ordering regressions;
|
|
239
|
+
- `scripts/spikes/codex-app-server-real.mjs`: generated-schema/runtime
|
|
240
|
+
assertions and gate evidence;
|
|
241
|
+
- `tests/codex-app-server-spike.test.js`: checker regressions; and
|
|
242
|
+
- `docs/codex-app-server-compatibility.md`: the corrected attachment contract
|
|
243
|
+
and gate output.
|
|
244
|
+
|
|
245
|
+
No change is expected in `lib/codex/app-server-client.js`,
|
|
246
|
+
`lib/codex/protocol-schema.json`, the factory, preflight, manager, supervisor,
|
|
247
|
+
or package runtime.
|
|
248
|
+
|
|
249
|
+
## Exact TDD plan
|
|
250
|
+
|
|
251
|
+
Add the focused tests before implementation and run them with the installed
|
|
252
|
+
Node 24.4.0 runtime.
|
|
253
|
+
|
|
254
|
+
### Process regression
|
|
255
|
+
|
|
256
|
+
In `tests/codex-process.test.js`, add:
|
|
257
|
+
|
|
258
|
+
```text
|
|
259
|
+
Codex attachment accepts schema-optional effort without containment
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Run it for both `thread/start` and `thread/resume`. Each fake attachment result
|
|
263
|
+
retains the required model and exact static policy but deletes
|
|
264
|
+
`reasoningEffort`.
|
|
265
|
+
|
|
266
|
+
Before the fix, both cases must fail with
|
|
267
|
+
`Codex thread omitted its dynamic settings`, enter `ContainmentFailed`, and
|
|
268
|
+
show that no `turn/start` occurred. After the fix, both must reach the expected
|
|
269
|
+
idle/recovery state without a containment event.
|
|
270
|
+
|
|
271
|
+
The model-only cases must also assert that `observedThreadSettings` remains
|
|
272
|
+
`null`. Their `thread-initialized` checkpoint may contain the locally selected
|
|
273
|
+
model and effort, but the test must not treat that checkpoint as observed
|
|
274
|
+
provider evidence.
|
|
275
|
+
|
|
276
|
+
### Shared production validator
|
|
277
|
+
|
|
278
|
+
Add table-driven unit coverage for the shared parser:
|
|
279
|
+
|
|
280
|
+
- required model at exactly 512 UTF-8 bytes is accepted;
|
|
281
|
+
- model at 513 UTF-8 bytes is rejected;
|
|
282
|
+
- a multibyte model whose JavaScript length is at most 512 but whose UTF-8
|
|
283
|
+
encoding exceeds 512 bytes is rejected;
|
|
284
|
+
- omitted and `null` effort are accepted as absent;
|
|
285
|
+
- present effort at exactly 512 UTF-8 bytes is accepted; and
|
|
286
|
+
- empty, non-string, 513-byte, and multibyte-over-512 effort values are
|
|
287
|
+
rejected.
|
|
288
|
+
|
|
289
|
+
The checker test must import this same production parser rather than restating
|
|
290
|
+
these conditions.
|
|
291
|
+
|
|
292
|
+
### Ordering and fail-closed regressions
|
|
293
|
+
|
|
294
|
+
Add:
|
|
295
|
+
|
|
296
|
+
```text
|
|
297
|
+
Codex attachment preserves a complete settings notification observed before an effort-omitting response
|
|
298
|
+
Codex attachment-only effort omission does not relax complete settings notifications
|
|
299
|
+
Codex attachment candidate precedence survives delayed thread initialization
|
|
300
|
+
Codex partial resume permits a complete first-turn override
|
|
301
|
+
Codex accepted turn settings retire provisional attachment authority
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
The first sends a complete matching notification before returning an
|
|
305
|
+
effort-omitting attachment response and asserts that the complete observed pair
|
|
306
|
+
survives. Independent fixtures must also prove these negative paths:
|
|
307
|
+
|
|
308
|
+
- a notification-before-response that omits effort enters containment as a
|
|
309
|
+
protocol error;
|
|
310
|
+
- notification `{model: M, effort: E1}` followed by an attachment response for
|
|
311
|
+
another model fails with `CODEX_THREAD_SETTINGS_MISMATCH`; and
|
|
312
|
+
- notification `{model: M, effort: E1}` followed by an attachment response
|
|
313
|
+
`{model: M, reasoningEffort: E2}` fails with
|
|
314
|
+
`CODEX_THREAD_SETTINGS_MISMATCH`.
|
|
315
|
+
|
|
316
|
+
The second case prevents the attachment-only optionality from becoming an
|
|
317
|
+
effort wildcard when the response actually supplied conflicting evidence.
|
|
318
|
+
|
|
319
|
+
The second starts from an effort-omitting response, then proves:
|
|
320
|
+
|
|
321
|
+
- a complete matching notification can establish the first complete
|
|
322
|
+
observation;
|
|
323
|
+
- a model-only attachment for `A` followed, with no other complete candidate,
|
|
324
|
+
by a complete exact-static notification for model `B` enters containment
|
|
325
|
+
with `CODEX_THREAD_SETTINGS_MISMATCH`;
|
|
326
|
+
- a notification omitting effort still enters containment;
|
|
327
|
+
- a notification conflicting with an admitting/active complete pair enters
|
|
328
|
+
containment; and
|
|
329
|
+
- a later selected turn still sends its exact model and effort.
|
|
330
|
+
|
|
331
|
+
The delayed-initialization regression holds the `thread-initialized`
|
|
332
|
+
checkpoint after the attachment response has been validated while the process
|
|
333
|
+
still reports `AttachingThread`. In independent fresh fixtures, it proves:
|
|
334
|
+
|
|
335
|
+
- a complete candidate is checked before the provisional model or any
|
|
336
|
+
pre-response rule;
|
|
337
|
+
- provisional model `A` plus admitting candidate `A/xhigh` rejects `A/high`
|
|
338
|
+
and accepts exactly `A/xhigh`;
|
|
339
|
+
- the same reject/accept pair holds with an active `A/xhigh` candidate; and
|
|
340
|
+
- without a complete candidate, provisional `A` may establish only a complete
|
|
341
|
+
observation whose model is exactly `A`.
|
|
342
|
+
|
|
343
|
+
Conflict and acceptance cases use separate fixtures because containment is a
|
|
344
|
+
terminal state. No test attempts a positive assertion after causing
|
|
345
|
+
containment in the same process.
|
|
346
|
+
|
|
347
|
+
The resume override regression returns old model `A` with omitted effort from
|
|
348
|
+
`thread/resume`, selects a complete new pair `B/xhigh` for the first turn, and
|
|
349
|
+
delivers a matching settings notification during admission or active
|
|
350
|
+
execution. The turn must complete without containment. This proves that the
|
|
351
|
+
complete admitting/active candidate wins even though the provisional
|
|
352
|
+
attachment model is stale.
|
|
353
|
+
|
|
354
|
+
The provisional-lifetime regression starts from model-only attachment `A`,
|
|
355
|
+
accepts and completes an `A/xhigh` turn without any settings notification, and
|
|
356
|
+
then delivers late settings evidence. In separate fixtures, exact `A/xhigh`
|
|
357
|
+
is accepted while `A/high` enters containment. The assertions must show that
|
|
358
|
+
the persistent last-accepted pair remains authoritative after the admitting
|
|
359
|
+
and active fields are cleared and that the provisional model never regains
|
|
360
|
+
effort-wildcard authority.
|
|
361
|
+
|
|
362
|
+
### Static-policy regression
|
|
363
|
+
|
|
364
|
+
Extend the named-profile attachment table with an effort-omitting response
|
|
365
|
+
whose static policy is drifted. It must still fail with
|
|
366
|
+
`CODEX_THREAD_POLICY_MISMATCH` before any turn is dispatched.
|
|
367
|
+
|
|
368
|
+
### Checker regressions
|
|
369
|
+
|
|
370
|
+
In `tests/codex-app-server-spike.test.js`, add:
|
|
371
|
+
|
|
372
|
+
```text
|
|
373
|
+
Codex U1a pins optional attachment effort while requiring the model
|
|
374
|
+
Codex U1a live responses pass the production attachment validator
|
|
375
|
+
Codex U1a separates raw schema evidence from production attachment evidence
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
The schema test must reject a required `reasoningEffort`, a missing required
|
|
379
|
+
model, and a non-nullable or missing effort property. Runtime characterization
|
|
380
|
+
must accept omitted/null effort, accept bounded non-empty strings, and reject
|
|
381
|
+
empty, non-string, or over-512-byte model/present-effort values through the
|
|
382
|
+
shared production parser. Include a multibyte over-limit case to prove the
|
|
383
|
+
bound is UTF-8 bytes rather than JavaScript code units.
|
|
384
|
+
|
|
385
|
+
The gate test must go red until both fresh and resume production-validation
|
|
386
|
+
evidence are required. A fixture with valid raw schema evidence but either
|
|
387
|
+
production-validation boolean missing or false must `STOP`.
|
|
388
|
+
|
|
389
|
+
### Malformed attachment containment
|
|
390
|
+
|
|
391
|
+
Use a fresh process fixture for every malformed response because attachment
|
|
392
|
+
containment is terminal. Cover empty, non-string, 513-byte, and multibyte
|
|
393
|
+
over-512 model values, plus present effort values with the same invalid
|
|
394
|
+
classes. Each case must prove:
|
|
395
|
+
|
|
396
|
+
- the accepted attachment response enters containment with a protocol error;
|
|
397
|
+
- no `turn/start` is written; and
|
|
398
|
+
- `null` and omitted effort remain the only accepted omission cases.
|
|
399
|
+
|
|
400
|
+
Suggested focused command:
|
|
401
|
+
|
|
402
|
+
```sh
|
|
403
|
+
/Users/ivanshumkov/.nvm/versions/node/v24.4.0/bin/node \
|
|
404
|
+
--test \
|
|
405
|
+
--test-name-pattern='schema-optional (attachment )?effort|production attachment validator|named-profile attachment accepts production omitted and null effort|attachment preserves|notification before|settings notifications enforce|attachment-only effort|candidate precedence|first-turn override|retire provisional|malformed attachment|named-profile attachment rejects|raw schema evidence' \
|
|
406
|
+
tests/codex-process.test.js tests/codex-app-server-spike.test.js
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
Record the initial failures, implement one correction, rerun the same command
|
|
410
|
+
to green, then run the complete affected files and one full Node 24.4.0 suite.
|
|
411
|
+
|
|
412
|
+
## Failure and security cases
|
|
413
|
+
|
|
414
|
+
- Missing, empty, non-string, or over-512-byte UTF-8 model: protocol error and
|
|
415
|
+
containment after an observed attachment response.
|
|
416
|
+
- Present empty, non-string, or over-512-byte UTF-8 effort: protocol error and
|
|
417
|
+
containment. Only `null` or omission is absent.
|
|
418
|
+
- Any static policy omission or mismatch: unchanged exact-policy failure.
|
|
419
|
+
- Notification missing effort: protocol error even during attachment.
|
|
420
|
+
- Notification static drift: unchanged containment.
|
|
421
|
+
- Notification/response model conflict: containment.
|
|
422
|
+
- Present response effort conflicting with an already observed complete
|
|
423
|
+
notification: containment.
|
|
424
|
+
- Notification conflicting with an observed, admitting, active, or
|
|
425
|
+
last-accepted complete pair: containment; provisional evidence cannot
|
|
426
|
+
override it.
|
|
427
|
+
- Notification after the attachment response but before `thread-initialized`
|
|
428
|
+
completes: complete-candidate and provisional rules apply; the
|
|
429
|
+
pre-response exception is unavailable.
|
|
430
|
+
- Notification after the first turn admission: provisional evidence has been
|
|
431
|
+
retired permanently.
|
|
432
|
+
- No matching complete candidate and no matching provisional attachment model:
|
|
433
|
+
containment.
|
|
434
|
+
- Response checkpoint uncertainty: unchanged non-replay and quarantine.
|
|
435
|
+
- No new raw response, model, effort, thread, credential, or policy data is
|
|
436
|
+
persisted by the checker.
|
|
437
|
+
|
|
438
|
+
## Alternatives rejected
|
|
439
|
+
|
|
440
|
+
### Substitute the selected effort
|
|
441
|
+
|
|
442
|
+
The selected effort is local intent for a later turn, not attachment evidence.
|
|
443
|
+
Substitution would lie about a resumed thread and could hide a provider
|
|
444
|
+
mismatch.
|
|
445
|
+
|
|
446
|
+
### Substitute the catalog default
|
|
447
|
+
|
|
448
|
+
The catalog default may differ from the selected per-turn effort and from a
|
|
449
|
+
resumed thread's retained value. It is not response evidence.
|
|
450
|
+
|
|
451
|
+
### Make `modelSettings` globally optional
|
|
452
|
+
|
|
453
|
+
This would weaken constructor, selection, turn admission, and notification
|
|
454
|
+
validation. The omission belongs only to attachment responses.
|
|
455
|
+
|
|
456
|
+
### Synthesize effort in the app-server projection
|
|
457
|
+
|
|
458
|
+
The client currently reflects the pinned generated schema exactly. Inventing a
|
|
459
|
+
field at the transport boundary would erase the distinction between absent and
|
|
460
|
+
observed state.
|
|
461
|
+
|
|
462
|
+
### Ignore attachment dynamic settings
|
|
463
|
+
|
|
464
|
+
The required model and any present effort remain useful consistency evidence,
|
|
465
|
+
especially when a notification arrives before the response.
|
|
466
|
+
|
|
467
|
+
### Keep raw schema-only checker evidence
|
|
468
|
+
|
|
469
|
+
Schema evidence proves what Codex may emit, not what Orchestra accepts. It
|
|
470
|
+
would reproduce the production blind spot. Fresh and resume live results must
|
|
471
|
+
also pass the shared production parser used by `CodexProcess`.
|
|
472
|
+
|
|
473
|
+
### Add a second checker-only parser
|
|
474
|
+
|
|
475
|
+
A duplicate implementation could drift from the process boundary and allow
|
|
476
|
+
the gate to continue while production fails. The one bounded parser is shared
|
|
477
|
+
instead.
|
|
478
|
+
|
|
479
|
+
### Require Codex to return effort
|
|
480
|
+
|
|
481
|
+
That contradicts the pinned schema and the verified production response. It
|
|
482
|
+
would preserve the outage rather than correct Orchestra.
|
|
483
|
+
|
|
484
|
+
## Release, recanary, and quarantine
|
|
485
|
+
|
|
486
|
+
Implementation and release are separate work:
|
|
487
|
+
|
|
488
|
+
1. Land only after focused red-to-green evidence, the complete affected tests,
|
|
489
|
+
one full Node 24.4.0 suite, and independent correctness/security/simplicity
|
|
490
|
+
review.
|
|
491
|
+
2. Keep any version bump and release metadata in the normal separate release
|
|
492
|
+
commit. Publish only through the repository release workflow.
|
|
493
|
+
3. Run the strengthened direct Linux checker with exact pinned Codex,
|
|
494
|
+
content-free inputs, and the existing operational containment gates before
|
|
495
|
+
recanary.
|
|
496
|
+
4. Recanary one attachment first and require: response observed, attachment
|
|
497
|
+
initialized without containment, no daemon quarantine, and the first
|
|
498
|
+
`turn/start` written with the exact selected model/effort pair.
|
|
499
|
+
5. Preserve the current quarantine record from the failed canary. Do not
|
|
500
|
+
force-clear it and do not retry Codex on the same boot.
|
|
501
|
+
6. Retry only after the production host has genuinely rebooted and the
|
|
502
|
+
persisted recovery record is restored on the same host with a different
|
|
503
|
+
boot-session identity. A daemon restart, process restart, or package
|
|
504
|
+
reinstall is not sufficient.
|
|
505
|
+
|
|
506
|
+
The quarantine is a correct consequence of an accepted state-changing
|
|
507
|
+
attachment followed by local validation failure. This fix changes validation
|
|
508
|
+
of future schema-valid attachments; it does not retroactively prove the
|
|
509
|
+
contained generation safe.
|
|
@@ -33,10 +33,23 @@ reads without a legacy `workspaceWrite` request policy.
|
|
|
33
33
|
- Orchestra baseline: `v0.5.0`, commit
|
|
34
34
|
`b788efb1f99e5fbf8669d4efa7ce5a1f9c0f7dcb`.
|
|
35
35
|
- Codex: `codex-cli 0.145.0`.
|
|
36
|
-
-
|
|
37
|
-
`
|
|
38
|
-
-
|
|
36
|
+
- Reviewed native target receipts:
|
|
37
|
+
- `aarch64-apple-darwin`:
|
|
38
|
+
`codex-cli 0.145.0`,
|
|
39
|
+
`1da3f4e0e96028b8a771814293c3033dafd1971f943f6c7e79b0897fe705f590`;
|
|
40
|
+
- `x86_64-unknown-linux-musl`:
|
|
41
|
+
`codex-cli 0.145.0`,
|
|
42
|
+
`a2a05dafaa1acb002a45eaec0a462de5b13694fcfcd7bc43305f14781ce7be14`.
|
|
43
|
+
- The deprecated scalar binary checksum remains macOS-arm64 provenance.
|
|
44
|
+
Runtime checks resolve the current target receipt lazily.
|
|
45
|
+
- Target-specific raw hashes pin the four deterministic stable and experimental
|
|
46
|
+
`ClientRequest.json` and legacy protocol files in
|
|
39
47
|
`tests/fixtures/codex-app-server-0.145.0/manifest.json`.
|
|
48
|
+
- The nondeterministically serialized stable and experimental v2 bundles are
|
|
49
|
+
enforced only through their shared recursively canonical hashes:
|
|
50
|
+
`02d8bf6651cd504bff0335f566c011e51ba77c5cc0538cb64ca7ac57739a1597`
|
|
51
|
+
and
|
|
52
|
+
`1bc09dedc506075562d4d49b702ecab6d947dd5a8c2a9014a5cde592a0938efb`.
|
|
40
53
|
- `turn/steer` still requires `threadId`, `input`, and `expectedTurnId`.
|
|
41
54
|
- The authenticated direct-binary checker passed every named-profile evidence
|
|
42
55
|
bit on 2026-07-26. This Mac has no configured session launcher, so the local
|
|
@@ -69,14 +82,41 @@ node scripts/spikes/codex-app-server-real.mjs \
|
|
|
69
82
|
--binary /absolute/versioned/path/to/codex \
|
|
70
83
|
--codex-home /absolute/non-temporary/codex-home \
|
|
71
84
|
--workspace /absolute/workspace \
|
|
72
|
-
--
|
|
85
|
+
--tmpdir /absolute/private/child-tmpdir \
|
|
86
|
+
--daemon-secret-root /absolute/private/child-tmpdir \
|
|
87
|
+
--external-network-host 1.1.1.1 \
|
|
88
|
+
--external-network-port 443
|
|
73
89
|
```
|
|
74
90
|
|
|
75
91
|
Environment fallbacks are `POLYGRAM_CODEX_BIN`, `ORCHESTRA_CODEX_HOME`,
|
|
76
|
-
`ORCHESTRA_CODEX_WORKSPACE`, `
|
|
77
|
-
path-delimited
|
|
92
|
+
`ORCHESTRA_CODEX_WORKSPACE`, `ORCHESTRA_CODEX_TMPDIR`,
|
|
93
|
+
`ORCHESTRA_SESSION_LAUNCHER`, and the path-delimited
|
|
94
|
+
`ORCHESTRA_CODEX_DAEMON_SECRET_ROOTS`. Linux also requires
|
|
95
|
+
`ORCHESTRA_CODEX_EXTERNAL_NETWORK_HOST` and
|
|
96
|
+
`ORCHESTRA_CODEX_EXTERNAL_NETWORK_PORT` when the corresponding flags are not
|
|
97
|
+
passed. The endpoint must be an operator-approved, globally routable numeric
|
|
98
|
+
IPv4 address and port that are reachable from the service environment; a
|
|
99
|
+
hostname or private, loopback, link-local, benchmark, or documentation address
|
|
100
|
+
is rejected. The checker requires the same endpoint to remain reachable from
|
|
101
|
+
the host immediately before and after the sandbox-denial probe.
|
|
78
102
|
Each synthetic daemon-secret root must contain an owner-only regular
|
|
79
103
|
`.orchestra-codex-u1a-deny-probe` sentinel with no symlink or hard-link alias.
|
|
104
|
+
On Linux, the child `TMPDIR` must be an existing canonical service-user-owned
|
|
105
|
+
directory with exact mode `0700`, separate from both the workspace and
|
|
106
|
+
`CODEX_HOME`. The same exact directory must also be supplied as a
|
|
107
|
+
`--daemon-secret-root`, so the filesystem enforcement probe proves that its
|
|
108
|
+
sentinel is unreadable from `command/exec`. Darwin does not require or validate
|
|
109
|
+
this additional child-temp input.
|
|
110
|
+
|
|
111
|
+
Before Linux app-server startup, the checker requires the reviewed profile to
|
|
112
|
+
run a bounded harmless command using the Codex 0.145.0 CLI surface:
|
|
113
|
+
|
|
114
|
+
```text
|
|
115
|
+
codex sandbox --permission-profile polygram-session -- /bin/true
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The checker does not trace bubblewrap. The final bounded VPS operational gate
|
|
119
|
+
must separately prove that this exact invocation reaches `/usr/bin/bwrap`.
|
|
80
120
|
|
|
81
121
|
The checker never creates, copies, reads, hashes, or prints authentication
|
|
82
122
|
contents. `CODEX_HOME` must already exist, be canonical, non-temporary, owned
|
|
@@ -180,9 +220,23 @@ Every production `turn/start` carries the complete catalog-validated
|
|
|
180
220
|
`model`/`effort` pair selected for that admission. Changing the local
|
|
181
221
|
selection preserves the process generation and provider thread, leaves an
|
|
182
222
|
active turn and its steering on their admitted pair, and applies to the next
|
|
183
|
-
turn.
|
|
184
|
-
|
|
185
|
-
|
|
223
|
+
turn.
|
|
224
|
+
|
|
225
|
+
The pinned `ThreadStartResponse` and `ThreadResumeResponse` schemas require
|
|
226
|
+
`model` but permit `reasoningEffort` to be omitted or `null`. Orchestra
|
|
227
|
+
validates attachment model and any present effort as non-empty strings of at
|
|
228
|
+
most 512 UTF-8 bytes. Missing effort remains unknown: it is not replaced with
|
|
229
|
+
the local selection or a catalog default. `thread/settings/updated` remains
|
|
230
|
+
stricter and must contain a complete model/effort pair.
|
|
231
|
+
|
|
232
|
+
Complete observed, admitting, active, and last-accepted turn settings take
|
|
233
|
+
precedence over partial attachment evidence. A model-only attachment may
|
|
234
|
+
authorize the first complete observation only by exact model, only before the
|
|
235
|
+
first turn admission, and only while no complete candidate exists. First turn
|
|
236
|
+
admission retires that partial authority permanently; the last accepted
|
|
237
|
+
complete pair remains authoritative after the turn finishes. All settings
|
|
238
|
+
notifications still require the full static permission, workspace, approval,
|
|
239
|
+
and provider policy to remain exact.
|
|
186
240
|
|
|
187
241
|
Codex does not persist a resumable rollout for `thread/start` alone. The
|
|
188
242
|
checker therefore completes one fixed no-tools text turn, requires the matching
|
|
@@ -206,6 +260,13 @@ the checker still requires its complete static settings view to be exact.
|
|
|
206
260
|
Notifications caused by explicit experimental `thread/settings/update` calls
|
|
207
261
|
are characterized separately and do not establish attachment-time emission.
|
|
208
262
|
|
|
263
|
+
The named-profile gate reports raw attachment-schema evidence separately from
|
|
264
|
+
live production attachment validation. Fresh and resume responses must pass
|
|
265
|
+
the same bounded parser used by `CodexProcess`; raw schema hashes or shape
|
|
266
|
+
checks alone cannot clear the gate. Output retains only validation booleans and
|
|
267
|
+
the effort presence class (`omitted`, `null`, or `present`), not model or effort
|
|
268
|
+
values.
|
|
269
|
+
|
|
209
270
|
Fresh and resume responses, and any observed `thread/settings/updated`, use the
|
|
210
271
|
same legacy compatibility envelope:
|
|
211
272
|
|
|
@@ -330,6 +391,25 @@ passed every control and denial. The Unix-socket control uses a short,
|
|
|
330
391
|
explicitly length-guarded macOS pathname and an asynchronous host runner so
|
|
331
392
|
the control cannot false-fail while Node's listener is blocked.
|
|
332
393
|
|
|
394
|
+
On Linux x64, the same gate additionally requires host-positive and
|
|
395
|
+
sandbox-negative reads of the owned process's `/proc` command line,
|
|
396
|
+
environment, and inherited file descriptor, plus a bounded `strace` attach
|
|
397
|
+
probe. Local TCP, UDP, DNS-protocol, Unix-socket, and direct inherited-FD
|
|
398
|
+
checks remain mandatory. Only the macOS Keychain checks are explicitly
|
|
399
|
+
inapplicable on Linux; an unavailable Linux process, IPC, or network probe
|
|
400
|
+
stops the gate.
|
|
401
|
+
|
|
402
|
+
UDP and DNS listeners remain active until their command completes and for a
|
|
403
|
+
bounded settle interval afterward, so delayed packets cannot be classified as
|
|
404
|
+
denied early. An exact Linux `strace` ESRCH/`No such process` result counts as
|
|
405
|
+
PID-namespace denial only when host-side process liveness and attach controls
|
|
406
|
+
pass both before and after the sandbox attempt; helper failures remain
|
|
407
|
+
fail-closed. The direct inherited-FD probe intentionally checks the production
|
|
408
|
+
app-server spawn boundary, which receives only stdio pipes. The separate
|
|
409
|
+
`/proc/<pid>/fd` probe checks whether a sandboxed same-UID command can recover a
|
|
410
|
+
descriptor inherited by another owned process; no secret descriptor is
|
|
411
|
+
deliberately passed to app-server.
|
|
412
|
+
|
|
333
413
|
## Transport-cut classification is deterministic; persistence is unproved
|
|
334
414
|
|
|
335
415
|
The checker now tracks every currently allowlisted state-changing request
|
package/index.js
CHANGED
|
@@ -25,6 +25,7 @@ const {
|
|
|
25
25
|
CodexAppServerClient,
|
|
26
26
|
CodexAppServerError,
|
|
27
27
|
protocolSchema: codexProtocolSchema,
|
|
28
|
+
resolveCodexTargetPin,
|
|
28
29
|
} = require('./lib/codex/app-server-client');
|
|
29
30
|
const sdkProcess = require('./lib/process/sdk-process');
|
|
30
31
|
const { SdkProcess, extractAssistantText, sumUsage, makeInputController } = sdkProcess;
|
|
@@ -52,7 +53,7 @@ const approvalsStore = require('./lib/approvals/store');
|
|
|
52
53
|
|
|
53
54
|
module.exports = {
|
|
54
55
|
// pool + driver
|
|
55
|
-
Process, UnsupportedOperationError, ProcessManager, CALLBACK_TO_EVENT, CliProcess, CodexProcess, CodexAppServerClient, CodexAppServerError, CodexPreflightError, SdkProcess, extractAssistantText, sumUsage, makeInputController, createProcessFactory, pickBackend, preflightCodexRuntime, reattestCodexStaticPolicy, createCodexSpawnProfile, assertCodexSpawnProfile, attestPinnedCodexHome, buildCodexAppServerEnv, codexProtocolSchema,
|
|
56
|
+
Process, UnsupportedOperationError, ProcessManager, CALLBACK_TO_EVENT, CliProcess, CodexProcess, CodexAppServerClient, CodexAppServerError, CodexPreflightError, SdkProcess, extractAssistantText, sumUsage, makeInputController, createProcessFactory, pickBackend, preflightCodexRuntime, reattestCodexStaticPolicy, createCodexSpawnProfile, assertCodexSpawnProfile, attestPinnedCodexHome, buildCodexAppServerEnv, resolveCodexTargetPin, codexProtocolSchema,
|
|
56
57
|
// channels bridge (MCP injection protocol)
|
|
57
58
|
ChannelsBridgeServer, bridgeProtocol,
|
|
58
59
|
// tmux lifecycle
|
|
@@ -104,6 +104,9 @@ function assertProtocolSchema() {
|
|
|
104
104
|
.filter(([, spec]) => spec.experimental)
|
|
105
105
|
.map(([method]) => method)
|
|
106
106
|
.sort();
|
|
107
|
+
const binaryTargets = Object.keys(
|
|
108
|
+
protocolSchema.binarySha256ByTarget ?? {},
|
|
109
|
+
).sort();
|
|
107
110
|
if (
|
|
108
111
|
JSON.stringify(experimental) !== JSON.stringify([
|
|
109
112
|
'thread/backgroundTerminals/clean',
|
|
@@ -114,6 +117,17 @@ function assertProtocolSchema() {
|
|
|
114
117
|
|| protocolSchema.requestIdTypes.join(',') !== 'integer,string'
|
|
115
118
|
|| typeof protocolSchema.generatedProtocolV2CanonicalSha256 !== 'string'
|
|
116
119
|
|| !/^[a-f0-9]{64}$/.test(protocolSchema.generatedProtocolV2CanonicalSha256)
|
|
120
|
+
|| JSON.stringify(binaryTargets) !== JSON.stringify([
|
|
121
|
+
'aarch64-apple-darwin',
|
|
122
|
+
'x86_64-unknown-linux-musl',
|
|
123
|
+
])
|
|
124
|
+
|| binaryTargets.some(
|
|
125
|
+
(target) => !/^[a-f0-9]{64}$/.test(
|
|
126
|
+
protocolSchema.binarySha256ByTarget[target],
|
|
127
|
+
),
|
|
128
|
+
)
|
|
129
|
+
|| protocolSchema.binarySha256
|
|
130
|
+
!== protocolSchema.binarySha256ByTarget['aarch64-apple-darwin']
|
|
117
131
|
) {
|
|
118
132
|
throw new Error('Codex app-server protocol pin is inconsistent');
|
|
119
133
|
}
|
|
@@ -141,6 +155,37 @@ class CodexAppServerError extends Error {
|
|
|
141
155
|
}
|
|
142
156
|
}
|
|
143
157
|
|
|
158
|
+
const CODEX_TARGET_BY_HOST = Object.freeze({
|
|
159
|
+
'darwin/arm64': 'aarch64-apple-darwin',
|
|
160
|
+
'linux/x64': 'x86_64-unknown-linux-musl',
|
|
161
|
+
});
|
|
162
|
+
const CODEX_TARGET_RECEIPTS = Object.freeze(Object.fromEntries(
|
|
163
|
+
Object.entries(protocolSchema.binarySha256ByTarget).map(
|
|
164
|
+
([target, binarySha256]) => [
|
|
165
|
+
target,
|
|
166
|
+
Object.freeze({
|
|
167
|
+
target,
|
|
168
|
+
cliVersion: protocolSchema.cliVersion,
|
|
169
|
+
binarySha256,
|
|
170
|
+
}),
|
|
171
|
+
],
|
|
172
|
+
),
|
|
173
|
+
));
|
|
174
|
+
|
|
175
|
+
function resolveCodexTargetPin(
|
|
176
|
+
platform = process.platform,
|
|
177
|
+
arch = process.arch,
|
|
178
|
+
) {
|
|
179
|
+
const target = CODEX_TARGET_BY_HOST[`${platform}/${arch}`];
|
|
180
|
+
if (!target) {
|
|
181
|
+
throw new CodexAppServerError(
|
|
182
|
+
'The native Codex app-server beta does not support this platform',
|
|
183
|
+
'CODEX_UNSUPPORTED_PLATFORM',
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
return CODEX_TARGET_RECEIPTS[target];
|
|
187
|
+
}
|
|
188
|
+
|
|
144
189
|
function buildCodexAppServerEnv(codexHome, hostEnv = process.env) {
|
|
145
190
|
return Object.fromEntries(
|
|
146
191
|
Object.entries({
|
|
@@ -185,7 +230,16 @@ async function hashFile(binary) {
|
|
|
185
230
|
return hash.digest('hex');
|
|
186
231
|
}
|
|
187
232
|
|
|
188
|
-
async function attestPinnedCodexBinary(
|
|
233
|
+
async function attestPinnedCodexBinary(
|
|
234
|
+
binary,
|
|
235
|
+
targetReceipt = resolveCodexTargetPin(),
|
|
236
|
+
) {
|
|
237
|
+
if (targetReceipt !== resolveCodexTargetPin()) {
|
|
238
|
+
throw new CodexAppServerError(
|
|
239
|
+
'pinned Codex target receipt mismatch',
|
|
240
|
+
'CODEX_BINARY_MISMATCH',
|
|
241
|
+
);
|
|
242
|
+
}
|
|
189
243
|
if (realpathSync(binary) !== binary) {
|
|
190
244
|
throw new CodexAppServerError(
|
|
191
245
|
'pinned Codex binary path is not canonical',
|
|
@@ -221,7 +275,7 @@ async function attestPinnedCodexBinary(binary) {
|
|
|
221
275
|
);
|
|
222
276
|
}
|
|
223
277
|
const sha256 = await hashFile(binary);
|
|
224
|
-
if (sha256 !==
|
|
278
|
+
if (sha256 !== targetReceipt.binarySha256) {
|
|
225
279
|
throw new CodexAppServerError(
|
|
226
280
|
'pinned Codex binary hash mismatch',
|
|
227
281
|
'CODEX_BINARY_MISMATCH',
|
|
@@ -241,7 +295,7 @@ async function attestPinnedCodexBinary(binary) {
|
|
|
241
295
|
'CODEX_BINARY_MISMATCH',
|
|
242
296
|
);
|
|
243
297
|
}
|
|
244
|
-
if (stdout.trim() !==
|
|
298
|
+
if (stdout.trim() !== targetReceipt.cliVersion) {
|
|
245
299
|
throw new CodexAppServerError(
|
|
246
300
|
'pinned Codex binary version mismatch',
|
|
247
301
|
'CODEX_BINARY_MISMATCH',
|
|
@@ -249,6 +303,7 @@ async function attestPinnedCodexBinary(binary) {
|
|
|
249
303
|
}
|
|
250
304
|
return {
|
|
251
305
|
path: binary,
|
|
306
|
+
target: targetReceipt.target,
|
|
252
307
|
sha256,
|
|
253
308
|
version: stdout.trim(),
|
|
254
309
|
fingerprint,
|
|
@@ -1732,12 +1787,7 @@ class CodexAppServerClient extends EventEmitter {
|
|
|
1732
1787
|
'CodexAppServerClient: expectedConfigSha256 must be a lowercase SHA-256',
|
|
1733
1788
|
);
|
|
1734
1789
|
}
|
|
1735
|
-
|
|
1736
|
-
throw new CodexAppServerError(
|
|
1737
|
-
'The native Codex app-server beta does not support Windows',
|
|
1738
|
-
'CODEX_UNSUPPORTED_PLATFORM',
|
|
1739
|
-
);
|
|
1740
|
-
}
|
|
1790
|
+
const targetReceipt = resolveCodexTargetPin();
|
|
1741
1791
|
for (const [value, label] of [
|
|
1742
1792
|
[cwd, 'cwd'],
|
|
1743
1793
|
[codexHome, 'codexHome'],
|
|
@@ -1824,6 +1874,7 @@ class CodexAppServerClient extends EventEmitter {
|
|
|
1824
1874
|
onFault,
|
|
1825
1875
|
attestBinaryFn,
|
|
1826
1876
|
attestCodexHomeFn,
|
|
1877
|
+
targetReceipt,
|
|
1827
1878
|
expectedConfigSha256,
|
|
1828
1879
|
requestTimeoutMs,
|
|
1829
1880
|
sinkTimeoutMs,
|
|
@@ -1889,7 +1940,7 @@ class CodexAppServerClient extends EventEmitter {
|
|
|
1889
1940
|
];
|
|
1890
1941
|
try {
|
|
1891
1942
|
const [attestation, homeAttestation] = await Promise.all([
|
|
1892
|
-
this.attestBinaryFn(this.binary),
|
|
1943
|
+
this.attestBinaryFn(this.binary, this.targetReceipt),
|
|
1893
1944
|
this.attestCodexHomeFn(
|
|
1894
1945
|
this.codexHome,
|
|
1895
1946
|
this.expectedConfigSha256,
|
|
@@ -1898,8 +1949,9 @@ class CodexAppServerClient extends EventEmitter {
|
|
|
1898
1949
|
if (
|
|
1899
1950
|
!attestation
|
|
1900
1951
|
|| attestation.path !== this.binary
|
|
1901
|
-
|| attestation.
|
|
1902
|
-
|| attestation.
|
|
1952
|
+
|| attestation.target !== this.targetReceipt.target
|
|
1953
|
+
|| attestation.sha256 !== this.targetReceipt.binarySha256
|
|
1954
|
+
|| attestation.version !== this.targetReceipt.cliVersion
|
|
1903
1955
|
) {
|
|
1904
1956
|
throw new CodexAppServerError(
|
|
1905
1957
|
'pinned Codex binary attestation was inconsistent',
|
|
@@ -2931,4 +2983,5 @@ module.exports = {
|
|
|
2931
2983
|
attestPinnedCodexHome,
|
|
2932
2984
|
buildCodexAppServerEnv,
|
|
2933
2985
|
protocolSchema,
|
|
2986
|
+
resolveCodexTargetPin,
|
|
2934
2987
|
};
|
package/lib/codex/preflight.js
CHANGED
|
@@ -7,6 +7,7 @@ const {
|
|
|
7
7
|
CodexAppServerClient,
|
|
8
8
|
buildCodexAppServerEnv,
|
|
9
9
|
protocolSchema,
|
|
10
|
+
resolveCodexTargetPin,
|
|
10
11
|
} = require('./app-server-client');
|
|
11
12
|
|
|
12
13
|
const MAX_PAGES = 16;
|
|
@@ -22,6 +23,7 @@ const SHA256_RE = /^[a-f0-9]{64}$/;
|
|
|
22
23
|
const EXPECTED_PROFILE_KEYS = new Set([
|
|
23
24
|
'runtime',
|
|
24
25
|
'binary',
|
|
26
|
+
'target',
|
|
25
27
|
'binarySha256',
|
|
26
28
|
'cliVersion',
|
|
27
29
|
'protocolSchemaSha256',
|
|
@@ -218,6 +220,7 @@ function exact(actual, expected, label) {
|
|
|
218
220
|
}
|
|
219
221
|
|
|
220
222
|
function normalizeExpectedProfile(value) {
|
|
223
|
+
const targetReceipt = resolveCodexTargetPin();
|
|
221
224
|
const source = plainObject(value, 'expectedStaticProfile');
|
|
222
225
|
for (const key of Object.keys(source)) {
|
|
223
226
|
if (!EXPECTED_PROFILE_KEYS.has(key)) {
|
|
@@ -246,14 +249,16 @@ function normalizeExpectedProfile(value) {
|
|
|
246
249
|
source.binarySha256,
|
|
247
250
|
'binarySha256',
|
|
248
251
|
);
|
|
252
|
+
const target = requiredString(source.target, 'target');
|
|
249
253
|
const cliVersion = requiredString(source.cliVersion, 'cliVersion');
|
|
250
254
|
const protocolSchemaSha256 = requiredSha256(
|
|
251
255
|
source.protocolSchemaSha256,
|
|
252
256
|
'protocolSchemaSha256',
|
|
253
257
|
);
|
|
254
258
|
if (
|
|
255
|
-
|
|
256
|
-
||
|
|
259
|
+
target !== targetReceipt.target
|
|
260
|
+
|| binarySha256 !== targetReceipt.binarySha256
|
|
261
|
+
|| cliVersion !== targetReceipt.cliVersion
|
|
257
262
|
|| protocolSchemaSha256
|
|
258
263
|
!== protocolSchema.generatedProtocolV2CanonicalSha256
|
|
259
264
|
) {
|
|
@@ -326,6 +331,7 @@ function normalizeExpectedProfile(value) {
|
|
|
326
331
|
const profile = {
|
|
327
332
|
runtime: 'codex',
|
|
328
333
|
binary,
|
|
334
|
+
target,
|
|
329
335
|
binarySha256,
|
|
330
336
|
cliVersion,
|
|
331
337
|
protocolSchemaSha256,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"cliVersion": "codex-cli 0.145.0",
|
|
3
3
|
"binarySha256": "1da3f4e0e96028b8a771814293c3033dafd1971f943f6c7e79b0897fe705f590",
|
|
4
|
+
"binarySha256ByTarget": {
|
|
5
|
+
"aarch64-apple-darwin": "1da3f4e0e96028b8a771814293c3033dafd1971f943f6c7e79b0897fe705f590",
|
|
6
|
+
"x86_64-unknown-linux-musl": "a2a05dafaa1acb002a45eaec0a462de5b13694fcfcd7bc43305f14781ce7be14"
|
|
7
|
+
},
|
|
4
8
|
"generatedProtocolV2CanonicalSha256": "1bc09dedc506075562d4d49b702ecab6d947dd5a8c2a9014a5cde592a0938efb",
|
|
5
9
|
"requestIdTypes": [
|
|
6
10
|
"integer",
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const MAX_ATTACHMENT_SETTING_BYTES = 512;
|
|
4
|
+
|
|
5
|
+
function boundedSetting(value, label) {
|
|
6
|
+
if (
|
|
7
|
+
typeof value !== 'string'
|
|
8
|
+
|| value.length === 0
|
|
9
|
+
|| Buffer.byteLength(value, 'utf8') > MAX_ATTACHMENT_SETTING_BYTES
|
|
10
|
+
) {
|
|
11
|
+
throw new TypeError(
|
|
12
|
+
`Codex attachment ${label} must be a non-empty string of at most `
|
|
13
|
+
+ `${MAX_ATTACHMENT_SETTING_BYTES} UTF-8 bytes`,
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function parseCodexAttachmentSettings(source) {
|
|
20
|
+
const model = boundedSetting(source?.model, 'model');
|
|
21
|
+
if (!source || !Object.hasOwn(source, 'reasoningEffort')) {
|
|
22
|
+
return Object.freeze({
|
|
23
|
+
complete: false,
|
|
24
|
+
effort: null,
|
|
25
|
+
effortPresence: 'omitted',
|
|
26
|
+
model,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (source.reasoningEffort === null) {
|
|
30
|
+
return Object.freeze({
|
|
31
|
+
complete: false,
|
|
32
|
+
effort: null,
|
|
33
|
+
effortPresence: 'null',
|
|
34
|
+
model,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return Object.freeze({
|
|
38
|
+
complete: true,
|
|
39
|
+
effort: boundedSetting(source.reasoningEffort, 'effort'),
|
|
40
|
+
effortPresence: 'present',
|
|
41
|
+
model,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
MAX_ATTACHMENT_SETTING_BYTES,
|
|
47
|
+
parseCodexAttachmentSettings,
|
|
48
|
+
};
|
|
@@ -4,6 +4,9 @@ const { randomUUID } = require('node:crypto');
|
|
|
4
4
|
const { isDeepStrictEqual } = require('node:util');
|
|
5
5
|
|
|
6
6
|
const { Process, UnsupportedOperationError } = require('./process');
|
|
7
|
+
const {
|
|
8
|
+
parseCodexAttachmentSettings,
|
|
9
|
+
} = require('../codex/thread-attachment-settings');
|
|
7
10
|
|
|
8
11
|
const DEFAULT_QUEUE_CAP = 50;
|
|
9
12
|
const DEFAULT_TURN_START_TIMEOUT_MS = 20_000;
|
|
@@ -77,9 +80,13 @@ function modelSettings(model, effort, label = 'settings') {
|
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
function dynamicSettings(source) {
|
|
83
|
+
const parsed = parseCodexAttachmentSettings({
|
|
84
|
+
model: source?.model,
|
|
85
|
+
reasoningEffort: source?.reasoningEffort ?? source?.effort,
|
|
86
|
+
});
|
|
80
87
|
return modelSettings(
|
|
81
|
-
|
|
82
|
-
|
|
88
|
+
parsed.model,
|
|
89
|
+
parsed.effort,
|
|
83
90
|
'thread settings',
|
|
84
91
|
);
|
|
85
92
|
}
|
|
@@ -328,8 +335,11 @@ class CodexProcess extends Process {
|
|
|
328
335
|
this.threadStatusType = null;
|
|
329
336
|
this.desiredSettings = null;
|
|
330
337
|
this.observedThreadSettings = null;
|
|
338
|
+
this.provisionalAttachmentModel = null;
|
|
339
|
+
this.attachmentResponseValidated = false;
|
|
331
340
|
this.admittingTurnSettings = null;
|
|
332
341
|
this.activeTurnSettings = null;
|
|
342
|
+
this.lastAcceptedTurnSettings = null;
|
|
333
343
|
this.settingsGate = Promise.resolve();
|
|
334
344
|
this.settingsAdmissionClosed = false;
|
|
335
345
|
this.client = null;
|
|
@@ -588,22 +598,22 @@ class CodexProcess extends Process {
|
|
|
588
598
|
);
|
|
589
599
|
}
|
|
590
600
|
this._validateAndObserveThreadPolicy(result, {
|
|
591
|
-
|
|
592
|
-
attachmentPolicy: true,
|
|
601
|
+
attachmentResponse: true,
|
|
593
602
|
});
|
|
603
|
+
this.attachmentResponseValidated = true;
|
|
594
604
|
}
|
|
595
605
|
|
|
596
606
|
_validateAndObserveThreadPolicy(
|
|
597
607
|
source,
|
|
598
|
-
{
|
|
608
|
+
{ attachmentResponse = false } = {},
|
|
599
609
|
) {
|
|
600
610
|
const actualStaticPolicy = staticThreadPolicy(source, {
|
|
601
611
|
includeRuntimeWorkspaceRoots: (
|
|
602
|
-
|
|
612
|
+
attachmentResponse
|
|
603
613
|
&& Object.hasOwn(this.expectedStaticPolicy, 'runtimeWorkspaceRoots')
|
|
604
614
|
),
|
|
605
615
|
});
|
|
606
|
-
const expectedStaticPolicy =
|
|
616
|
+
const expectedStaticPolicy = attachmentResponse
|
|
607
617
|
? this.expectedStaticPolicy
|
|
608
618
|
: this.expectedSettingsPolicy;
|
|
609
619
|
if (!isDeepStrictEqual(actualStaticPolicy, expectedStaticPolicy)) {
|
|
@@ -612,6 +622,73 @@ class CodexProcess extends Process {
|
|
|
612
622
|
'CODEX_THREAD_POLICY_MISMATCH',
|
|
613
623
|
);
|
|
614
624
|
}
|
|
625
|
+
if (attachmentResponse) {
|
|
626
|
+
let attachmentSettings;
|
|
627
|
+
try {
|
|
628
|
+
attachmentSettings = parseCodexAttachmentSettings(source);
|
|
629
|
+
} catch (cause) {
|
|
630
|
+
throw processError(
|
|
631
|
+
'Codex thread returned malformed attachment settings',
|
|
632
|
+
'CODEX_PROTOCOL_ERROR',
|
|
633
|
+
{ cause },
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
const collaboration = source?.collaborationMode;
|
|
637
|
+
if (
|
|
638
|
+
collaboration != null
|
|
639
|
+
&& (
|
|
640
|
+
collaboration.mode !== 'default'
|
|
641
|
+
|| collaboration.model !== attachmentSettings.model
|
|
642
|
+
|| (
|
|
643
|
+
attachmentSettings.complete
|
|
644
|
+
&& collaboration.reasoningEffort != null
|
|
645
|
+
&& collaboration.reasoningEffort !== attachmentSettings.effort
|
|
646
|
+
)
|
|
647
|
+
)
|
|
648
|
+
) {
|
|
649
|
+
throw processError(
|
|
650
|
+
'Codex collaboration settings disagreed with the observed turn settings',
|
|
651
|
+
'CODEX_THREAD_POLICY_MISMATCH',
|
|
652
|
+
);
|
|
653
|
+
}
|
|
654
|
+
const accepted = this._completeThreadSettingsCandidates();
|
|
655
|
+
if (attachmentSettings.complete) {
|
|
656
|
+
const observed = modelSettings(
|
|
657
|
+
attachmentSettings.model,
|
|
658
|
+
attachmentSettings.effort,
|
|
659
|
+
'thread settings',
|
|
660
|
+
);
|
|
661
|
+
if (
|
|
662
|
+
accepted.length > 0
|
|
663
|
+
&& !accepted.some((candidate) => isDeepStrictEqual(candidate, observed))
|
|
664
|
+
) {
|
|
665
|
+
throw processError(
|
|
666
|
+
'Codex thread attachment reported inconsistent dynamic settings',
|
|
667
|
+
'CODEX_THREAD_SETTINGS_MISMATCH',
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
this.observedThreadSettings = observed;
|
|
671
|
+
this.provisionalAttachmentModel = null;
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
if (
|
|
675
|
+
accepted.length > 0
|
|
676
|
+
&& !accepted.some(
|
|
677
|
+
(candidate) => candidate.model === attachmentSettings.model,
|
|
678
|
+
)
|
|
679
|
+
) {
|
|
680
|
+
throw processError(
|
|
681
|
+
'Codex thread attachment reported inconsistent dynamic settings',
|
|
682
|
+
'CODEX_THREAD_SETTINGS_MISMATCH',
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
if (accepted.length === 0) {
|
|
686
|
+
this.provisionalAttachmentModel = attachmentSettings.model;
|
|
687
|
+
} else {
|
|
688
|
+
this.provisionalAttachmentModel = null;
|
|
689
|
+
}
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
615
692
|
let observed;
|
|
616
693
|
try {
|
|
617
694
|
observed = dynamicSettings(source);
|
|
@@ -639,13 +716,9 @@ class CodexProcess extends Process {
|
|
|
639
716
|
'CODEX_THREAD_POLICY_MISMATCH',
|
|
640
717
|
);
|
|
641
718
|
}
|
|
642
|
-
const accepted =
|
|
643
|
-
this.observedThreadSettings,
|
|
644
|
-
this.admittingTurnSettings,
|
|
645
|
-
this.activeTurnSettings,
|
|
646
|
-
].filter(Boolean);
|
|
719
|
+
const accepted = this._completeThreadSettingsCandidates();
|
|
647
720
|
if (
|
|
648
|
-
|
|
721
|
+
accepted.length > 0
|
|
649
722
|
&& !accepted.some((candidate) => isDeepStrictEqual(candidate, observed))
|
|
650
723
|
) {
|
|
651
724
|
throw processError(
|
|
@@ -654,16 +727,39 @@ class CodexProcess extends Process {
|
|
|
654
727
|
);
|
|
655
728
|
}
|
|
656
729
|
if (
|
|
657
|
-
|
|
658
|
-
&& this.
|
|
659
|
-
&&
|
|
730
|
+
accepted.length === 0
|
|
731
|
+
&& this.provisionalAttachmentModel
|
|
732
|
+
&& observed.model !== this.provisionalAttachmentModel
|
|
660
733
|
) {
|
|
661
734
|
throw processError(
|
|
662
|
-
'Codex thread
|
|
735
|
+
'Codex thread reported unexplained dynamic settings',
|
|
736
|
+
'CODEX_THREAD_SETTINGS_MISMATCH',
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
if (
|
|
740
|
+
accepted.length === 0
|
|
741
|
+
&& !this.provisionalAttachmentModel
|
|
742
|
+
&& !(
|
|
743
|
+
this.state === 'AttachingThread'
|
|
744
|
+
&& !this.attachmentResponseValidated
|
|
745
|
+
)
|
|
746
|
+
) {
|
|
747
|
+
throw processError(
|
|
748
|
+
'Codex thread reported unexplained dynamic settings',
|
|
663
749
|
'CODEX_THREAD_SETTINGS_MISMATCH',
|
|
664
750
|
);
|
|
665
751
|
}
|
|
666
752
|
this.observedThreadSettings = observed;
|
|
753
|
+
this.provisionalAttachmentModel = null;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
_completeThreadSettingsCandidates() {
|
|
757
|
+
return [
|
|
758
|
+
this.observedThreadSettings,
|
|
759
|
+
this.admittingTurnSettings,
|
|
760
|
+
this.activeTurnSettings,
|
|
761
|
+
this.lastAcceptedTurnSettings,
|
|
762
|
+
].filter(Boolean);
|
|
667
763
|
}
|
|
668
764
|
|
|
669
765
|
_validatedModelSettings(settings) {
|
|
@@ -847,6 +943,7 @@ class CodexProcess extends Process {
|
|
|
847
943
|
const admittedSettings = this.desiredSettings;
|
|
848
944
|
pending.admittedSettings = admittedSettings;
|
|
849
945
|
this.admittingTurnSettings = admittedSettings;
|
|
946
|
+
this.provisionalAttachmentModel = null;
|
|
850
947
|
const params = {
|
|
851
948
|
threadId: this.providerSessionId,
|
|
852
949
|
input: [{ type: 'text', text: pending.prompt }],
|
|
@@ -915,6 +1012,7 @@ class CodexProcess extends Process {
|
|
|
915
1012
|
effort: admittedSettings.effort,
|
|
916
1013
|
});
|
|
917
1014
|
this._assertLifecycle(lifecycle);
|
|
1015
|
+
this.lastAcceptedTurnSettings = admittedSettings;
|
|
918
1016
|
this.activeTurnSettings = admittedSettings;
|
|
919
1017
|
return turnId;
|
|
920
1018
|
} finally {
|
|
@@ -1885,9 +1983,7 @@ class CodexProcess extends Process {
|
|
|
1885
1983
|
}
|
|
1886
1984
|
if (method === 'thread/settings/updated') {
|
|
1887
1985
|
try {
|
|
1888
|
-
this._validateAndObserveThreadPolicy(params.threadSettings
|
|
1889
|
-
attaching: this.state === 'AttachingThread',
|
|
1890
|
-
});
|
|
1986
|
+
this._validateAndObserveThreadPolicy(params.threadSettings);
|
|
1891
1987
|
} catch (error) {
|
|
1892
1988
|
await this._enterContainment(
|
|
1893
1989
|
'thread-settings-drift',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shumkov/orchestra",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Transport-agnostic session engine for Claude Code and the native Codex app-server: spawn, steer, supervise, observe turns, and recover.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "index.js",
|