@shumkov/orchestra 0.10.0 → 0.10.2
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 +24 -3
- package/lib/codex/thread-attachment-settings.js +48 -0
- package/lib/process/channels-bridge.mjs +16 -6
- package/lib/process/cli-process.js +44 -11
- 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.
|
|
@@ -220,9 +220,23 @@ Every production `turn/start` carries the complete catalog-validated
|
|
|
220
220
|
`model`/`effort` pair selected for that admission. Changing the local
|
|
221
221
|
selection preserves the process generation and provider thread, leaves an
|
|
222
222
|
active turn and its steering on their admitted pair, and applies to the next
|
|
223
|
-
turn.
|
|
224
|
-
|
|
225
|
-
|
|
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.
|
|
226
240
|
|
|
227
241
|
Codex does not persist a resumable rollout for `thread/start` alone. The
|
|
228
242
|
checker therefore completes one fixed no-tools text turn, requires the matching
|
|
@@ -246,6 +260,13 @@ the checker still requires its complete static settings view to be exact.
|
|
|
246
260
|
Notifications caused by explicit experimental `thread/settings/update` calls
|
|
247
261
|
are characterized separately and do not establish attachment-time emission.
|
|
248
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
|
+
|
|
249
270
|
Fresh and resume responses, and any observed `thread/settings/updated`, use the
|
|
250
271
|
same legacy compatibility envelope:
|
|
251
272
|
|
|
@@ -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
|
+
};
|
|
@@ -369,13 +369,23 @@ mcp.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
|
369
369
|
},
|
|
370
370
|
}, {
|
|
371
371
|
// 0.13: edit a message already sent via `reply`, in place — the progressive-
|
|
372
|
-
// status primitive. Update one bubble instead of sending several.
|
|
372
|
+
// status primitive. Update one bubble instead of sending several. The edit is
|
|
373
|
+
// re-rendered the same way the reply was, so a checklist stays a checklist.
|
|
373
374
|
name: 'edit_message',
|
|
374
|
-
description: 'Edit a message you previously sent via `reply`, in place.
|
|
375
|
-
'
|
|
376
|
-
'
|
|
377
|
-
'
|
|
378
|
-
'
|
|
375
|
+
description: 'Edit a message you previously sent via `reply`, in place. In a chat that ' +
|
|
376
|
+
'renders rich, an edited checklist/table/heading is re-rendered rich rather ' +
|
|
377
|
+
'than flattened. Canonical use: send a plan as `- [ ] step` items, then edit ' +
|
|
378
|
+
'that same message_id with the WHOLE list again and `- [x]` on completed ' +
|
|
379
|
+
'steps — check items off as you go and the user watches one bubble update. ' +
|
|
380
|
+
'Also fine for a short one-line status. An edit REPLACES the body, so always ' +
|
|
381
|
+
're-send the full text. An edit is TEXT-ONLY: image markdown degrades to its ' +
|
|
382
|
+
'caption and cannot add media to a bubble (send media with `reply(files:)`). ' +
|
|
383
|
+
'Keep status in PLAIN LANGUAGE — never tool names like Bash/Edit. One bubble, ' +
|
|
384
|
+
'never chunked: ~4,000 chars for plain text, much more (~32,000) when it ' +
|
|
385
|
+
'renders rich; over the limit the tool tells you which one applied — send ' +
|
|
386
|
+
'long content as a fresh `reply` instead. An edit does NOT notify the user ' +
|
|
387
|
+
'and carries no consumed_turn_ids: it is a mid-turn update, never the final ' +
|
|
388
|
+
'answer.',
|
|
379
389
|
inputSchema: {
|
|
380
390
|
type: 'object',
|
|
381
391
|
properties: {
|
|
@@ -951,10 +951,33 @@ class CliProcess extends Process {
|
|
|
951
951
|
'calls without replying, or the request plainly needs research / several steps —',
|
|
952
952
|
'send a SHORT one-line status via `reply` WITH `interim: true` (it returns a',
|
|
953
953
|
`\`message_id\`), then use \`mcp__${b}__edit_message\` on that SAME`,
|
|
954
|
-
'`message_id` to update the bubble as you progress.
|
|
955
|
-
'INTERIM status ONLY.',
|
|
954
|
+
'`message_id` to update the bubble as you progress.',
|
|
956
955
|
'',
|
|
957
|
-
'
|
|
956
|
+
'An edit re-renders the bubble exactly as the original `reply` did — a chat',
|
|
957
|
+
'that renders rich re-renders an edited checklist, table or heading rich, not',
|
|
958
|
+
'flat. So on multi-step work the strongest progress bubble is a CHECKLIST:',
|
|
959
|
+
'send the plan as `- [ ] step` items, then `edit_message` that same message_id',
|
|
960
|
+
'with the list again and `- [x]` on what you have finished. Check items off as',
|
|
961
|
+
'you complete them — the user watches ONE bubble fill in instead of collecting',
|
|
962
|
+
'a trail of status messages. Always re-send the WHOLE list (an edit REPLACES',
|
|
963
|
+
'the body, so a partial re-send loses everything you left out).',
|
|
964
|
+
'',
|
|
965
|
+
'Short one-line status text is still fine for an interim bubble — a checklist',
|
|
966
|
+
'is the better shape when the work has steps worth showing, not a requirement.',
|
|
967
|
+
'',
|
|
968
|
+
'An edit is TEXT-ONLY. Checklists, tables and headings re-render; image',
|
|
969
|
+
'markdown degrades to its caption, and an edit can never ADD media to a',
|
|
970
|
+
`bubble — send files with \`reply(files:)\`. An edit that is nothing but`,
|
|
971
|
+
'media has nothing left to say and will come back as an error.',
|
|
972
|
+
'',
|
|
973
|
+
'Length: an edit is ONE bubble, never chunked. Plain text is capped around',
|
|
974
|
+
'4,000 characters; a rich-rendered structure in a rich-enabled chat gets a',
|
|
975
|
+
'much larger one (~32,000). You cannot see which applies — if you go over, the',
|
|
976
|
+
'tool tells you the limit that applied, so shorten the edit or send the long',
|
|
977
|
+
'content as a fresh `reply`.',
|
|
978
|
+
'',
|
|
979
|
+
'HARD RULE — a status bubble or progress checklist is a MID-TURN update, NOT',
|
|
980
|
+
'the end of work, and `edit_message` NEVER delivers the final answer. After an',
|
|
958
981
|
'interim reply you MUST keep working in the SAME turn and deliver the real',
|
|
959
982
|
'result. NEVER end your turn on a status / "give me a couple min" / "looking',
|
|
960
983
|
'into it" reply with no result behind it — that leaves the user staring at a',
|
|
@@ -975,20 +998,30 @@ class CliProcess extends Process {
|
|
|
975
998
|
// that puts `stream` in the bridge's tool list), so the contract below can
|
|
976
999
|
// never coach the agent toward a tool that isn't there.
|
|
977
1000
|
...(this.streamToolEnabled ? [
|
|
978
|
-
'### Showing your answer as you write it',
|
|
1001
|
+
'### Showing your answer as you write it — HARD CONTRACT',
|
|
1002
|
+
'',
|
|
1003
|
+
'The user is watching a LIVE bubble the whole time you compose, and',
|
|
1004
|
+
`\`mcp__${b}__stream\` is the ONLY thing that fills it in. Writing a long`,
|
|
1005
|
+
'answer in silence and dropping it at the end is a CONTRACT VIOLATION, not a',
|
|
1006
|
+
'style choice: the user sat watching an empty bubble for the entire time you',
|
|
1007
|
+
'were writing.',
|
|
1008
|
+
'',
|
|
1009
|
+
'So if your answer will run longer than about two paragraphs, this is the',
|
|
1010
|
+
'cadence: after EVERY section you finish — or after every paragraph, when',
|
|
1011
|
+
'the answer has no sections — and BEFORE you start writing the next one,',
|
|
1012
|
+
`you MUST call \`mcp__${b}__stream\` with the FULL answer-so-far.`,
|
|
1013
|
+
'Not once at the end, not "at a natural checkpoint" — after each one,',
|
|
1014
|
+
'every time. Four sections means four stream calls, and then the reply.',
|
|
979
1015
|
'',
|
|
980
|
-
|
|
981
|
-
'
|
|
982
|
-
'finished thought). Each call replaces the preview, so always send the whole',
|
|
983
|
-
'answer up to that point — never just the new part. The user watches it fill in',
|
|
984
|
-
'instead of staring at silence.',
|
|
1016
|
+
'Each call REPLACES the preview, so always send the whole answer up to that',
|
|
1017
|
+
'point — never just the part you added.',
|
|
985
1018
|
'',
|
|
986
1019
|
'HARD RULE — `stream` is a PREVIEW, not a delivery. It never ends a turn and',
|
|
987
1020
|
`it is not the answer. ALWAYS finish with a normal \`mcp__${b}__reply\``,
|
|
988
1021
|
'carrying the complete answer; NEVER end a turn on a stream call.',
|
|
989
1022
|
'',
|
|
990
|
-
'
|
|
991
|
-
'
|
|
1023
|
+
'A couple of sentences is short — just reply, no stream. And never retry a',
|
|
1024
|
+
'stream call: it cannot fail in a way that matters.',
|
|
992
1025
|
'',
|
|
993
1026
|
] : []),
|
|
994
1027
|
// TEMPORARY mitigation (2026-06-08 Shumabit@UMI wedge): AskUserQuestion opens
|
|
@@ -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.10.
|
|
3
|
+
"version": "0.10.2",
|
|
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",
|