@ducci/jarvis 1.0.26 → 1.0.27

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.
@@ -0,0 +1,121 @@
1
+ # Finding 010: Non-String `checkpoint.remaining` Crashes Zero-Progress Detection
2
+
3
+ **Date:** 2026-03-01
4
+ **Severity:** High — caused "Sorry, something went wrong" in Telegram with no useful context; crashed the handoff loop mid-run
5
+ **Status:** Fixed
6
+
7
+ ---
8
+
9
+ ## Observed Session
10
+
11
+ The session ran 13+ agent runs working on OWASP ZAP installation. Runs 8–13 were consecutive `checkpoint_reached` handoffs. On entry 14 (immediately after entry 13), the server logged:
12
+
13
+ ```
14
+ status: error
15
+ response: "An unexpected server error occurred: (run.checkpoint.remaining || "").trim is not a function"
16
+ ```
17
+
18
+ The Telegram user received:
19
+
20
+ ```
21
+ Sorry, something went wrong: (run.checkpoint.remaining || "").trim is not a function
22
+ ```
23
+
24
+ ---
25
+
26
+ ## Bug Chain
27
+
28
+ ### Step 1 — Wrap-up call returns non-string `remaining`
29
+
30
+ At iteration limit, `runAgentLoop` sends the `WRAP_UP_NOTE` and parses the model's JSON response. The model returned `checkpoint.remaining` as a non-string value (array or object) instead of a plain text string. `parsedWrapUp.checkpoint` was stored and returned with no type validation.
31
+
32
+ ### Step 2 — Zero-progress detection crashes on `.trim()`
33
+
34
+ In `_runHandleChat`, finding 007 introduced zero-progress detection:
35
+
36
+ ```js
37
+ const currentRemaining = (run.checkpoint.remaining || '').trim();
38
+ ```
39
+
40
+ The `|| ''` guard only catches falsy values (null, undefined). A truthy non-string (array, object) passes through the `||` and `.trim()` is called on a non-string:
41
+
42
+ ```
43
+ TypeError: (run.checkpoint.remaining || "").trim is not a function
44
+ ```
45
+
46
+ ### Step 3 — Outer catch logs the error and re-throws
47
+
48
+ The `try/catch` at the top of the handoff loop caught the TypeError, wrote an `error` status log entry, and re-threw. The Telegram handler surfaced the raw error message.
49
+
50
+ ---
51
+
52
+ ## Secondary Issues
53
+
54
+ **`resumeContent` (line 520)**: `run.checkpoint.remaining || 'Continue with the task.'` — if `remaining` is a truthy non-string, it would be pushed directly into `session.messages` as the next user message content. The message API expects a string, so this would produce a malformed conversation message.
55
+
56
+ **`failedApproaches` spread (lines 461–463)**: If the model returns `failedApproaches` as a non-array (string, object), `push(...value)` would spread wrong data. A string spreads individual characters; an object spreads its enumerable values.
57
+
58
+ ---
59
+
60
+ ## Root Cause
61
+
62
+ Same class of bug as finding 009 (non-string `response` field). Finding 009 hardened `response` and `logSummary` extraction, but the `checkpoint` sub-object fields were not included in that hardening pass. Models — especially smaller/free models under iteration-limit pressure — sometimes return structured data (arrays, objects) in fields the system prompt specifies as plain text strings.
63
+
64
+ ---
65
+
66
+ ## Fix
67
+
68
+ ### `src/server/agent.js` — normalize checkpoint fields at source
69
+
70
+ Added a normalization block immediately inside the `if (parsedWrapUp.checkpoint)` branch, before any checkpoint field is accessed downstream:
71
+
72
+ ```js
73
+ const cp = parsedWrapUp.checkpoint;
74
+ // remaining must be a string — used as the next run's resume prompt
75
+ if (typeof cp.remaining !== 'string') {
76
+ cp.remaining = Array.isArray(cp.remaining)
77
+ ? cp.remaining.map(String).join('\n')
78
+ : cp.remaining != null ? JSON.stringify(cp.remaining) : '';
79
+ }
80
+ // failedApproaches must be an array of strings — spread into session metadata
81
+ if (!Array.isArray(cp.failedApproaches)) {
82
+ cp.failedApproaches = [];
83
+ } else {
84
+ cp.failedApproaches = cp.failedApproaches.map(item =>
85
+ typeof item === 'string' ? item : JSON.stringify(item)
86
+ );
87
+ }
88
+ ```
89
+
90
+ **Array coercion for `remaining`**: when the model returns an array (e.g., `["install Java", "create symlink"]`), elements are joined with newlines rather than JSON-stringified — producing a natural readable resume prompt rather than raw JSON syntax.
91
+
92
+ **Centralized normalization**: fixing at source (right after parse) rather than at each use site means lines 469 and 520 need no change. Any future use of `checkpoint.remaining` or `checkpoint.failedApproaches` is automatically safe.
93
+
94
+ ### `src/server/agent.js` — update `WRAP_UP_NOTE`
95
+
96
+ Added explicit type constraints to the `remaining` field description and a trailing instruction:
97
+
98
+ ```
99
+ "remaining": "What still needs to be done — as a plain text string, never an array or object."
100
+ ...
101
+ remaining must be a plain text string. failedApproaches must be a JSON array of strings.
102
+ ```
103
+
104
+ ---
105
+
106
+ ## What Was Not Changed
107
+
108
+ - `agent.js` lines 469 and 520 — no changes needed; normalization at source makes them safe
109
+ - `src/channels/telegram/index.js` — finding 007 and 009 already added `.catch(() => {})` and type guards on delivery
110
+ - `sessions.js`, `tools.js` — no changes needed
111
+
112
+ ---
113
+
114
+ ## Outcome
115
+
116
+ | Fix | Files changed |
117
+ |-----|--------------|
118
+ | Normalize `checkpoint.remaining` to string and `checkpoint.failedApproaches` to string array at source | `src/server/agent.js` |
119
+ | Add explicit type constraints to WRAP_UP_NOTE | `src/server/agent.js` |
120
+
121
+ **Effect**: instead of a `TypeError` crash mid-handoff-loop, the model's non-string `remaining` value is coerced to a readable string and used as the resume prompt. The session continues normally.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ducci/jarvis",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "A fully automated agent system that lives on a server.",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -19,12 +19,12 @@ Respond with your normal JSON, but add a checkpoint field:
19
19
  "logSummary": "Human-readable summary of what happened in this run.",
20
20
  "checkpoint": {
21
21
  "progress": "What has been fully completed so far.",
22
- "remaining": "What still needs to be done to finish the task.",
22
+ "remaining": "What still needs to be done to finish the task — as a plain text string, never an array or object.",
23
23
  "failedApproaches": ["Concise description of each approach that was tried and failed, e.g. 'downloading subfinder via curl from GitHub releases — connection reset'. Omit array entries for things that succeeded. Leave as empty array if nothing failed."]
24
24
  }
25
25
  }
26
26
 
27
- The checkpoint field will be used to automatically resume the task in the next run. failedApproaches is injected into the next run so the agent does not waste iterations repeating strategies that already failed.]`;
27
+ The checkpoint field will be used to automatically resume the task in the next run. failedApproaches is injected into the next run so the agent does not waste iterations repeating strategies that already failed. remaining must be a plain text string. failedApproaches must be a JSON array of strings.]`;
28
28
 
29
29
  // Serializes concurrent requests for the same session. Maps sessionId to the
30
30
  // tail of the current request chain (a Promise that resolves when the last
@@ -319,6 +319,22 @@ async function runAgentLoop(client, config, session, prepareMessages) {
319
319
  : parsedWrapUp.response != null ? JSON.stringify(parsedWrapUp.response, null, 2) : '';
320
320
  logSummary = parsedWrapUp.logSummary || '';
321
321
  if (parsedWrapUp.checkpoint) {
322
+ // Normalize checkpoint fields to their expected types. Models sometimes
323
+ // return arrays or objects in fields that must be strings — the same class
324
+ // of bug fixed for `response` in finding 009.
325
+ const cp = parsedWrapUp.checkpoint;
326
+ if (typeof cp.remaining !== 'string') {
327
+ cp.remaining = Array.isArray(cp.remaining)
328
+ ? cp.remaining.map(String).join('\n')
329
+ : cp.remaining != null ? JSON.stringify(cp.remaining) : '';
330
+ }
331
+ if (!Array.isArray(cp.failedApproaches)) {
332
+ cp.failedApproaches = [];
333
+ } else {
334
+ cp.failedApproaches = cp.failedApproaches.map(item =>
335
+ typeof item === 'string' ? item : JSON.stringify(item)
336
+ );
337
+ }
322
338
  return {
323
339
  iteration,
324
340
  response,