gestalt-mobile 0.63.0 → 0.64.0

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.
@@ -16,7 +16,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
16
16
  <link rel="icon" href="/icons/gestalt-mobile-192.png" />
17
17
  <link rel="apple-touch-icon" href="/icons/gestalt-mobile-180.png" />
18
18
  <title>Gestalt Mobile</title>
19
- <script type="module" crossorigin src="/assets/index-wfX7p68b.js"></script>
19
+ <script type="module" crossorigin src="/assets/index-Cj7IlGeB.js"></script>
20
20
  <link rel="stylesheet" crossorigin href="/assets/index-DS139o-V.css">
21
21
  </head>
22
22
  <body>
@@ -2360,6 +2360,7 @@ export async function composeRelayApp(options) {
2360
2360
  }
2361
2361
  catch (error) {
2362
2362
  await hostTests?.close();
2363
+ await retrievalCapability.close?.();
2363
2364
  authorization?.close();
2364
2365
  database.close();
2365
2366
  throw error;
@@ -2416,6 +2417,7 @@ export async function composeRelayApp(options) {
2416
2417
  closing = true;
2417
2418
  providerRecovery.dispose();
2418
2419
  await hostTests?.close();
2420
+ await retrievalCapability.close?.();
2419
2421
  await xerjIndexer.close();
2420
2422
  for (const [sessionId, timer] of capacityRecoveryTimers) {
2421
2423
  clearTimeout(timer);
@@ -28,6 +28,9 @@ export class CodexCapabilities {
28
28
  const serenaPath = input.skills.find((skill) => skill.name === 'gestalt:serena')?.path;
29
29
  const state = {
30
30
  repositories: new RepositoryReadiness(input.cwd),
31
+ get backendPreparation() {
32
+ return xerj.backendPreparation;
33
+ },
31
34
  deadline: Math.max(input.deadline, xerj.ready ? xerj.deadline : input.deadline, serena.ready ? serena.deadline : input.deadline),
32
35
  get ready() {
33
36
  return xerj.ready || serena.ready;
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { parseMcpStartupFailure, parseMcpStartupStatus, startupIdentifier, startupServers, } from '../../../shared/contracts/mcp-startup-failure.js';
7
7
  import { randomUUID } from 'node:crypto';
8
+ import { parseXerjStartupReason } from '../../../shared/contracts/xerj-startup.js';
8
9
  /**
9
10
  * Codex 0.164.0 generated experimental schema: McpServerStatusUpdatedNotification.
10
11
  * Upstream supplies error prose and one structured failure reason, but no child
@@ -43,6 +44,30 @@ export function observedMcpStartupFailure(correlation, observation) {
43
44
  export class McpStartupTracker {
44
45
  runtimeId = randomUUID();
45
46
  attempts = new Map();
47
+ /** Trusted local observation only; upstream notifications cannot supply this phase. */
48
+ observeReadiness(status, reason) {
49
+ const observation = this.observe({
50
+ method: 'mcpServer/statusUpdated',
51
+ params: { name: 'gestalt-xerj', status },
52
+ });
53
+ if (!observation)
54
+ return undefined;
55
+ const local = parseMcpStartupStatus({
56
+ ...observation,
57
+ phase: 'readiness',
58
+ failure: observation.failure
59
+ ? {
60
+ ...observation.failure,
61
+ phase: 'readiness',
62
+ code: 'readiness-failed',
63
+ readinessReason: parseXerjStartupReason(reason),
64
+ }
65
+ : null,
66
+ });
67
+ if (local)
68
+ this.attempts.set(JSON.stringify([null, 'gestalt-xerj']), local);
69
+ return local;
70
+ }
46
71
  observe(notification) {
47
72
  if (!['mcpServer/startupStatus/updated', 'mcpServer/statusUpdated'].includes(notification.method ?? '') ||
48
73
  !notification.params ||
@@ -1464,8 +1464,19 @@ export class CodexSessionRuntime {
1464
1464
  resource.retrieval = state;
1465
1465
  resource.skillsConfig = state.skillsConfig;
1466
1466
  resource.modelConfig = state.config;
1467
+ if (state.backendPreparation) {
1468
+ const status = state.backendPreparation.status === 'starting' ? 'starting' : 'failed';
1469
+ this.publishStartupStatus(resource, resource.mcpStartup.observeReadiness(status, state.backendPreparation.reason));
1470
+ if (status === 'failed') {
1471
+ resource.retrievalFailureReported = true;
1472
+ this.onNotification?.(session.id, {
1473
+ method: 'mcpServer/statusUpdated',
1474
+ params: { name: 'gestalt-xerj', status },
1475
+ }, { kind: 'root' });
1476
+ }
1477
+ }
1467
1478
  this.reportCapabilityFailures(resource, session);
1468
- if (state.diagnostic && !resource.retrievalFailureReported) {
1479
+ if (state.diagnostic && !state.backendPreparation && !resource.retrievalFailureReported) {
1469
1480
  resource.retrievalFailureReported = true;
1470
1481
  this.publishMcpStartup(resource, {
1471
1482
  method: 'mcpServer/statusUpdated',
@@ -1479,6 +1490,8 @@ export class CodexSessionRuntime {
1479
1490
  }
1480
1491
  reportCapabilityFailures(resource, session) {
1481
1492
  for (const capability of resource.retrieval?.capabilities ?? []) {
1493
+ if (capability.serverName === 'gestalt-xerj' && resource.retrieval?.backendPreparation)
1494
+ continue;
1482
1495
  if (!capability.diagnostic || resource.capabilityFailuresReported.has(capability.serverName))
1483
1496
  continue;
1484
1497
  resource.capabilityFailuresReported.add(capability.serverName);
@@ -1548,6 +1561,9 @@ export class CodexSessionRuntime {
1548
1561
  }
1549
1562
  publishMcpStartup(resource, notification) {
1550
1563
  const status = resource.mcpStartup.observe(notification);
1564
+ this.publishStartupStatus(resource, status);
1565
+ }
1566
+ publishStartupStatus(resource, status) {
1551
1567
  if (!status)
1552
1568
  return;
1553
1569
  this.onNotification?.(resource.sessionId, { method: 'gestalt/mcpStartup', params: status }, {
@@ -4,6 +4,7 @@
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
6
  import { readFile } from 'node:fs/promises';
7
+ import { parseXerjStartupReason, } from '../../../shared/contracts/xerj-startup.js';
7
8
  import { ReadinessEvidence } from './readiness-evidence.js';
8
9
  export const xerjServerName = 'gestalt-xerj';
9
10
  export const xerjTools = ['xerj_search', 'xerj_map', 'xerj_code_search'];
@@ -83,8 +84,15 @@ export class CodexXerj {
83
84
  start: input.start,
84
85
  });
85
86
  if (ready.status !== 'ready') {
86
- if (ready.status === 'unavailable')
87
+ if (ready.status === 'starting')
88
+ state.backendPreparation = { status: 'starting' };
89
+ if (ready.status === 'unavailable') {
87
90
  state.diagnostic = 'backend-unavailable';
91
+ state.backendPreparation = {
92
+ status: 'unavailable',
93
+ reason: parseXerjStartupReason(ready.reason),
94
+ };
95
+ }
88
96
  return state;
89
97
  }
90
98
  const guidance = await beforeDeadline(readFile(skill.path, 'utf8'), input.deadline);
@@ -7,58 +7,118 @@ import { spawn } from 'node:child_process';
7
7
  import { access } from 'node:fs/promises';
8
8
  import { constants } from 'node:fs';
9
9
  import { isAbsolute, join } from 'node:path';
10
+ import { parseXerjStartupReason } from '../../../shared/contracts/xerj-startup.js';
10
11
  /** The manager alone owns backend identity, authentication and shared lifetime. */
11
12
  export class ManagedXerj {
12
13
  environment;
14
+ startup;
15
+ probes = new Set();
16
+ closed = false;
13
17
  constructor(environment = process.env) {
14
18
  this.environment = environment;
15
19
  }
16
20
  async check(input) {
21
+ if (this.closed)
22
+ return { status: 'unavailable', reason: 'cancelled' };
17
23
  const manager = await this.manager();
24
+ if (this.closed)
25
+ return { status: 'unavailable', reason: 'cancelled' };
18
26
  if (!manager)
19
27
  return { status: 'absent' };
20
28
  const remaining = input.deadline - Date.now();
29
+ if (this.startup?.manager === manager)
30
+ return this.wait(this.startup.result, Math.max(0, remaining));
21
31
  // The shipped manager rejects sub-100ms operations because it reserves
22
32
  // cleanup time inside the overall deadline. Do not spend the remaining
23
33
  // budget spawning a request that cannot satisfy that contract.
24
34
  if (remaining < minimumXerjTimeoutMs)
25
35
  return { status: 'unavailable', reason: 'readiness-timeout' };
36
+ // A short-lived session waiter never owns the shared startup process.
37
+ // Read-only discovery can observe an existing startup but cannot initiate one.
38
+ if (!input.start)
39
+ return this.run(manager, input.cwd, 'probe', Math.min(remaining, maximumXerjTimeoutMs));
40
+ const startup = {
41
+ manager,
42
+ result: this.run(manager, input.cwd, 'ensure-ready', xerjStartupTimeout(this.environment)),
43
+ };
44
+ this.startup = startup;
45
+ void startup.result.then(() => {
46
+ if (this.startup === startup)
47
+ this.startup = undefined;
48
+ });
49
+ return this.wait(startup.result, remaining);
50
+ }
51
+ async wait(result, timeout) {
52
+ let timer;
53
+ try {
54
+ return await Promise.race([
55
+ result,
56
+ new Promise((resolve) => {
57
+ timer = setTimeout(() => resolve({ status: 'starting' }), timeout);
58
+ }),
59
+ ]);
60
+ }
61
+ finally {
62
+ clearTimeout(timer);
63
+ }
64
+ }
65
+ run(manager, cwd, operation, timeout) {
26
66
  return new Promise((resolve) => {
27
- const child = spawn(manager, ['xerj', input.start ? 'ensure-ready' : 'probe'], {
28
- cwd: input.cwd,
29
- env: { ...this.environment, XERJ_READY_TIMEOUT_MS: String(remaining) },
67
+ const child = spawn(manager, ['xerj', operation], {
68
+ cwd,
69
+ env: { ...this.environment, XERJ_READY_TIMEOUT_MS: String(timeout) },
30
70
  shell: false,
31
71
  stdio: ['ignore', 'pipe', 'ignore'],
32
72
  });
33
73
  let output = '';
34
74
  let finished = false;
75
+ let failure;
76
+ let escalation;
77
+ let closed;
78
+ const probe = {
79
+ stop: () => stop('cancelled'),
80
+ closed: new Promise((resolve) => {
81
+ closed = resolve;
82
+ }),
83
+ };
84
+ this.probes.add(probe);
35
85
  const settle = (result) => {
36
86
  if (finished)
37
87
  return;
38
88
  finished = true;
39
89
  clearTimeout(timer);
90
+ clearTimeout(escalation);
91
+ this.probes.delete(probe);
92
+ closed();
40
93
  resolve(result);
41
94
  };
42
95
  const unavailable = (reason) => ({
43
96
  status: 'unavailable',
44
97
  reason,
45
98
  });
46
- const timer = setTimeout(() => {
47
- // Reap the owned probe; never signal the manager's shared backend.
99
+ const stop = (reason) => {
100
+ if (finished || failure)
101
+ return;
102
+ failure = unavailable(reason);
103
+ // Reap only our manager client; its lifecycle contract owns launch cleanup.
48
104
  child.kill('SIGTERM');
49
- const kill = setTimeout(() => child.kill('SIGKILL'), 100).unref();
50
- child.once('close', () => clearTimeout(kill));
51
- settle(unavailable('readiness-timeout'));
52
- }, remaining);
53
- child.on('error', () => settle(unavailable('manager-unavailable')));
105
+ escalation = setTimeout(() => child.kill('SIGKILL'), 100).unref();
106
+ };
107
+ const timer = setTimeout(() => stop('readiness-timeout'), timeout);
108
+ child.on('error', () => {
109
+ failure = unavailable('manager-unavailable');
110
+ });
54
111
  child.stdout.on('data', (data) => {
112
+ if (failure)
113
+ return;
55
114
  output += data.toString();
56
115
  if (output.length > 16_384) {
57
- child.kill('SIGKILL');
58
- settle(unavailable('invalid-manager-response'));
116
+ stop('invalid-manager-response');
59
117
  }
60
118
  });
61
119
  child.once('close', (code) => {
120
+ if (failure)
121
+ return settle(failure);
62
122
  try {
63
123
  const value = JSON.parse(output);
64
124
  if (code !== 0 || value.schemaVersion !== 1)
@@ -66,7 +126,7 @@ export class ManagedXerj {
66
126
  if (value.status === 'absent')
67
127
  return settle({ status: 'absent' });
68
128
  if (value.status === 'unavailable')
69
- return settle(unavailable('managed-backend-unavailable'));
129
+ return settle(unavailable(parseXerjStartupReason(value.reason)));
70
130
  if (value.status !== 'ready' ||
71
131
  typeof value.version !== 'string' ||
72
132
  !/^[0-9]+\.[0-9]+\.[0-9]+(?:[-+][A-Za-z0-9.-]+)?$/.test(value.version) ||
@@ -82,7 +142,14 @@ export class ManagedXerj {
82
142
  settle(unavailable('invalid-manager-response'));
83
143
  }
84
144
  });
85
- });
145
+ }).catch(() => ({ status: 'unavailable', reason: 'manager-unavailable' }));
146
+ }
147
+ async close() {
148
+ this.closed = true;
149
+ const probes = [...this.probes];
150
+ for (const probe of probes)
151
+ probe.stop();
152
+ await Promise.all(probes.map((probe) => probe.closed));
86
153
  }
87
154
  async manager() {
88
155
  const explicit = this.environment.GESTALT_MANAGER_BIN;
@@ -118,3 +185,11 @@ export function xerjDeadline(environment = process.env) {
118
185
  const minimumXerjTimeoutMs = 100;
119
186
  const maximumXerjTimeoutMs = 60_000;
120
187
  const defaultXerjTimeoutMs = 5_000;
188
+ export function xerjStartupTimeout(environment = process.env) {
189
+ const configured = Number(environment.XERJ_STARTUP_TIMEOUT_MS);
190
+ return Number.isInteger(configured) &&
191
+ configured >= minimumXerjTimeoutMs &&
192
+ configured <= maximumXerjTimeoutMs
193
+ ? configured
194
+ : 30_000;
195
+ }
@@ -9,9 +9,10 @@ import { realpath, writeFile } from 'node:fs/promises';
9
9
  import { join } from 'node:path';
10
10
  import { homedir } from 'node:os';
11
11
  import { checkXerjIndexConfig, saveXerjIndexConfig, xerjContentArguments, xerjIndexConfig, } from './xerj-index-config.js';
12
- import { xerjDeadline } from './managed-xerj.js';
12
+ import { xerjStartupTimeout } from './managed-xerj.js';
13
13
  import { ReadinessEvidence } from './readiness-evidence.js';
14
14
  import { saveXerjIndexDiagnostic, xerjIndexDiagnostic } from './xerj-index-diagnostic.js';
15
+ import { parseXerjStartupReason, xerjStartupMessage, } from '../../../shared/contracts/xerj-startup.js';
15
16
  // Native gitignore syntax, editable by the host operator. Hidden directories and
16
17
  // symlinks are already skipped by XERJ. Never replace an existing root policy.
17
18
  export const xerjDefaultIgnores = `# Gestalt source discovery. Edit these native XERJ rules to change scope.
@@ -97,7 +98,9 @@ export class XerjIndexer {
97
98
  this.value = { ...this.value, root, namespace };
98
99
  const ready = await this.capability.check({
99
100
  cwd: root,
100
- deadline: xerjDeadline(this.environment),
101
+ // This background task waits for backend startup, not the chat allowance.
102
+ // Leave room for the owned manager client's bounded shutdown.
103
+ deadline: Date.now() + xerjStartupTimeout(this.environment) + 1_000,
101
104
  start: true,
102
105
  });
103
106
  if (this.closed)
@@ -113,7 +116,7 @@ export class XerjIndexer {
113
116
  }
114
117
  if (ready.status !== 'ready') {
115
118
  this.evidence.connection('unavailable');
116
- this.fail('XERJ backend unavailable. Run gestalt doctor; check the managed data directory and local port.');
119
+ this.fail(`${xerjStartupMessage(parseXerjStartupReason(ready.status === 'unavailable' ? ready.reason : 'unknown'))} Inspect gestalt xerj status.`);
117
120
  return;
118
121
  }
119
122
  this.evidence.connection('ready');
@@ -3,13 +3,14 @@
3
3
  * Designed by Denis Roio <jaromil@dyne.org>
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
+ import { parseXerjStartupReason } from './xerj-startup.js';
6
7
  export const startupServers = [
7
8
  'context-mode',
8
9
  'gestalt-context-mode',
9
10
  'gestalt-serena',
10
11
  'gestalt-xerj',
11
12
  ];
12
- export const startupPhases = ['artifact', 'spawn', 'initialize', 'startup'];
13
+ export const startupPhases = ['artifact', 'spawn', 'initialize', 'startup', 'readiness'];
13
14
  export const startupFailureCodes = [
14
15
  'artifact-unavailable',
15
16
  'process-exited',
@@ -18,6 +19,7 @@ export const startupFailureCodes = [
18
19
  'reauthentication-required',
19
20
  'startup-failed',
20
21
  'cancelled',
22
+ 'readiness-failed',
21
23
  ];
22
24
  const signals = [
23
25
  'SIGHUP',
@@ -60,6 +62,9 @@ export function parseMcpStartupFailure(value) {
60
62
  !member(startupPhases, r.phase) ||
61
63
  !member(startupFailureCodes, r.code))
62
64
  return undefined;
65
+ if ((r.phase === 'readiness' || r.code === 'readiness-failed') &&
66
+ !(r.phase === 'readiness' && r.code === 'readiness-failed' && r.serverName === 'gestalt-xerj'))
67
+ return undefined;
63
68
  return {
64
69
  schemaVersion: 1,
65
70
  failureId,
@@ -80,6 +85,9 @@ export function parseMcpStartupFailure(value) {
80
85
  ? r.exitCode
81
86
  : null,
82
87
  signal: member(signals, r.signal) ? r.signal : null,
88
+ ...(r.phase === 'readiness' && r.code === 'readiness-failed' && r.serverName === 'gestalt-xerj'
89
+ ? { readinessReason: parseXerjStartupReason(r.readinessReason) }
90
+ : {}),
83
91
  };
84
92
  }
85
93
  export function parseMcpStartupStatus(value) {
@@ -118,6 +126,9 @@ export function parseMcpStartupStatus(value) {
118
126
  observedAt,
119
127
  status: r.status,
120
128
  failure: failure ?? null,
129
+ ...(r.phase === 'readiness' && r.serverName === 'gestalt-xerj'
130
+ ? { phase: 'readiness' }
131
+ : {}),
121
132
  };
122
133
  }
123
134
  /** One current row per physical thread/tool; unattributed lifetimes stay separate. */
@@ -126,7 +137,9 @@ export function mcpStartupActivity(status) {
126
137
  id: `mcp-startup:${status.threadId ?? `unattributed:${status.runtimeId}`}:${status.serverName}`,
127
138
  label: `${status.serverName} · ${status.status}`,
128
139
  detail: status.failure
129
- ? `Startup observation: ${status.failure.code}. Child exit diagnostics are unavailable.`
140
+ ? status.failure.phase === 'readiness'
141
+ ? `Backend readiness: ${status.failure.readinessReason ?? 'unknown'}.`
142
+ : `Startup observation: ${status.failure.code}. Child exit diagnostics are unavailable.`
130
143
  : `Startup observation: ${status.status}.`,
131
144
  mcpStartup: status,
132
145
  };
@@ -147,6 +160,7 @@ export function startupFailureReason(code) {
147
160
  'reauthentication-required': 'Codex reported that authentication is required again.',
148
161
  'startup-failed': 'Codex reported a startup failure without a more specific reason.',
149
162
  cancelled: 'Startup was cancelled.',
163
+ 'readiness-failed': 'Gestalt could not prepare the XERJ backend.',
150
164
  }[code];
151
165
  }
152
166
  export function startupRecoveryGuidance(server) {
@@ -0,0 +1,76 @@
1
+ /*
2
+ * Copyright (C) 2026 Dyne.org foundation
3
+ * Designed by Denis Roio <jaromil@dyne.org>
4
+ * SPDX-License-Identifier: AGPL-3.0-or-later
5
+ */
6
+ /** Manager reason codes only; never propagate subprocess prose or environment values. */
7
+ const reasons = [
8
+ 'cancelled',
9
+ 'timeout',
10
+ 'readiness-timeout',
11
+ 'unsafe-path',
12
+ 'unsupported-installation',
13
+ 'unsupported-version',
14
+ 'unsupported-binary',
15
+ 'unsafe-endpoint',
16
+ 'credentials-unavailable',
17
+ 'authentication-failed',
18
+ 'backend-unavailable',
19
+ 'invalid-backend',
20
+ 'invalid-mcp',
21
+ 'incompatible-mcp',
22
+ 'invalid-deadline',
23
+ 'invalid-lifecycle-record',
24
+ 'lifecycle-busy',
25
+ 'endpoint-in-use',
26
+ 'launch-failed',
27
+ 'probe-failed',
28
+ 'manager-unavailable',
29
+ 'invalid-manager-response',
30
+ 'unknown',
31
+ ];
32
+ export function parseXerjStartupReason(value) {
33
+ return typeof value === 'string' && reasons.includes(value)
34
+ ? value
35
+ : 'unknown';
36
+ }
37
+ export function xerjStartupMessage(reason) {
38
+ switch (reason) {
39
+ case 'timeout':
40
+ case 'readiness-timeout':
41
+ return 'XERJ backend preparation exceeded its time budget.';
42
+ case 'credentials-unavailable':
43
+ case 'authentication-failed':
44
+ return 'XERJ backend authentication is unavailable or was rejected.';
45
+ case 'endpoint-in-use':
46
+ return 'The selected XERJ endpoint is already occupied.';
47
+ case 'unsafe-path':
48
+ case 'unsafe-endpoint':
49
+ case 'unsupported-installation':
50
+ case 'invalid-lifecycle-record':
51
+ case 'invalid-deadline':
52
+ return 'XERJ manager configuration or managed state failed validation.';
53
+ case 'unsupported-version':
54
+ case 'unsupported-binary':
55
+ case 'incompatible-mcp':
56
+ return 'The installed XERJ runtime is incompatible or unavailable.';
57
+ case 'manager-unavailable':
58
+ return 'The Gestalt manager could not be executed.';
59
+ case 'backend-unavailable':
60
+ return 'The XERJ backend could not be reached.';
61
+ case 'launch-failed':
62
+ return 'The managed XERJ backend could not be started.';
63
+ case 'probe-failed':
64
+ return 'The Gestalt manager could not complete its readiness check.';
65
+ case 'invalid-backend':
66
+ case 'invalid-mcp':
67
+ case 'invalid-manager-response':
68
+ return 'XERJ readiness returned an invalid response.';
69
+ case 'lifecycle-busy':
70
+ return 'Another XERJ lifecycle operation is still in progress.';
71
+ case 'cancelled':
72
+ return 'XERJ backend preparation was cancelled.';
73
+ default:
74
+ return 'XERJ backend preparation failed; no more specific cause is available.';
75
+ }
76
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gestalt-mobile",
3
- "version": "0.63.0",
3
+ "version": "0.64.0",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",