gestalt-mobile 0.55.8 → 0.57.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.
- package/dist/client/assets/index-Cp-JfcNd.css +1 -0
- package/dist/client/assets/index-DeNYHfGR.js +123 -0
- package/dist/client/index.html +2 -2
- package/dist/server/client/features/chat/chat-projection.js +11 -0
- package/dist/server/server/composition.contracts.js +219 -1
- package/dist/server/server/composition.js +26 -1
- package/dist/server/server/features/agent-activity/tool-efficiency-projection.js +179 -0
- package/dist/server/server/features/agent-activity/tool-efficiency.js +13 -0
- package/dist/server/server/features/catalog/get-xerj-status/endpoint.js +3 -1
- package/dist/server/server/features/control-plane-trace/export-trace.js +18 -3
- package/dist/server/server/features/sessions/get-history/endpoint.js +3 -0
- package/dist/server/server/features/sessions/get-retrieval-readiness/endpoint.js +19 -0
- package/dist/server/server/features/sessions/get-session/endpoint.js +3 -1
- package/dist/server/server/features/sessions/register-routes.js +7 -1
- package/dist/server/server/platform/codex/activity-facts.js +2 -0
- package/dist/server/server/platform/codex/codex-capabilities.js +4 -0
- package/dist/server/server/platform/codex/codex-serena.js +16 -3
- package/dist/server/server/platform/codex/mcp-startup-failure.js +96 -0
- package/dist/server/server/platform/codex/normalizer.js +69 -0
- package/dist/server/server/platform/codex/session-runtime.js +101 -4
- package/dist/server/server/platform/codex/tool-efficiency-facts.js +178 -0
- package/dist/server/server/platform/persistence/migrate.js +1 -0
- package/dist/server/server/platform/persistence/sqlite-event-journal.js +16 -0
- package/dist/server/server/platform/persistence/sqlite-tool-efficiency-store.js +23 -0
- package/dist/server/server/platform/retrieval/codex-xerj.js +17 -3
- package/dist/server/server/platform/retrieval/read-authority.js +55 -0
- package/dist/server/server/platform/retrieval/readiness-evidence.js +92 -0
- package/dist/server/server/platform/retrieval/repository-readiness.js +464 -0
- package/dist/server/server/platform/retrieval/xerj-indexer.js +19 -1
- package/dist/server/shared/contracts/mcp-startup-failure.js +158 -0
- package/dist/server/shared/contracts/retrieval-readiness.js +47 -0
- package/dist/server/shared/contracts/tool-efficiency.js +125 -0
- package/dist/server/shared/contracts/tool-efficiency.test-fixture.js +77 -0
- package/package.json +1 -1
- package/dist/client/assets/index-CGA0jSom.css +0 -1
- package/dist/client/assets/index-DOfpAofv.js +0 -116
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
export function registerGetRetrievalReadiness(app, deps) {
|
|
7
|
+
app.get('/api/sessions/:id/retrieval-readiness', async (request, reply) => {
|
|
8
|
+
const id = request.params.id;
|
|
9
|
+
if (!deps.exists(id))
|
|
10
|
+
return reply.code(404).send({ code: 'SESSION_NOT_FOUND' });
|
|
11
|
+
reply.header('Cache-Control', 'no-store');
|
|
12
|
+
try {
|
|
13
|
+
return (await deps.read(id)) ?? { connections: [], repositories: [] };
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return reply.code(503).send({ code: 'RETRIEVAL_READINESS_UNAVAILABLE' });
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { buildResumeCommand } from '../application/resume-command.js';
|
|
7
7
|
import { toAgentActivityDto } from '../../agent-activity/activity-dto.js';
|
|
8
8
|
import { deriveSessionStatus } from '../session-status.js';
|
|
9
|
-
export function registerGetSession(app, find, activity, autopilot, plan) {
|
|
9
|
+
export function registerGetSession(app, find, activity, autopilot, plan, toolEfficiency, currentSequence) {
|
|
10
10
|
app.get('/api/sessions/:id', async (request, reply) => {
|
|
11
11
|
const session = find(request.params.id);
|
|
12
12
|
if (!session)
|
|
@@ -16,9 +16,11 @@ export function registerGetSession(app, find, activity, autopilot, plan) {
|
|
|
16
16
|
const retainedPlan = plan?.(session.id) ?? null;
|
|
17
17
|
return reply.send({
|
|
18
18
|
...session,
|
|
19
|
+
...(currentSequence ? { currentSequence: currentSequence(session.id) } : {}),
|
|
19
20
|
...(activitySnapshot ? { agentActivity: toAgentActivityDto(activitySnapshot) } : {}),
|
|
20
21
|
...(autopilotSnapshot ? { autopilot: autopilotSnapshot } : {}),
|
|
21
22
|
...(retainedPlan ? { plan: retainedPlan } : {}),
|
|
23
|
+
...(toolEfficiency ? { toolEfficiency: toolEfficiency(session.id) } : {}),
|
|
22
24
|
sessionStatus: deriveSessionStatus({
|
|
23
25
|
session,
|
|
24
26
|
plan: retainedPlan,
|
|
@@ -23,6 +23,7 @@ import { registerStartSession } from './start-session/endpoint.js';
|
|
|
23
23
|
import { registerStartTurn } from './start-turn/endpoint.js';
|
|
24
24
|
import { registerStopSession } from './stop-session/endpoint.js';
|
|
25
25
|
import { registerRefreshActivity } from './refresh-activity/endpoint.js';
|
|
26
|
+
import { registerGetRetrievalReadiness } from './get-retrieval-readiness/endpoint.js';
|
|
26
27
|
export function registerSessionRoutes(app, deps) {
|
|
27
28
|
const sessions = deps.sessionRoutes;
|
|
28
29
|
if (deps.recentThreads) {
|
|
@@ -47,13 +48,18 @@ export function registerSessionRoutes(app, deps) {
|
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
50
|
if (sessions) {
|
|
51
|
+
if (sessions.retrievalReadiness)
|
|
52
|
+
registerGetRetrievalReadiness(app, {
|
|
53
|
+
exists: (id) => sessions.find(id) !== null,
|
|
54
|
+
read: sessions.retrievalReadiness,
|
|
55
|
+
});
|
|
50
56
|
if (sessions.sessionModels)
|
|
51
57
|
registerListSessionModels(app, sessions.sessionModels);
|
|
52
58
|
registerStartSession(app, {
|
|
53
59
|
...sessions,
|
|
54
60
|
reportFailure: (operation, error) => deps.logger.error(`${operation} failed: ${safeErrorLabel(error)}`),
|
|
55
61
|
});
|
|
56
|
-
registerGetSession(app, sessions.find, sessions.agentActivity, sessions.autopilotSnapshot, sessions.plan);
|
|
62
|
+
registerGetSession(app, sessions.find, sessions.agentActivity, sessions.autopilotSnapshot, sessions.plan, sessions.toolEfficiency, sessions.currentSequence);
|
|
57
63
|
if (sessions.refreshActivity)
|
|
58
64
|
registerRefreshActivity(app, {
|
|
59
65
|
exists: (id) => sessions.find(id) !== null,
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
|
+
// Cost observations have their own contract; they must not change agent liveness.
|
|
7
|
+
export { decodeToolEfficiencyFacts } from './tool-efficiency-facts.js';
|
|
6
8
|
const id = (value) => typeof value === 'string' && value.length > 0 && value.length <= 256 ? value : undefined;
|
|
7
9
|
const record = (value) => value && typeof value === 'object' && !Array.isArray(value)
|
|
8
10
|
? value
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { CodexXerj } from '../retrieval/codex-xerj.js';
|
|
7
7
|
import { CodexSerena } from './codex-serena.js';
|
|
8
|
+
import { RepositoryReadiness } from '../retrieval/repository-readiness.js';
|
|
8
9
|
/** The two managed capabilities share lifecycle, but never share availability or approvals. */
|
|
9
10
|
export class CodexCapabilities {
|
|
10
11
|
xerj;
|
|
@@ -26,6 +27,7 @@ export class CodexCapabilities {
|
|
|
26
27
|
serena.deadline = Date.now() + serenaVerificationMs;
|
|
27
28
|
const serenaPath = input.skills.find((skill) => skill.name === 'gestalt:serena')?.path;
|
|
28
29
|
const state = {
|
|
30
|
+
repositories: new RepositoryReadiness(input.cwd),
|
|
29
31
|
deadline: Math.max(input.deadline, serena.ready ? serena.deadline : input.deadline),
|
|
30
32
|
get ready() {
|
|
31
33
|
return xerj.ready || serena.ready;
|
|
@@ -37,12 +39,14 @@ export class CodexCapabilities {
|
|
|
37
39
|
serverName: 'gestalt-xerj',
|
|
38
40
|
ready: xerj.ready,
|
|
39
41
|
diagnostic: xerj.diagnostic,
|
|
42
|
+
readiness: xerj.readiness,
|
|
40
43
|
},
|
|
41
44
|
{
|
|
42
45
|
skillName: 'gestalt:serena',
|
|
43
46
|
serverName: 'gestalt-serena',
|
|
44
47
|
ready: serena.ready,
|
|
45
48
|
diagnostic: serena.diagnostic,
|
|
49
|
+
readiness: serena.readiness,
|
|
46
50
|
},
|
|
47
51
|
];
|
|
48
52
|
},
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { readFile } from 'node:fs/promises';
|
|
7
7
|
import { beforeDeadline, } from '../retrieval/codex-xerj.js';
|
|
8
8
|
import { ManagedSerena, serenaTools } from './managed-serena.js';
|
|
9
|
+
import { ReadinessEvidence } from '../retrieval/readiness-evidence.js';
|
|
9
10
|
export const serenaServerName = 'gestalt-serena';
|
|
10
11
|
// config/read includes unset defaults as null. Thread overrides cannot encode
|
|
11
12
|
// those as TOML values; retain explicit settings, including tool approvals.
|
|
@@ -25,6 +26,7 @@ export class CodexSerena {
|
|
|
25
26
|
this.installation = installation;
|
|
26
27
|
}
|
|
27
28
|
async prepare(input) {
|
|
29
|
+
const evidence = new ReadinessEvidence();
|
|
28
30
|
const skill = input.skills.find((entry) => entry.name === 'gestalt:serena');
|
|
29
31
|
let native = {};
|
|
30
32
|
let compatible = false;
|
|
@@ -46,11 +48,16 @@ export class CodexSerena {
|
|
|
46
48
|
}
|
|
47
49
|
const instructions = typeof native.developer_instructions === 'string' ? native.developer_instructions : '';
|
|
48
50
|
const state = {
|
|
51
|
+
evidence,
|
|
52
|
+
get readiness() {
|
|
53
|
+
return evidence.snapshot();
|
|
54
|
+
},
|
|
49
55
|
ready: false,
|
|
50
56
|
deadline: input.deadline,
|
|
51
57
|
config: {},
|
|
52
58
|
skillsConfig: input.skillsConfig,
|
|
53
59
|
fallback: () => {
|
|
60
|
+
evidence.connection('unavailable');
|
|
54
61
|
state.ready = false;
|
|
55
62
|
state.skillsConfig = input.skillsConfig.map((entry) => ({
|
|
56
63
|
...entry,
|
|
@@ -122,13 +129,14 @@ export class CodexSerena {
|
|
|
122
129
|
startup_timeout_ms: Math.max(1, input.deadline - Date.now()),
|
|
123
130
|
},
|
|
124
131
|
},
|
|
125
|
-
developer_instructions: `${instructions}\n<gestalt_serena_capability>\nSerena is bound to this workspace. Connection and listed tools do not prove language readiness.
|
|
132
|
+
developer_instructions: `${instructions}\n<gestalt_serena_capability>\nSerena is bound to this workspace. Connection and listed tools do not prove language readiness. Verify usable symbols on a current source file before semantic editing, and usable references before impact claims. Empty results remain unverified; use native current-source tools when permissions or semantic checks are unknown. Native session and child permissions and approvals apply. Plan mode prohibits edits. Do not switch projects or modes.\n${guidance}\n</gestalt_serena_capability>`,
|
|
126
133
|
};
|
|
127
134
|
state.skillsConfig = [
|
|
128
135
|
...input.skillsConfig.filter((entry) => entry.path !== skill.path),
|
|
129
136
|
{ path: skill.path, enabled: true },
|
|
130
137
|
];
|
|
131
138
|
state.ready = true;
|
|
139
|
+
evidence.connection('unknown');
|
|
132
140
|
}
|
|
133
141
|
catch {
|
|
134
142
|
state.fallback();
|
|
@@ -149,16 +157,21 @@ export class CodexSerena {
|
|
|
149
157
|
const server = result.data?.find((entry) => entry.name === serenaServerName);
|
|
150
158
|
if (server?.runtimeStatus === 'connected' &&
|
|
151
159
|
!server.toolsError &&
|
|
152
|
-
serenaTools.every((tool) => Object.hasOwn(server.tools ?? {}, tool)))
|
|
160
|
+
serenaTools.every((tool) => Object.hasOwn(server.tools ?? {}, tool))) {
|
|
161
|
+
state.evidence?.connection('ready');
|
|
153
162
|
return true;
|
|
154
|
-
|
|
163
|
+
}
|
|
164
|
+
if (server?.runtimeStatus !== 'starting') {
|
|
165
|
+
state.evidence?.connection('unavailable');
|
|
155
166
|
return false;
|
|
167
|
+
}
|
|
156
168
|
await beforeDeadline(new Promise((resolve) => setTimeout(resolve, 25)), state.deadline);
|
|
157
169
|
}
|
|
158
170
|
}
|
|
159
171
|
catch {
|
|
160
172
|
/* Optional connection failure must not prevent a session. */
|
|
161
173
|
}
|
|
174
|
+
state.evidence?.connection('unavailable');
|
|
162
175
|
return false;
|
|
163
176
|
}
|
|
164
177
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
import { parseMcpStartupFailure, parseMcpStartupStatus, startupIdentifier, startupServers, } from '../../../shared/contracts/mcp-startup-failure.js';
|
|
7
|
+
import { randomUUID } from 'node:crypto';
|
|
8
|
+
/**
|
|
9
|
+
* Codex 0.164.0 generated experimental schema: McpServerStatusUpdatedNotification.
|
|
10
|
+
* Upstream supplies error prose and one structured failure reason, but no child
|
|
11
|
+
* exit/signal or artifact identity. Never classify prose or treat app-server exit
|
|
12
|
+
* as an MCP child's exit. Legacy Mobile notifications remain compatible.
|
|
13
|
+
*/
|
|
14
|
+
export function decodeMcpStartupFailure(notification, correlation) {
|
|
15
|
+
if (!['mcpServer/startupStatus/updated', 'mcpServer/statusUpdated'].includes(notification.method ?? '') ||
|
|
16
|
+
!notification.params ||
|
|
17
|
+
typeof notification.params !== 'object' ||
|
|
18
|
+
Array.isArray(notification.params))
|
|
19
|
+
return undefined;
|
|
20
|
+
const params = notification.params;
|
|
21
|
+
if (params.status !== 'failed' && params.status !== 'cancelled')
|
|
22
|
+
return undefined;
|
|
23
|
+
return parseMcpStartupFailure({
|
|
24
|
+
...correlation,
|
|
25
|
+
schemaVersion: 1,
|
|
26
|
+
threadId: params.threadId ?? correlation.threadId,
|
|
27
|
+
serverName: params.name,
|
|
28
|
+
phase: 'startup',
|
|
29
|
+
code: params.status === 'cancelled'
|
|
30
|
+
? 'cancelled'
|
|
31
|
+
: params.failureReason === 'reauthenticationRequired'
|
|
32
|
+
? 'reauthentication-required'
|
|
33
|
+
: 'startup-failed',
|
|
34
|
+
exitCode: null,
|
|
35
|
+
signal: null,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/** Only callers that directly observed this boundary may supply local evidence. */
|
|
39
|
+
export function observedMcpStartupFailure(correlation, observation) {
|
|
40
|
+
return parseMcpStartupFailure({ ...correlation, ...observation, schemaVersion: 1 });
|
|
41
|
+
}
|
|
42
|
+
/** Bounded, process-local correlation. No upstream attempt ID is currently exposed. */
|
|
43
|
+
export class McpStartupTracker {
|
|
44
|
+
runtimeId = randomUUID();
|
|
45
|
+
attempts = new Map();
|
|
46
|
+
observe(notification) {
|
|
47
|
+
if (!['mcpServer/startupStatus/updated', 'mcpServer/statusUpdated'].includes(notification.method ?? '') ||
|
|
48
|
+
!notification.params ||
|
|
49
|
+
typeof notification.params !== 'object' ||
|
|
50
|
+
Array.isArray(notification.params))
|
|
51
|
+
return undefined;
|
|
52
|
+
const params = notification.params;
|
|
53
|
+
if (!startupServers.includes(params.name))
|
|
54
|
+
return undefined;
|
|
55
|
+
const status = params.status === 'connected' ? 'ready' : params.status;
|
|
56
|
+
if (!['starting', 'ready', 'failed', 'cancelled'].includes(String(status)))
|
|
57
|
+
return undefined;
|
|
58
|
+
const threadId = params.threadId == null ? null : startupIdentifier(params.threadId);
|
|
59
|
+
// Invalid identity is not permission to attach a child failure to the root.
|
|
60
|
+
if (params.threadId != null && !threadId)
|
|
61
|
+
return undefined;
|
|
62
|
+
const key = JSON.stringify([threadId, params.name]);
|
|
63
|
+
const before = this.attempts.get(key);
|
|
64
|
+
if (!before && this.attempts.size >= 256)
|
|
65
|
+
return undefined;
|
|
66
|
+
if (before?.status === status ||
|
|
67
|
+
(before?.failure && (status === 'failed' || status === 'cancelled')))
|
|
68
|
+
return undefined;
|
|
69
|
+
const observedAt = new Date().toISOString();
|
|
70
|
+
const attemptId = !before ||
|
|
71
|
+
(status === 'starting' && before.status !== 'starting') ||
|
|
72
|
+
(before.status === 'ready' && (status === 'failed' || status === 'cancelled'))
|
|
73
|
+
? randomUUID()
|
|
74
|
+
: before.attemptId;
|
|
75
|
+
const failure = decodeMcpStartupFailure(notification, {
|
|
76
|
+
failureId: randomUUID(),
|
|
77
|
+
attemptId,
|
|
78
|
+
occurredAt: observedAt,
|
|
79
|
+
runtimeId: this.runtimeId,
|
|
80
|
+
threadId,
|
|
81
|
+
});
|
|
82
|
+
const observation = parseMcpStartupStatus({
|
|
83
|
+
schemaVersion: 1,
|
|
84
|
+
runtimeId: this.runtimeId,
|
|
85
|
+
attemptId,
|
|
86
|
+
threadId,
|
|
87
|
+
serverName: params.name,
|
|
88
|
+
observedAt,
|
|
89
|
+
status,
|
|
90
|
+
failure: failure ?? null,
|
|
91
|
+
});
|
|
92
|
+
if (observation)
|
|
93
|
+
this.attempts.set(key, observation);
|
|
94
|
+
return observation;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -5,9 +5,77 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { countDiffLines } from '../../../shared/contracts/file-change.js';
|
|
7
7
|
import { relative } from 'node:path';
|
|
8
|
+
import { mcpStartupActivity, parseMcpStartupStatus, } from '../../../shared/contracts/mcp-startup-failure.js';
|
|
9
|
+
import { unknownReadiness, readinessLabel, repositoryLabel, semanticState, } from '../../../shared/contracts/retrieval-readiness.js';
|
|
8
10
|
export function normalizeCodexNotification(sessionId, sequence, occurredAt, notification, workspacePath, activeTurnId, origin = { kind: 'root' }) {
|
|
9
11
|
const connection = record(notification.params);
|
|
12
|
+
if (notification.method === 'gestalt/mcpStartup') {
|
|
13
|
+
const status = parseMcpStartupStatus(connection);
|
|
14
|
+
if (!status)
|
|
15
|
+
return null;
|
|
16
|
+
return {
|
|
17
|
+
sessionId,
|
|
18
|
+
sequence,
|
|
19
|
+
occurredAt: status.observedAt,
|
|
20
|
+
type: 'activity.updated',
|
|
21
|
+
payload: mcpStartupActivity(status),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (notification.method === 'gestalt/retrievalReadiness') {
|
|
25
|
+
const readiness = record(connection?.readiness);
|
|
26
|
+
const repository = record(readiness?.repository);
|
|
27
|
+
if (typeof connection?.runtimeId !== 'string' ||
|
|
28
|
+
!/^[a-zA-Z0-9-]{1,128}$/.test(connection.runtimeId) ||
|
|
29
|
+
typeof connection?.threadId !== 'string' ||
|
|
30
|
+
!/^[a-zA-Z0-9_.-]{1,128}$/.test(connection.threadId) ||
|
|
31
|
+
typeof repository?.id !== 'string' ||
|
|
32
|
+
!/^[a-f0-9]{64}$/.test(repository.id) ||
|
|
33
|
+
typeof repository.label !== 'string')
|
|
34
|
+
return null;
|
|
35
|
+
const observation = (value) => {
|
|
36
|
+
const observed = record(value);
|
|
37
|
+
if (!observed ||
|
|
38
|
+
!['ready', 'unknown', 'stale', 'unavailable'].includes(String(observed.state)) ||
|
|
39
|
+
typeof observed.generation !== 'string' ||
|
|
40
|
+
!/^[a-zA-Z0-9-]{1,128}$/.test(observed.generation) ||
|
|
41
|
+
typeof observed.observedAt !== 'string' ||
|
|
42
|
+
!Number.isFinite(Date.parse(observed.observedAt)))
|
|
43
|
+
return unknownReadiness().symbols;
|
|
44
|
+
return {
|
|
45
|
+
state: observed.state,
|
|
46
|
+
observedAt: observed.observedAt,
|
|
47
|
+
generation: observed.generation,
|
|
48
|
+
scope: 'source',
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const safe = {
|
|
52
|
+
...unknownReadiness(),
|
|
53
|
+
repository: { id: repository.id, label: repositoryLabel(repository.label) },
|
|
54
|
+
connection: observation(readiness?.connection),
|
|
55
|
+
symbols: observation(readiness?.symbols),
|
|
56
|
+
references: observation(readiness?.references),
|
|
57
|
+
};
|
|
58
|
+
const threadId = connection.threadId;
|
|
59
|
+
const compactLabel = safe.repository.label.length > 36
|
|
60
|
+
? `${safe.repository.label.slice(0, 35)}…`
|
|
61
|
+
: safe.repository.label;
|
|
62
|
+
return {
|
|
63
|
+
sessionId,
|
|
64
|
+
sequence,
|
|
65
|
+
occurredAt,
|
|
66
|
+
type: 'activity.updated',
|
|
67
|
+
payload: {
|
|
68
|
+
id: `gestalt-retrieval-${threadId}-${repository.id}`,
|
|
69
|
+
label: `Semantic checks · ${readinessLabel(semanticState(safe)).toLowerCase()}`,
|
|
70
|
+
detail: `${compactLabel} (${repository.id.slice(0, 8)}) · Symbols ${readinessLabel(safe.symbols.state)}; references ${readinessLabel(safe.references.state)}. Observed source only; compiler selection and repository index coverage are unverified.`,
|
|
71
|
+
repositoryReadiness: { threadId, readiness: safe },
|
|
72
|
+
runtimeId: connection.runtimeId,
|
|
73
|
+
...(activeTurnId ? { turnId: activeTurnId } : {}),
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
10
77
|
if (notification.method === 'mcpServer/statusUpdated' &&
|
|
78
|
+
!connection?.threadId &&
|
|
11
79
|
connection?.name === 'gestalt-xerj' &&
|
|
12
80
|
['failed', 'cancelled'].includes(String(connection.status))) {
|
|
13
81
|
return {
|
|
@@ -24,6 +92,7 @@ export function normalizeCodexNotification(sessionId, sequence, occurredAt, noti
|
|
|
24
92
|
};
|
|
25
93
|
}
|
|
26
94
|
if (notification.method === 'mcpServer/statusUpdated' &&
|
|
95
|
+
!connection?.threadId &&
|
|
27
96
|
connection?.name === 'gestalt-serena' &&
|
|
28
97
|
['connected', 'failed', 'cancelled'].includes(String(connection.status))) {
|
|
29
98
|
const connected = connection.status === 'connected';
|
|
@@ -22,6 +22,7 @@ import { WriterAcquisitionError, } from '../../features/sessions/application/wri
|
|
|
22
22
|
import { CodexJsonRpcError, isCodexThreadWriterBusy, isMissingCodexThreadRollout, } from './json-rpc-client.js';
|
|
23
23
|
import { resolvedServerRequestId } from './server-request.js';
|
|
24
24
|
import { xerjDeadline } from '../retrieval/managed-xerj.js';
|
|
25
|
+
import { McpStartupTracker } from './mcp-startup-failure.js';
|
|
25
26
|
/** Sticky thread config keeps skill paths out of the app-server process argv. */
|
|
26
27
|
export function threadSkillConfig(skillsConfig, modelConfig = {}) {
|
|
27
28
|
const conditional = modelConfig.skills?.config ?? [];
|
|
@@ -61,6 +62,7 @@ class SessionResource {
|
|
|
61
62
|
completedProcessActions = new Map();
|
|
62
63
|
turnThreads = new Map();
|
|
63
64
|
childThreads = new Set();
|
|
65
|
+
mcpStartup = new McpStartupTracker();
|
|
64
66
|
constructor(sessionId, process, skillsConfig, modelConfig, planStatusLease, planMeasurementToken, unregister, onDisposed) {
|
|
65
67
|
this.sessionId = sessionId;
|
|
66
68
|
this.process = process;
|
|
@@ -74,6 +76,7 @@ class SessionResource {
|
|
|
74
76
|
retrieval;
|
|
75
77
|
retrievalFailureReported = false;
|
|
76
78
|
capabilityFailuresReported = new Set();
|
|
79
|
+
readinessPublished = new Map();
|
|
77
80
|
readinessDeadline = xerjDeadline();
|
|
78
81
|
dispose() {
|
|
79
82
|
if (this.disposed)
|
|
@@ -160,6 +163,25 @@ export class CodexSessionRuntime {
|
|
|
160
163
|
historyReads = new Map();
|
|
161
164
|
childTopologyReads = new Map();
|
|
162
165
|
writerAcquisitions = new Map();
|
|
166
|
+
/** Current runtime observations only; durable workspace selection is never rewritten. */
|
|
167
|
+
async readRetrievalReadiness(sessionId) {
|
|
168
|
+
const resource = this.sessions.get(sessionId);
|
|
169
|
+
if (!resource?.active || !resource.threadId || !resource.retrieval)
|
|
170
|
+
return null;
|
|
171
|
+
const current = () => resource.active && this.sessions.get(sessionId) === resource;
|
|
172
|
+
const repositories = (await resource.retrieval.repositories?.snapshot(resource.process.rpc, resource.threadId, current)) ?? [];
|
|
173
|
+
if (!current())
|
|
174
|
+
return null;
|
|
175
|
+
return {
|
|
176
|
+
runtimeId: resource.retrieval.repositories?.runtimeId ?? null,
|
|
177
|
+
observedAt: new Date().toISOString(),
|
|
178
|
+
connections: (resource.retrieval.capabilities ?? []).map(({ serverName, readiness }) => ({
|
|
179
|
+
serverName,
|
|
180
|
+
readiness,
|
|
181
|
+
})),
|
|
182
|
+
repositories,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
163
185
|
async start(session, now) {
|
|
164
186
|
const resource = await this.createResource(session);
|
|
165
187
|
try {
|
|
@@ -1130,6 +1152,46 @@ export class CodexSessionRuntime {
|
|
|
1130
1152
|
const notificationUnsubscribe = process.rpc.onNotification((notification) => {
|
|
1131
1153
|
if (!resource.active)
|
|
1132
1154
|
return;
|
|
1155
|
+
// Internal evidence may only be constructed by this resource's tracker.
|
|
1156
|
+
if (notification.method === 'gestalt/mcpStartup')
|
|
1157
|
+
return;
|
|
1158
|
+
this.publishMcpStartup(resource, notification);
|
|
1159
|
+
// Current Codex renamed the legacy notification without adding child telemetry.
|
|
1160
|
+
if (notification.method === 'mcpServer/startupStatus/updated')
|
|
1161
|
+
notification = { ...notification, method: 'mcpServer/statusUpdated' };
|
|
1162
|
+
if (resource.retrieval?.repositories) {
|
|
1163
|
+
void resource.retrieval.repositories
|
|
1164
|
+
.observe(resource.process.rpc, resource.threadId ?? '', notification, () => resource.active && this.sessions.get(session.id) === resource)
|
|
1165
|
+
.then(() => {
|
|
1166
|
+
if (!resource.active ||
|
|
1167
|
+
this.sessions.get(session.id) !== resource ||
|
|
1168
|
+
!['item/completed', 'thread/settings/updated', 'mcpServer/statusUpdated'].includes(notification.method))
|
|
1169
|
+
return;
|
|
1170
|
+
for (const observed of resource.retrieval?.repositories?.peek() ?? []) {
|
|
1171
|
+
const repository = observed.readiness.repository;
|
|
1172
|
+
if (!repository)
|
|
1173
|
+
continue;
|
|
1174
|
+
const key = `${observed.threadId}:${repository.id}`;
|
|
1175
|
+
const state = JSON.stringify([
|
|
1176
|
+
observed.readiness.symbols.state,
|
|
1177
|
+
observed.readiness.references.state,
|
|
1178
|
+
]);
|
|
1179
|
+
if (resource.readinessPublished.get(key) === state)
|
|
1180
|
+
continue;
|
|
1181
|
+
resource.readinessPublished.set(key, state);
|
|
1182
|
+
this.onNotification?.(session.id, {
|
|
1183
|
+
method: 'gestalt/retrievalReadiness',
|
|
1184
|
+
params: { ...observed, runtimeId: resource.retrieval?.repositories?.runtimeId },
|
|
1185
|
+
}, {
|
|
1186
|
+
kind: observed.threadId === resource.threadId ? 'root' : 'child',
|
|
1187
|
+
physicalThreadId: observed.threadId,
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
})
|
|
1191
|
+
.catch(() => {
|
|
1192
|
+
/* Optional observations must not interrupt the owning turn. */
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1133
1195
|
if (notification.method === 'thread/settings/updated' ||
|
|
1134
1196
|
notification.method === 'turn/started') {
|
|
1135
1197
|
const threadId = boundedString(asRecord(notification.params)?.threadId, 256);
|
|
@@ -1140,13 +1202,15 @@ export class CodexSessionRuntime {
|
|
|
1140
1202
|
}
|
|
1141
1203
|
if (notification.method === 'mcpServer/statusUpdated') {
|
|
1142
1204
|
const status = notification.params;
|
|
1143
|
-
if (
|
|
1205
|
+
if (!asRecord(notification.params)?.threadId &&
|
|
1206
|
+
status?.name === 'gestalt-serena' &&
|
|
1144
1207
|
['failed', 'cancelled'].includes(status.status ?? '')) {
|
|
1145
1208
|
if (resource.capabilityFailuresReported.has(status.name))
|
|
1146
1209
|
return;
|
|
1147
1210
|
resource.capabilityFailuresReported.add(status.name);
|
|
1148
1211
|
}
|
|
1149
|
-
if (
|
|
1212
|
+
if (!asRecord(notification.params)?.threadId &&
|
|
1213
|
+
status?.name === 'gestalt-xerj' &&
|
|
1150
1214
|
['failed', 'cancelled'].includes(status.status ?? '')) {
|
|
1151
1215
|
if (resource.retrievalFailureReported)
|
|
1152
1216
|
return;
|
|
@@ -1167,7 +1231,10 @@ export class CodexSessionRuntime {
|
|
|
1167
1231
|
// The notification callback reconciles the durable interaction record.
|
|
1168
1232
|
pending?.reject(new Error('CODEX_SERVER_REQUEST_CLEARED'));
|
|
1169
1233
|
}
|
|
1170
|
-
this.onNotification?.(session.id, notification,
|
|
1234
|
+
this.onNotification?.(session.id, notification, {
|
|
1235
|
+
...this.resolveNotificationOrigin(resource, notification),
|
|
1236
|
+
runtimeId: resource.mcpStartup.runtimeId,
|
|
1237
|
+
});
|
|
1171
1238
|
});
|
|
1172
1239
|
const requestUnsubscribe = process.rpc.onServerRequest((request) => this.holdServerRequest(resource, request));
|
|
1173
1240
|
const responseUnsubscribe = process.rpc.onServerResponseSettled?.((settlement) => {
|
|
@@ -1233,6 +1300,10 @@ export class CodexSessionRuntime {
|
|
|
1233
1300
|
this.reportCapabilityFailures(resource, session);
|
|
1234
1301
|
if (state.diagnostic && !resource.retrievalFailureReported) {
|
|
1235
1302
|
resource.retrievalFailureReported = true;
|
|
1303
|
+
this.publishMcpStartup(resource, {
|
|
1304
|
+
method: 'mcpServer/statusUpdated',
|
|
1305
|
+
params: { name: 'gestalt-xerj', status: 'failed' },
|
|
1306
|
+
});
|
|
1236
1307
|
this.onNotification?.(session.id, {
|
|
1237
1308
|
method: 'mcpServer/statusUpdated',
|
|
1238
1309
|
params: { name: 'gestalt-xerj', status: 'failed' },
|
|
@@ -1244,6 +1315,10 @@ export class CodexSessionRuntime {
|
|
|
1244
1315
|
if (!capability.diagnostic || resource.capabilityFailuresReported.has(capability.serverName))
|
|
1245
1316
|
continue;
|
|
1246
1317
|
resource.capabilityFailuresReported.add(capability.serverName);
|
|
1318
|
+
this.publishMcpStartup(resource, {
|
|
1319
|
+
method: 'mcpServer/statusUpdated',
|
|
1320
|
+
params: { name: capability.serverName, status: 'failed' },
|
|
1321
|
+
});
|
|
1247
1322
|
this.onNotification?.(session.id, {
|
|
1248
1323
|
method: 'mcpServer/statusUpdated',
|
|
1249
1324
|
params: { name: capability.serverName, status: 'failed' },
|
|
@@ -1255,17 +1330,26 @@ export class CodexSessionRuntime {
|
|
|
1255
1330
|
if (!state?.ready || !resource.threadId || !this.retrieval)
|
|
1256
1331
|
return;
|
|
1257
1332
|
if (await this.retrieval.verify(resource.process.rpc, resource.threadId, state)) {
|
|
1258
|
-
if (state.capabilities?.some((capability) => capability.serverName === 'gestalt-serena' && capability.ready))
|
|
1333
|
+
if (state.capabilities?.some((capability) => capability.serverName === 'gestalt-serena' && capability.ready)) {
|
|
1334
|
+
this.publishMcpStartup(resource, {
|
|
1335
|
+
method: 'mcpServer/statusUpdated',
|
|
1336
|
+
params: { name: 'gestalt-serena', status: 'connected' },
|
|
1337
|
+
});
|
|
1259
1338
|
this.onNotification?.(session.id, {
|
|
1260
1339
|
method: 'mcpServer/statusUpdated',
|
|
1261
1340
|
params: { name: 'gestalt-serena', status: 'connected' },
|
|
1262
1341
|
}, { kind: 'root' });
|
|
1342
|
+
}
|
|
1263
1343
|
return;
|
|
1264
1344
|
}
|
|
1265
1345
|
state.fallback();
|
|
1266
1346
|
this.reportCapabilityFailures(resource, session);
|
|
1267
1347
|
if (!state.capabilities && !resource.retrievalFailureReported) {
|
|
1268
1348
|
resource.retrievalFailureReported = true;
|
|
1349
|
+
this.publishMcpStartup(resource, {
|
|
1350
|
+
method: 'mcpServer/statusUpdated',
|
|
1351
|
+
params: { name: 'gestalt-xerj', status: 'failed' },
|
|
1352
|
+
});
|
|
1269
1353
|
this.onNotification?.(session.id, {
|
|
1270
1354
|
method: 'mcpServer/statusUpdated',
|
|
1271
1355
|
params: {
|
|
@@ -1294,6 +1378,19 @@ export class CodexSessionRuntime {
|
|
|
1294
1378
|
...this.permissionParams(session),
|
|
1295
1379
|
});
|
|
1296
1380
|
}
|
|
1381
|
+
publishMcpStartup(resource, notification) {
|
|
1382
|
+
const status = resource.mcpStartup.observe(notification);
|
|
1383
|
+
if (!status)
|
|
1384
|
+
return;
|
|
1385
|
+
this.onNotification?.(resource.sessionId, { method: 'gestalt/mcpStartup', params: status }, {
|
|
1386
|
+
kind: status.threadId === resource.threadId
|
|
1387
|
+
? 'root'
|
|
1388
|
+
: status.threadId && resource.childThreads.has(status.threadId)
|
|
1389
|
+
? 'child'
|
|
1390
|
+
: 'unknown',
|
|
1391
|
+
...(status.threadId ? { physicalThreadId: status.threadId } : {}),
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1297
1394
|
resolveNotificationOrigin(resource, notification) {
|
|
1298
1395
|
const params = asRecord(notification.params);
|
|
1299
1396
|
if (!params)
|