Bugfix: Session 135: Fix ~8 unsafe .getTime() calls on JSON-deserial...
Documentation for Sessions
🐛 Bugfix: Session 135: Fix ~8 unsafe .getTime() calls on JSON-deserial...
Date: 2026-02-22
Time: 21:01:33 UTC
Session: gspace1-135.10
Agent: architecture
Confidence: 95%
Status: ✅ Documented
📋 Decision Context
Question:
Session 135: Fix ~8 unsafe .getTime() calls on JSON-deserialized date fields across MCP services that would throw TypeError at runtime
Task: Fix unsafe .getTime() calls in MCP services
🎯 Decision Made
Chosen:
Wrapped all bare field.getTime() calls in new Date(field).getTime(). Added toMs() utility function to MCP utils/index.ts for future use. Fixed files: ai-learning-dashboard.ts, cross-tier-transfer.ts (2 calls), advanced-pattern-miner.ts, predictive-intelligence.ts, federated-learning-network.ts, realtime-alerting.ts (8 calls). TypeScript compilation verified clean.
Options Considered:
- No alternatives documented
💭 Reasoning
ROOT CAUSE: JSON.parse() converts Date objects to ISO strings. Any code that calls .getTime() on a field that was originally a Date but went through JSON serialization/deserialization will crash with TypeError. This is the same class of bug as the report-outcome.ts timestamp fix. The pattern is pervasive because developers write code against in-memory Date objects but forget that the memory store is loaded from JSON files on startup. PREVENTION: Added toMs() utility function to utils/index.ts that safely handles Date, string, number, null, and undefined inputs.
📁 Files Involved
MCP/mcp-gograb-ai/src/utils/index.tsMCP/mcp-gograb-ai/src/services/ai-learning-dashboard.tsMCP/mcp-gograb-ai/src/services/cross-tier-transfer.tsMCP/mcp-gograb-ai/src/services/advanced-pattern-miner.tsMCP/mcp-gograb-ai/src/services/predictive-intelligence.tsMCP/mcp-gograb-ai/src/services/federated-learning-network.tsMCP/mcp-gograb-ai/src/services/realtime-alerting.ts
🔗 Related
- Decision ID:
dev_1771794093585_ravi8ro - Session: 135
- Workspace: gspace1
Auto-generated by MCP Smart Consolidation