oh-my-codex 0.22.7 → 0.22.9
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/Cargo.lock +6 -6
- package/Cargo.toml +1 -1
- package/dist/hooks/__tests__/code-review-skill-contract.test.js +81 -0
- package/dist/hooks/__tests__/code-review-skill-contract.test.js.map +1 -1
- package/dist/hooks/extensibility/runtime.d.ts.map +1 -1
- package/dist/hooks/extensibility/runtime.js +12 -2
- package/dist/hooks/extensibility/runtime.js.map +1 -1
- package/dist/scripts/__tests__/issue-4086-stop-hook-stale-lock.test.d.ts +2 -0
- package/dist/scripts/__tests__/issue-4086-stop-hook-stale-lock.test.d.ts.map +1 -0
- package/dist/scripts/__tests__/issue-4086-stop-hook-stale-lock.test.js +134 -0
- package/dist/scripts/__tests__/issue-4086-stop-hook-stale-lock.test.js.map +1 -0
- package/dist/scripts/codex-native-hook.d.ts.map +1 -1
- package/dist/scripts/codex-native-hook.js +85 -36
- package/dist/scripts/codex-native-hook.js.map +1 -1
- package/package.json +1 -1
- package/plugins/oh-my-codex/.codex-plugin/plugin.json +1 -1
- package/plugins/oh-my-codex/skills/code-review/SKILL.md +84 -0
- package/skills/code-review/SKILL.md +84 -0
- package/src/scripts/__tests__/issue-4086-stop-hook-stale-lock.test.ts +203 -0
- package/src/scripts/codex-native-hook.ts +84 -36
package/package.json
CHANGED
|
@@ -29,6 +29,20 @@ git diff --stat
|
|
|
29
29
|
git diff -- <scope>
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
## Continuation Decision Table
|
|
33
|
+
|
|
34
|
+
When a user requests `continue` or provides existing artifacts, check the source binding and decide the next step:
|
|
35
|
+
|
|
36
|
+
| Condition | Action |
|
|
37
|
+
|-----------|--------|
|
|
38
|
+
| **Fresh Review** (no prior receipt, OR source/requirements/gates changed) | Launch both code-reviewer and architect lanes in parallel on clean contexts. Treat prior artifacts as context only; do not reuse evidence. |
|
|
39
|
+
| **Resuming Missing Lane** (one lane has evidence, other missing, source/requirements/gates unchanged) | Re-launch the missing lane only. Carry prior evidence from the complete lane. |
|
|
40
|
+
| **Resuming Missing Validation** (both lanes returned, validation incomplete, source/requirements/gates unchanged) | Collect missing validation inputs/results. Reuse lane evidence. |
|
|
41
|
+
| **Repair Re-review** (implementation changed source after prior review, authorized repair owner confirmed) | Re-launch both lanes on the revised scope. Include prior findings as context; preserve dispositions unless new evidence justifies reopening. Carry repair authorization through the review. |
|
|
42
|
+
| **Complete Evidence** (all lanes returned, all validation complete, source/requirements/gates unchanged) | Return the existing scoped result and stop. No re-review needed. |
|
|
43
|
+
|
|
44
|
+
**Binding Rules**: A source-bound receipt tracks scope identity (commit, uncommitted changes, file hashes), requirements, configured gates, and lane results. Missing or unverifiable bindings (stale/unbound artifacts, changed source not signed by repair authorization) prevent evidence reuse. Invalidation triggers a fresh review; partial evidence loss triggers lane resumption, not full restart.
|
|
45
|
+
|
|
32
46
|
## Execution
|
|
33
47
|
|
|
34
48
|
1. Identify changed files and review boundaries; do not silently widen the scope.
|
|
@@ -116,6 +130,76 @@ RECOMMENDATION: COMMENT
|
|
|
116
130
|
Replace the illustrative counts and verdict with observed values. Include scope,
|
|
117
131
|
lane evidence/artifact references, unresolved risks, and validation gaps.
|
|
118
132
|
|
|
133
|
+
## Source-Bound Review Receipt
|
|
134
|
+
|
|
135
|
+
When a review completes or a user requests continuation, record a source-bound receipt that binds the review result to its input context. This receipt is the basis for deciding whether to reuse evidence or perform a fresh review.
|
|
136
|
+
|
|
137
|
+
**Receipt Structure**:
|
|
138
|
+
|
|
139
|
+
```text
|
|
140
|
+
SOURCE-BOUND REVIEW RECEIPT
|
|
141
|
+
|
|
142
|
+
REVIEW SCOPE
|
|
143
|
+
Files Reviewed: <count>
|
|
144
|
+
Changed Lines: <+/->
|
|
145
|
+
Boundaries: <scope description>
|
|
146
|
+
|
|
147
|
+
SOURCE IDENTITY
|
|
148
|
+
Base Commit: <commit hash>
|
|
149
|
+
Uncommitted Changes: <yes|no> [file hashes if present]
|
|
150
|
+
Source Binding: <valid|stale|unbound>
|
|
151
|
+
|
|
152
|
+
REQUIREMENTS & GATES
|
|
153
|
+
Specification: [reference or summary]
|
|
154
|
+
Acceptance Criteria: [reference or summary]
|
|
155
|
+
Test/CI Evidence: [references]
|
|
156
|
+
Configured Quality Gates: [list of blocking/advisory gates]
|
|
157
|
+
|
|
158
|
+
LANE RESULTS
|
|
159
|
+
code-reviewer:
|
|
160
|
+
Recommendation: APPROVE | REQUEST CHANGES | COMMENT
|
|
161
|
+
Finding Severity: CRITICAL (N) | HIGH (N) | MEDIUM (N) | LOW (N)
|
|
162
|
+
Artifact: [reference or hash]
|
|
163
|
+
Status: complete | unavailable
|
|
164
|
+
|
|
165
|
+
architect:
|
|
166
|
+
Status: CLEAR | WATCH | BLOCK
|
|
167
|
+
Finding Severity: CRITICAL (N) | HIGH (N) | MEDIUM (N) | LOW (N)
|
|
168
|
+
Artifact: [reference or hash]
|
|
169
|
+
Status: complete | unavailable
|
|
170
|
+
|
|
171
|
+
[custom gates]:
|
|
172
|
+
Gate Name: <skill name>
|
|
173
|
+
Mode: blocking | advisory
|
|
174
|
+
Verdict: pass | fail | unavailable
|
|
175
|
+
Artifact: [reference or hash]
|
|
176
|
+
Status: complete | unavailable
|
|
177
|
+
|
|
178
|
+
VALIDATION
|
|
179
|
+
Inputs Recorded: [list of validation requirements met]
|
|
180
|
+
Validation Results: [status of each requirement]
|
|
181
|
+
Validation Status: complete | incomplete
|
|
182
|
+
|
|
183
|
+
FINDINGS & GAPS
|
|
184
|
+
Unresolved High/Critical: [count and list]
|
|
185
|
+
Evidence Gaps: [any missing evidence from required lanes or gates]
|
|
186
|
+
Blockers: [any blocking conditions preventing approval]
|
|
187
|
+
|
|
188
|
+
FINAL RECOMMENDATION
|
|
189
|
+
Recommendation: APPROVE | REQUEST CHANGES | COMMENT
|
|
190
|
+
Merge-Ready: yes | no
|
|
191
|
+
Binding Status: bound | unbound
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**Invalidation Triggers**: The receipt becomes invalid if:
|
|
195
|
+
- Base commit or uncommitted changes differ from the initial review (source changed)
|
|
196
|
+
- Requirements or acceptance criteria are updated
|
|
197
|
+
- Configured quality gates change (gates added, removed, or mode changed)
|
|
198
|
+
- Validation inputs/results are unavailable or stale
|
|
199
|
+
- Required lanes (code-reviewer or architect) are missing or unavailable
|
|
200
|
+
|
|
201
|
+
**Reuse Rules**: Evidence may be reused across continuation requests only if all binding conditions match and the receipt status is `bound`. A `stale` or `unbound` receipt requires fresh review. Missing or unverifiable bindings never establish approval.
|
|
202
|
+
|
|
119
203
|
## Exit condition
|
|
120
204
|
|
|
121
205
|
Stop when the scoped diff has two independent lane results and a deterministic final
|
|
@@ -29,6 +29,20 @@ git diff --stat
|
|
|
29
29
|
git diff -- <scope>
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
## Continuation Decision Table
|
|
33
|
+
|
|
34
|
+
When a user requests `continue` or provides existing artifacts, check the source binding and decide the next step:
|
|
35
|
+
|
|
36
|
+
| Condition | Action |
|
|
37
|
+
|-----------|--------|
|
|
38
|
+
| **Fresh Review** (no prior receipt, OR source/requirements/gates changed) | Launch both code-reviewer and architect lanes in parallel on clean contexts. Treat prior artifacts as context only; do not reuse evidence. |
|
|
39
|
+
| **Resuming Missing Lane** (one lane has evidence, other missing, source/requirements/gates unchanged) | Re-launch the missing lane only. Carry prior evidence from the complete lane. |
|
|
40
|
+
| **Resuming Missing Validation** (both lanes returned, validation incomplete, source/requirements/gates unchanged) | Collect missing validation inputs/results. Reuse lane evidence. |
|
|
41
|
+
| **Repair Re-review** (implementation changed source after prior review, authorized repair owner confirmed) | Re-launch both lanes on the revised scope. Include prior findings as context; preserve dispositions unless new evidence justifies reopening. Carry repair authorization through the review. |
|
|
42
|
+
| **Complete Evidence** (all lanes returned, all validation complete, source/requirements/gates unchanged) | Return the existing scoped result and stop. No re-review needed. |
|
|
43
|
+
|
|
44
|
+
**Binding Rules**: A source-bound receipt tracks scope identity (commit, uncommitted changes, file hashes), requirements, configured gates, and lane results. Missing or unverifiable bindings (stale/unbound artifacts, changed source not signed by repair authorization) prevent evidence reuse. Invalidation triggers a fresh review; partial evidence loss triggers lane resumption, not full restart.
|
|
45
|
+
|
|
32
46
|
## Execution
|
|
33
47
|
|
|
34
48
|
1. Identify changed files and review boundaries; do not silently widen the scope.
|
|
@@ -116,6 +130,76 @@ RECOMMENDATION: COMMENT
|
|
|
116
130
|
Replace the illustrative counts and verdict with observed values. Include scope,
|
|
117
131
|
lane evidence/artifact references, unresolved risks, and validation gaps.
|
|
118
132
|
|
|
133
|
+
## Source-Bound Review Receipt
|
|
134
|
+
|
|
135
|
+
When a review completes or a user requests continuation, record a source-bound receipt that binds the review result to its input context. This receipt is the basis for deciding whether to reuse evidence or perform a fresh review.
|
|
136
|
+
|
|
137
|
+
**Receipt Structure**:
|
|
138
|
+
|
|
139
|
+
```text
|
|
140
|
+
SOURCE-BOUND REVIEW RECEIPT
|
|
141
|
+
|
|
142
|
+
REVIEW SCOPE
|
|
143
|
+
Files Reviewed: <count>
|
|
144
|
+
Changed Lines: <+/->
|
|
145
|
+
Boundaries: <scope description>
|
|
146
|
+
|
|
147
|
+
SOURCE IDENTITY
|
|
148
|
+
Base Commit: <commit hash>
|
|
149
|
+
Uncommitted Changes: <yes|no> [file hashes if present]
|
|
150
|
+
Source Binding: <valid|stale|unbound>
|
|
151
|
+
|
|
152
|
+
REQUIREMENTS & GATES
|
|
153
|
+
Specification: [reference or summary]
|
|
154
|
+
Acceptance Criteria: [reference or summary]
|
|
155
|
+
Test/CI Evidence: [references]
|
|
156
|
+
Configured Quality Gates: [list of blocking/advisory gates]
|
|
157
|
+
|
|
158
|
+
LANE RESULTS
|
|
159
|
+
code-reviewer:
|
|
160
|
+
Recommendation: APPROVE | REQUEST CHANGES | COMMENT
|
|
161
|
+
Finding Severity: CRITICAL (N) | HIGH (N) | MEDIUM (N) | LOW (N)
|
|
162
|
+
Artifact: [reference or hash]
|
|
163
|
+
Status: complete | unavailable
|
|
164
|
+
|
|
165
|
+
architect:
|
|
166
|
+
Status: CLEAR | WATCH | BLOCK
|
|
167
|
+
Finding Severity: CRITICAL (N) | HIGH (N) | MEDIUM (N) | LOW (N)
|
|
168
|
+
Artifact: [reference or hash]
|
|
169
|
+
Status: complete | unavailable
|
|
170
|
+
|
|
171
|
+
[custom gates]:
|
|
172
|
+
Gate Name: <skill name>
|
|
173
|
+
Mode: blocking | advisory
|
|
174
|
+
Verdict: pass | fail | unavailable
|
|
175
|
+
Artifact: [reference or hash]
|
|
176
|
+
Status: complete | unavailable
|
|
177
|
+
|
|
178
|
+
VALIDATION
|
|
179
|
+
Inputs Recorded: [list of validation requirements met]
|
|
180
|
+
Validation Results: [status of each requirement]
|
|
181
|
+
Validation Status: complete | incomplete
|
|
182
|
+
|
|
183
|
+
FINDINGS & GAPS
|
|
184
|
+
Unresolved High/Critical: [count and list]
|
|
185
|
+
Evidence Gaps: [any missing evidence from required lanes or gates]
|
|
186
|
+
Blockers: [any blocking conditions preventing approval]
|
|
187
|
+
|
|
188
|
+
FINAL RECOMMENDATION
|
|
189
|
+
Recommendation: APPROVE | REQUEST CHANGES | COMMENT
|
|
190
|
+
Merge-Ready: yes | no
|
|
191
|
+
Binding Status: bound | unbound
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**Invalidation Triggers**: The receipt becomes invalid if:
|
|
195
|
+
- Base commit or uncommitted changes differ from the initial review (source changed)
|
|
196
|
+
- Requirements or acceptance criteria are updated
|
|
197
|
+
- Configured quality gates change (gates added, removed, or mode changed)
|
|
198
|
+
- Validation inputs/results are unavailable or stale
|
|
199
|
+
- Required lanes (code-reviewer or architect) are missing or unavailable
|
|
200
|
+
|
|
201
|
+
**Reuse Rules**: Evidence may be reused across continuation requests only if all binding conditions match and the receipt status is `bound`. A `stale` or `unbound` receipt requires fresh review. Missing or unverifiable bindings never establish approval.
|
|
202
|
+
|
|
119
203
|
## Exit condition
|
|
120
204
|
|
|
121
205
|
Stop when the scoped diff has two independent lane results and a deterministic final
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdir, mkdtemp, readFile, rm, utimes, writeFile } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { afterEach, describe, it } from "node:test";
|
|
6
|
+
import { dispatchCodexNativeHook } from "../codex-native-hook.js";
|
|
7
|
+
import { initTeamState, writeWorkerIdentity } from "../../team/state.js";
|
|
8
|
+
|
|
9
|
+
const roots: string[] = [];
|
|
10
|
+
afterEach(async () => {
|
|
11
|
+
await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
async function workspace(): Promise<string> {
|
|
15
|
+
const cwd = await mkdtemp(join(tmpdir(), "omx-issue-4086-stop-hook-lock-"));
|
|
16
|
+
roots.push(cwd);
|
|
17
|
+
return cwd;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function staleLock(lockDir: string, token?: string): Promise<void> {
|
|
21
|
+
await mkdir(lockDir, { recursive: true });
|
|
22
|
+
if (token !== undefined) await writeFile(join(lockDir, 'owner'), token);
|
|
23
|
+
await writeFile(join(lockDir, 'lease'), 'abandoned');
|
|
24
|
+
const old = new Date(Date.now() - 10 * 60_000);
|
|
25
|
+
await utimes(join(lockDir, 'lease'), old, old);
|
|
26
|
+
await utimes(lockDir, old, old);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe('issue #4086: stop hook with stale team lock', () => {
|
|
30
|
+
it('stop hook with stale team lock should return continue:false (terminal)', async () => {
|
|
31
|
+
const cwd = await workspace();
|
|
32
|
+
const team = 'audit';
|
|
33
|
+
const workerName = 'executor-1';
|
|
34
|
+
|
|
35
|
+
// Initialize team state
|
|
36
|
+
await initTeamState(team, 'stop hook lock test', 'executor', 1, cwd);
|
|
37
|
+
|
|
38
|
+
// Write worker identity to make this appear as a team worker
|
|
39
|
+
await writeWorkerIdentity(team, workerName, {
|
|
40
|
+
name: workerName,
|
|
41
|
+
index: 1,
|
|
42
|
+
role: 'executor',
|
|
43
|
+
assigned_tasks: [],
|
|
44
|
+
}, cwd);
|
|
45
|
+
|
|
46
|
+
// Create a stale team membership lock
|
|
47
|
+
const lockDir = join(cwd, '.omx/state/.team-locks', `${team}.membership`);
|
|
48
|
+
const staleLockToken = '99999999.0.dead';
|
|
49
|
+
await staleLock(lockDir, staleLockToken);
|
|
50
|
+
|
|
51
|
+
// Set up environment to identify as a team worker
|
|
52
|
+
const originalEnv = process.env;
|
|
53
|
+
process.env.OMX_TEAM_WORKER_NAME = workerName;
|
|
54
|
+
process.env.OMX_TEAM_WORKER_TEAM_NAME = team;
|
|
55
|
+
process.env.OMX_TEAM_WORKER_TEAM_LEADER = 'leader-1';
|
|
56
|
+
process.env.OMX_TEAM_WORKER_INTERNAL_CANONICAL = 'true';
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
// Invoke Stop hook while team has a stale lock
|
|
60
|
+
const result = await dispatchCodexNativeHook(
|
|
61
|
+
{
|
|
62
|
+
hook_event_name: "Stop",
|
|
63
|
+
cwd,
|
|
64
|
+
session_id: "test-stop-hook",
|
|
65
|
+
stop_hook_active: false,
|
|
66
|
+
},
|
|
67
|
+
{ cwd },
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// Exact assertions for terminal output: continue:false, no decision, no reason
|
|
71
|
+
assert.ok(result.outputJson, 'outputJson must be present');
|
|
72
|
+
const outputJson = result.outputJson as Record<string, unknown>;
|
|
73
|
+
|
|
74
|
+
assert.strictEqual(
|
|
75
|
+
outputJson.continue,
|
|
76
|
+
false,
|
|
77
|
+
'continue must be false to make Stop terminal'
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
assert.strictEqual(
|
|
81
|
+
outputJson.decision,
|
|
82
|
+
undefined,
|
|
83
|
+
'decision must be undefined for terminal output (no decision property)'
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
assert.strictEqual(
|
|
87
|
+
outputJson.reason,
|
|
88
|
+
undefined,
|
|
89
|
+
'reason must be undefined so model never receives recovery instructions'
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
assert.strictEqual(
|
|
93
|
+
outputJson.stopReason,
|
|
94
|
+
'team_lock_recovery_required',
|
|
95
|
+
'stopReason must identify the lock recovery issue'
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
// Recovery steps must be only in systemMessage, never exposed to model as decision/reason
|
|
99
|
+
const systemMessage = String(outputJson.systemMessage || '');
|
|
100
|
+
assert.ok(
|
|
101
|
+
systemMessage.length > 0,
|
|
102
|
+
'systemMessage must contain recovery instructions'
|
|
103
|
+
);
|
|
104
|
+
assert.ok(
|
|
105
|
+
systemMessage.includes('stale lock') || systemMessage.includes(lockDir),
|
|
106
|
+
'systemMessage must describe the stale lock location'
|
|
107
|
+
);
|
|
108
|
+
} finally {
|
|
109
|
+
process.env = originalEnv;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('two consecutive Stop invocations are both terminal with lock preserved', async () => {
|
|
114
|
+
const cwd = await workspace();
|
|
115
|
+
const team = 'audit';
|
|
116
|
+
const workerName = 'executor-1';
|
|
117
|
+
|
|
118
|
+
// Initialize team state
|
|
119
|
+
await initTeamState(team, 'lock preservation test', 'executor', 1, cwd);
|
|
120
|
+
|
|
121
|
+
const lockDir = join(cwd, '.omx/state/.team-locks', `${team}.membership`);
|
|
122
|
+
const staleLockToken = '99999999.0.dead';
|
|
123
|
+
await staleLock(lockDir, staleLockToken);
|
|
124
|
+
|
|
125
|
+
// Write worker identity
|
|
126
|
+
await writeWorkerIdentity(team, workerName, {
|
|
127
|
+
name: workerName,
|
|
128
|
+
index: 1,
|
|
129
|
+
role: 'executor',
|
|
130
|
+
assigned_tasks: [],
|
|
131
|
+
}, cwd);
|
|
132
|
+
|
|
133
|
+
const originalEnv = process.env;
|
|
134
|
+
process.env.OMX_TEAM_WORKER_NAME = workerName;
|
|
135
|
+
process.env.OMX_TEAM_WORKER_TEAM_NAME = team;
|
|
136
|
+
process.env.OMX_TEAM_WORKER_TEAM_LEADER = 'leader-1';
|
|
137
|
+
process.env.OMX_TEAM_WORKER_INTERNAL_CANONICAL = 'true';
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
// First Stop invocation
|
|
141
|
+
const result1 = await dispatchCodexNativeHook(
|
|
142
|
+
{
|
|
143
|
+
hook_event_name: "Stop",
|
|
144
|
+
cwd,
|
|
145
|
+
session_id: "test-stop-hook-1",
|
|
146
|
+
stop_hook_active: false,
|
|
147
|
+
},
|
|
148
|
+
{ cwd },
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
assert.ok(result1.outputJson, 'First Stop result must have outputJson');
|
|
152
|
+
const output1 = result1.outputJson as Record<string, unknown>;
|
|
153
|
+
assert.strictEqual(
|
|
154
|
+
output1.continue,
|
|
155
|
+
false,
|
|
156
|
+
'First Stop must have continue:false (terminal)'
|
|
157
|
+
);
|
|
158
|
+
assert.strictEqual(
|
|
159
|
+
output1.stopReason,
|
|
160
|
+
'team_lock_recovery_required',
|
|
161
|
+
'First Stop must identify lock recovery reason'
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// Verify lock state is preserved after first Stop
|
|
165
|
+
let owner = await readFile(join(lockDir, 'owner'), 'utf8');
|
|
166
|
+
let lease = await readFile(join(lockDir, 'lease'), 'utf8');
|
|
167
|
+
assert.strictEqual(owner, staleLockToken, 'Lock owner must be preserved after first Stop');
|
|
168
|
+
assert.strictEqual(lease, 'abandoned', 'Lock lease must be preserved after first Stop');
|
|
169
|
+
|
|
170
|
+
// Second Stop invocation (simulating operator retrying after fixing)
|
|
171
|
+
const result2 = await dispatchCodexNativeHook(
|
|
172
|
+
{
|
|
173
|
+
hook_event_name: "Stop",
|
|
174
|
+
cwd,
|
|
175
|
+
session_id: "test-stop-hook-2",
|
|
176
|
+
stop_hook_active: false,
|
|
177
|
+
},
|
|
178
|
+
{ cwd },
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
assert.ok(result2.outputJson, 'Second Stop result must have outputJson');
|
|
182
|
+
const output2 = result2.outputJson as Record<string, unknown>;
|
|
183
|
+
assert.strictEqual(
|
|
184
|
+
output2.continue,
|
|
185
|
+
false,
|
|
186
|
+
'Second Stop must have continue:false (terminal)'
|
|
187
|
+
);
|
|
188
|
+
assert.strictEqual(
|
|
189
|
+
output2.stopReason,
|
|
190
|
+
'team_lock_recovery_required',
|
|
191
|
+
'Second Stop must identify lock recovery reason'
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
// Verify lock state is still preserved
|
|
195
|
+
owner = await readFile(join(lockDir, 'owner'), 'utf8');
|
|
196
|
+
lease = await readFile(join(lockDir, 'lease'), 'utf8');
|
|
197
|
+
assert.strictEqual(owner, staleLockToken, 'Lock owner must be preserved after second Stop');
|
|
198
|
+
assert.strictEqual(lease, 'abandoned', 'Lock lease must be preserved after second Stop');
|
|
199
|
+
} finally {
|
|
200
|
+
process.env = originalEnv;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
@@ -2933,9 +2933,18 @@ async function resolveTeamStateDirForWorkerContext(
|
|
|
2933
2933
|
cwd: string,
|
|
2934
2934
|
workerContext: { teamName: string; workerName: string },
|
|
2935
2935
|
): Promise<string | null> {
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2936
|
+
try {
|
|
2937
|
+
const resolved = await resolveWorkerTeamStateRootPath(cwd, workerContext, process.env);
|
|
2938
|
+
if (resolved) return resolved;
|
|
2939
|
+
return null;
|
|
2940
|
+
} catch (error) {
|
|
2941
|
+
// Re-throw team lock recovery errors so they're handled by the Stop hook error handler
|
|
2942
|
+
if (error instanceof Error && error.message.includes('team_lock_recovery_required')) {
|
|
2943
|
+
throw error;
|
|
2944
|
+
}
|
|
2945
|
+
// Suppress other errors (state root resolution failures)
|
|
2946
|
+
return null;
|
|
2947
|
+
}
|
|
2939
2948
|
}
|
|
2940
2949
|
|
|
2941
2950
|
async function isConfirmedTeamWorkerPromptSubmitPane(cwd: string): Promise<boolean> {
|
|
@@ -22891,41 +22900,51 @@ export async function dispatchCodexNativeHook(
|
|
|
22891
22900
|
}
|
|
22892
22901
|
outputJson ??= buildNativePostToolUseOutput(payload);
|
|
22893
22902
|
} else if (hookEventName === "Stop") {
|
|
22894
|
-
|
|
22895
|
-
|
|
22896
|
-
|
|
22897
|
-
|
|
22898
|
-
|
|
22899
|
-
|
|
22900
|
-
|
|
22901
|
-
|
|
22902
|
-
|
|
22903
|
-
|
|
22904
|
-
|
|
22905
|
-
|
|
22906
|
-
|
|
22907
|
-
|
|
22908
|
-
|
|
22909
|
-
|
|
22910
|
-
|
|
22911
|
-
|
|
22912
|
-
|
|
22913
|
-
|
|
22914
|
-
|
|
22903
|
+
try {
|
|
22904
|
+
if (declaredTeamWorkerStopOnly) {
|
|
22905
|
+
outputJson = await buildStopHookOutput(payload, cwd, stateDir, { teamWorkerOnly: true });
|
|
22906
|
+
} else if (allowImplicitSessionSideEffects) {
|
|
22907
|
+
const stopOutput = await buildStopHookOutput(payload, cwd, stateDir, {
|
|
22908
|
+
canonicalSessionId: canonicalSessionId || undefined,
|
|
22909
|
+
skipRalphStopBlock: isSubagentStop,
|
|
22910
|
+
skipAutoNudge: isSubagentStop,
|
|
22911
|
+
sessionScopedOnly: !allowGlobalSideEffects,
|
|
22912
|
+
});
|
|
22913
|
+
// Record bounded completion evidence for native subagent Stop events
|
|
22914
|
+
if (isSubagentStop) {
|
|
22915
|
+
const threadId = readPayloadThreadId(payload);
|
|
22916
|
+
if (canonicalSessionId?.trim() && threadId?.trim()) {
|
|
22917
|
+
await recordSubagentTurnForSession(cwd, {
|
|
22918
|
+
sessionId: canonicalSessionId.trim(),
|
|
22919
|
+
threadId: threadId.trim(),
|
|
22920
|
+
turnId: readPayloadTurnId(payload) || undefined,
|
|
22921
|
+
completed: true,
|
|
22922
|
+
completionSource: 'native_stop_event',
|
|
22923
|
+
timestamp: new Date().toISOString(),
|
|
22924
|
+
}).catch(() => {});
|
|
22925
|
+
}
|
|
22915
22926
|
}
|
|
22927
|
+
outputJson = stopOutput ?? (
|
|
22928
|
+
allowGlobalSideEffects
|
|
22929
|
+
? await buildCompletedGoalCleanupStopOutput(payload, cwd)
|
|
22930
|
+
: null
|
|
22931
|
+
);
|
|
22932
|
+
} else {
|
|
22933
|
+
// Authorization failure never grants continuation authority. It also must not
|
|
22934
|
+
// inject a repair request: the same provenance failure can deny every tool the
|
|
22935
|
+
// model would need to repair it, turning a Stop denial into an unbounded loop.
|
|
22936
|
+
// Returning no hook output permits termination while preserving the denial of
|
|
22937
|
+
// all session-scoped and global side effects above.
|
|
22938
|
+
outputJson = null;
|
|
22939
|
+
}
|
|
22940
|
+
} catch (err) {
|
|
22941
|
+
// Handle errors from Stop hook processing, particularly manual recovery errors
|
|
22942
|
+
// like team_lock_recovery_required that should not result in continuation
|
|
22943
|
+
if (isTeamLockRecoveryRequiredError(err)) {
|
|
22944
|
+
outputJson = buildTeamLockRecoveryStopOutput(err);
|
|
22945
|
+
} else {
|
|
22946
|
+
throw err;
|
|
22916
22947
|
}
|
|
22917
|
-
outputJson = stopOutput ?? (
|
|
22918
|
-
allowGlobalSideEffects
|
|
22919
|
-
? await buildCompletedGoalCleanupStopOutput(payload, cwd)
|
|
22920
|
-
: null
|
|
22921
|
-
);
|
|
22922
|
-
} else {
|
|
22923
|
-
// Authorization failure never grants continuation authority. It also must not
|
|
22924
|
-
// inject a repair request: the same provenance failure can deny every tool the
|
|
22925
|
-
// model would need to repair it, turning a Stop denial into an unbounded loop.
|
|
22926
|
-
// Returning no hook output permits termination while preserving the denial of
|
|
22927
|
-
// all session-scoped and global side effects above.
|
|
22928
|
-
outputJson = null;
|
|
22929
22948
|
}
|
|
22930
22949
|
}
|
|
22931
22950
|
|
|
@@ -23194,7 +23213,36 @@ function isPostCancelCommitTestTrigger(payload: CodexHookPayload, output: Record
|
|
|
23194
23213
|
}
|
|
23195
23214
|
|
|
23196
23215
|
|
|
23216
|
+
function isTeamLockRecoveryRequiredError(error: unknown): boolean {
|
|
23217
|
+
if (!(error instanceof Error)) return false;
|
|
23218
|
+
return error.message.includes('team_lock_recovery_required');
|
|
23219
|
+
}
|
|
23220
|
+
|
|
23221
|
+
function extractTeamLockDirFromError(error: unknown): string | null {
|
|
23222
|
+
if (!(error instanceof Error)) return null;
|
|
23223
|
+
const match = error.message.match(/team_lock_recovery_required:([^:]+):/);
|
|
23224
|
+
return match ? match[1] : null;
|
|
23225
|
+
}
|
|
23226
|
+
|
|
23227
|
+
function buildTeamLockRecoveryStopOutput(error: unknown): Record<string, unknown> {
|
|
23228
|
+
const lockDir = extractTeamLockDirFromError(error);
|
|
23229
|
+
const systemMessage = lockDir
|
|
23230
|
+
? `OMX Stop terminal: stale team lock at ${lockDir} requires manual recovery. ` +
|
|
23231
|
+
`Confirm no other operations are accessing the lock, then remove: rm -rf "${lockDir}"`
|
|
23232
|
+
: `OMX Stop terminal: stale team lock requires manual recovery.`;
|
|
23233
|
+
return {
|
|
23234
|
+
continue: false,
|
|
23235
|
+
stopReason: "team_lock_recovery_required",
|
|
23236
|
+
systemMessage,
|
|
23237
|
+
};
|
|
23238
|
+
}
|
|
23239
|
+
|
|
23197
23240
|
function buildStopDispatchFailureOutput(error: unknown): Record<string, unknown> {
|
|
23241
|
+
// Check if this is a manual recovery error that should be treated as terminal
|
|
23242
|
+
if (isTeamLockRecoveryRequiredError(error)) {
|
|
23243
|
+
return buildTeamLockRecoveryStopOutput(error);
|
|
23244
|
+
}
|
|
23245
|
+
|
|
23198
23246
|
const detail = error instanceof Error ? error.message : String(error);
|
|
23199
23247
|
const reason =
|
|
23200
23248
|
"OMX native Stop hook failed before normal continuation handling. Continue once more, preserve runtime state, inspect the hook logs, and retry with a valid Stop JSON response.";
|