teapot-coding-agent 0.37.3 → 0.37.4

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.
@@ -10,7 +10,7 @@ import { promises as fs, existsSync, readFileSync, readdirSync, statSync } from
10
10
  import path from "node:path";
11
11
  import { EventLog, readEvents } from "../log/events.js";
12
12
  import { chat, chatStream } from "./llm.js";
13
- import { executeTool, toolSpecs, currentSkills, safeJoin, isContextOverflow, hasRunningBgShells, hasRunningBgShellsFor, killBgShells } from "./tools.js";
13
+ import { executeTool, toolSpecs, currentSkills, safeJoin, isContextOverflow, isRequestNodeLimit, hasRunningBgShells, hasRunningBgShellsFor, killBgShells } from "./tools.js";
14
14
  import { effortChoosable } from "./llm.js";
15
15
  import { sessionTitleFrom } from "../session-title.js";
16
16
  import { mcp } from "./mcp-registry.js";
@@ -3033,6 +3033,34 @@ export class Agent {
3033
3033
  continue;
3034
3034
  }
3035
3035
  }
3036
+ /**
3037
+ * A STRUCTURAL cap is not an overflow, and no retry or compaction can clear it.
3038
+ *
3039
+ * Command Code's gateway refuses a body whose JSON node count exceeds its limit while the
3040
+ * session is nowhere near its token window — measured upstream at 22.6% of a 1M-token model
3041
+ * with 1,436 messages and 61 image parts. `isContextOverflow` correctly declines to claim
3042
+ * it, so without this branch the loop would exhaust its retries and surface the raw 400 with
3043
+ * no advice.
3044
+ *
3045
+ * Compacting anyway would be worse than useless: it costs a full-price summarisation pass
3046
+ * and the same structure is refused again. The honest answer is fewer messages, fewer tool
3047
+ * calls, fewer images — or a new session.
3048
+ */
3049
+ const nodeCap = isRequestNodeLimit(err);
3050
+ if (nodeCap.hit && !this.stopRequested) {
3051
+ await this.log.append("system_note", this.currentSession, this.currentBranch, {
3052
+ event: "request-node-limit",
3053
+ limit: nodeCap.limit,
3054
+ messages: this.messages.length,
3055
+ detail: String(err.message).slice(0, 200),
3056
+ });
3057
+ throw new Error(`this request is too LARGE IN STRUCTURE for the provider, not in tokens: the gateway caps ` +
3058
+ `the body at ${nodeCap.limit ?? "a fixed number"} JSON nodes and this session sends ` +
3059
+ `${this.messages.length} messages on top of its tool calls and images. Compacting does ` +
3060
+ `not reliably get under that cap — start a new session, or reduce the message/tool/image ` +
3061
+ `count (a fork at a recent point keeps the context you need). The provider's own words: ` +
3062
+ `${String(err.message).slice(0, 300)}`);
3063
+ }
3036
3064
  throw err;
3037
3065
  }
3038
3066
  // a request the provider accepted: the current depth is enough, so the next
@@ -2494,3 +2494,28 @@ export async function executeTool(name, rawArgs, ctx) {
2494
2494
  return { ok: false, result: `tool error: ${err.message}` };
2495
2495
  }
2496
2496
  }
2497
+ /**
2498
+ * The gateway's cap on the REQUEST BODY'S STRUCTURE, not on its token count.
2499
+ *
2500
+ * Command Code's `/alpha` gateway rejects with
2501
+ * `400 Invalid request JSON: JSON node count cannot exceed 32768`, and the distinction matters
2502
+ * because every usual recovery is wrong for it:
2503
+ *
2504
+ * - COMPACTING does not reliably help. It does reduce message and content-part counts, but a
2505
+ * session heavy in tool calls and images stays above the cap — measured upstream at 22.6% of a
2506
+ * 1,000,000-token window with 1,436 messages and 61 image parts. Retrying after a compaction
2507
+ * therefore burns a full-price summarisation to be refused again.
2508
+ * - RESENDING the same structure cannot succeed at all, so this is not a transient error.
2509
+ *
2510
+ * So it is detected SEPARATELY from `isContextOverflow`, and the remedy is the honest one: a new
2511
+ * session, or fewer messages / tool calls / images in this one.
2512
+ *
2513
+ * Reference: Mars-Sea/dsh-commandcode-provider issue #96 and its `JSON_NODE_LIMIT_REJECTION`.
2514
+ */
2515
+ export function isRequestNodeLimit(err) {
2516
+ const msg = String(err?.message ?? "");
2517
+ const m = /JSON node count cannot exceed\s+(\d+)/i.exec(msg);
2518
+ if (!m)
2519
+ return { hit: false };
2520
+ return { hit: true, ...(m[1] ? { limit: Number(m[1]) } : {}) };
2521
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.37.3",
3
+ "version": "0.37.4",
4
4
  "description": "A lightweight, always-on multi-agent harness for AI coding agents",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-or-later",