fix(db): add startup delays to prevent resource race conditions (#398)

* feat(chat): redesign attachments with ContentBlock format and file downloads

- Redesign attachment handling using Anthropic-style ContentBlock array format
  with discriminated unions (text, image, file types)
- Add frontend file download functionality supporting both ContentBlock
  and Markdown formats with authentication tokens
- Fix multi-process conflict causing SQLite database resets by eliminating
  redundant nodemon instances
- Update chat store to build ContentBlock arrays from attachments
- Improve image handling with base64 conversion for upstream API

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(db): add startup delays to prevent resource race conditions

- Add 1 second delay after gateway manager initialization
- Add 1 second delay after store initialization before session sync
- Code formatting cleanup in schemas.ts

These delays ensure all resources are fully initialized before
proceeding to the next startup step, preventing potential race
conditions and database access issues during server bootstrap.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ekko
2026-05-02 17:02:33 +08:00
committed by GitHub
parent 793003fcf6
commit 8af1951f13
2 changed files with 5 additions and 3 deletions
+2 -2
View File
@@ -543,8 +543,8 @@ export function initAllHermesTables(retryCount = 0): void {
}
// 3. 删除 WAL 和 SHM 文件
try { unlinkSync(dbPath + '-wal') } catch {}
try { unlinkSync(dbPath + '-shm') } catch {}
try { unlinkSync(dbPath + '-wal') } catch { }
try { unlinkSync(dbPath + '-shm') } catch { }
// 4. 重新初始化(增加重试计数)
console.log('[Schema] Reinitializing database...')
+3 -1
View File
@@ -48,10 +48,12 @@ export async function bootstrap() {
await initGatewayManager()
console.log('[bootstrap] gateway manager initialized')
await new Promise(resolve => setTimeout(resolve, 1000))
// Initialize all web-ui SQLite tables
const { initAllStores } = await import('./db/hermes/init')
// Wait 1 second before initializing stores to ensure all resources are ready
initAllStores()
await new Promise(resolve => setTimeout(resolve, 1000))
console.log('[bootstrap] all stores initialized')
// Sync Hermes sessions from all profiles (only if local DB is empty)