ftown-bridge 0.30.70 → 0.30.72
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/attention-cli.d.ts +1 -0
- package/dist/attention-cli.js +3 -1
- package/dist/attention-cli.js.map +1 -1
- package/dist/centrifugo-client.d.ts +1 -0
- package/dist/centrifugo-client.js +18 -13
- package/dist/centrifugo-client.js.map +1 -1
- package/dist/cli-client.d.ts +2 -0
- package/dist/cli-client.js +19 -0
- package/dist/cli-client.js.map +1 -1
- package/dist/coordination/attention-routing.d.ts +1 -0
- package/dist/coordination/attention-routing.js +44 -30
- package/dist/coordination/attention-routing.js.map +1 -1
- package/dist/coordination/board.d.ts +2 -0
- package/dist/coordination/board.js +34 -17
- package/dist/coordination/board.js.map +1 -1
- package/dist/coordination/contract-c.d.ts +1 -0
- package/dist/coordination/contract-c.js.map +1 -1
- package/dist/coordination/contract.d.ts +6 -1
- package/dist/coordination/contract.js +1 -1
- package/dist/coordination/contract.js.map +1 -1
- package/dist/coordination/peer-team.d.ts +44 -0
- package/dist/coordination/peer-team.js +77 -0
- package/dist/coordination/peer-team.js.map +1 -0
- package/dist/coordination/plan.d.ts +5 -3
- package/dist/coordination/plan.js +79 -49
- package/dist/coordination/plan.js.map +1 -1
- package/dist/coordination/tree-events.js +14 -4
- package/dist/coordination/tree-events.js.map +1 -1
- package/dist/coordination/wiring.d.ts +6 -1
- package/dist/coordination/wiring.js +30 -12
- package/dist/coordination/wiring.js.map +1 -1
- package/dist/create-ftown-session.d.ts +8 -3
- package/dist/create-ftown-session.js +44 -22
- package/dist/create-ftown-session.js.map +1 -1
- package/dist/harness-commands.js +11 -8
- package/dist/harness-commands.js.map +1 -1
- package/dist/index.js +122 -70
- package/dist/index.js.map +1 -1
- package/dist/local-api-server.d.ts +12 -1
- package/dist/local-api-server.js +249 -26
- package/dist/local-api-server.js.map +1 -1
- package/dist/mail-delivery.d.ts +1 -0
- package/dist/mail-delivery.js +3 -0
- package/dist/mail-delivery.js.map +1 -1
- package/dist/peer-control.d.ts +2 -2
- package/dist/peer-control.js +3 -1
- package/dist/peer-control.js.map +1 -1
- package/dist/peer-link.d.ts +3 -0
- package/dist/peer-link.js +18 -9
- package/dist/peer-link.js.map +1 -1
- package/dist/peer-session-cache.d.ts +144 -1
- package/dist/peer-session-cache.js +61 -7
- package/dist/peer-session-cache.js.map +1 -1
- package/dist/project-board-commands.d.ts +2 -0
- package/dist/project-board-commands.js +18 -1
- package/dist/project-board-commands.js.map +1 -1
- package/dist/project-board-store.d.ts +4 -0
- package/dist/project-board-store.js +53 -16
- package/dist/project-board-store.js.map +1 -1
- package/dist/project-cli.js +35 -10
- package/dist/project-cli.js.map +1 -1
- package/dist/project-directory-protocol.d.ts +3 -1
- package/dist/project-directory-protocol.js +3 -1
- package/dist/project-directory-protocol.js.map +1 -1
- package/dist/project-storage-move.d.ts +30 -0
- package/dist/project-storage-move.js +421 -0
- package/dist/project-storage-move.js.map +1 -0
- package/dist/remote-child-plan.d.ts +23 -0
- package/dist/remote-child-plan.js +68 -0
- package/dist/remote-child-plan.js.map +1 -0
- package/dist/security/bridge/permissions.js +9 -1
- package/dist/security/bridge/permissions.js.map +1 -1
- package/dist/security/bridge/security.js +1 -1
- package/dist/security/bridge/security.js.map +1 -1
- package/dist/session-block.d.ts +2 -0
- package/dist/session-block.js +7 -2
- package/dist/session-block.js.map +1 -1
- package/dist/session-board-snapshot.d.ts +1 -1
- package/dist/session-controller.d.ts +3 -2
- package/dist/session-controller.js +35 -16
- package/dist/session-controller.js.map +1 -1
- package/dist/session-handoff.d.ts +1 -0
- package/dist/session-handoff.js +2 -1
- package/dist/session-handoff.js.map +1 -1
- package/dist/session-parent.d.ts +13 -4
- package/dist/session-parent.js +51 -9
- package/dist/session-parent.js.map +1 -1
- package/dist/sessions-commands.js +32 -23
- package/dist/sessions-commands.js.map +1 -1
- package/dist/ticket-notifications.js +5 -3
- package/dist/ticket-notifications.js.map +1 -1
- package/dist/wire-types.d.ts +1 -0
- package/dist/wire-types.js.map +1 -1
- package/package.json +2 -2
- package/skills/ftown/SKILL.md +2 -2
- package/skills/ftown/references/orchestrator.md +1 -1
- package/skills/ftown/references/sessions.md +18 -5
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ import { DirectPeerManager } from './direct-transport/peer-manager.js';
|
|
|
17
17
|
import { PublishRouter } from './direct-transport/publish-router.js';
|
|
18
18
|
import { LoopbackPeerServer } from './direct-transport/loopback-server.js';
|
|
19
19
|
import { ProcessRunner } from './claude-runner.js';
|
|
20
|
+
import { ProjectStorageMoves } from './project-storage-move.js';
|
|
20
21
|
import { ProjectBoardStore, sessionBlocksTicket } from './project-board-store.js';
|
|
21
22
|
import { SessionStore } from './session-store.js';
|
|
22
23
|
import { MailStore } from './mail-store.js';
|
|
@@ -26,7 +27,8 @@ import { BridgePushNotifier } from './push-notifier.js';
|
|
|
26
27
|
import { LocalApiServer } from './local-api-server.js';
|
|
27
28
|
import { parsePeerSessions, startPeerSessionCache, startPeerProjectDirectory } from './peer-session-cache.js';
|
|
28
29
|
import { hostResourceSampler } from './host-resources.js';
|
|
29
|
-
import { parseRemoteParent, sessionRequestPrincipal } from './session-parent.js';
|
|
30
|
+
import { hasPendingChild, parseRemoteParent, sessionRequestPrincipal, SessionHierarchyWrites } from './session-parent.js';
|
|
31
|
+
import { remoteChildPlanStore, remotePlanBlocksHandoff } from './remote-child-plan.js';
|
|
30
32
|
import { PeerControl } from './peer-control.js';
|
|
31
33
|
import { PeerLinks } from './peer-link.js';
|
|
32
34
|
import { launchCapabilities, probeLaunchCapabilities } from './harness-registry.js';
|
|
@@ -48,6 +50,7 @@ import { PullRequestStatusService } from './pull-request-status.js';
|
|
|
48
50
|
import { createPrReviewService } from './pull-request-review.js';
|
|
49
51
|
import { PullRequestEventWatcher } from './pull-request-events.js';
|
|
50
52
|
import { createSessionBoardPublisher, liveSessionBoardRoots } from './session-board-snapshot.js';
|
|
53
|
+
import { PeerTeamOutbox } from './coordination/peer-team.js';
|
|
51
54
|
import { createCoordination } from './coordination/wiring.js';
|
|
52
55
|
import { removeFtownSession } from './remove-ftown-session.js';
|
|
53
56
|
import { SessionResurrection, shouldResurrectStoredSession } from './session-resurrection.js';
|
|
@@ -853,8 +856,15 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
853
856
|
const mailStore = new MailStore((sessionId) => store.sessionDir(sessionId));
|
|
854
857
|
localApiServer.setMailStore(mailStore);
|
|
855
858
|
const pullRequestStatuses = new PullRequestStatusService();
|
|
859
|
+
let teamOutbox;
|
|
860
|
+
let remoteChildren = async () => [];
|
|
856
861
|
const coordination = createCoordination({
|
|
857
862
|
store,
|
|
863
|
+
remotePlanLifecycle: async (child, action) => teamOutbox.plan(child, action),
|
|
864
|
+
remoteEvent: (child, event) => teamOutbox.event(child, event),
|
|
865
|
+
remoteParentRunning: (child) => localApiServer.managerCanAnswer(child),
|
|
866
|
+
remoteChildren: id => remoteChildren(id),
|
|
867
|
+
remoteResultSender: (id, manager) => localApiServer.remoteResultSender(id, manager),
|
|
858
868
|
attention: attentionStore,
|
|
859
869
|
prStatus: async (url) => (await pullRequestStatuses.get([url])).statuses[0] ?? null,
|
|
860
870
|
prStatusFresh: (url) => pullRequestStatuses.getFresh(url),
|
|
@@ -884,7 +894,7 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
884
894
|
boardPublisher.schedule(rootId);
|
|
885
895
|
bootstrapBoardRoots.clear();
|
|
886
896
|
const stopBoardObserver = centrifugo.onLocalPublication(boardPublisher.observePublication);
|
|
887
|
-
localApiServer.setCoordination(coordination);
|
|
897
|
+
localApiServer.setCoordination(coordination, scheduleBoard);
|
|
888
898
|
const stopPushSessionObserver = centrifugo.onLocalPublication((channel, data) => {
|
|
889
899
|
if (channel !== `sessions:updates#${userId}` || !data || typeof data !== 'object')
|
|
890
900
|
return;
|
|
@@ -925,7 +935,10 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
925
935
|
}),
|
|
926
936
|
});
|
|
927
937
|
const peerControl = new PeerControl(security, centrifugo, peerLinks);
|
|
938
|
+
teamOutbox = new PeerTeamOutbox(join(dataDir, 'team-outbox-' + security.endpoint.id + '.sqlite'), peerControl);
|
|
939
|
+
const hierarchyWrites = new SessionHierarchyWrites();
|
|
928
940
|
const sessionFactoryDeps = {
|
|
941
|
+
hierarchyWrites,
|
|
929
942
|
loadRemoteParent: async (owner, id) => {
|
|
930
943
|
const actor = sessionRequestPrincipal.getStore();
|
|
931
944
|
if (actor && !security.permitsPeerLookup(actor))
|
|
@@ -945,9 +958,10 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
945
958
|
const result = await peerControl.http(peer.bridgeId, 'GET', '/api/sessions');
|
|
946
959
|
if (result.status !== 200)
|
|
947
960
|
throw new Error('Cannot verify children on peer bridge');
|
|
948
|
-
return parsePeerSessions(result.body, peer.bridgeId)
|
|
961
|
+
return hasPendingChild(result.body, bridgeId, id) || parsePeerSessions(result.body, peer.bridgeId)
|
|
962
|
+
.some(row => row.parentSessionId === id && (row.parentBridgeId ?? row.bridgeId) === bridgeId);
|
|
949
963
|
}));
|
|
950
|
-
return snapshots.some(
|
|
964
|
+
return snapshots.some(Boolean);
|
|
951
965
|
},
|
|
952
966
|
store,
|
|
953
967
|
updateAdmission,
|
|
@@ -961,6 +975,8 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
961
975
|
wireTerminalInput,
|
|
962
976
|
getTerminalSize: (sid) => terminalManager.getSize(sid),
|
|
963
977
|
planStore: coordination.plan,
|
|
978
|
+
remotePlanStore: owner => remoteChildPlanStore(peerControl, owner),
|
|
979
|
+
releaseRemotePlan: child => teamOutbox.plan(child, 'release'),
|
|
964
980
|
isWsl2,
|
|
965
981
|
};
|
|
966
982
|
localApiServer.setSessionFactory(sessionFactoryDeps);
|
|
@@ -992,7 +1008,9 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
992
1008
|
loadTerminalLog: (id) => store.loadTerminalLog(id),
|
|
993
1009
|
loadActivity: async (id) => (await attentionStore.list(id, { limit: 1 })).activity.state,
|
|
994
1010
|
listMail: async (sessionId) => (await mailStore.listAll(sessionId, 0)).map((message) => ({ from: message.from, type: message.type })),
|
|
995
|
-
|
|
1011
|
+
loadParent: child => localApiServer.loadManager(child),
|
|
1012
|
+
remoteResultReported: child => localApiServer.remoteResultReported(child),
|
|
1013
|
+
acceptMail: (parent, body) => localApiServer.mailManager(parent, body),
|
|
996
1014
|
recordAttention: async (sessionId, input) => {
|
|
997
1015
|
const item = await attentionStore.record(sessionId, 'Notification', {
|
|
998
1016
|
notification_type: 'agent_needs_input',
|
|
@@ -1170,6 +1188,7 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
1170
1188
|
}).finally(release);
|
|
1171
1189
|
});
|
|
1172
1190
|
let ready = false;
|
|
1191
|
+
let shutdownRun;
|
|
1173
1192
|
const modelRouting = createRealModelRoutingService(homedir());
|
|
1174
1193
|
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
1175
1194
|
const stopHandoffSession = async (id) => {
|
|
@@ -1187,37 +1206,64 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
1187
1206
|
}
|
|
1188
1207
|
throw new Error(`old tmux session ${id} is still running; handoff was not started`);
|
|
1189
1208
|
};
|
|
1190
|
-
const runHandoff = (sessionId, request) =>
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
+
const runHandoff = async (sessionId, request) => {
|
|
1210
|
+
const release = hierarchyWrites.begin(sessionId);
|
|
1211
|
+
try {
|
|
1212
|
+
return await handoffSession({
|
|
1213
|
+
loadSession: (id) => store.loadSession(id),
|
|
1214
|
+
saveSession: (session) => store.saveSession(session),
|
|
1215
|
+
publishSession: (session) => centrifugo.publishSessionUpdate(userId, session),
|
|
1216
|
+
createSession: (input) => createFtownSession(sessionFactoryDeps, input),
|
|
1217
|
+
checkHierarchy: async (session) => {
|
|
1218
|
+
const pending = hierarchyWrites.pendingParents().some(p => p.bridgeId === bridgeId && p.id === session.id);
|
|
1219
|
+
const local = await store.listSessions();
|
|
1220
|
+
if (pending || local.some(s => s.parentSessionId === session.id && (s.parentBridgeId ?? s.bridgeId) === session.bridgeId)
|
|
1221
|
+
|| await sessionFactoryDeps.hasRemoteChildren(session.id))
|
|
1222
|
+
throw new Error('Hand off the child sessions before their manager');
|
|
1223
|
+
if (await remotePlanBlocksHandoff(peerControl, session))
|
|
1224
|
+
throw new Error('Release the active plan item on the parent bridge before handoff');
|
|
1225
|
+
},
|
|
1226
|
+
stopSession: stopHandoffSession,
|
|
1227
|
+
isSessionHealthy: (id) => waitForSessionHealthy(async () => {
|
|
1228
|
+
const session = await store.loadSession(id);
|
|
1229
|
+
return { status: session?.status, processActive: runner.isRunning(id) };
|
|
1230
|
+
}),
|
|
1231
|
+
archiveSession: async (id) => {
|
|
1232
|
+
const result = await sessionController.remove(id, undefined, 'keep');
|
|
1233
|
+
if (!result.removed)
|
|
1234
|
+
throw new Error(`could not archive session ${id}`);
|
|
1235
|
+
},
|
|
1236
|
+
plan: coordination.plan,
|
|
1237
|
+
loadTerminalLog: (id) => store.loadTerminalLog(id),
|
|
1238
|
+
routing: modelRouting,
|
|
1239
|
+
}, sessionId, request);
|
|
1240
|
+
}
|
|
1241
|
+
finally {
|
|
1242
|
+
release();
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1209
1245
|
localApiServer.setHandoff(runHandoff);
|
|
1210
1246
|
const projectBoards = new ProjectBoardStore(dataDir, bridgeId);
|
|
1211
|
-
const peerCache = await startPeerSessionCache(peerControl, join(dataDir, "peer-sessions-" + security.endpoint.id + ".json")
|
|
1247
|
+
const peerCache = await startPeerSessionCache(peerControl, join(dataDir, "peer-sessions-" + security.endpoint.id + ".json"), rows => {
|
|
1248
|
+
for (const id of new Set(rows.filter(row => row.parentBridgeId === bridgeId).map(row => row.parentSessionId))) {
|
|
1249
|
+
if (id)
|
|
1250
|
+
scheduleBoard(id);
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
remoteChildren = async (managerId) => (await peerCache.list()).flatMap(child => child.parentSessionId === managerId && child.parentBridgeId === bridgeId && child.status !== 'disconnected'
|
|
1254
|
+
? [{ ...child, status: child.status }] : []);
|
|
1212
1255
|
const projectDirectory = await startPeerProjectDirectory(peerControl, join(dataDir, "peer-projects-" + security.endpoint.id + ".json"));
|
|
1256
|
+
const storageMoves = new ProjectStorageMoves(dataDir, bridgeId, projectBoards, peerControl, projectDirectory.rememberMove);
|
|
1213
1257
|
localApiServer.setLocalProjects(() => projectBoards.list());
|
|
1214
1258
|
const findDiscussionSession = (origin, id) => discussionSession(bridgeId, sid => store.loadSession(sid), peerControl, origin, id);
|
|
1215
|
-
localApiServer.setBoardCommands({ discussionSession: findDiscussionSession, bridgeId, security, projectBoards, rememberedProjects: projectDirectory.list, observeProject,
|
|
1259
|
+
localApiServer.setBoardCommands({ discussionSession: findDiscussionSession, bridgeId, security, projectBoards, storageMoves, rememberedProjects: projectDirectory.list, observeProject,
|
|
1216
1260
|
ready: () => ready && !updateAdmission.isFrozen, deliverProject });
|
|
1217
1261
|
const ticketInbox = new TicketNotificationInbox(join(dataDir, 'ticket-inboxes', security.endpoint.id + '.sqlite'), bridgeId);
|
|
1218
1262
|
localApiServer.setTicketInbox(ticketInbox);
|
|
1219
1263
|
const deliveries = new Map();
|
|
1220
1264
|
function deliverProject(id) {
|
|
1265
|
+
if (!ready)
|
|
1266
|
+
return Promise.resolve(); // Unsent outbox records are retried on the next start.
|
|
1221
1267
|
const current = deliveries.get(id);
|
|
1222
1268
|
if (current)
|
|
1223
1269
|
return current;
|
|
@@ -1281,6 +1327,7 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
1281
1327
|
if (!projects.length)
|
|
1282
1328
|
return;
|
|
1283
1329
|
await Promise.all(projects.map(async ({ id }) => {
|
|
1330
|
+
storageMoves.recover(id);
|
|
1284
1331
|
try {
|
|
1285
1332
|
await observeProject(id);
|
|
1286
1333
|
}
|
|
@@ -1293,7 +1340,8 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
1293
1340
|
const ticketTimer = setInterval(() => {
|
|
1294
1341
|
if (!ready || updateAdmission.isFrozen)
|
|
1295
1342
|
return;
|
|
1296
|
-
|
|
1343
|
+
void teamOutbox.flush().catch(err => console.warn('[Bridge] Failed to refresh team notifications:', err));
|
|
1344
|
+
maintenance ??= Promise.all([refreshProjects(), coordination.escalateOrphanedParentItems()]).then(() => { }).catch(() => console.error('[Bridge] Could not refresh project boards'))
|
|
1297
1345
|
.finally(() => { maintenance = undefined; });
|
|
1298
1346
|
}, 30_000);
|
|
1299
1347
|
ticketTimer.unref();
|
|
@@ -1311,7 +1359,7 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
1311
1359
|
return { type: 'command_response', response: { requestId: route.requestId, success: true } };
|
|
1312
1360
|
}
|
|
1313
1361
|
let result;
|
|
1314
|
-
await createCommandHandler({ bridgeId, hostResources, projectBoards, rememberedProjects: projectDirectory.list,
|
|
1362
|
+
await createCommandHandler({ bridgeId, hostResources, projectBoards, storageMoves, rememberedProjects: projectDirectory.list,
|
|
1315
1363
|
discussionSession: findDiscussionSession, observeProject, security, sessionController, attentionStore, updates, updateEffects, pullRequestStatuses,
|
|
1316
1364
|
directAddress: () => addressed?.address() ?? null, pullRequestReview,
|
|
1317
1365
|
modelRouting: () => modelRouting,
|
|
@@ -1325,7 +1373,7 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
1325
1373
|
})(message.application.data, message);
|
|
1326
1374
|
if (route.command === 'mutate_project_discussion' || route.command === 'mutate_project_board' || route.command === 'get_project_board') {
|
|
1327
1375
|
const payload = message.application.data?.payload;
|
|
1328
|
-
if (result?.success && typeof payload?.projectId === 'string')
|
|
1376
|
+
if (result?.success && payload?.action !== 'move_project' && typeof payload?.projectId === 'string')
|
|
1329
1377
|
void deliverProject(payload.projectId);
|
|
1330
1378
|
}
|
|
1331
1379
|
return applicationJson({ type: 'command_response', response: result ?? { requestId: route.requestId, success: false, error: 'bridge_error' } });
|
|
@@ -1355,8 +1403,9 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
1355
1403
|
throw new BridgeStartingError();
|
|
1356
1404
|
return localApiServer.dispatchSecure(message);
|
|
1357
1405
|
}, updateEffects);
|
|
1358
|
-
|
|
1359
|
-
|
|
1406
|
+
let startupWork;
|
|
1407
|
+
const startupTimer = setTimeout(() => {
|
|
1408
|
+
startupWork = (async () => {
|
|
1360
1409
|
if (!updateRestart) {
|
|
1361
1410
|
ready = true;
|
|
1362
1411
|
console.log('[Bridge] Ready and listening for commands');
|
|
@@ -1370,6 +1419,8 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
1370
1419
|
}
|
|
1371
1420
|
try {
|
|
1372
1421
|
await resurrection.resurrectSessions();
|
|
1422
|
+
if (shutdownRun)
|
|
1423
|
+
return;
|
|
1373
1424
|
resurrectionComplete = true;
|
|
1374
1425
|
// Start-up sweep: parents already dead (or removed) before this
|
|
1375
1426
|
// bridge started never hit resurrection's dead path, so escalate
|
|
@@ -1380,12 +1431,14 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
1380
1431
|
await attentionStore.restoreIdleNotifications(knownSessions
|
|
1381
1432
|
.filter(session => session.status === 'running' && session.shellType !== 'shell')
|
|
1382
1433
|
.map(session => session.id));
|
|
1383
|
-
if (updateRestart) {
|
|
1434
|
+
if (updateRestart && !shutdownRun) {
|
|
1384
1435
|
if (!bridgePointerPublished)
|
|
1385
1436
|
throw new Error('Update restart pointer unavailable');
|
|
1386
1437
|
if (!opts.local)
|
|
1387
1438
|
await centrifugo.waitUntilSecureCommandsReady(45_000);
|
|
1388
1439
|
await finishUpdateRestartAdmission(updateAdmission, () => reportUpdateReady({ version: BRIDGE_VERSION, bridgeId, ownerId: auth.ownerId, endpointId: security.endpoint.id }));
|
|
1440
|
+
if (shutdownRun)
|
|
1441
|
+
return;
|
|
1389
1442
|
ready = true;
|
|
1390
1443
|
console.log('[Bridge] Update restart ready and listening for commands');
|
|
1391
1444
|
}
|
|
@@ -1402,16 +1455,14 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
1402
1455
|
autoUpdateTimer.unref();
|
|
1403
1456
|
// Leaves tmux sessions running and the process alive; a revoked restart re-executes this same PID
|
|
1404
1457
|
// afterwards, so the local port, pointer, relay connection and timers must all be released here.
|
|
1405
|
-
let shutdownRun;
|
|
1406
1458
|
function shutdown() {
|
|
1407
1459
|
shutdownRun ??= (async () => {
|
|
1460
|
+
console.log('\n[Bridge] Shutting down...');
|
|
1461
|
+
ready = false;
|
|
1462
|
+
clearTimeout(startupTimer);
|
|
1408
1463
|
clearInterval(autoUpdateTimer);
|
|
1409
1464
|
clearInterval(ticketTimer);
|
|
1410
|
-
console.log('\n[Bridge] Shutting down...');
|
|
1411
1465
|
try {
|
|
1412
|
-
await maintenance;
|
|
1413
|
-
await Promise.all([...deliveries.values(), peerCache.stop(), projectDirectory.stop()]);
|
|
1414
|
-
await pullRequestEvents.stop();
|
|
1415
1466
|
attentionStore.stopNotifications();
|
|
1416
1467
|
stopPushSessionObserver();
|
|
1417
1468
|
stopBoardObserver();
|
|
@@ -1419,47 +1470,38 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
1419
1470
|
pushNotifier?.stop();
|
|
1420
1471
|
ledgerRelay?.stop();
|
|
1421
1472
|
accountRegistrar?.stop();
|
|
1422
|
-
// Solo L2 ordering: stop accepting first, then children (panel before
|
|
1423
|
-
// hub), then the rest of the bridge teardown.
|
|
1424
1473
|
if (solo) {
|
|
1425
1474
|
void solo.front.close().catch(() => { });
|
|
1426
1475
|
solo.panel.stop();
|
|
1427
1476
|
solo.hub.stop();
|
|
1428
1477
|
}
|
|
1478
|
+
// Close ingress and release pending network requests before draining their callers.
|
|
1479
|
+
localApiServer.stop();
|
|
1480
|
+
loopbackServer.closeAll();
|
|
1481
|
+
addressed?.listener.stop();
|
|
1482
|
+
directPeers.closeAll();
|
|
1483
|
+
peerLinks.closeAll();
|
|
1484
|
+
watchRegistry.dispose();
|
|
1485
|
+
centrifugo.disconnect();
|
|
1486
|
+
const drained = await Promise.allSettled([
|
|
1487
|
+
teamOutbox.close(), localApiServer.closeTransfers(), peerCache.stop(), projectDirectory.stop(), pullRequestEvents.stop(),
|
|
1488
|
+
maintenance, ...deliveries.values(),
|
|
1489
|
+
// An already-started resurrection can still attach a PTY. Detach once it finishes.
|
|
1490
|
+
Promise.resolve(startupWork).then(() => terminalOutput.stop()),
|
|
1491
|
+
]);
|
|
1492
|
+
for (const result of drained)
|
|
1493
|
+
if (result.status === 'rejected')
|
|
1494
|
+
throw result.reason;
|
|
1429
1495
|
}
|
|
1430
1496
|
finally {
|
|
1431
|
-
|
|
1497
|
+
cleanupPointer();
|
|
1498
|
+
// node-datachannel module-level cleanup — avoids the native crash-on-exit race.
|
|
1432
1499
|
try {
|
|
1433
|
-
|
|
1500
|
+
ndcCleanup();
|
|
1434
1501
|
}
|
|
1435
|
-
|
|
1436
|
-
try {
|
|
1437
|
-
localApiServer.stop();
|
|
1438
|
-
}
|
|
1439
|
-
finally {
|
|
1440
|
-
cleanupPointer();
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
await terminalOutput.stop();
|
|
1445
|
-
loopbackServer.closeAll();
|
|
1446
|
-
addressed?.listener.stop();
|
|
1447
|
-
directPeers.closeAll();
|
|
1448
|
-
peerLinks.closeAll();
|
|
1449
|
-
watchRegistry.dispose();
|
|
1450
|
-
// node-datachannel module-level cleanup — avoids the native crash-on-exit race.
|
|
1451
|
-
try {
|
|
1452
|
-
ndcCleanup();
|
|
1453
|
-
}
|
|
1454
|
-
catch { /* native lib already torn down */ }
|
|
1455
|
-
centrifugo.disconnect();
|
|
1456
|
-
try {
|
|
1502
|
+
catch { /* native lib already torn down */ }
|
|
1457
1503
|
await security.close();
|
|
1458
1504
|
}
|
|
1459
|
-
catch (err) {
|
|
1460
|
-
console.error('[Bridge] Failed to persist security shutdown state.');
|
|
1461
|
-
throw err;
|
|
1462
|
-
}
|
|
1463
1505
|
})();
|
|
1464
1506
|
return shutdownRun;
|
|
1465
1507
|
}
|
|
@@ -1467,14 +1509,24 @@ export async function runBridge(argv, commandName = 'ftown-bridge', deps = {}) {
|
|
|
1467
1509
|
try {
|
|
1468
1510
|
await shutdown();
|
|
1469
1511
|
}
|
|
1470
|
-
catch {
|
|
1512
|
+
catch (err) {
|
|
1513
|
+
console.error('[Bridge] Shutdown failed:', err instanceof Error ? err.message : err);
|
|
1471
1514
|
process.exit(1);
|
|
1472
1515
|
}
|
|
1473
1516
|
process.exit(0);
|
|
1474
1517
|
};
|
|
1475
1518
|
releaseForRestart = shutdown;
|
|
1476
|
-
|
|
1477
|
-
|
|
1519
|
+
let receivedStopSignal = false;
|
|
1520
|
+
const onStopSignal = (signal) => {
|
|
1521
|
+
if (receivedStopSignal) {
|
|
1522
|
+
console.error('[Bridge] Second stop signal received; exiting immediately.');
|
|
1523
|
+
process.exit(signal === 'SIGINT' ? 130 : 143);
|
|
1524
|
+
}
|
|
1525
|
+
receivedStopSignal = true;
|
|
1526
|
+
void shutdownAndExit();
|
|
1527
|
+
};
|
|
1528
|
+
process.on('SIGINT', onStopSignal);
|
|
1529
|
+
process.on('SIGTERM', onStopSignal);
|
|
1478
1530
|
});
|
|
1479
1531
|
registerLocalBrowserCommands(program);
|
|
1480
1532
|
try {
|