polygram 0.32.0 → 0.33.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.
@@ -1,24 +1,15 @@
1
1
  'use strict';
2
2
 
3
- function codexError(message, code) {
4
- const error = new Error(message);
5
- error.code = code;
6
- return error;
7
- }
8
-
9
- function requiredString(value, label) {
10
- if (
11
- typeof value !== 'string'
12
- || value.length === 0
13
- || value.length > 512
14
- ) {
15
- throw codexError(
16
- `Codex ${label} must be a non-empty bounded string`,
17
- 'CODEX_PERSISTENCE_INPUT_INVALID',
18
- );
19
- }
20
- return value;
21
- }
3
+ const {
4
+ settleCodexFailedGeneration,
5
+ } = require('./codex-failed-generation');
6
+ const {
7
+ codexError,
8
+ requiredString,
9
+ } = require('./codex-input');
10
+ const {
11
+ CODEX_APP_SERVER_NAMESPACE,
12
+ } = require('./sessions');
22
13
 
23
14
  function listRecoveryAttempts(rawDb) {
24
15
  const replayableAttemptIds = rawDb.prepare(`
@@ -28,30 +19,16 @@ function listRecoveryAttempts(rawDb) {
28
19
  AND recovery_state = 'prepared'
29
20
  ORDER BY created_ts, attempt_id
30
21
  `).all().map((row) => row.attempt_id);
31
- const unresolved = rawDb.prepare(`
32
- SELECT attempt.attempt_id,
33
- EXISTS (
34
- SELECT 1
35
- FROM codex_reboot_releases release
36
- WHERE release.stable_host_id = generation.stable_host_id
37
- AND release.incident_boot_session_id = generation.boot_session_id
38
- ) AS reboot_released
22
+ const unresolvedAttemptIds = rawDb.prepare(`
23
+ SELECT attempt.attempt_id
39
24
  FROM codex_turn_attempts attempt
40
- JOIN codex_generations generation
41
- ON generation.generation_id = attempt.generation_id
42
25
  WHERE attempt.delivery_state != 'prepared'
43
26
  AND attempt.recovery_state NOT IN ('settled', 'cancelled')
44
27
  ORDER BY attempt.created_ts, attempt.attempt_id
45
- `).all();
28
+ `).all().map((row) => row.attempt_id);
46
29
  return {
47
30
  replayableAttemptIds,
48
- unresolvedAttemptIds: unresolved.map((row) => row.attempt_id),
49
- blockingAttemptIds: unresolved
50
- .filter((row) => !row.reboot_released)
51
- .map((row) => row.attempt_id),
52
- releasedAttemptIds: unresolved
53
- .filter((row) => row.reboot_released)
54
- .map((row) => row.attempt_id),
31
+ unresolvedAttemptIds,
55
32
  };
56
33
  }
57
34
 
@@ -59,9 +36,6 @@ function publicRecoveryAttempts(attempts) {
59
36
  return {
60
37
  replayableAttemptIds: attempts.replayableAttemptIds,
61
38
  unresolvedAttemptIds: attempts.unresolvedAttemptIds,
62
- ...(attempts.releasedAttemptIds.length > 0
63
- ? { releasedAttemptIds: attempts.releasedAttemptIds }
64
- : {}),
65
39
  };
66
40
  }
67
41
 
@@ -150,9 +124,23 @@ function listUnresolvedCodexAttempts(rawDb, input = {}) {
150
124
  ) AS telegram_message_id,
151
125
  message.user_id AS owner_user_id,
152
126
  message.user AS owner_user,
153
- lease.status AS containment_status,
154
- lease.quarantine_reason
127
+ CASE
128
+ WHEN unresolved.generation_state = 'containment-failed'
129
+ AND EXISTS (
130
+ SELECT 1
131
+ FROM codex_attempt_checkpoints checkpoint
132
+ WHERE checkpoint.generation_id = unresolved.generation_id
133
+ AND checkpoint.kind = 'containment-cleanup-completed'
134
+ )
135
+ THEN 'failed-settled'
136
+ WHEN unresolved.generation_state = 'containment-failed'
137
+ THEN 'cleanup-unverified'
138
+ ELSE unresolved.generation_state
139
+ END AS containment_status,
140
+ generation.containment_reason AS quarantine_reason
155
141
  FROM unresolved
142
+ JOIN codex_generations generation
143
+ ON generation.generation_id = unresolved.generation_id
156
144
  LEFT JOIN ranked_locations location
157
145
  ON location.attempt_id = unresolved.attempt_id
158
146
  AND location.location_rank = 1
@@ -164,8 +152,6 @@ function listUnresolvedCodexAttempts(rawDb, input = {}) {
164
152
  location.telegram_message_id,
165
153
  unresolved.telegram_source_message_id
166
154
  )
167
- LEFT JOIN codex_daemon_lease lease
168
- ON lease.singleton = 1
169
155
  ORDER BY unresolved.ambiguous_ts,
170
156
  unresolved.attempt_id
171
157
  `).all(sessionKey, sessionKey);
@@ -272,7 +258,7 @@ function reconcileCodexAttempt(rawDb, input) {
272
258
  })();
273
259
  }
274
260
 
275
- function reconstructCodexRecovery(rawDb, input) {
261
+ function reconstructCodexRecoveryState(rawDb, input) {
276
262
  let stableHostId;
277
263
  let bootSessionId;
278
264
  try {
@@ -280,7 +266,7 @@ function reconstructCodexRecovery(rawDb, input) {
280
266
  bootSessionId = requiredString(input?.boot_session_id, 'boot-session identity');
281
267
  } catch {
282
268
  return {
283
- status: 'quarantined',
269
+ status: 'integrity-blocked',
284
270
  reason: 'current-identity-invalid',
285
271
  containmentReleased: false,
286
272
  replayableAttemptIds: [],
@@ -295,182 +281,103 @@ function reconstructCodexRecovery(rawDb, input) {
295
281
  );
296
282
  }
297
283
 
298
- return rawDb.transaction(() => {
299
- const attempts = listRecoveryAttempts(rawDb);
300
- const identity = rawDb.prepare(`
284
+ const attempts = listRecoveryAttempts(rawDb);
285
+ const identity = rawDb.prepare(`
301
286
  SELECT stable_host_id, last_boot_session_id
302
287
  FROM codex_runtime_identity
303
288
  WHERE singleton = 1
304
- `).get();
305
- const lease = rawDb.prepare(`
289
+ `).get();
290
+ const lease = rawDb.prepare(`
306
291
  SELECT * FROM codex_daemon_lease WHERE singleton = 1
307
- `).get();
308
- const generations = rawDb.prepare(`
292
+ `).get();
293
+ const generations = rawDb.prepare(`
309
294
  SELECT COUNT(*) AS count FROM codex_generations
310
- `).get().count;
311
- const hasOperationalState = Boolean(
312
- generations
313
- || lease
314
- || attempts.replayableAttemptIds.length
315
- || attempts.unresolvedAttemptIds.length
316
- );
295
+ `).get().count;
296
+ const hasOperationalState = Boolean(generations || lease);
317
297
 
318
- if (!identity) {
319
- if (!hasOperationalState) {
320
- rawDb.prepare(`
298
+ if (!identity) {
299
+ if (!hasOperationalState) {
300
+ rawDb.prepare(`
321
301
  INSERT INTO codex_runtime_identity (
322
302
  singleton, stable_host_id, last_boot_session_id,
323
303
  established_ts, updated_ts
324
304
  ) VALUES (1, ?, ?, ?, ?)
325
- `).run(stableHostId, bootSessionId, now, now);
326
- return {
327
- status: 'clear',
328
- reason: null,
329
- containmentReleased: false,
330
- ...publicRecoveryAttempts(attempts),
331
- };
332
- }
333
- rawDb.prepare(`
334
- INSERT INTO codex_daemon_lease (
335
- singleton, generation_id, stable_host_id, boot_session_id,
336
- status, quarantine_reason, updated_ts
337
- ) VALUES (1, NULL, ?, ?, 'quarantined',
338
- 'persisted-identity-missing', ?)
339
- ON CONFLICT(singleton) DO UPDATE SET
340
- status = 'quarantined',
341
- quarantine_reason = 'persisted-identity-missing',
342
- updated_ts = excluded.updated_ts
343
- `).run(stableHostId, bootSessionId, now);
305
+ `).run(stableHostId, bootSessionId, now, now);
344
306
  return {
345
- status: 'quarantined',
346
- reason: 'persisted-identity-missing',
307
+ status: 'clear',
308
+ reason: null,
347
309
  containmentReleased: false,
348
310
  ...publicRecoveryAttempts(attempts),
349
311
  };
350
312
  }
313
+ return {
314
+ status: 'integrity-blocked',
315
+ reason: 'persisted-identity-missing',
316
+ containmentReleased: false,
317
+ ...publicRecoveryAttempts(attempts),
318
+ };
319
+ }
320
+
321
+ if (
322
+ typeof identity.stable_host_id !== 'string'
323
+ || identity.stable_host_id.length === 0
324
+ || typeof identity.last_boot_session_id !== 'string'
325
+ || identity.last_boot_session_id.length === 0
326
+ ) {
327
+ return {
328
+ status: 'integrity-blocked',
329
+ reason: 'persisted-identity-corrupt',
330
+ containmentReleased: false,
331
+ ...publicRecoveryAttempts(attempts),
332
+ };
333
+ }
334
+ if (identity.stable_host_id !== stableHostId) {
335
+ return {
336
+ status: 'integrity-blocked',
337
+ reason: 'stable-host-mismatch',
338
+ containmentReleased: false,
339
+ ...publicRecoveryAttempts(attempts),
340
+ };
341
+ }
351
342
 
343
+ if (!lease || lease.status === 'clear') {
352
344
  if (
353
- typeof identity.stable_host_id !== 'string'
354
- || identity.stable_host_id.length === 0
355
- || typeof identity.last_boot_session_id !== 'string'
356
- || identity.last_boot_session_id.length === 0
345
+ lease
346
+ && (
347
+ lease.generation_id != null
348
+ || lease.stable_host_id !== stableHostId
349
+ )
357
350
  ) {
358
351
  return {
359
- status: 'quarantined',
360
- reason: 'persisted-identity-corrupt',
361
- containmentReleased: false,
362
- ...publicRecoveryAttempts(attempts),
363
- };
364
- }
365
- if (identity.stable_host_id !== stableHostId) {
366
- const incidentBoot = lease?.boot_session_id
367
- ?? identity.last_boot_session_id;
368
- rawDb.prepare(`
369
- INSERT INTO codex_daemon_lease (
370
- singleton, generation_id, stable_host_id, boot_session_id,
371
- status, quarantine_reason, updated_ts
372
- ) VALUES (1, NULL, ?, ?, 'quarantined', 'stable-host-mismatch', ?)
373
- ON CONFLICT(singleton) DO UPDATE SET
374
- status = 'quarantined',
375
- quarantine_reason = 'stable-host-mismatch',
376
- updated_ts = excluded.updated_ts
377
- `).run(identity.stable_host_id, incidentBoot, now);
378
- return {
379
- status: 'quarantined',
380
- reason: 'stable-host-mismatch',
352
+ status: 'integrity-blocked',
353
+ reason: 'persisted-lease-inconsistent',
381
354
  containmentReleased: false,
382
355
  ...publicRecoveryAttempts(attempts),
383
356
  };
384
357
  }
385
-
386
358
  if (identity.last_boot_session_id !== bootSessionId) {
387
- const containmentReleased = Boolean(
388
- lease?.status === 'quarantined'
389
- || lease?.status === 'active'
390
- || attempts.blockingAttemptIds.length
391
- );
392
359
  rawDb.prepare(`
393
- INSERT INTO codex_reboot_releases (
394
- stable_host_id, incident_boot_session_id,
395
- released_boot_session_id, released_ts
396
- ) VALUES (?, ?, ?, ?)
397
- ON CONFLICT(stable_host_id, incident_boot_session_id) DO NOTHING
360
+ UPDATE codex_runtime_identity
361
+ SET last_boot_session_id = ?, updated_ts = ?
362
+ WHERE singleton = 1
363
+ AND stable_host_id = ?
364
+ AND last_boot_session_id = ?
398
365
  `).run(
399
- stableHostId,
400
- identity.last_boot_session_id,
401
366
  bootSessionId,
402
367
  now,
368
+ stableHostId,
369
+ identity.last_boot_session_id,
403
370
  );
404
- rawDb.prepare(`
405
- UPDATE codex_runtime_identity
406
- SET last_boot_session_id = ?, updated_ts = ?
407
- WHERE singleton = 1
408
- `).run(bootSessionId, now);
409
371
  if (lease) {
410
372
  rawDb.prepare(`
411
373
  UPDATE codex_daemon_lease
412
- SET generation_id = NULL,
413
- stable_host_id = ?,
374
+ SET stable_host_id = ?,
414
375
  boot_session_id = ?,
415
- status = 'clear',
416
- quarantine_reason = NULL,
417
- updated_ts = ?,
418
- released_ts = ?
376
+ updated_ts = ?
419
377
  WHERE singleton = 1
420
- `).run(stableHostId, bootSessionId, now, now);
378
+ AND status = 'clear'
379
+ `).run(stableHostId, bootSessionId, now);
421
380
  }
422
- return {
423
- status: 'clear',
424
- reason: null,
425
- containmentReleased,
426
- ...publicRecoveryAttempts(listRecoveryAttempts(rawDb)),
427
- };
428
- }
429
-
430
- if (lease?.status === 'quarantined') {
431
- return {
432
- status: 'quarantined',
433
- reason: 'persisted-containment',
434
- containmentReleased: false,
435
- ...publicRecoveryAttempts(attempts),
436
- };
437
- }
438
- if (lease?.status === 'active') {
439
- return {
440
- status: 'quarantined',
441
- reason: 'persisted-active-generation',
442
- containmentReleased: false,
443
- ...publicRecoveryAttempts(attempts),
444
- };
445
- }
446
- if (attempts.blockingAttemptIds.length > 0) {
447
- const generation = rawDb.prepare(`
448
- SELECT generation_id
449
- FROM codex_turn_attempts
450
- WHERE attempt_id = ?
451
- `).get(attempts.blockingAttemptIds[0]);
452
- rawDb.prepare(`
453
- INSERT INTO codex_daemon_lease (
454
- singleton, generation_id, stable_host_id, boot_session_id,
455
- status, quarantine_reason, updated_ts
456
- ) VALUES (1, ?, ?, ?, 'quarantined', 'unresolved-codex-work', ?)
457
- ON CONFLICT(singleton) DO UPDATE SET
458
- generation_id = excluded.generation_id,
459
- status = 'quarantined',
460
- quarantine_reason = 'unresolved-codex-work',
461
- updated_ts = excluded.updated_ts
462
- `).run(
463
- generation?.generation_id ?? null,
464
- stableHostId,
465
- bootSessionId,
466
- now,
467
- );
468
- return {
469
- status: 'quarantined',
470
- reason: 'unresolved-codex-work',
471
- containmentReleased: false,
472
- ...publicRecoveryAttempts(attempts),
473
- };
474
381
  }
475
382
  return {
476
383
  status: 'clear',
@@ -478,13 +385,100 @@ function reconstructCodexRecovery(rawDb, input) {
478
385
  containmentReleased: false,
479
386
  ...publicRecoveryAttempts(attempts),
480
387
  };
481
- })();
388
+ }
389
+
390
+ if (!['active', 'quarantined'].includes(lease.status)) {
391
+ return {
392
+ status: 'integrity-blocked',
393
+ reason: 'persisted-lease-inconsistent',
394
+ containmentReleased: false,
395
+ ...publicRecoveryAttempts(attempts),
396
+ };
397
+ }
398
+ const generation = rawDb.prepare(`
399
+ SELECT * FROM codex_generations WHERE generation_id = ?
400
+ `).get(lease.generation_id);
401
+ if (
402
+ !generation
403
+ || generation.stable_host_id !== stableHostId
404
+ || generation.boot_session_id !== identity.last_boot_session_id
405
+ || lease.stable_host_id !== generation.stable_host_id
406
+ || lease.boot_session_id !== generation.boot_session_id
407
+ || !['active', 'containment-failed'].includes(generation.state)
408
+ ) {
409
+ return {
410
+ status: 'integrity-blocked',
411
+ reason: 'persisted-generation-inconsistent',
412
+ containmentReleased: false,
413
+ ...publicRecoveryAttempts(attempts),
414
+ };
415
+ }
416
+ if (
417
+ input?.startup_recovery?.exclusive_daemon_ownership !== true
418
+ || input?.startup_recovery?.supervisor_grace_elapsed !== true
419
+ ) {
420
+ return {
421
+ status: 'recovery-blocked',
422
+ reason: 'exclusive-startup-recovery-unproven',
423
+ containmentReleased: false,
424
+ ...publicRecoveryAttempts(attempts),
425
+ };
426
+ }
427
+
428
+ const provider = rawDb.prepare(`
429
+ SELECT provider, provider_session_id, app_server_session_id
430
+ FROM agent_runtime_sessions
431
+ WHERE session_key = ?
432
+ AND namespace = ?
433
+ `).get(generation.session_key, CODEX_APP_SERVER_NAMESPACE);
434
+ const providerSessionId = generation.thread_id ?? null;
435
+ const appServerSessionId = generation.app_server_session_id ?? null;
436
+ if (
437
+ provider
438
+ && (
439
+ provider.provider !== 'codex'
440
+ || provider.provider_session_id !== providerSessionId
441
+ || provider.app_server_session_id !== appServerSessionId
442
+ )
443
+ ) {
444
+ return {
445
+ status: 'integrity-blocked',
446
+ reason: 'persisted-generation-inconsistent',
447
+ containmentReleased: false,
448
+ ...publicRecoveryAttempts(attempts),
449
+ };
450
+ }
451
+ settleCodexFailedGeneration(rawDb, {
452
+ generation_id: generation.generation_id,
453
+ session_key: generation.session_key,
454
+ stable_host_id: stableHostId,
455
+ incident_boot_session_id: generation.boot_session_id,
456
+ current_boot_session_id: bootSessionId,
457
+ provider_session_id: providerSessionId,
458
+ app_server_session_id: appServerSessionId,
459
+ reason: generation.containment_reason
460
+ ?? lease.quarantine_reason
461
+ ?? 'startup-recovered-generation',
462
+ source: 'exclusive-takeover-grace',
463
+ allow_missing_generation: false,
464
+ ts: now,
465
+ });
466
+ return {
467
+ status: 'clear',
468
+ reason: null,
469
+ containmentReleased: true,
470
+ ...publicRecoveryAttempts(listRecoveryAttempts(rawDb)),
471
+ };
472
+ }
473
+
474
+ function reconstructCodexRecovery(rawDb, input) {
475
+ return rawDb.transaction(
476
+ () => reconstructCodexRecoveryState(rawDb, input),
477
+ )();
482
478
  }
483
479
 
484
480
  module.exports = {
485
481
  listUnresolvedCodexAttempts,
486
482
  reconcileCodexAttempt,
487
483
  reconstructCodexRecovery,
488
- codexError,
489
- requiredString,
490
484
  };
@@ -31,7 +31,7 @@ function pruneCodexOperationalData(rawDb, {
31
31
  DELETE FROM codex_turn_attempts
32
32
  WHERE (
33
33
  (
34
- recovery_state = 'settled'
34
+ recovery_state IN ('settled', 'cancelled')
35
35
  AND settled_ts IS NOT NULL
36
36
  AND settled_ts < @settledCutoff
37
37
  )
@@ -71,19 +71,6 @@ function pruneCodexOperationalData(rawDb, {
71
71
  )
72
72
  AND retry.state != 'retired'
73
73
  )
74
- AND NOT EXISTS (
75
- SELECT 1
76
- FROM codex_generations generation
77
- WHERE generation.generation_id = codex_turn_attempts.generation_id
78
- AND generation.state = 'containment-failed'
79
- AND NOT EXISTS (
80
- SELECT 1
81
- FROM codex_reboot_releases release
82
- WHERE release.stable_host_id = generation.stable_host_id
83
- AND release.incident_boot_session_id =
84
- generation.boot_session_id
85
- )
86
- )
87
74
  `).run({ settledCutoff, ambiguousCutoff });
88
75
 
89
76
  const generations = rawDb.prepare(`
@@ -105,10 +92,10 @@ function pruneCodexOperationalData(rawDb, {
105
92
  AND updated_ts < @ambiguousCutoff
106
93
  AND EXISTS (
107
94
  SELECT 1
108
- FROM codex_reboot_releases release
109
- WHERE release.stable_host_id = codex_generations.stable_host_id
110
- AND release.incident_boot_session_id =
111
- codex_generations.boot_session_id
95
+ FROM codex_attempt_checkpoints checkpoint
96
+ WHERE checkpoint.generation_id =
97
+ codex_generations.generation_id
98
+ AND checkpoint.kind = 'containment-cleanup-completed'
112
99
  )
113
100
  )
114
101
  )
package/lib/db.js CHANGED
@@ -12,12 +12,17 @@ const {
12
12
  pruneCodexOperationalData,
13
13
  } = require('./db/codex-retention');
14
14
  const {
15
- codexError,
16
15
  listUnresolvedCodexAttempts,
17
- requiredString: requiredCodexString,
18
16
  reconcileCodexAttempt,
19
17
  reconstructCodexRecovery,
20
18
  } = require('./db/codex-reconciliation');
19
+ const {
20
+ settleCodexFailedGeneration,
21
+ } = require('./db/codex-failed-generation');
22
+ const {
23
+ codexError,
24
+ requiredString: requiredCodexString,
25
+ } = require('./db/codex-input');
21
26
 
22
27
  // 0.8.0 Phase 1: bumped from 9 → 10. Adds migration
23
28
  // 010-tool-use-id.sql (pending_approvals.tool_use_id column for the
@@ -3157,7 +3162,7 @@ function wrap(db) {
3157
3162
  }
3158
3163
  if (reservation.original_generation_id === generationId) {
3159
3164
  throw codexError(
3160
- 'Codex retry requires a new generation after reboot release',
3165
+ 'Codex retry requires a distinct replacement generation',
3161
3166
  'CODEX_RETRY_NEW_GENERATION_REQUIRED',
3162
3167
  );
3163
3168
  }
@@ -3170,21 +3175,20 @@ function wrap(db) {
3170
3175
  'CODEX_RETRY_RESERVATION_MISMATCH',
3171
3176
  );
3172
3177
  }
3173
- const released = db.prepare(`
3178
+ const cleanupCommitted = db.prepare(`
3174
3179
  SELECT 1
3175
- FROM codex_reboot_releases
3176
- WHERE stable_host_id = ?
3177
- AND incident_boot_session_id = ?
3178
- AND released_boot_session_id = ?
3179
- `).get(
3180
- reservation.original_stable_host_id,
3181
- reservation.original_boot_session_id,
3182
- generation.boot_session_id,
3183
- );
3184
- if (!released) {
3180
+ FROM codex_attempt_checkpoints
3181
+ WHERE generation_id = ?
3182
+ AND kind = 'containment-cleanup-completed'
3183
+ LIMIT 1
3184
+ `).get(reservation.original_generation_id);
3185
+ if (
3186
+ reservation.original_generation_state !== 'containment-failed'
3187
+ || !cleanupCommitted
3188
+ ) {
3185
3189
  throw codexError(
3186
- 'Codex retry requires a durable reboot release',
3187
- 'CODEX_RETRY_REBOOT_RELEASE_REQUIRED',
3190
+ 'Codex retry requires committed failed-generation cleanup',
3191
+ 'CODEX_RETRY_CLEANUP_REQUIRED',
3188
3192
  );
3189
3193
  }
3190
3194
  const existing = db.prepare(`
@@ -3813,6 +3817,9 @@ function wrap(db) {
3813
3817
  },
3814
3818
  markCodexContainment,
3815
3819
  markCodexGenerationRetired,
3820
+ settleCodexFailedGeneration(input) {
3821
+ return settleCodexFailedGeneration(db, input);
3822
+ },
3816
3823
  reconstructCodexRecovery(input) {
3817
3824
  return reconstructCodexRecovery(db, input);
3818
3825
  },
@@ -4068,6 +4075,13 @@ function wrap(db) {
4068
4075
  WHERE chat_id = ? AND msg_id = ? AND direction = 'in'
4069
4076
  `).run(status, chat_id, msg_id);
4070
4077
  },
4078
+ setInboundHandlerStatusUnlessCodexTerminal({ chat_id, msg_id, status }) {
4079
+ return db.prepare(`
4080
+ UPDATE messages SET handler_status = ?
4081
+ WHERE chat_id = ? AND msg_id = ? AND direction = 'in'
4082
+ AND handler_status NOT IN ('codex-ambiguous', 'failed')
4083
+ `).run(status, chat_id, msg_id);
4084
+ },
4071
4085
 
4072
4086
  // 0.9.0: True when a specific inbound msg is still being processed
4073
4087
  // by the SDK turn loop (handler_status in dispatched/processing).
@@ -243,6 +243,7 @@ const CODEX_ERROR_CODES = {
243
243
  'CODEX_CONTAINMENT_QUARANTINED',
244
244
  'CODEX_BOOT_RECONSTRUCTION_FAILED',
245
245
  'CODEX_BOOT_RECONSTRUCTION_REQUIRED',
246
+ 'CODEX_RECOVERY_BLOCKED',
246
247
  'CODEX_PERSISTED_IDENTITY_MISSING',
247
248
  ], CODEX_ERROR_SHAPES.durability),
248
249
  ...mapCodes([
@@ -56,10 +56,10 @@ function buildCodexReconciliationView(attempt) {
56
56
  ) {
57
57
  throw new TypeError('Codex reconciliation view requires a located attempt');
58
58
  }
59
- const quarantined = attempt.containment_status === 'quarantined';
60
- const containment = quarantined
61
- ? 'This decision does not release containment quarantine; the prescribed host reboot is still required.'
62
- : 'This decision does not release containment quarantine.';
59
+ const containment = (
60
+ 'This decision records how to handle the old input; '
61
+ + 'it does not control runtime availability.'
62
+ );
63
63
  return {
64
64
  text: [
65
65
  '⚠️ Codex input needs reconciliation',
@@ -296,7 +296,10 @@ function createDispatcher({
296
296
  : isShuttingDown
297
297
  ? (isReplay ? 'replay-attempted' : 'replay-pending')
298
298
  : 'failed';
299
- dbWrite(() => db.setInboundHandlerStatus({
299
+ dbWrite(() => (
300
+ db.setInboundHandlerStatusUnlessCodexTerminal
301
+ ?? db.setInboundHandlerStatus
302
+ ).call(db, {
300
303
  chat_id: chatId, msg_id: msg.message_id, status,
301
304
  }), `set handler_status=${status}`);
302
305
  logEvent('handler-error', {