instar 1.3.340 → 1.3.341

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.
@@ -0,0 +1,54 @@
1
+ export interface PendingInjectRecord {
2
+ /** tmux session name the inject targets (also the record's key). */
3
+ tmuxSession: string;
4
+ /** The message queued for injection (may be a bootstrap-file pointer). */
5
+ initialMessage: string;
6
+ /** Telegram topic the message belongs to, when known. */
7
+ telegramTopicId?: number;
8
+ /** ISO timestamp the record was written (spawn time). */
9
+ createdAt: string;
10
+ }
11
+ export declare class PendingInjectStore {
12
+ private dir;
13
+ constructor(stateDir: string);
14
+ /** Key → filename. tmux session names are already shell-safe, but clamp anyway. */
15
+ private fileFor;
16
+ /** Write (or overwrite) the pending record for a session. Never throws —
17
+ * a failed durability write must not block the spawn itself. */
18
+ record(entry: Omit<PendingInjectRecord, 'createdAt'> & {
19
+ createdAt?: string;
20
+ }): void;
21
+ /** Remove the record after a verified inject. Never throws. */
22
+ clear(tmuxSession: string): void;
23
+ /** All surviving records (corrupt files are skipped, reported via return). */
24
+ list(): {
25
+ records: PendingInjectRecord[];
26
+ corrupt: string[];
27
+ };
28
+ }
29
+ export interface PendingInjectSweepDeps {
30
+ sessionAlive(tmuxSession: string): boolean;
31
+ /** Re-deliver through the normal readiness path; resolves once injected (or throws). */
32
+ redeliver(record: PendingInjectRecord): Promise<void>;
33
+ /** Loud reporting for the cases recovery cannot fix on its own. */
34
+ reportLoss(record: PendingInjectRecord, reason: string): void;
35
+ now?: () => number;
36
+ /** Records older than this are expired (reported, not re-injected). Default 6h. */
37
+ maxAgeMs?: number;
38
+ }
39
+ export interface PendingInjectSweepResult {
40
+ redelivered: string[];
41
+ expired: string[];
42
+ deadSession: string[];
43
+ failed: string[];
44
+ }
45
+ /**
46
+ * Boot-time recovery over surviving records. Decision per record:
47
+ * - older than maxAge → expire + reportLoss (stale enough that re-injecting
48
+ * mid-conversation would confuse more than help)
49
+ * - tmux session still alive → redeliver via the readiness path, clear on success
50
+ * - tmux session gone → reportLoss + clear (the bridge respawns on the
51
+ * user's next message; the loss is now VISIBLE)
52
+ */
53
+ export declare function sweepPendingInjects(store: PendingInjectStore, deps: PendingInjectSweepDeps): Promise<PendingInjectSweepResult>;
54
+ //# sourceMappingURL=PendingInjectStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PendingInjectStore.d.ts","sourceRoot":"","sources":["../../src/core/PendingInjectStore.ts"],"names":[],"mappings":"AA8BA,MAAM,WAAW,mBAAmB;IAClC,oEAAoE;IACpE,WAAW,EAAE,MAAM,CAAC;IACpB,0EAA0E;IAC1E,cAAc,EAAE,MAAM,CAAC;IACvB,yDAAyD;IACzD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,GAAG,CAAS;gBAER,QAAQ,EAAE,MAAM;IAI5B,mFAAmF;IACnF,OAAO,CAAC,OAAO;IAKf;qEACiE;IACjE,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,WAAW,CAAC,GAAG;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAkBpF,+DAA+D;IAC/D,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAehC,8EAA8E;IAC9E,IAAI,IAAI;QAAE,OAAO,EAAE,mBAAmB,EAAE,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE;CA8B9D;AAED,MAAM,WAAW,sBAAsB;IACrC,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3C,wFAAwF;IACxF,SAAS,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,mEAAmE;IACnE,UAAU,CAAC,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9D,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,mFAAmF;IACnF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,wBAAwB;IACvC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,kBAAkB,EACzB,IAAI,EAAE,sBAAsB,GAC3B,OAAO,CAAC,wBAAwB,CAAC,CAkCnC"}
@@ -0,0 +1,152 @@
1
+ /**
2
+ * PendingInjectStore — durable record of in-flight initial-message injects.
3
+ *
4
+ * THE GAP THIS CLOSES (finding 8d300555, 2026-06-06): when a session is
5
+ * spawned with an initial message, the inject happens AFTER an async
6
+ * readiness wait (codex can take tens of seconds to boot). That pending
7
+ * inject was process-local state — a server restart in the window between
8
+ * spawn and inject silently dropped the user's message. The live incident:
9
+ * the auto-updater's scheduled restart (60s delay) killed the server while
10
+ * the fresh-spawned codex session was still booting; tmux survived showing
11
+ * an idle prompt, the bootstrap file sat unconsumed on disk, the operator
12
+ * waited 50+ minutes, and nothing anywhere knew a message had been lost.
13
+ *
14
+ * The store is one JSON file per pending inject, keyed by tmux session name,
15
+ * under `<stateDir>/pending-injects/`. Records are written at spawn time and
16
+ * cleared ONLY after the inject actually runs. Boot-time recovery
17
+ * (SessionManager.recoverPendingInjects) sweeps survivors: a still-alive
18
+ * session gets the message re-delivered through the normal readiness path; a
19
+ * dead session is reported loudly (DegradationReporter) and expired — never
20
+ * silently dropped.
21
+ *
22
+ * Delivery semantics are deliberately AT-LEAST-ONCE: if the server dies
23
+ * after the inject but before the clear, the next boot re-injects a
24
+ * duplicate. A duplicated message to an agent session is recoverable noise;
25
+ * a silently dropped user message is not.
26
+ */
27
+ import fs from 'node:fs';
28
+ import path from 'node:path';
29
+ import { SafeFsExecutor } from './SafeFsExecutor.js';
30
+ export class PendingInjectStore {
31
+ dir;
32
+ constructor(stateDir) {
33
+ this.dir = path.join(stateDir, 'pending-injects');
34
+ }
35
+ /** Key → filename. tmux session names are already shell-safe, but clamp anyway. */
36
+ fileFor(tmuxSession) {
37
+ const safe = tmuxSession.replace(/[^a-zA-Z0-9._-]/g, '_').slice(0, 200);
38
+ return path.join(this.dir, `${safe}.json`);
39
+ }
40
+ /** Write (or overwrite) the pending record for a session. Never throws —
41
+ * a failed durability write must not block the spawn itself. */
42
+ record(entry) {
43
+ try {
44
+ fs.mkdirSync(this.dir, { recursive: true });
45
+ const full = {
46
+ tmuxSession: entry.tmuxSession,
47
+ initialMessage: entry.initialMessage,
48
+ ...(entry.telegramTopicId !== undefined ? { telegramTopicId: entry.telegramTopicId } : {}),
49
+ createdAt: entry.createdAt ?? new Date().toISOString(),
50
+ };
51
+ fs.writeFileSync(this.fileFor(entry.tmuxSession), JSON.stringify(full, null, 2));
52
+ }
53
+ catch (err) {
54
+ // @silent-fallback-ok a durable-ledger write must NEVER break the spawn it
55
+ // is protecting — warn with context and continue; a missed record only
56
+ // means this one inject isn't restart-recoverable (the pre-fix behavior).
57
+ console.warn(`[PendingInjectStore] record failed for "${entry.tmuxSession}" (non-fatal): ${err instanceof Error ? err.message : String(err)}`);
58
+ }
59
+ }
60
+ /** Remove the record after a verified inject. Never throws. */
61
+ clear(tmuxSession) {
62
+ try {
63
+ SafeFsExecutor.safeUnlinkSync(this.fileFor(tmuxSession), {
64
+ operation: 'PendingInjectStore.clear',
65
+ });
66
+ }
67
+ catch (err) {
68
+ if (err?.code !== 'ENOENT') {
69
+ // Already-cleared (ENOENT) is the expected no-op; anything else is
70
+ // non-fatal — a stale record is re-examined (and expired) by the next
71
+ // boot sweep, so we report rather than throw into the inject path.
72
+ console.warn(`[PendingInjectStore] clear failed for "${tmuxSession}" (non-fatal): ${err instanceof Error ? err.message : String(err)}`);
73
+ }
74
+ }
75
+ }
76
+ /** All surviving records (corrupt files are skipped, reported via return). */
77
+ list() {
78
+ const records = [];
79
+ const corrupt = [];
80
+ let files = [];
81
+ try {
82
+ files = fs.readdirSync(this.dir).filter((f) => f.endsWith('.json'));
83
+ }
84
+ catch {
85
+ // @silent-fallback-ok no pending-injects dir yet (fresh install / nothing
86
+ // ever queued) is the normal empty case, not a degradation — return empty.
87
+ return { records, corrupt };
88
+ }
89
+ for (const f of files) {
90
+ try {
91
+ const parsed = JSON.parse(fs.readFileSync(path.join(this.dir, f), 'utf8'));
92
+ if (parsed && typeof parsed === 'object' &&
93
+ typeof parsed.tmuxSession === 'string' &&
94
+ typeof parsed.initialMessage === 'string' &&
95
+ typeof parsed.createdAt === 'string') {
96
+ records.push(parsed);
97
+ }
98
+ else {
99
+ corrupt.push(f);
100
+ }
101
+ }
102
+ catch {
103
+ corrupt.push(f);
104
+ }
105
+ }
106
+ return { records, corrupt };
107
+ }
108
+ }
109
+ /**
110
+ * Boot-time recovery over surviving records. Decision per record:
111
+ * - older than maxAge → expire + reportLoss (stale enough that re-injecting
112
+ * mid-conversation would confuse more than help)
113
+ * - tmux session still alive → redeliver via the readiness path, clear on success
114
+ * - tmux session gone → reportLoss + clear (the bridge respawns on the
115
+ * user's next message; the loss is now VISIBLE)
116
+ */
117
+ export async function sweepPendingInjects(store, deps) {
118
+ const result = { redelivered: [], expired: [], deadSession: [], failed: [] };
119
+ const now = deps.now ?? (() => Date.now());
120
+ const maxAgeMs = deps.maxAgeMs ?? 6 * 60 * 60 * 1000;
121
+ const { records, corrupt } = store.list();
122
+ for (const f of corrupt) {
123
+ console.warn(`[PendingInjectStore] corrupt pending-inject file skipped: ${f}`);
124
+ }
125
+ for (const record of records) {
126
+ const age = now() - Date.parse(record.createdAt);
127
+ if (!Number.isFinite(age) || age > maxAgeMs) {
128
+ deps.reportLoss(record, `record expired (age ${Math.round(age / 60000)}m > ${Math.round(maxAgeMs / 60000)}m)`);
129
+ store.clear(record.tmuxSession);
130
+ result.expired.push(record.tmuxSession);
131
+ continue;
132
+ }
133
+ if (!deps.sessionAlive(record.tmuxSession)) {
134
+ deps.reportLoss(record, 'target tmux session no longer exists');
135
+ store.clear(record.tmuxSession);
136
+ result.deadSession.push(record.tmuxSession);
137
+ continue;
138
+ }
139
+ try {
140
+ await deps.redeliver(record);
141
+ store.clear(record.tmuxSession);
142
+ result.redelivered.push(record.tmuxSession);
143
+ }
144
+ catch (err) {
145
+ // Keep the record — the NEXT boot retries. Failing loudly beats dropping.
146
+ deps.reportLoss(record, `redeliver failed: ${err instanceof Error ? err.message : String(err)}`);
147
+ result.failed.push(record.tmuxSession);
148
+ }
149
+ }
150
+ return result;
151
+ }
152
+ //# sourceMappingURL=PendingInjectStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PendingInjectStore.js","sourceRoot":"","sources":["../../src/core/PendingInjectStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAarD,MAAM,OAAO,kBAAkB;IACrB,GAAG,CAAS;IAEpB,YAAY,QAAgB;QAC1B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;IACpD,CAAC;IAED,mFAAmF;IAC3E,OAAO,CAAC,WAAmB;QACjC,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QACxE,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED;qEACiE;IACjE,MAAM,CAAC,KAAsE;QAC3E,IAAI,CAAC;YACH,EAAE,CAAC,SAAS,CA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,CAAC,CAAC;YACxC,SAAS;QACX,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;YAC3C,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,sCAAsC,CAAC,CAAC;YAChE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YAChC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YAC5C,SAAS;QACX,CAAC;QACD,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAC7B,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YAChC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAC9C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,0EAA0E;YAC1E,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,qBAAqB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACjG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -168,6 +168,7 @@ export declare class SessionManager extends EventEmitter {
168
168
  /** Worktree manager — when set, spawnSession resolves an isolated worktree per topic. */
169
169
  private worktreeManager;
170
170
  private buildContextStore;
171
+ private pendingInjects;
171
172
  /** Per-session shim directory root (one subdir per session). Used for K9 mandatory shim. */
172
173
  private shimRoot;
173
174
  constructor(config: SessionManagerConfig, state: StateManager);
@@ -682,6 +683,22 @@ export declare class SessionManager extends EventEmitter {
682
683
  * via the existing degradation reporter and the bridge's own respawn paths.
683
684
  */
684
685
  private handleReadyAndInject;
686
+ /**
687
+ * Boot-time recovery for injects orphaned by a server restart (finding
688
+ * 8d300555). Sweeps the durable pending-inject records: a still-alive
689
+ * session gets its message re-delivered through the normal readiness path
690
+ * (the live incident — codex idle at a fresh prompt, bootstrap unread); a
691
+ * dead or expired record is reported via DegradationReporter and expired —
692
+ * the loss becomes VISIBLE instead of vanishing with the old process.
693
+ * At-least-once by design: server death between inject and clear means one
694
+ * duplicate on the next boot, which beats a silent drop.
695
+ */
696
+ recoverPendingInjects(): Promise<{
697
+ redelivered: string[];
698
+ expired: string[];
699
+ deadSession: string[];
700
+ failed: string[];
701
+ }>;
685
702
  /**
686
703
  * Spawn a scoped triage session with restricted tool access.
687
704
  * Unlike interactive sessions, triage sessions use --allowedTools + --permission-mode dontAsk
@@ -1 +1 @@
1
- {"version":3,"file":"SessionManager.d.ts","sourceRoot":"","sources":["../../src/core/SessionManager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,OAAO,EAAE,qBAAqB,EAAoC,MAAM,4BAA4B,CAAC;AACrG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAMhD,+CAA+C;AAC/C,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,oCAAoC;AACpC,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,CAAC;AAEtE,qEAAqE;AACrE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,a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BAAyB,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAMrF;6EACyE;IACzE,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS;IAIlH;;gBAEY;IACZ,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAInD;2DACuD;IACvD,2BAA2B,IAAI,MAAM,EAAE;IAIvC;;;;;;OAMG;IACH,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAoBlE;;;OAGG;IACG,kBAAkB,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,GAAE,MAAc,GAAG,OAAO,CAAC,OAAO,CAAC;IAqB1F;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IAmD1B;;;;;;;;;OASG;YACW,2BAA2B;IA6BzC,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAcxC,OAAO,CAAC,UAAU;CAGnB"}
@@ -27,6 +27,7 @@ import { buildInjectionTag } from '../types/pipeline.js';
27
27
  import { sanitizeSenderName, sanitizeTopicName } from '../utils/sanitize.js';
28
28
  import { getTelegramInboundDir } from '../messaging/shared/telegramInboundFiles.js';
29
29
  import { SessionBuildContextStore } from './SessionBuildContextStore.js';
30
+ import { PendingInjectStore, sweepPendingInjects } from './PendingInjectStore.js';
30
31
  import { AgeKillBackoff } from './AgeKillBackoff.js';
31
32
  /** Absolute maximum session duration (4 hours) — safety net for sessions without explicit timeout */
32
33
  const DEFAULT_MAX_DURATION_MINUTES = 240;
@@ -236,12 +237,22 @@ export class SessionManager extends EventEmitter {
236
237
  /** Worktree manager — when set, spawnSession resolves an isolated worktree per topic. */
237
238
  worktreeManager = null;
238
239
  buildContextStore = null;
240
+ pendingInjects;
239
241
  /** Per-session shim directory root (one subdir per session). Used for K9 mandatory shim. */
240
242
  shimRoot = null;
241
243
  constructor(config, state) {
242
244
  super();
243
245
  this.config = config;
244
246
  this.state = state;
247
+ // Durable in-flight inject ledger (finding 8d300555) — records survive a
248
+ // server restart in the spawn→ready→inject window; recoverPendingInjects()
249
+ // sweeps them at boot. Mock StateManagers in tests may lack baseDir —
250
+ // fall back to the projectDir-derived state root rather than crashing
251
+ // construction (the ledger path just needs to be stable per install).
252
+ const stateBase = typeof state?.baseDir === 'string'
253
+ ? state.baseDir
254
+ : path.join(config.projectDir, '.instar');
255
+ this.pendingInjects = new PendingInjectStore(path.join(stateBase, 'state'));
245
256
  // Age-gate kill back-off: default 10 min between re-requests for a kept session
246
257
  // (config.ageKillBackoffMinutes; 0 disables → legacy every-tick behavior).
247
258
  const backoffMin = typeof config.ageKillBackoffMinutes === 'number' ? config.ageKillBackoffMinutes : 10;
@@ -2144,6 +2155,18 @@ rm() { "${shimRunner}" rm "$@"; }
2144
2155
  // large CLAUDE.md loading, and session-start hook execution.
2145
2156
  const readyTimeout = options?.resumeSessionId ? 120_000 : 90_000;
2146
2157
  if (effectiveInitialMessage) {
2158
+ // DURABILITY (finding 8d300555): the inject below happens after an async
2159
+ // readiness wait — codex can take tens of seconds to boot, and a server
2160
+ // restart in that window used to silently drop the message (the pending
2161
+ // inject was process-local; tmux survived idle, the bootstrap file sat
2162
+ // unconsumed, the operator waited on nothing). Record the pending inject
2163
+ // BEFORE the wait; handleReadyAndInject clears it only after the inject
2164
+ // actually runs; recoverPendingInjects sweeps survivors at boot.
2165
+ this.pendingInjects.record({
2166
+ tmuxSession,
2167
+ initialMessage: effectiveInitialMessage,
2168
+ telegramTopicId: options?.telegramTopicId,
2169
+ });
2147
2170
  this.handleReadyAndInject(tmuxSession, name, effectiveInitialMessage, readyTimeout, options).catch((err) => {
2148
2171
  console.error(`[SessionManager] Error during ready-and-inject for "${tmuxSession}": ${err}`);
2149
2172
  });
@@ -2170,6 +2193,7 @@ rm() { "${shimRunner}" rm "$@"; }
2170
2193
  const stabilizationMs = options?.resumeSessionId ? 5000 : 1000;
2171
2194
  await new Promise(r => setTimeout(r, stabilizationMs));
2172
2195
  this.injectMessage(tmuxSession, initialMessage);
2196
+ this.pendingInjects.clear(tmuxSession);
2173
2197
  console.log(`[SessionManager] Injected initial message into "${tmuxSession}" (${initialMessage.length} chars${stabilizationMs ? ', after stabilization delay' : ''})`);
2174
2198
  return;
2175
2199
  }
@@ -2218,7 +2242,11 @@ rm() { "${shimRunner}" rm "$@"; }
2218
2242
  telegramTopicId: options.telegramTopicId,
2219
2243
  slackChannelId: options.slackChannelId,
2220
2244
  });
2221
- console.log(`[SessionManager] Fresh-spawn fallback succeeded for "${tmuxSession}".`);
2245
+ // HONEST LOG (finding 8d300555): the recursive spawn returns BEFORE its
2246
+ // own readiness wait + inject complete — "succeeded" here only means
2247
+ // "launched". The pending-inject record (re-written by the recursive
2248
+ // call) is what guarantees delivery survives a restart in that window.
2249
+ console.log(`[SessionManager] Fresh-spawn fallback launched for "${tmuxSession}" (inject pending — durable record held until verified).`);
2222
2250
  }
2223
2251
  catch (err) {
2224
2252
  const errMsg = err instanceof Error ? err.message : String(err);
@@ -2239,11 +2267,14 @@ rm() { "${shimRunner}" rm "$@"; }
2239
2267
  console.error(`[SessionManager] Claude not ready in session "${tmuxSession}" — message NOT injected. Session may need manual intervention.`);
2240
2268
  console.log(`[SessionManager] Session "${tmuxSession}" still alive — attempting injection anyway`);
2241
2269
  this.injectMessage(tmuxSession, initialMessage);
2270
+ this.pendingInjects.clear(tmuxSession);
2242
2271
  return;
2243
2272
  }
2244
2273
  // tmux dead AND not a resume case — fresh spawn that crashed during startup.
2245
2274
  // No fallback (no UUID to blame); surface as a degradation so the bridge can
2246
2275
  // notice. The bridge already retries on the next inbound message.
2276
+ // (The pending-inject record is deliberately NOT cleared here — the boot
2277
+ // sweep reports the loss loudly instead of letting it vanish.)
2247
2278
  console.error(`[SessionManager] Claude not ready in session "${tmuxSession}" — tmux died during fresh startup. Message NOT injected.`);
2248
2279
  DegradationReporter.getInstance().report({
2249
2280
  feature: 'SessionManager.handleReadyAndInject',
@@ -2253,6 +2284,44 @@ rm() { "${shimRunner}" rm "$@"; }
2253
2284
  impact: 'Initial message dropped; bridge will respawn on next inbound message',
2254
2285
  });
2255
2286
  }
2287
+ /**
2288
+ * Boot-time recovery for injects orphaned by a server restart (finding
2289
+ * 8d300555). Sweeps the durable pending-inject records: a still-alive
2290
+ * session gets its message re-delivered through the normal readiness path
2291
+ * (the live incident — codex idle at a fresh prompt, bootstrap unread); a
2292
+ * dead or expired record is reported via DegradationReporter and expired —
2293
+ * the loss becomes VISIBLE instead of vanishing with the old process.
2294
+ * At-least-once by design: server death between inject and clear means one
2295
+ * duplicate on the next boot, which beats a silent drop.
2296
+ */
2297
+ async recoverPendingInjects() {
2298
+ const result = await sweepPendingInjects(this.pendingInjects, {
2299
+ sessionAlive: (tmux) => this.tmuxSessionExists(tmux),
2300
+ redeliver: async (record) => {
2301
+ console.log(`[SessionManager] Recovering orphaned pending inject for "${record.tmuxSession}" (queued ${record.createdAt})`);
2302
+ // Reuse the normal readiness machinery; no resume options — the target
2303
+ // session is already running, we only need ready + inject. The inject
2304
+ // path clears the record on success.
2305
+ await this.handleReadyAndInject(record.tmuxSession, undefined, record.initialMessage, 90_000, {
2306
+ telegramTopicId: record.telegramTopicId,
2307
+ });
2308
+ },
2309
+ reportLoss: (record, reason) => {
2310
+ DegradationReporter.getInstance().report({
2311
+ feature: 'SessionManager.recoverPendingInjects',
2312
+ primary: 'Re-deliver an inject orphaned by a server restart',
2313
+ fallback: `Pending inject for "${record.tmuxSession}" not re-delivered: ${reason}`,
2314
+ reason: `Why: queued ${record.createdAt}${record.telegramTopicId !== undefined ? ` for topic ${record.telegramTopicId}` : ''}`,
2315
+ impact: 'A queued initial message may not have reached its session; the bridge respawns on the next inbound message.',
2316
+ });
2317
+ },
2318
+ });
2319
+ const total = result.redelivered.length + result.expired.length + result.deadSession.length + result.failed.length;
2320
+ if (total > 0) {
2321
+ console.log(`[SessionManager] Pending-inject recovery: ${result.redelivered.length} redelivered, ${result.deadSession.length} dead-session, ${result.expired.length} expired, ${result.failed.length} failed.`);
2322
+ }
2323
+ return result;
2324
+ }
2256
2325
  /**
2257
2326
  * Spawn a scoped triage session with restricted tool access.
2258
2327
  * Unlike interactive sessions, triage sessions use --allowedTools + --permission-mode dontAsk