@clagentic/console 1.3.0 → 1.3.1-beta.1
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/lib/public/css/home-hub.css +1 -1
- package/lib/public/index.html +7 -7
- package/lib/sdk-bridge.js +92 -0
- package/package.json +1 -1
package/lib/public/index.html
CHANGED
|
@@ -151,6 +151,13 @@
|
|
|
151
151
|
|
|
152
152
|
<div id="home-hub-mates" class="home-hub-mates hidden"></div>
|
|
153
153
|
|
|
154
|
+
<div class="hub-card hub-recent-sessions">
|
|
155
|
+
<div class="hub-card-header">
|
|
156
|
+
<span class="hub-card-title">Recent Sessions</span>
|
|
157
|
+
</div>
|
|
158
|
+
<div class="hub-recent-sessions-list" id="hub-recent-sessions-list"></div>
|
|
159
|
+
</div>
|
|
160
|
+
|
|
154
161
|
<div class="hub-columns">
|
|
155
162
|
<div class="hub-card hub-upcoming">
|
|
156
163
|
<div class="hub-card-header">
|
|
@@ -174,13 +181,6 @@
|
|
|
174
181
|
<div class="hub-week-strip" id="hub-week-strip"></div>
|
|
175
182
|
</div>
|
|
176
183
|
|
|
177
|
-
<div class="hub-card hub-recent-sessions">
|
|
178
|
-
<div class="hub-card-header">
|
|
179
|
-
<span class="hub-card-title">Recent Sessions</span>
|
|
180
|
-
</div>
|
|
181
|
-
<div class="hub-recent-sessions-list" id="hub-recent-sessions-list"></div>
|
|
182
|
-
</div>
|
|
183
|
-
|
|
184
184
|
</div>
|
|
185
185
|
</div>
|
|
186
186
|
<div id="sidebar-column">
|
package/lib/sdk-bridge.js
CHANGED
|
@@ -10,6 +10,17 @@ var { createMessageQueue } = require("./sdk-message-queue");
|
|
|
10
10
|
var { attachMessageProcessor } = require("./sdk-message-processor");
|
|
11
11
|
var { readAgentToolsFromFile } = require("./agents");
|
|
12
12
|
|
|
13
|
+
// --- lr-29f9: Global concurrent-session ceiling ---
|
|
14
|
+
// Counts queries that are actively running (startQuery entered, processQueryStream
|
|
15
|
+
// finally not yet reached) across ALL project bridge instances in this daemon process.
|
|
16
|
+
// Each project's sdk-bridge instance shares this module-level counter.
|
|
17
|
+
// Env override: CLAGENTIC_MAX_CONCURRENT_SESSIONS (must be a positive integer).
|
|
18
|
+
var _activeLiveCount = 0;
|
|
19
|
+
var MAX_CONCURRENT_SESSIONS = (function () {
|
|
20
|
+
var env = parseInt(process.env.CLAGENTIC_MAX_CONCURRENT_SESSIONS, 10);
|
|
21
|
+
return (env > 0) ? env : 6;
|
|
22
|
+
})();
|
|
23
|
+
|
|
13
24
|
// Extract serializable tool descriptors from MCP server instances.
|
|
14
25
|
// Used for IPC to worker processes (McpSdkServerConfigWithInstance is not serializable).
|
|
15
26
|
function extractMcpDescriptors(mcpServers) {
|
|
@@ -900,6 +911,33 @@ function createSDKBridge(opts) {
|
|
|
900
911
|
}
|
|
901
912
|
session.messageQueue = null;
|
|
902
913
|
if (session.abortController === myAbortController) session.abortController = null;
|
|
914
|
+
|
|
915
|
+
// lr-29f9: Reap the worker process immediately on query completion.
|
|
916
|
+
// The worker is kept alive between turns by _adapterWorkerState reuse, but
|
|
917
|
+
// once processQueryStream exits there is nothing left to receive from it.
|
|
918
|
+
// Kill it now so dead processes do not accumulate. Session history is on
|
|
919
|
+
// disk and unaffected; startQuery will spawn a fresh worker next turn.
|
|
920
|
+
// We use the exitPromise stored at query-start time so startQuery's
|
|
921
|
+
// _workerExitPromise guard (which serialises consecutive queries) still works.
|
|
922
|
+
if (session._adapterWorkerState && session._adapterWorkerState.worker) {
|
|
923
|
+
var doneWorker = session._adapterWorkerState.worker;
|
|
924
|
+
var doneExitPromise = session._adapterWorkerState.exitPromise;
|
|
925
|
+
// Hand the exitPromise to startQuery so it can await worker termination
|
|
926
|
+
// before spawning the next one (prevents session-file race on resume).
|
|
927
|
+
session._workerExitPromise = doneExitPromise || null;
|
|
928
|
+
// Null out worker state so the next startQuery spawns fresh.
|
|
929
|
+
session._adapterWorkerState = null;
|
|
930
|
+
session.worker = null;
|
|
931
|
+
console.log("[sdk-bridge] Reaping worker pid=" + (doneWorker.process ? doneWorker.process.pid : "?") + " for session " + session.localId + " on query completion");
|
|
932
|
+
try { doneWorker.kill(); } catch (e) {}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// lr-29f9: Release the live-session slot claimed in startQuery.
|
|
936
|
+
if (session._isCountedLive) {
|
|
937
|
+
session._isCountedLive = false;
|
|
938
|
+
_activeLiveCount = Math.max(0, _activeLiveCount - 1);
|
|
939
|
+
console.log("[sdk-bridge] Live query count: " + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + " (session " + session.localId + " done)");
|
|
940
|
+
}
|
|
903
941
|
session.taskStopRequested = false;
|
|
904
942
|
session.pendingPermissions = {};
|
|
905
943
|
session.pendingAskUser = {};
|
|
@@ -1142,6 +1180,44 @@ function createSDKBridge(opts) {
|
|
|
1142
1180
|
|
|
1143
1181
|
var t0 = session._queryStartTs || Date.now();
|
|
1144
1182
|
|
|
1183
|
+
// lr-29f9: Enforce concurrent-session ceiling.
|
|
1184
|
+
// Count only NEW queries (session has no active queryInstance).
|
|
1185
|
+
// Multi-turn pushes to an existing query are not new processes — don't gate them.
|
|
1186
|
+
var isNewQuery = !session.queryInstance;
|
|
1187
|
+
if (isNewQuery && _activeLiveCount >= MAX_CONCURRENT_SESSIONS) {
|
|
1188
|
+
console.warn("[sdk-bridge] Concurrent session ceiling hit (" + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + ") — rejecting new query for session " + session.localId);
|
|
1189
|
+
session.isProcessing = false;
|
|
1190
|
+
onProcessingChanged();
|
|
1191
|
+
sendAndRecord(session, {
|
|
1192
|
+
type: "error",
|
|
1193
|
+
text: "Too many active sessions (" + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + "). Wait for another session to finish, or increase CLAGENTIC_MAX_CONCURRENT_SESSIONS.",
|
|
1194
|
+
});
|
|
1195
|
+
sendAndRecord(session, { type: "done", code: 1 });
|
|
1196
|
+
sm.broadcastSessionList();
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
// Claim the slot now so concurrent callers see the updated count immediately.
|
|
1200
|
+
// Set _isCountedLive on the session at the same time so any early-return path
|
|
1201
|
+
// below (sync throw, createQuery failure) can release it via releaseSlot().
|
|
1202
|
+
// A local helper is used so there is no window where the slot is claimed but
|
|
1203
|
+
// _isCountedLive is not yet set — the two always move together.
|
|
1204
|
+
function releaseSlot() {
|
|
1205
|
+
if (session._isCountedLive) {
|
|
1206
|
+
session._isCountedLive = false;
|
|
1207
|
+
_activeLiveCount = Math.max(0, _activeLiveCount - 1);
|
|
1208
|
+
console.log("[sdk-bridge] Live query count: " + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + " (session " + session.localId + " slot released)");
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
if (isNewQuery) {
|
|
1212
|
+
_activeLiveCount++;
|
|
1213
|
+
session._isCountedLive = true;
|
|
1214
|
+
console.log("[sdk-bridge] Live query count: " + _activeLiveCount + "/" + MAX_CONCURRENT_SESSIONS + " (session " + session.localId + " starting)");
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
// Guard the rest of startQuery so any unexpected synchronous throw releases
|
|
1218
|
+
// the slot claimed above and surfaces a visible error (no spinner-forever).
|
|
1219
|
+
try {
|
|
1220
|
+
|
|
1145
1221
|
// Wait for previous worker to fully exit before spawning a new one.
|
|
1146
1222
|
// Without this, the new worker may try to resume the SDK session file
|
|
1147
1223
|
// while the old worker is still flushing it to disk, causing
|
|
@@ -1333,6 +1409,7 @@ function createSDKBridge(opts) {
|
|
|
1333
1409
|
console.error("[sdk-bridge] Failed to create query for session " + session.localId + ":", e.message || e);
|
|
1334
1410
|
console.error("[sdk-bridge] cliSessionId:", session.cliSessionId, "resume:", !!session.cliSessionId);
|
|
1335
1411
|
console.error("[sdk-bridge] Stack:", e.stack || "(no stack)");
|
|
1412
|
+
releaseSlot();
|
|
1336
1413
|
session.isProcessing = false;
|
|
1337
1414
|
onProcessingChanged();
|
|
1338
1415
|
session.queryInstance = null;
|
|
@@ -1396,6 +1473,21 @@ function createSDKBridge(opts) {
|
|
|
1396
1473
|
sendToSession(session, { type: "error", text: "Stream error: " + (err && err.message || String(err)) });
|
|
1397
1474
|
sendToSession(session, { type: "done", code: 1 });
|
|
1398
1475
|
});
|
|
1476
|
+
|
|
1477
|
+
} catch (startErr) {
|
|
1478
|
+
// Unexpected synchronous throw anywhere in the post-slot-claim body.
|
|
1479
|
+
// Release the slot and surface the error so the UI does not spin forever.
|
|
1480
|
+
releaseSlot();
|
|
1481
|
+
session.isProcessing = false;
|
|
1482
|
+
onProcessingChanged();
|
|
1483
|
+
session.queryInstance = null;
|
|
1484
|
+
session.messageQueue = null;
|
|
1485
|
+
session.abortController = null;
|
|
1486
|
+
console.error("[sdk-bridge] Unexpected error in startQuery for session " + session.localId + ":", startErr && startErr.message || startErr);
|
|
1487
|
+
sendAndRecord(session, { type: "error", text: "Failed to start query: " + (startErr && startErr.message || String(startErr)) });
|
|
1488
|
+
sendAndRecord(session, { type: "done", code: 1 });
|
|
1489
|
+
sm.broadcastSessionList();
|
|
1490
|
+
}
|
|
1399
1491
|
}
|
|
1400
1492
|
|
|
1401
1493
|
function pushMessage(session, text, images) {
|
package/package.json
CHANGED