Skip to content

Commit 9666623

Browse files
author
Brendan Gray
committed
fix: TDZ crash - move longTermMemory declaration before buildStaticPrompt() call
v1.8.34 crashed on every message with 'Cannot access longTermMemory before initialization'. Root cause: const longTermMemory was declared at line 876 but buildStaticPrompt() (which references longTermMemory at line 767) was called at line 842. Fix: reorder declarations so longTermMemory is initialized before buildStaticPrompt() runs.
1 parent c09242a commit 9666623

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

main/agenticChat.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,20 @@ function register(ctx) {
839839
// ──────────────────────────────────────────────────────
840840
// Agentic Loop State
841841
// ──────────────────────────────────────────────────────
842+
843+
const summarizer = new ConversationSummarizer();
844+
summarizer.setGoal(message);
845+
846+
const rollingSummary = new RollingSummary();
847+
rollingSummary.setGoal(message);
848+
849+
// ── Long-Term Memory (Phase 4) — cross-session memory injection & extraction ──
850+
// MUST be initialized before buildStaticPrompt() which references it
851+
const longTermMemory = new LongTermMemory();
852+
try { longTermMemory.initialize(context?.projectPath); } catch (e) {
853+
console.warn('[AI Chat] Long-term memory init failed:', e.message);
854+
}
855+
842856
let basePrompt = buildStaticPrompt();
843857
let allToolResults = [];
844858
let gatheredWebData = [];
@@ -866,18 +880,6 @@ function register(ctx) {
866880
let nonContextRetries = 0;
867881
const executionState = new ExecutionState();
868882

869-
const summarizer = new ConversationSummarizer();
870-
summarizer.setGoal(message);
871-
872-
const rollingSummary = new RollingSummary();
873-
rollingSummary.setGoal(message);
874-
875-
// ── Long-Term Memory (Phase 4) — cross-session memory injection & extraction ──
876-
const longTermMemory = new LongTermMemory();
877-
try { longTermMemory.initialize(context?.projectPath); } catch (e) {
878-
console.warn('[AI Chat] Long-term memory init failed:', e.message);
879-
}
880-
881883
// ── Session Store (Phase 3) — persistent session state for crash recovery ──
882884
const sessionBasePath = path.join(ctx.userDataPath || require('electron').app.getPath('userData'), 'sessions');
883885
const sessionStore = new SessionStore(sessionBasePath);

0 commit comments

Comments
 (0)