Skip to content

Commit 8b603e5

Browse files
authored
fix(build): pin Node 24.18.0 to stop the agent crash loop (#214)
Since the 2026-09-07 release the agent aborts whenever a scheduled job starts, so the morning briefing and every other daily job stopped. Cause: the Dockerfiles used the floating node:24-alpine tag. The rebuild pulled Node 24.20, and Node 24.19 added cleanup hooks to node::ObjectWrap (nodejs/node#65446). better-sqlite3 builds on ObjectWrap, so when garbage collection frees one of its objects Node fails "RemoveEnvironmentCleanupHook ... (env) != nullptr" and aborts. - Pin node:24.18.0-alpine (the last good build) in all five Dockerfiles, with a note on when to move it. Match CI and .nvmrc. - searchMessages: the LIKE pattern was "% q % ", which only matched text ending in a space, so searchMemory/searchHistory never found chat history. Use "%q%" and escape LIKE wildcards. - sendMessage: keep an explicit "@lid" target. It rebuilt every target as "<digits>@s.whatsapp.net", which reaches nobody for LID-only contacts.
1 parent 87e5f80 commit 8b603e5

11 files changed

Lines changed: 106 additions & 18 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
- uses: actions/setup-node@v4
1515
with:
16-
node-version: 20
16+
node-version: 24.18.0
1717
cache: npm
1818

1919
- run: npm ci
@@ -27,7 +27,7 @@ jobs:
2727

2828
- uses: actions/setup-node@v4
2929
with:
30-
node-version: 20
30+
node-version: 24.18.0
3131
cache: npm
3232

3333
- run: npm ci

‎.nvmrc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v18.20.8
1+
v24.18.0

‎apps/agent/Dockerfile‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
FROM node:24-alpine AS base
1+
# Pinned to 24.18.0: Node 24.19+ aborts when better-sqlite3 objects are garbage-collected
2+
# ("RemoveEnvironmentCleanupHook ... (env) != nullptr", nodejs/node#65446).
3+
# Only move this forward to a release that fixes that issue.
4+
FROM node:24.18.0-alpine AS base
25
RUN apk add --no-cache libc6-compat python3 py3-pip make g++ git
36
RUN npm install turbo --global
47

@@ -40,7 +43,7 @@ RUN npm prune --production
4043
COPY . .
4144

4245
# --- Runner Stage ---
43-
FROM node:24-alpine AS runner
46+
FROM node:24.18.0-alpine AS runner
4447
WORKDIR /app
4548
ENV LANG=C.UTF-8
4649
ENV NODE_ENV=production

‎apps/agent/src/db.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,14 +1617,16 @@ class AgentDB {
16171617

16181618
// --- Search & Consolidation ---
16191619
searchMessages(query, limit = 10) {
1620-
// Simple LIKE search
1620+
// Substring LIKE search. Escape LIKE wildcards so a literal "%" or "_"
1621+
// in the query doesn't match everything.
16211622
const stmt = this.db.prepare(`
1622-
SELECT timestamp, role, content FROM messages
1623-
WHERE content LIKE ? OR parts LIKE ?
1623+
SELECT timestamp, role, content FROM messages
1624+
WHERE content LIKE ? ESCAPE '\\' OR parts LIKE ? ESCAPE '\\'
16241625
ORDER BY timestamp DESC
16251626
LIMIT ?
16261627
`);
1627-
const likeQuery = `% ${query} % `;
1628+
const escaped = String(query ?? '').replace(/[\\%_]/g, '\\$&');
1629+
const likeQuery = `%${escaped}%`;
16281630
return stmt.all(likeQuery, likeQuery, limit);
16291631
}
16301632

‎apps/agent/src/executors/communication.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,12 @@ class CommunicationExecutor extends BaseExecutor {
129129
}
130130

131131
// Construct metadata
132-
// WhatsApp JID format: [digits]@s.whatsapp.net
132+
// WhatsApp JID format: [digits]@s.whatsapp.net. Keep an explicit
133+
// "@lid" suffix: LID-only contacts have no phone JID, so
134+
// rebuilding "@s.whatsapp.net" from their digits targets nobody.
135+
const jidDomain = svc === 'whatsapp' && /@lid$/i.test(target) ? 'lid' : 's.whatsapp.net';
133136
const metadata = {
134-
chatId: `${cleanTo}@s.whatsapp.net`,
137+
chatId: `${cleanTo}@${jidDomain}`,
135138
session: session || 'assistant'
136139
};
137140

‎apps/agent/tests/communication.test.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,30 @@ describe('CommunicationExecutor', () => {
240240
expect(mockInterfaceService.send).not.toHaveBeenCalled();
241241
});
242242
});
243+
244+
describe('CommunicationExecutor LID targets', () => {
245+
let send;
246+
let executor;
247+
248+
beforeEach(() => {
249+
send = jest.fn().mockResolvedValue({ success: true });
250+
executor = new CommunicationExecutor({
251+
interface: { send },
252+
db: { isVerifiedContact: jest.fn().mockReturnValue(true), verifyContact: jest.fn(), searchPeople: jest.fn() }
253+
});
254+
});
255+
256+
test('keeps the @lid domain for LID-only contacts', async () => {
257+
await executor.execute('sendMessage', { to: '100000000000001@lid', content: 'hi', session: 'user' }, { message: {} });
258+
expect(send).toHaveBeenCalledWith(expect.objectContaining({
259+
metadata: expect.objectContaining({ chatId: '100000000000001@lid', session: 'user' })
260+
}));
261+
});
262+
263+
test('still builds a phone JID from bare digits', async () => {
264+
await executor.execute('sendMessage', { to: '+54 9 000 000-0000', content: 'hi' }, { message: {} });
265+
expect(send).toHaveBeenCalledWith(expect.objectContaining({
266+
metadata: expect.objectContaining({ chatId: '[email protected]' })
267+
}));
268+
});
269+
});

‎apps/agent/tests/db.test.js‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,44 @@ describe('AgentDB', () => {
140140
});
141141
});
142142
});
143+
144+
describe('AgentDB.searchMessages', () => {
145+
const searchDir = path.join(__dirname, 'tmp_db_search');
146+
let db;
147+
148+
const save = (content) => db.saveMessage({
149+
id: crypto.randomUUID(),
150+
role: 'user',
151+
content,
152+
source: 'web',
153+
metadata: { chatId: 'search-test' },
154+
timestamp: new Date().toISOString()
155+
});
156+
157+
beforeEach(() => {
158+
fs.rmSync(searchDir, { recursive: true, force: true });
159+
db = new AgentDB(searchDir);
160+
});
161+
162+
afterEach(() => {
163+
if (db) db.close();
164+
fs.rmSync(searchDir, { recursive: true, force: true });
165+
});
166+
167+
test('finds a word anywhere in the message, not only when padded by spaces', () => {
168+
save('dentist appointment moved to friday');
169+
save('Dentist, again.');
170+
save('unrelated note');
171+
172+
const rows = db.searchMessages('dentist', 10);
173+
expect(rows.map(r => r.content).sort()).toEqual(['Dentist, again.', 'dentist appointment moved to friday']);
174+
});
175+
176+
test('treats LIKE wildcards in the query literally', () => {
177+
save('battery at 50% now');
178+
save('battery at 500 now');
179+
180+
const rows = db.searchMessages('50%', 10);
181+
expect(rows.map(r => r.content)).toEqual(['battery at 50% now']);
182+
});
183+
});

‎apps/api/Dockerfile‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
FROM node:24-alpine AS base
1+
# Pinned to 24.18.0: Node 24.19+ aborts when better-sqlite3 objects are garbage-collected
2+
# ("RemoveEnvironmentCleanupHook ... (env) != nullptr", nodejs/node#65446).
3+
# Only move this forward to a release that fixes that issue.
4+
FROM node:24.18.0-alpine AS base
25
RUN apk add --no-cache libc6-compat python3 py3-pip make g++
36
RUN npm install turbo --global
47

@@ -35,7 +38,7 @@ RUN npm prune --production
3538
COPY . .
3639

3740
# --- Runner Stage ---
38-
FROM node:24-alpine AS runner
41+
FROM node:24.18.0-alpine AS runner
3942
WORKDIR /app
4043

4144
COPY --from=builder /app/node_modules ./node_modules

‎apps/interfaces/Dockerfile‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
FROM node:24-alpine AS base
1+
# Pinned to 24.18.0: Node 24.19+ aborts when better-sqlite3 objects are garbage-collected
2+
# ("RemoveEnvironmentCleanupHook ... (env) != nullptr", nodejs/node#65446).
3+
# Only move this forward to a release that fixes that issue.
4+
FROM node:24.18.0-alpine AS base
25
RUN apk add --no-cache libc6-compat python3 py3-pip make g++
36
RUN npm install turbo --global
47

@@ -35,7 +38,7 @@ RUN npm prune --production
3538
COPY . .
3639

3740
# --- Runner Stage ---
38-
FROM node:24-alpine AS runner
41+
FROM node:24.18.0-alpine AS runner
3942
RUN apk add --no-cache ffmpeg
4043
WORKDIR /app
4144
ENV LANG=C.UTF-8

‎apps/supervisor/Dockerfile‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
FROM node:24-alpine AS base
1+
# Pinned to 24.18.0: Node 24.19+ aborts when better-sqlite3 objects are garbage-collected
2+
# ("RemoveEnvironmentCleanupHook ... (env) != nullptr", nodejs/node#65446).
3+
# Only move this forward to a release that fixes that issue.
4+
FROM node:24.18.0-alpine AS base
25
RUN apk add --no-cache libc6-compat python3 py3-pip make g++ git
36
RUN npm install turbo --global
47

@@ -35,7 +38,7 @@ RUN npm prune --production
3538
COPY . .
3639

3740
# --- Runner Stage ---
38-
FROM node:24-alpine AS runner
41+
FROM node:24.18.0-alpine AS runner
3942
WORKDIR /app
4043
ENV LANG=C.UTF-8
4144
ENV NODE_ENV=production

0 commit comments

Comments
 (0)