teapot-coding-agent 0.37.2 → 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
@@ -3819,7 +3847,27 @@ export class Agent {
3819
3847
  if (call.function.name === "report_progress") {
3820
3848
  await this.recordProgress(call.function.arguments);
3821
3849
  }
3822
- this.messages.push({ role: "tool", tool_call_id: call.id, content: "progress recorded" });
3850
+ /**
3851
+ * EVERY tool call needs a `tool` message, but only `report_progress` was a report.
3852
+ *
3853
+ * This loop used to answer `"progress recorded"` to whatever the model called, so a `bash`
3854
+ * invocation came back with the text "progress recorded" and `durationMs: 0` — it never ran.
3855
+ * MEASURED in this session (seq 62247/62248): the assistant turn carried exactly one tool
3856
+ * call, `bash <npm view polling loop>`, and its result was `"progress recorded"`, while the
3857
+ * very next `progress` row read "(no report produced)". The command's real output appeared
3858
+ * only on the NEXT turn, which is what made it look like a stray duplicate.
3859
+ *
3860
+ * The model did nothing wrong: it was asked for a progress report and chose to run its work
3861
+ * instead. Answering that call with the report text both lies to the model (the tool result
3862
+ * is its only view of what happened) and drops the command's output.
3863
+ *
3864
+ * A non-report call is answered with a plain acknowledgement — it is NOT executed here,
3865
+ * because this path has no tool context and must not run side effects a second time. The
3866
+ * round then continues and the model sees that it still owes a report.
3867
+ */
3868
+ const isReport = call.function.name === "report_progress";
3869
+ const answer = isReport ? "progress recorded" : "not run — this turn was a progress request";
3870
+ this.messages.push({ role: "tool", tool_call_id: call.id, content: answer });
3823
3871
  // log both sides so restores replay the exact exchange (meta-style)
3824
3872
  await this.log.append("tool_call", this.currentSession, this.currentBranch, {
3825
3873
  callId: call.id,
@@ -3830,9 +3878,10 @@ export class Agent {
3830
3878
  await this.log.append("tool_result", this.currentSession, this.currentBranch, {
3831
3879
  callId: call.id,
3832
3880
  name: call.function.name,
3881
+ // a not-run answer is not a FAILURE, so `ok` stays true — the row must not read as an error
3833
3882
  ok: true,
3834
3883
  durationMs: 0,
3835
- result: "progress recorded",
3884
+ result: answer,
3836
3885
  });
3837
3886
  }
3838
3887
  if (!reported && !(res.message.content ?? "").trim()) {
@@ -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.2",
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",