clay-server 2.26.0-beta.14 → 2.26.0-beta.16

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/project.js CHANGED
@@ -1591,7 +1591,8 @@ function createProjectContext(opts) {
1591
1591
  if (session.scheduledMessage && session.scheduledMessage.timer) {
1592
1592
  clearTimeout(session.scheduledMessage.timer);
1593
1593
  }
1594
- var schedDelay = Math.max(0, resetsAt - Date.now()) + 180000; // +3min buffer after reset
1594
+ var isPastReset = resetsAt <= Date.now();
1595
+ var schedDelay = isPastReset ? 5000 : Math.max(0, resetsAt - Date.now()) + 60000; // +1min buffer after reset, or 5s for immediate
1595
1596
  var schedEntry = {
1596
1597
  type: "scheduled_message_queued",
1597
1598
  text: text,
package/lib/public/app.js CHANGED
@@ -3715,7 +3715,7 @@ import { initDebate, handleDebatePreparing, handleDebateStarted, handleDebateRes
3715
3715
  // Auto-switch input to schedule mode: any message typed will be queued for after reset
3716
3716
  var delayUntilReset = msg.resetsAt - Date.now();
3717
3717
  if (delayUntilReset > 0) {
3718
- setScheduleDelayMs(delayUntilReset + 180000); // +3min buffer after reset
3718
+ setScheduleDelayMs(delayUntilReset + 60000); // +1min buffer after reset
3719
3719
  }
3720
3720
  rateLimitResetTimer = setTimeout(function () {
3721
3721
  rateLimitResetsAt = null;
package/lib/sdk-bridge.js CHANGED
@@ -443,6 +443,7 @@ function createSDKBridge(opts) {
443
443
  if (parsed.total_cost_usd && parsed.total_cost_usd > 0) {
444
444
  session.rateLimitResetsAt = null;
445
445
  }
446
+ console.log("[sdk-bridge] result handler: session " + session.localId + " cost=" + parsed.total_cost_usd + " rateLimitResetsAt=" + session.rateLimitResetsAt);
446
447
 
447
448
  // Handle SDK execution errors: show the error to the user instead of
448
449
  // silently swallowing it. These have subtype "error_during_execution".
@@ -597,6 +598,7 @@ function createSDKBridge(opts) {
597
598
 
598
599
  } else if (parsed.type === "rate_limit_event" && parsed.rate_limit_info) {
599
600
  var info = parsed.rate_limit_info;
601
+ console.log("[sdk-bridge] rate_limit_event for session " + session.localId + ": status=" + info.status + " resetsAt=" + info.resetsAt + " isUsingOverage=" + info.isUsingOverage + " isProcessing=" + session.isProcessing);
600
602
 
601
603
  // Broadcast reset time for top-bar usage link
602
604
  if (info.rateLimitType && info.resetsAt) {
@@ -619,23 +621,32 @@ function createSDKBridge(opts) {
619
621
  isUsingOverage: info.isUsingOverage || false,
620
622
  });
621
623
  // Track rejection for auto-continue / scheduled message support
622
- // Skip if using overage (extra usage) user can continue immediately
623
- if (info.status === "rejected" && info.resetsAt && !info.isUsingOverage) {
624
+ if (info.status === "rejected" && info.resetsAt) {
624
625
  session.rateLimitResetsAt = info.resetsAt * 1000;
625
626
 
626
- // Defensive: if query already completed before this event arrived,
627
- // schedule auto-continue now (handles race condition where
628
- // rate_limit_event arrives after the result/done event).
629
- if (!session.isProcessing && !session.scheduledMessage && !session.destroying) {
630
- var lateACEnabled = session.onQueryComplete ||
627
+ // Schedule auto-continue immediately on rejection (don't wait for
628
+ // query completion which has timing issues with worker/non-worker paths).
629
+ if (!session.scheduledMessage && !session.destroying) {
630
+ var acEnabled = session.onQueryComplete ||
631
631
  (typeof opts.getAutoContinueSetting === "function" && opts.getAutoContinueSetting(session));
632
- if (lateACEnabled) {
633
- var lateResetsAt = session.rateLimitResetsAt;
634
- session.rateLimitResetsAt = null;
632
+ console.log("[sdk-bridge] rate_limit rejected: acEnabled=" + acEnabled + " overage=" + !!info.isUsingOverage + " session=" + session.localId);
633
+ if (acEnabled) {
635
634
  session.rateLimitAutoContinuePending = true;
636
- console.log("[sdk-bridge] Rate limit event arrived late, scheduling auto-continue for session " + session.localId);
637
- if (typeof opts.scheduleMessage === "function") {
638
- opts.scheduleMessage(session, "continue", lateResetsAt);
635
+ if (info.isUsingOverage) {
636
+ // Extra usage available: send continue immediately (5s delay for query to finish)
637
+ console.log("[sdk-bridge] Overage available, sending immediate continue for session " + session.localId);
638
+ session.rateLimitResetsAt = null;
639
+ if (typeof opts.scheduleMessage === "function") {
640
+ opts.scheduleMessage(session, "continue", Date.now());
641
+ }
642
+ } else {
643
+ // No overage: schedule after rate limit resets
644
+ var acResetsAt = session.rateLimitResetsAt;
645
+ session.rateLimitResetsAt = null;
646
+ console.log("[sdk-bridge] Scheduling auto-continue on rate limit rejection for session " + session.localId);
647
+ if (typeof opts.scheduleMessage === "function") {
648
+ opts.scheduleMessage(session, "continue", acResetsAt);
649
+ }
639
650
  }
640
651
  }
641
652
  }
@@ -1272,7 +1283,24 @@ function createSDKBridge(opts) {
1272
1283
  sm.broadcastSessionList();
1273
1284
  }
1274
1285
  cleanupSessionWorker(session, worker);
1275
- if (session.onQueryComplete) {
1286
+ // Mark session as done so late rate_limit_event can detect race condition
1287
+ session.isProcessing = false;
1288
+ // Auto-continue on rate limit (scheduler sessions, or user setting)
1289
+ var doneDidScheduleAC = false;
1290
+ var doneACEnabled = session.onQueryComplete || (typeof opts.getAutoContinueSetting === "function" && opts.getAutoContinueSetting(session));
1291
+ console.log("[sdk-bridge] query_done: session " + session.localId + " rateLimitResetsAt=" + session.rateLimitResetsAt + " acEnabled=" + doneACEnabled + " destroying=" + session.destroying + " scheduledMessage=" + !!session.scheduledMessage);
1292
+ if (session.rateLimitResetsAt && session.rateLimitResetsAt > Date.now()
1293
+ && doneACEnabled && !session.destroying) {
1294
+ var doneResetsAt = session.rateLimitResetsAt;
1295
+ session.rateLimitResetsAt = null;
1296
+ session.rateLimitAutoContinuePending = true;
1297
+ doneDidScheduleAC = true;
1298
+ console.log("[sdk-bridge] Rate limited (worker/query_done), scheduling auto-continue for session " + session.localId);
1299
+ if (typeof opts.scheduleMessage === "function") {
1300
+ opts.scheduleMessage(session, "continue", doneResetsAt);
1301
+ }
1302
+ }
1303
+ if (session.onQueryComplete && !doneDidScheduleAC) {
1276
1304
  try { session.onQueryComplete(session); } catch (err) {
1277
1305
  console.error("[sdk-bridge] onQueryComplete error:", err.message || err);
1278
1306
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clay-server",
3
- "version": "2.26.0-beta.14",
3
+ "version": "2.26.0-beta.16",
4
4
  "description": "Self-hosted Claude Code in your browser. Multi-session, multi-user, push notifications.",
5
5
  "bin": {
6
6
  "clay-server": "./bin/cli.js",