@clagentic/console 1.9.0-beta.1 → 1.9.0-beta.2

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.
Files changed (50) hide show
  1. package/bin/cli.js +12 -1
  2. package/lib/agents.js +13 -3
  3. package/lib/build-sha.json +2 -2
  4. package/lib/cli/ipc-subcommands.js +40 -4
  5. package/lib/daemon.js +25 -1
  6. package/lib/project-connection.js +15 -2
  7. package/lib/project-loop.js +46 -2
  8. package/lib/project-sessions.js +31 -3
  9. package/lib/project-user-message.js +70 -3
  10. package/lib/project.js +7 -1
  11. package/lib/public/app.js +14 -4
  12. package/lib/public/css/base.css +14 -0
  13. package/lib/public/css/home-hub.css +28 -8
  14. package/lib/public/css/icon-strip.css +17 -0
  15. package/lib/public/css/messages.css +11 -0
  16. package/lib/public/css/mobile-nav.css +22 -0
  17. package/lib/public/css/sidebar.css +15 -0
  18. package/lib/public/css/title-bar.css +10 -1
  19. package/lib/public/index.html +1 -0
  20. package/lib/public/modules/activity-latch.js +159 -0
  21. package/lib/public/modules/activity-state.js +157 -0
  22. package/lib/public/modules/app-connection.js +10 -4
  23. package/lib/public/modules/app-favicon.js +88 -1
  24. package/lib/public/modules/app-home-hub.js +14 -11
  25. package/lib/public/modules/app-loop-ui.js +86 -2
  26. package/lib/public/modules/app-messages.js +118 -54
  27. package/lib/public/modules/app-panels.js +91 -32
  28. package/lib/public/modules/app-projects.js +28 -8
  29. package/lib/public/modules/app-rate-limit.js +13 -1
  30. package/lib/public/modules/sidebar-mobile.js +32 -22
  31. package/lib/public/modules/sidebar-projects.js +42 -14
  32. package/lib/public/modules/sidebar-sessions.js +168 -48
  33. package/lib/public/modules/tools.js +11 -39
  34. package/lib/sdk-bridge.js +301 -22
  35. package/lib/sdk-message-processor.js +98 -15
  36. package/lib/sdk-skill-discovery.js +46 -6
  37. package/lib/sdk-slash-enrichment.js +5 -2
  38. package/lib/server-hub-sessions.js +70 -0
  39. package/lib/server.js +24 -22
  40. package/lib/session-activity.js +8 -1
  41. package/lib/sessions.js +47 -1
  42. package/lib/smtp.js +10 -1
  43. package/lib/ws-schema.js +16 -0
  44. package/lib/yoke/adapters/claude.js +7 -1
  45. package/lib/yoke/adapters/codex.js +219 -31
  46. package/package.json +2 -2
  47. package/scripts/check-test-count.js +397 -0
  48. package/scripts/test-file-completion-reporter.js +43 -0
  49. package/lib/model-context-windows.js +0 -74
  50. package/lib/public/modules/model-context-windows.js +0 -71
@@ -16,6 +16,27 @@ var pendingIterations = 20;
16
16
  // ========================================================
17
17
  // Init
18
18
  // ========================================================
19
+
20
+ // lr-fd38ac follow-up: re-check the queue-mode gate whenever the fields it
21
+ // depends on change, not only when a handler happens to remember to call
22
+ // updateLoopInputVisibility() itself. loop_iteration/loop_judging
23
+ // (app-messages.js) write loopCurrentSessionId without re-invoking the
24
+ // gate — that used to leave loopQueueMode stale-false for a client already
25
+ // viewing the loop's own session (queued messages silently dropped instead
26
+ // of queued, the inverse of the original lr-fd38ac bug). See
27
+ // recheckLoopQueueModeFromState() for why this branch does not need the
28
+ // raw per-session `loop` object that updateLoopInputVisibility()'s direct
29
+ // callers (session_switched et al.) pass in.
30
+ //
31
+ // Split out from initLoopUi() so it can be installed on its own — the rest
32
+ // of initLoopUi() renders DOM (banners, buttons) that a unit test covering
33
+ // only this reactive gate has no reason to depend on.
34
+ export function initLoopQueueModeSync() {
35
+ store.subscribe(['loopActive', 'loopCurrentSessionId', 'activeSessionId'], function () {
36
+ recheckLoopQueueModeFromState();
37
+ });
38
+ }
39
+
19
40
  export function initLoopUi() {
20
41
 
21
42
  // --- Reactive UI sync for loop state ---
@@ -34,6 +55,8 @@ export function initLoopUi() {
34
55
  }
35
56
  });
36
57
 
58
+ initLoopQueueModeSync();
59
+
37
60
  // --- Preview modal listeners ---
38
61
  // Backdrop click intentionally does NOT close the modal (no way to reopen it)
39
62
 
@@ -156,6 +179,32 @@ function sendLoopStart() {
156
179
  // Loop UI (exported)
157
180
  // ========================================================
158
181
 
182
+ // lr-6fe5fc: single derivation of "should THIS session's composer present
183
+ // queue-mode UI", used by both call sites below. Takes the three server-
184
+ // pushed inputs directly (never a per-session `loop` object) — see the
185
+ // invariant note on recheckLoopQueueModeFromState() for why the per-session
186
+ // `loop.active`/`loop.role` fields the pre-lr-6fe5fc code additionally
187
+ // checked here are provably redundant with this three-input check and are
188
+ // no longer consulted: project-loop.js only ever sets loopCurrentSessionId
189
+ // to a session whose own loop.active is true and role is coder/judge, and
190
+ // finishLoop() atomically nulls loopCurrentSessionId in the same pass that
191
+ // clears every affected session's loop.active. So loopCurrentSessionId ===
192
+ // activeSessionId already implies everything the per-session object could
193
+ // have told us; carrying it as a second, separately-checked condition is
194
+ // exactly the shape of the bug this task is fixing (two things that are
195
+ // supposed to always agree, checked independently, able to drift).
196
+ //
197
+ // This is a client-side UX gate only — which WS message type the composer
198
+ // sends (`loop_message` vs `message`). It is not a permission check: the
199
+ // server's handleLoopMessage() gate independently and authoritatively
200
+ // decides whether to accept a queued `loop_message` off loopState.active,
201
+ // which is a coarser, correctly-project-scoped question (see that
202
+ // function's comment for why the two predicates are intentionally not the
203
+ // same one).
204
+ export function isLoopQueueSession(loopActive, loopCurrentSessionId, activeSessionId) {
205
+ return !!(loopActive && loopCurrentSessionId != null && loopCurrentSessionId === activeSessionId);
206
+ }
207
+
159
208
  // lr-e31b: An active (non-crafting) loop iteration session used to hide the
160
209
  // composer outright, leaving no way for a human to get a message into a
161
210
  // running loop. Loop iterations are single-turn SDK sessions whose input
@@ -164,12 +213,30 @@ function sendLoopStart() {
164
213
  // into the in-flight turn — it is queued and delivered at the next
165
214
  // iteration boundary instead. The composer stays visible and enabled;
166
215
  // input.js routes the send through `loop_message` while loopQueueMode is set.
216
+ //
217
+ // lr-fd38ac / lr-6fe5fc: the per-session `loop.active` marker (persisted on
218
+ // the session itself, see sessions.js:109/711) is not a reliable input to
219
+ // this gate — see isLoopQueueSession()'s comment for why the three
220
+ // server-pushed store values are sufficient on their own. The `loop`
221
+ // parameter is accepted for backward compatibility with callers that pass
222
+ // the per-session object from a WS message (session_switched et al.) but is
223
+ // intentionally unused in the derivation itself.
167
224
  export function updateLoopInputVisibility(loop) {
168
225
  var inputArea = document.getElementById("input-area");
169
226
  if (!inputArea) return;
170
227
  inputArea.style.display = "";
171
- var queueMode = !!(loop && loop.active && loop.role !== "crafting");
172
- store.set({ loopQueueMode: queueMode });
228
+ var s = store.snap();
229
+ var queueMode = isLoopQueueSession(s.loopActive, s.loopCurrentSessionId, s.activeSessionId);
230
+ applyLoopQueueMode(queueMode);
231
+ }
232
+
233
+ // lr-fd38ac follow-up: shared by updateLoopInputVisibility() (per-session
234
+ // `loop` object supplied by the caller — session_switched, loop_available,
235
+ // loop_finished) and recheckLoopQueueModeFromState() (no `loop` object
236
+ // available; see that function's comment for why store state alone is
237
+ // sufficient there). Applies the derived boolean to the store and syncs
238
+ // the composer placeholder.
239
+ function applyLoopQueueMode(queueMode) {
173
240
  var inputEl = document.getElementById("input");
174
241
  if (inputEl) {
175
242
  if (queueMode) {
@@ -178,6 +245,23 @@ export function updateLoopInputVisibility(loop) {
178
245
  inputEl.placeholder = "Message Claude Code...";
179
246
  }
180
247
  }
248
+ store.set({ loopQueueMode: queueMode });
249
+ }
250
+
251
+ // lr-fd38ac follow-up / lr-6fe5fc: re-derive queue mode from store state
252
+ // alone, for the reactive subscriber in initLoopUi() — it fires on
253
+ // loopActive/loopCurrentSessionId/activeSessionId changes, none of which
254
+ // carry a per-session `loop` object the way session_switched's msg.loop
255
+ // does. Uses the same isLoopQueueSession() predicate as
256
+ // updateLoopInputVisibility() — see that function's comment for the
257
+ // server-side invariant that makes the three store values sufficient on
258
+ // their own, without a per-session `loop` object.
259
+ function recheckLoopQueueModeFromState() {
260
+ var inputArea = document.getElementById("input-area");
261
+ if (!inputArea) return;
262
+ var s = store.snap();
263
+ var queueMode = isLoopQueueSession(s.loopActive, s.loopCurrentSessionId, s.activeSessionId);
264
+ applyLoopQueueMode(queueMode);
181
265
  }
182
266
 
183
267
  export function updateLoopButton() {
@@ -35,7 +35,7 @@ import { handleAgentsList, handleAgentFavoriteToggled } from './agent-picker.js'
35
35
  import { handleProjectAgentsList, requestProjectAgents } from './at-agents.js';
36
36
  import { handleFindInSessionResults } from './session-search.js';
37
37
  import { handleInputSync, autoResize, resetAutoResize, builtinCommands, setScheduleBtnDisabled } from './input.js';
38
- import { startThinking, appendThinking, stopThinking, resetThinkingGroup, createToolItem, updateToolExecuting, updateToolResult, markAllToolsDone, closeToolGroup, removeToolFromGroup, resetToolState, getTools, getPlanContent, setPlanContent, renderPlanBanner, renderPlanCard, getTodoTools, handleTodoWrite, handleTaskCreate, handleTaskUpdate, applyDeadSessionTodoCompaction, isPlanFilePath, enableMainInput, addTurnMeta, updateSubagentActivity, addSubagentToolEntry, markSubagentDone, initSubagentStop, updateSubagentProgress, updateSubagentTaskStatus, hasActiveSubagents, renderAskUserQuestion, markAskUserAnswered, renderPermissionRequest, markPermissionCancelled, markPermissionResolved, renderElicitationRequest, markElicitationResolved } from './tools.js';
38
+ import { startThinking, appendThinking, stopThinking, resetThinkingGroup, createToolItem, updateToolExecuting, updateToolResult, markAllToolsDone, closeToolGroup, removeToolFromGroup, resetToolState, getTools, getPlanContent, setPlanContent, renderPlanBanner, renderPlanCard, getTodoTools, handleTodoWrite, handleTaskCreate, handleTaskUpdate, applyDeadSessionTodoCompaction, isPlanFilePath, enableMainInput, addTurnMeta, updateSubagentActivity, addSubagentToolEntry, markSubagentDone, initSubagentStop, updateSubagentProgress, updateSubagentTaskStatus, renderAskUserQuestion, markAskUserAnswered, renderPermissionRequest, markPermissionCancelled, markPermissionResolved, renderElicitationRequest, markElicitationResolved } from './tools.js';
39
39
  import { showDoneNotification, playDoneSound, isNotifAlertEnabled, isNotifSoundEnabled } from './notifications.js';
40
40
  import { handleFsRead, refreshIfOpen } from './filebrowser.js';
41
41
  import { isProjectSettingsOpen, refreshProjectSettingsModels, handleInstructionsRead, handleInstructionsWrite, handleProjectEnv, handleProjectEnvSaved, handleProjectSharedEnv, handleProjectSharedEnvSaved, handleProjectOwnerChanged, updateLiteVisibility, handleLiteProjectStatus, handleLiteEnrollResult, handleLiteUnenrollResult } from './project-settings.js';
@@ -53,7 +53,7 @@ import { handleLoopRegistryUpdated, handleScheduleRunStarted, handleScheduleRunF
53
53
 
54
54
  // --- App module imports ---
55
55
  import { scrollToBottom, addToMessages, addUserMessage, addSystemMessage, appendDelta, finalizeAssistantBlock, addConflictMessage, addContextOverflowMessage, showSuggestionChips, removePreThinking } from './app-rendering.js';
56
- import { setActivity, startUrgentBlink, stopUrgentBlink, blinkSessionDot, updateCrossProjectBlink } from './app-favicon.js';
56
+ import { startUrgentBlink, stopUrgentBlink, blinkSessionDot, updateCrossProjectBlink } from './app-favicon.js';
57
57
  import { setStatus } from './app-connection.js';
58
58
  import { getModelEffortLevels, accumulateUsage, setSessionUsage, updateUsagePanel, accumulateContext, updateContextPanel, renderCtxPopover, updateStatusPanel } from './app-panels.js';
59
59
  import { updateProjectList, resetClientState, showUpdateAvailable, handleRemoveProjectCheckResult, handleRemoveProjectResult, handleBrowseDirResult, handleAddProjectResult, handleCloneProgress } from './app-projects.js';
@@ -69,6 +69,7 @@ import { handleMentionStart, handleMentionActivity, handleMentionStream, handleM
69
69
  import { handleTeamState, handleTeamMemberUpdate, handleTeamTaskUpdate, handleTeamMessage as handleTeamMsg, handleTeamGone } from './team-panel.js';
70
70
  import { addDiagnostic } from './diagnostics.js';
71
71
  import { handleHistoryMeta, handleHistoryDone } from './app-history-replay.js';
72
+ import { shouldApplyActivityEdge, recordActivityEdgeDecision } from './activity-latch.js';
72
73
 
73
74
  // --- DOM refs (cached once, stable for page lifetime) ---
74
75
  var messagesEl = document.getElementById("messages");
@@ -442,7 +443,25 @@ registerHandlers({
442
443
  } else if (_prevSid) {
443
444
  delete store.get('sessionDrafts')[_prevSid];
444
445
  }
446
+ // Reconcile the footer's edge-latch field from the server-authoritative
447
+ // snapshot on every session switch/hydration, not only
448
+ // sessionIsProcessing. 'processing' (the field app-favicon.js's
449
+ // initActivityFooter subscribes to) was a pure client-local edge latch
450
+ // with no reconciliation path — missing a single 1->0 done edge (e.g. a
451
+ // cross-session race, see the session-scoping fix in the status/done/
452
+ // auth_required handlers below) left it stuck true forever.
453
+ // session_switched now always carries msg.isProcessing
454
+ // (project-connection.js's hydration path previously omitted it —
455
+ // sessions.js's own switchSession() send already had it).
445
456
  store.set({ activeSessionId: msg.id, cliSessionId: msg.cliSessionId || null, vendorCapabilities: msg.capabilities || {}, sessionIsProcessing: !!msg.isProcessing });
457
+ // Re-derive 'processing' from the store field just set above
458
+ // (sessionIsProcessing), NOT from a second raw msg.isProcessing read —
459
+ // this file's CI invariant test locks .isProcessing reads to exactly
460
+ // the one documented site immediately above, so every switch/reconnect/
461
+ // hydration re-derives 'processing' from that already-read,
462
+ // already-reconciled value instead of trusting whatever the
463
+ // client-local latch happened to be left at.
464
+ store.set({ processing: store.get('sessionIsProcessing') });
446
465
  if (msg.vendor) {
447
466
  if (!store.get('vendorSelectionLocked') || msg.hasHistory) {
448
467
  store.set({ currentVendor: msg.vendor });
@@ -605,26 +624,48 @@ registerHandlers({
605
624
  },
606
625
 
607
626
  status: function (msg) {
627
+ // Session-scope this edge write, mirroring the lr-0827ba pattern
628
+ // already used by scheduled_message_*/other handlers (msg.localId ==
629
+ // null || msg.localId === activeSessionId). This handler previously
630
+ // raised the global 'processing' latch for ANY session's
631
+ // status:"processing", including one the client is not currently
632
+ // focused on — a background session's edge could raise the FOCUSED
633
+ // session's dot with no done ever routed back to clear it. msg.localId
634
+ // is now always populated server-side (see sessions.js
635
+ // stampActivityLocalId / project.js sendToSession); a missing localId
636
+ // (e.g. an older server) falls back to applying the edge
637
+ // unconditionally, same as before this fix.
608
638
  if (msg.status === "processing") {
609
- setStatus("processing");
610
- // Session became live — undo any dead-session todo compaction
611
- // applied at history_done time.
612
- store.set({ sessionIsProcessing: true });
613
- applyDeadSessionTodoCompaction();
614
- if (!store.get('dmMode')) {
615
- removePreThinking(); // drop pre-thinking dots before showing activity indicator
616
- setActivity("thinking");
639
+ var _statusActiveSid = store.get('activeSessionId');
640
+ var _statusEdgeAccepted = shouldApplyActivityEdge(msg.localId, _statusActiveSid);
641
+ // lr-58c813: ledger this edge's outcome for observability only — the
642
+ // decision below (same _statusEdgeAccepted value) is unchanged.
643
+ recordActivityEdgeDecision("status", msg.localId, _statusActiveSid, _statusEdgeAccepted);
644
+ if (_statusEdgeAccepted) {
645
+ setStatus("processing");
646
+ // Session became live — undo any dead-session todo compaction
647
+ // applied at history_done time.
648
+ store.set({ sessionIsProcessing: true });
649
+ applyDeadSessionTodoCompaction();
650
+ if (!store.get('dmMode')) {
651
+ removePreThinking(); // drop pre-thinking dots before showing activity indicator
652
+ }
617
653
  }
618
654
  }
619
655
  },
620
656
 
621
- compacting: function (msg) {
622
- if (msg.active) {
623
- setActivity("compacting");
624
- } else if (!store.get('dmMode')) {
625
- setActivity("thinking");
626
- }
627
- },
657
+ // lr-66c118: setActivity("thinking"/"compacting") re-raise removed here.
658
+ // setActivity collapses to ONE optimistic raise (input.js, on send) — the
659
+ // widget's job is to bridge the gap before the FIRST real server signal
660
+ // arrives; once real streaming UI exists (thinking block, tool items,
661
+ // delta text) that IS the activity indicator, so re-raising the bubble
662
+ // widget mid-turn only risked stacking it on top of the real UI.
663
+ // lr-3af675: the context meter itself no longer needs anything here either
664
+ // — the server re-reads vendor usage on the compacting -> not-compacting
665
+ // transition and pushes a fresh 'context_usage' message (see the 'status'
666
+ // handler in sdk-message-processor.js), which the context_usage handler
667
+ // below already applies to the meter.
668
+ compacting: function (msg) {},
628
669
 
629
670
  thinking_start: function (msg) {
630
671
  removePreThinking();
@@ -637,9 +678,6 @@ registerHandlers({
637
678
 
638
679
  thinking_stop: function (msg) {
639
680
  stopThinking(msg.duration);
640
- if (!store.get('dmMode')) {
641
- setActivity("thinking");
642
- }
643
681
  },
644
682
 
645
683
  delta: function (msg) {
@@ -647,14 +685,12 @@ registerHandlers({
647
685
  removePreThinking();
648
686
  stopThinking();
649
687
  resetThinkingGroup();
650
- // lr-1317b8 (Defect 2): this was an ungated clear-site, missed by the
651
- // lr-255e clear-site audit. Any parent-turn assistant text delta after a
652
- // subagent dispatch (e.g. the model narrating between tool calls) killed
653
- // the indicator while the subagent was still genuinely running. Same
654
- // guard as the 'result'/'done' handlers below.
655
- if (!hasActiveSubagents()) {
656
- setActivity(null);
657
- }
688
+ // lr-66c118: the setActivity clear-call removed here (was gated on
689
+ // hasActiveSubagents() per lr-1317b8 Defect 2 — that gate is now moot,
690
+ // there is nothing left to clear here). setActivity collapses to ONE
691
+ // optimistic raise (input.js); real streaming text arriving is itself
692
+ // the strongest possible "not idle" signal, so there is no risk of a
693
+ // stuck indicator from removing this clear.
658
694
  appendDelta(msg.text);
659
695
  },
660
696
 
@@ -806,16 +842,11 @@ registerHandlers({
806
842
  },
807
843
 
808
844
  result: function (msg) {
809
- // lr-255e: the parent turn's SDK stream ends with a normal 'result' as
810
- // soon as a Task tool call is dispatched -- the Task itself keeps
811
- // running as a background subagent. Clearing the activity indicator
812
- // unconditionally here made the "thinking dots" vanish while a
813
- // dispatched subagent was still genuinely working. Only clear it if no
814
- // subagent is currently live; markSubagentDone() clears it once the
815
- // last live subagent actually finishes.
816
- if (!hasActiveSubagents()) {
817
- setActivity(null);
818
- }
845
+ // lr-66c118: the lr-255e hasActiveSubagents()-gated setActivity clear
846
+ // call is removed — setActivity collapses to ONE optimistic raise
847
+ // (input.js) with no manual clears anywhere. The subagent-liveness
848
+ // tracking itself (activeSubagentToolIds, markSubagentDone) is untouched
849
+ // and still governs the real per-tool subagent UI.
819
850
  stopThinking();
820
851
  markAllToolsDone();
821
852
  closeToolGroup();
@@ -832,23 +863,30 @@ registerHandlers({
832
863
  }
833
864
  },
834
865
 
866
+ // Only setStatus("connected") below is session-scoped — a done for a
867
+ // BACKGROUND session must not clear the FOCUSED session's 'processing'
868
+ // latch (see activity-latch.js's header comment for the full rationale).
869
+ // Every other cleanup call in this handler stays unconditional: it
870
+ // targets DOM/tool state for whatever session this client's own WS
871
+ // connection is bound to server-side (ws._clayActiveSession), so it is
872
+ // never cross-session — only the store-wide latch write needs the guard.
835
873
  done: function (msg) {
836
874
  removePreThinking();
837
- // lr-255e: 'done' can also fire while a backgrounded Task subagent is
838
- // still genuinely running (task-stop/error/abort paths that bypass the
839
- // 'result' handler never clear activeTaskToolIds). Same rule as the
840
- // 'result' handler: don't kill the indicator out from under a live
841
- // subagent. resetToolState() below intentionally still clears all
842
- // per-turn tool tracking (including subagent liveness) once this
843
- // handler is done deciding whether to clear the indicator.
844
- if (!hasActiveSubagents()) {
845
- setActivity(null);
846
- }
875
+ // lr-66c118: the setActivity clear call is removed here too — see the
876
+ // 'result' handler above. resetToolState() below still clears all
877
+ // per-turn tool tracking (including subagent liveness) unconditionally.
847
878
  stopThinking();
848
879
  markAllToolsDone();
849
880
  closeToolGroup();
850
881
  finalizeAssistantBlock();
851
- setStatus("connected");
882
+ var _doneActiveSid = store.get('activeSessionId');
883
+ var _doneEdgeAccepted = shouldApplyActivityEdge(msg.localId, _doneActiveSid);
884
+ // lr-58c813: ledger this edge's outcome for observability only — the
885
+ // decision below (same _doneEdgeAccepted value) is unchanged.
886
+ recordActivityEdgeDecision("done", msg.localId, _doneActiveSid, _doneEdgeAccepted);
887
+ if (_doneEdgeAccepted) {
888
+ setStatus("connected");
889
+ }
852
890
  // Re-enable input unless this is one of the loop's own sessions (coder/judge).
853
891
  // A loop running in a separate session must not suppress input here.
854
892
  var _doneLoopSid = store.get('loopCurrentSessionId');
@@ -867,9 +905,11 @@ registerHandlers({
867
905
  addSystemMessage(msg.text, false);
868
906
  },
869
907
 
908
+ // lr-66c118: setActivity clear calls removed below (error,
909
+ // process_conflict, context_overflow, auth_required) — setActivity
910
+ // collapses to ONE optimistic raise (input.js) with no manual clears.
870
911
  error: function (msg) {
871
912
  removePreThinking();
872
- setActivity(null);
873
913
  addSystemMessage(msg.text, true);
874
914
  },
875
915
 
@@ -883,24 +923,31 @@ registerHandlers({
883
923
 
884
924
  process_conflict: function (msg) {
885
925
  removePreThinking();
886
- setActivity(null);
887
926
  addConflictMessage(msg);
888
927
  },
889
928
 
890
929
  context_overflow: function (msg) {
891
930
  removePreThinking();
892
- setActivity(null);
893
931
  addContextOverflowMessage(msg);
894
932
  },
895
933
 
896
934
  auth_required: function (msg) {
897
935
  removePreThinking();
898
- setActivity(null);
899
936
  stopThinking();
900
937
  markAllToolsDone();
901
938
  closeToolGroup();
902
939
  appendDelta((msg.text || "Authentication required.") + "\n");
903
- setStatus("connected");
940
+ // Same session-scoping as the done handler above — a background
941
+ // session's auth_required must not clear the focused session's
942
+ // 'processing' latch.
943
+ var _authActiveSid = store.get('activeSessionId');
944
+ var _authEdgeAccepted = shouldApplyActivityEdge(msg.localId, _authActiveSid);
945
+ // lr-58c813: ledger this edge's outcome for observability only — the
946
+ // decision below (same _authEdgeAccepted value) is unchanged.
947
+ recordActivityEdgeDecision("auth_required", msg.localId, _authActiveSid, _authEdgeAccepted);
948
+ if (_authEdgeAccepted) {
949
+ setStatus("connected");
950
+ }
904
951
  var _authLoopSid = store.get('loopCurrentSessionId');
905
952
  if (!store.get('loopActive') || !_authLoopSid || store.get('activeSessionId') !== _authLoopSid) {
906
953
  enableMainInput();
@@ -1240,6 +1287,20 @@ registerHandlers({
1240
1287
  // loop's own session — updateLoopInputVisibility() already switched
1241
1288
  // it into queue mode so a human message is queued for the next
1242
1289
  // iteration boundary rather than dropped or blocked outright.
1290
+ //
1291
+ // lr-fd38ac follow-up: loopCurrentSessionId (set just above) is what
1292
+ // makes updateLoopInputVisibility()'s gate condition
1293
+ // (loopCurrentSessionId === activeSessionId) newly true when a
1294
+ // client is already viewing the loop's new session — the
1295
+ // session_switched broadcast that forced every client onto this
1296
+ // session fired earlier with loop: null (session.loop is assigned
1297
+ // server-side only after createSession() returns; see
1298
+ // project-loop.js runNextIteration()), so that call armed nothing.
1299
+ // The re-invocation itself lives in app-loop-ui.js's reactive
1300
+ // store.subscribe(), keyed on loopActive/loopCurrentSessionId, so
1301
+ // every writer of those two fields (this handler, loop_judging,
1302
+ // loop_finished) gets the re-check for free instead of each call
1303
+ // site having to remember to do it.
1243
1304
  },
1244
1305
 
1245
1306
  loop_judging: function (msg) {
@@ -1248,6 +1309,9 @@ registerHandlers({
1248
1309
  updateLoopBanner(_ljs.loopIteration, _ljs.loopMaxIterations, "judging");
1249
1310
  addSystemMessage("Judging iteration #" + msg.iteration + "...", false);
1250
1311
  // lr-e31b: composer stays enabled in queue mode (see loop_iteration above).
1312
+ // lr-fd38ac follow-up: same re-arm requirement as loop_iteration —
1313
+ // loopCurrentSessionId changes to the judge session here, and the
1314
+ // reactive subscriber in app-loop-ui.js re-checks the gate.
1251
1315
  },
1252
1316
 
1253
1317
  loop_verdict: function (msg) {