fix(container): gracefully handle missing on_wake column in pre-migration session DBs
The container opens inbound.db read-only, so it can't ALTER TABLE. If the host hasn't run migrateMessagesInTable yet (e.g., container rebuilt before host restart), the on_wake column won't exist and the query crashes, causing a restart loop. Detect the column via PRAGMA table_info and conditionally include the filter clause. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,19 @@
|
|||||||
import { getConfig } from '../config.js';
|
import { getConfig } from '../config.js';
|
||||||
import { openInboundDb, getOutboundDb } from './connection.js';
|
import { openInboundDb, getOutboundDb } from './connection.js';
|
||||||
|
|
||||||
|
// Cache whether inbound.db has the on_wake column (added in v2.0.48).
|
||||||
|
// The container opens inbound.db read-only, so it can't ALTER —
|
||||||
|
// gracefully degrade when running against an older session DB.
|
||||||
|
let _hasOnWake: boolean | null = null;
|
||||||
|
function hasOnWakeColumn(db: ReturnType<typeof openInboundDb>): boolean {
|
||||||
|
if (_hasOnWake !== null) return _hasOnWake;
|
||||||
|
const cols = new Set(
|
||||||
|
(db.prepare("PRAGMA table_info('messages_in')").all() as Array<{ name: string }>).map((c) => c.name),
|
||||||
|
);
|
||||||
|
_hasOnWake = cols.has('on_wake');
|
||||||
|
return _hasOnWake;
|
||||||
|
}
|
||||||
|
|
||||||
export interface MessageInRow {
|
export interface MessageInRow {
|
||||||
id: string;
|
id: string;
|
||||||
seq: number | null;
|
seq: number | null;
|
||||||
@@ -54,12 +67,13 @@ export function getPendingMessages(isFirstPoll = false): MessageInRow[] {
|
|||||||
const outbound = getOutboundDb();
|
const outbound = getOutboundDb();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const onWakeFilter = hasOnWakeColumn(inbound) ? 'AND (on_wake = 0 OR ?1 = 1)' : '';
|
||||||
const pending = inbound
|
const pending = inbound
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT * FROM messages_in
|
`SELECT * FROM messages_in
|
||||||
WHERE status = 'pending'
|
WHERE status = 'pending'
|
||||||
AND (process_after IS NULL OR datetime(process_after) <= datetime('now'))
|
AND (process_after IS NULL OR datetime(process_after) <= datetime('now'))
|
||||||
AND (on_wake = 0 OR ?1 = 1)
|
${onWakeFilter}
|
||||||
ORDER BY seq DESC
|
ORDER BY seq DESC
|
||||||
LIMIT ?2`,
|
LIMIT ?2`,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user