polygram 0.33.0 → 0.33.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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://anthropic.com/claude-code/plugin.schema.json",
3
3
  "name": "polygram",
4
- "version": "0.33.0",
4
+ "version": "0.33.2",
5
5
  "description": "Telegram integration for Claude Code that preserves the OpenClaw per-chat session model. Migration target for OpenClaw users. Multi-bot, multi-chat, per-topic isolation; SQLite transcripts; inline-keyboard approvals. Bundles /polygram:status|logs|pair-code|approvals admin commands plus history (transcript queries) and polygram-send (out-of-turn IPC sends with file-upload validation) skills.",
6
6
  "keywords": [
7
7
  "telegram",
@@ -263,13 +263,14 @@ function leaseCheck(db) {
263
263
  return check(
264
264
  'codex-lease',
265
265
  'fail',
266
- 'daemon-wide Codex quarantine is active; same-host reboot required before release',
266
+ 'daemon-wide Codex cleanup is unverified; restart the Polygram service after containment completes',
267
267
  {
268
268
  runtime: 'codex',
269
269
  scope: 'daemon',
270
270
  status: 'quarantined',
271
271
  ownerPresent: typeof lease.generation_id === 'string',
272
- rebootRequired: true,
272
+ rebootRequired: false,
273
+ serviceRestartRequired: true,
273
274
  reasonCode,
274
275
  },
275
276
  );
@@ -282,7 +283,8 @@ function leaseCheck(db) {
282
283
  runtime: 'codex',
283
284
  scope: 'daemon',
284
285
  status: 'invalid',
285
- rebootRequired: true,
286
+ rebootRequired: false,
287
+ serviceRestartRequired: true,
286
288
  },
287
289
  );
288
290
  }
@@ -568,11 +570,12 @@ async function collectCodexDoctorChecks({
568
570
  checks.push(check(
569
571
  'codex-native-background',
570
572
  'warn',
571
- 'detached and background servers are unsupported in the native beta and may require a host reboot after hard loss',
573
+ 'detached and background servers are unsupported in the native beta; hard loss requires verified containment cleanup',
572
574
  {
573
575
  runtime: 'codex',
574
576
  detachedBackgroundSupported: false,
575
- hardLossRebootRequired: true,
577
+ hardLossRebootRequired: false,
578
+ containmentCleanupRequired: true,
576
579
  },
577
580
  ));
578
581
  return checks;
@@ -129,6 +129,59 @@ function deliveryResultString(value, label) {
129
129
  return value;
130
130
  }
131
131
 
132
+ async function resolveCodexStartupRecovery(pidClaim, {
133
+ claimThrowsOnSurvivingPredecessor = false,
134
+ persistedLeaseStatus = null,
135
+ supervisorGraceMs = null,
136
+ wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
137
+ } = {}) {
138
+ const unproven = Object.freeze({
139
+ exclusive_daemon_ownership: false,
140
+ supervisor_grace_elapsed: false,
141
+ });
142
+ if (claimThrowsOnSurvivingPredecessor !== true) return unproven;
143
+
144
+ const priorAction = pidClaim?.priorAction;
145
+ const hasPersistedOwnership = ['active', 'quarantined'].includes(
146
+ persistedLeaseStatus,
147
+ );
148
+ if (
149
+ persistedLeaseStatus != null
150
+ && persistedLeaseStatus !== 'clear'
151
+ && !hasPersistedOwnership
152
+ ) {
153
+ return unproven;
154
+ }
155
+ if (priorAction === 'malformed-overwritten') return unproven;
156
+ if (
157
+ priorAction === 'self-skip'
158
+ || (priorAction === 'no-prior' && !hasPersistedOwnership)
159
+ ) {
160
+ return Object.freeze({
161
+ exclusive_daemon_ownership: true,
162
+ supervisor_grace_elapsed: true,
163
+ });
164
+ }
165
+ if (
166
+ priorAction !== 'no-prior'
167
+ && ![
168
+ 'stale-overwritten',
169
+ 'sigterm-killed',
170
+ 'sigkill-killed',
171
+ ].includes(priorAction)
172
+ ) {
173
+ return unproven;
174
+ }
175
+ if (!Number.isSafeInteger(supervisorGraceMs) || supervisorGraceMs < 0) {
176
+ return unproven;
177
+ }
178
+ await wait(supervisorGraceMs);
179
+ return Object.freeze({
180
+ exclusive_daemon_ownership: true,
181
+ supervisor_grace_elapsed: true,
182
+ });
183
+ }
184
+
132
185
  function createCodexRuntimeController({
133
186
  config,
134
187
  db,
@@ -147,6 +200,10 @@ function createCodexRuntimeController({
147
200
  logger = console,
148
201
  preflightAdmissionTimeoutMs = 120_000,
149
202
  catalogMaxAgeMs = DEFAULT_CATALOG_MAX_AGE_MS,
203
+ startupRecovery = Object.freeze({
204
+ exclusive_daemon_ownership: false,
205
+ supervisor_grace_elapsed: false,
206
+ }),
150
207
  now = Date.now,
151
208
  } = {}) {
152
209
  if (
@@ -160,6 +217,7 @@ function createCodexRuntimeController({
160
217
  || typeof db.markCodexDispatchDisposition !== 'function'
161
218
  || typeof db.settleCodexQueuedDispatch !== 'function'
162
219
  || typeof db.settleCodexStoppedGeneration !== 'function'
220
+ || typeof db.settleCodexFailedGeneration !== 'function'
163
221
  || typeof db.recordCodexDeliveryCheckpoint !== 'function'
164
222
  || typeof resolveHostIdentity !== 'function'
165
223
  || typeof resolveBinary !== 'function'
@@ -314,6 +372,7 @@ function createCodexRuntimeController({
314
372
  const recovery = db.reconstructCodexRecovery({
315
373
  stable_host_id: identity.stableHostId,
316
374
  boot_session_id: identity.bootSessionId,
375
+ startup_recovery: startupRecovery,
317
376
  now: Date.now(),
318
377
  });
319
378
  let codexRecoveryState;
@@ -324,11 +383,11 @@ function createCodexRuntimeController({
324
383
  codexRecoveryState = Object.freeze({
325
384
  status: 'quarantined',
326
385
  hostIdentity: boundedString(
327
- lease?.stable_host_id ?? identity.stableHostId,
386
+ identity.stableHostId,
328
387
  'incident stable host identity',
329
388
  ),
330
389
  bootSessionIdentity: boundedString(
331
- lease?.boot_session_id ?? identity.bootSessionId,
390
+ identity.bootSessionId,
332
391
  'incident boot-session identity',
333
392
  ),
334
393
  generationId: boundedString(
@@ -365,9 +424,9 @@ function createCodexRuntimeController({
365
424
  const state = initialize();
366
425
  if (state.recovery.status !== 'clear') {
367
426
  throw controllerError(
368
- `Codex remains quarantined: ${state.recovery.reason ?? 'unknown reason'}.`,
369
- 'CODEX_CONTAINMENT_QUARANTINED',
370
- 'Reconcile the incident; containment releases only after a verified same-host reboot.',
427
+ `Codex recovery is blocked: ${state.recovery.reason ?? 'unknown reason'}.`,
428
+ 'CODEX_RECOVERY_BLOCKED',
429
+ 'Keep Codex unavailable until exclusive cleanup or persisted integrity is verified.',
371
430
  );
372
431
  }
373
432
  return state;
@@ -696,6 +755,7 @@ function createCodexRuntimeController({
696
755
  proc.once?.('close', () => {
697
756
  record.closed = true;
698
757
  try {
758
+ if (record.retired) return;
699
759
  if (!record.durable && proc.startupReleaseSafe === true) {
700
760
  record.retired = true;
701
761
  processesByGeneration.delete(proc.generationId);
@@ -1312,6 +1372,55 @@ function createCodexRuntimeController({
1312
1372
  );
1313
1373
  }
1314
1374
 
1375
+ if (payload.kind === 'containment-cleanup-completed') {
1376
+ const expectedThreadId = (
1377
+ record.proc.providerSessionId
1378
+ ?? record.proc.attachingThreadId
1379
+ ?? null
1380
+ );
1381
+ const expectedAppServerSessionId =
1382
+ record.proc.appServerSessionId ?? null;
1383
+ if (
1384
+ currentProcessBySession.get(record.proc.sessionKey) !== record
1385
+ || record.proc.generationId !== payload.generationId
1386
+ || record.proc.state !== 'ContainmentFailed'
1387
+ || record.proc.hostIdentity !== payload.hostIdentity
1388
+ || record.proc.bootSessionIdentity !== payload.bootSessionIdentity
1389
+ || expectedThreadId !== (payload.threadId ?? null)
1390
+ || expectedAppServerSessionId
1391
+ !== (payload.appServerSessionId ?? null)
1392
+ || (
1393
+ record.proc.containmentReason != null
1394
+ && record.proc.containmentReason !== payload.reason
1395
+ )
1396
+ ) {
1397
+ throw controllerError(
1398
+ 'Codex containment cleanup does not match the failed process owner.',
1399
+ 'CODEX_CHECKPOINT_STALE_GENERATION',
1400
+ 'Keep the failed generation fenced.',
1401
+ );
1402
+ }
1403
+ const result = db.settleCodexFailedGeneration({
1404
+ generation_id: record.proc.generationId,
1405
+ session_key: record.proc.sessionKey,
1406
+ stable_host_id: state.identity.stableHostId,
1407
+ incident_boot_session_id: state.identity.bootSessionId,
1408
+ current_boot_session_id: state.identity.bootSessionId,
1409
+ provider_session_id: expectedThreadId,
1410
+ app_server_session_id: expectedAppServerSessionId,
1411
+ reason: deliveryResultString(payload.reason, 'containment reason'),
1412
+ source: 'managed-group-empty',
1413
+ allow_missing_generation: !record.durable,
1414
+ ts: payload.ts ?? Date.now(),
1415
+ });
1416
+ record.retired = true;
1417
+ if (processesByGeneration.get(record.proc.generationId) === record) {
1418
+ processesByGeneration.delete(record.proc.generationId);
1419
+ }
1420
+ forgetRetiredSession(record);
1421
+ return Object.freeze({ ...result });
1422
+ }
1423
+
1315
1424
  if (!record.durable) {
1316
1425
  activateWithPreparedCheckpoint(record, payload);
1317
1426
  } else {
@@ -1350,4 +1459,5 @@ function createCodexRuntimeController({
1350
1459
  module.exports = {
1351
1460
  CodexRuntimeControllerError,
1352
1461
  createCodexRuntimeController,
1462
+ resolveCodexStartupRecovery,
1353
1463
  };