fix(autonomous): guard rowTo* JSON.parse with safe fallback (AUDIT-H1)#261
fix(autonomous): guard rowTo* JSON.parse with safe fallback (AUDIT-H1)#261xlabtg merged 4 commits intoxlabtg:mainfrom
Conversation
Adding .gitkeep for PR creation (default mode). This file will be removed when the task is complete. Issue: xlabtg#260
A single row with malformed JSON in success_criteria, failure_conditions, constraints, retry_policy, context, state, tool_calls, or data would throw out of rowToTask/rowToCheckpoint/rowToLogEntry and DoS /api/autonomous. Wrap every parse in a safeJSONParse helper that logs a warning with task/checkpoint context and returns a typed fallback so one bad row no longer takes down listing.
Solution summarySummary of changes
Verification: full vitest run (2943/2943), lint, prettier, and tsc all pass. This summary was automatically extracted from the AI working session output. |
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost: $2.344123📊 Context and tokens usage:Claude Opus 4.7:
Total: (86.6K + 2.6M cached) input tokens, 15.0K output tokens, $2.235939 cost Claude Haiku 4.5:
Total: (35.5K + 428.3K cached) input tokens, 4.2K output tokens, $0.108184 cost 🤖 Models used:
📎 Log file uploaded as Gist (1617KB)Now working session is ended, feel free to review and add any feedback on the solution draft. |
🔄 Auto-restart triggered (iteration 1)Reason: Merge conflicts detected Starting new session to address the issues. Auto-restart-until-mergeable mode is active. Will continue until PR becomes mergeable. |
# Conflicts: # .gitkeep
# Conflicts: # .gitkeep
🔄 Auto-restart-until-mergeable Log (iteration 1)This log file contains the complete execution trace of the AI solution draft process. 💰 Cost: $2.173186📊 Context and tokens usage:
Total: (60.6K + 2.9M cached) input tokens, 13.5K output tokens, $2.173186 cost 🤖 Models used:
📎 Log file uploaded as Gist (2978KB)Now working session is ended, feel free to review and add any feedback on the solution draft. |
Fixes #260 — AUDIT-H1:
JSON.parseinrowTo*has no try/catch — one bad row DoSes listing.Problem
rowToTask,rowToCheckpoint, androwToLogEntryinsrc/memory/agent/autonomous-tasks.tscalledJSON.parse(...)on ten different columns without any error handling. A single row with corrupt JSON (manual DB edits, crashed writes, buggy backfills) propagated aSyntaxErrorout oflistTasks/getTask/getCheckpoint/getExecutionLogs, breaking the entire/api/autonomouspage and leaving the operator no in-UI path to diagnose which row was bad.Fix
Added a
safeJSONParse<T>(value, fallback, context?)helper at the top ofautonomous-tasks.ts:JSON.parsethrows.warnvia the module logger withtaskId/checkpointId/columncontext and a truncated copy of the offending value so operators can locate the bad row.[]for array columns (success_criteria,failure_conditions,tool_calls),{}for object columns (constraints,context,state), a sane defaultRetryPolicyforretry_policy, andundefinedfor the optionalexecution_logs.data.Reproduction + Test Coverage
New
src/memory/__tests__/autonomous-tasks.test.tswith 13 tests covering the acceptance criteria:listTaskswith one corrupt row returns all three rows (two good + the corrupt one with fallback fields) and does not throw.taskId.rowToTaskfallbacks verified per column: corruptcontext→{},success_criteria→[],failure_conditions→[],constraints→{},retry_policy→ default{maxRetries, backoff}.rowToCheckpointfallbacks: corruptstate→{}, corrupttool_calls→[], warning includescheckpointId.rowToLogEntry: corruptdatacolumn →undefined;NULLdata does not log a warning.Acceptance criteria
JSON.parseinrowTo*are wrapped insafeJSONParsewith a safe fallback.listTasksreturns all remaining rows and logs a warning instead of throwing.rowToTaskon corruptmetadata/contextreturns fallback{}.rowToCheckpointon corruptstatereturns fallback{}.taskIdfor diagnostics.Verification
npx vitest run src/memory/__tests__/autonomous-tasks.test.ts→ 13/13 ✅npx vitest run→ 2943/2943 ✅npm run lint→ clean ✅npx tsc --noEmit→ clean ✅npx prettier --check …→ clean ✅Test plan
npm testlocallynpm run lintnpm run typecheck