Skip to content

SQLite Database Corrupt Error on new site #649

Closed

Description

@claughinghouse

Description

When deploying a new blank site I see this error when attempting to update any page on a site. Replicated with new site, D1 db, and bucket. Only occurs when editing a published page or post.

Steps to reproduce

  1. Create a new site using the Deploy to cloud button
  2. Create admin account and login
  3. Create a page or post
  4. Add Contents and click save
  5. Re-open post or page and edit any content
  6. Click publish
  7. Failed toast pops up with above log in the cloudflare logs.

Environment

EmDash - 0.4.0
Node 22
Cloudflare workers

Logs / error output

{ "message": "Content publish error: Error: D1_ERROR: database disk image is malformed: SQLITE_CORRUPT (extended: SQLITE_CORRUPT_VTAB)", "level": "error", "$workers": { "truncated": false, "event": { "request": { "url": "https://emdas.example.com/_emdash/api/content/pages/01KPGMSTHB085S85Z1ESJNPKZ0/publish", "method": "POST", "path": "/_emdash/api/content/pages/01KPGMSTHB085S85Z1ESJNPKZ0/publish" } }, "outcome": "ok", "scriptName": "example-com-emdash", "eventType": "fetch", "executionModel": "stateless", "scriptVersion": { "id": "2c05b7ee-8c16-46f4-84e7-97deb96e87d6" }, "requestId": "9ee4d9627fd4573a" }, "$metadata": { "id": "01KPGMT6SJA7PQTJ48600W6ZDH", "requestId": "9ee4d9627fd4573a", "trigger": "POST /_emdash/api/content/pages/01KPGMSTHB085S85Z1ESJNPKZ0/publish", "service": "example-com-emdash", "level": "error", "error": "Content publish error: Error: D1_ERROR: database disk image is malformed: SQLITE_CORRUPT (extended: SQLITE_CORRUPT_VTAB)", "message": "Content publish error: Error: D1_ERROR: database disk image is malformed: SQLITE_CORRUPT (extended: SQLITE_CORRUPT_VTAB)", "account": "483669ea821828435edea4557f0620ea", "type": "cf-worker", "fingerprint": "b64558f2c0cad7b5e17f30191a8fb5e3", "origin": "fetch", "messageTemplate": "Content publish error: Error: D1_ERROR: database disk image is malformed: SQLITE_CORRUPT (extended: SQLITE_CORRUPT_VTAB)", } }
{ "message": "POST https://emdash.example.com/_emdash/api/content/pages/01KPGMSTHB085S85Z1ESJNPKZ0/publish", "level": "error", "$workers": { "event": { "request": { "cf": { "requestHeaderNames": {}, "botManagement": { "detectionIds": {}, "corporateProxy": false, "verifiedBot": false, "jsDetection": { "passed": false, }, "staticResource": false, "score": 99, }, "isEUCountry": false, "tlsClientAuth": { "certRFC9440TooLarge": false, "certChainRFC9440TooLarge": false, "certPresented": "0", "certVerified": "NONE", "certRevoked": "0", "certIssuerDN": "", "certSubjectDN": "", "certIssuerDNRFC2253": "", "certSubjectDNRFC2253": "", "certIssuerDNLegacy": "", "certSubjectDNLegacy": "", "certSerial": "", "certIssuerSerial": "", "certSKI": "", "certIssuerSKI": "", "certFingerprintSHA1": "", "certFingerprintSHA256": "", "certNotBefore": "", "certNotAfter": "", "certRFC9440": "", "certChainRFC9440": "" }, "httpProtocol": "HTTP/3", "clientAcceptEncoding": "gzip, deflate, br", "requestPriority": "", "colo": "N/A", "asOrganization": "n/a", "country": "US", "city": "redacted", "continent": "NA", "region": "redacted", "regionCode": "NA", "timezone": "America/New_York", "longitude": "-redacted", "latitude": "redacted", "postalCode": "removed", "metroCode": "n/a", "tlsVersion": "TLSv1.3", "tlsCipher": "AEAD-AES256-GCM-SHA384", "tlsClientRandom": "wTqNGGU/lKt/OMu26rWBl38qL8YAE7UMyS1zVf78Xrw=", "tlsClientCiphersSha1": "Vvu1Wqm1r1OJOzu1ymEBLTp6Bxo=", "tlsClientExtensionsSha1": "5pSNXikPa/3pTynT+T6ETjQsEYQ=", "tlsClientExtensionsSha1Le": "otS3Q5sCQV2RmDJaBvTzr4DwJAc=", "tlsClientHelloLength": "1478", "verifiedBotCategory": "", "edgeRequestKeepAliveStatus": 1, "clientTcpRtt": 0, "clientQuicRtt": 26, "asn": n/a, "edgeL4": { "deliveryRate": 19336647, } }, "url": "https://emdash.example.com/_emdash/api/content/pages/01KPGMSTHB085S85Z1ESJNPKZ0/publish", "method": "POST", "headers": { "accept": "*/*", "accept-encoding": "gzip, br", "accept-language": "en-US,en;q=0.9", "cf-connecting-ip": "redacted", "cf-ipcountry": "US", "cf-ray": "9ee4d9627fd4573a", "cf-visitor": "{"scheme":"https"}", "connection": "Keep-Alive", "content-length": "0", "cookie": "REDACTED", "host": "emdash.example.com", "origin": "https://emdash.example.com", "priority": "u=3, i", "referer": "https://emdash.example.com/_emdash/admin/content/pages/01KPGMSTHB085S85Z1ESJNPKZ0", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-origin", "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.4 Safari/605.1.15", "x-emdash-request": "1", "x-forwarded-proto": "https", "x-real-ip": "redacted" }, "path": "/_emdash/api/content/pages/01KPGMSTHB085S85Z1ESJNPKZ0/publish" }, "rayId": "9ee4d9627fd4573a", "response": { "status": 500, } }, "truncated": false, "scriptName": "example-com-emdash", "outcome": "ok", "eventType": "fetch", "executionModel": "stateless", "scriptVersion": { "id": "2c05b7ee-8c16-46f4-84e7-97deb96e87d6" }, "requestId": "9ee4d9627fd4573a", "cpuTimeMs": 9, "wallTimeMs": 448, }, "$metadata": { "id": "01KPGMT6MJ8HMS9QKBRRNCNWB3", "requestId": "9ee4d9627fd4573a", "trigger": "POST /_emdash/api/content/pages/01KPGMSTHB085S85Z1ESJNPKZ0/publish", "service": "example-com-emdash", "level": "error", "error": "POST https://emdash.example.com/_emdash/api/content/pages/01KPGMSTHB085S85Z1ESJNPKZ0/publish", "message": "POST https://emdash.example.com/_emdash/api/content/pages/01KPGMSTHB085S85Z1ESJNPKZ0/publish", "account": "483669ea821828435edea4557f0620ea", "type": "cf-worker-event", "fingerprint": "1a50c4deb71e224689a699e1a96190e5", "origin": "fetch", "messageTemplate": "POST https://emdash.example.com/_emdash/api/content/pages/01KPGMSTHB085S85Z1ESJNPKZ0/publish", } }

Activity

  1. added
    bug
    on Apr 18, 2026
  2. wchiquito commented on Apr 19, 2026

    @wchiquito

    Same error in a local environment trying to publish the page: About (emdash-demo (/emdash/demos/simple/)).

    Environment

    EmDash: commit ada4ac7 (HEAD -> main, origin/main, origin/HEAD)
    Node.js: v25.9.0
    SQLite: 3.46.1

    Logs / error output

    Content publish error: SqliteError: database disk image is malformed
        at SqliteConnection.executeQuery (/path/to/emdash/node_modules/.pnpm/[email protected]/node_modules/kysely/dist/cjs/dialect/sqlite/sqlite-driver.js:61:55)
        at file:///path/to/emdash/node_modules/.pnpm/[email protected]/node_modules/kysely/dist/esm/query-executor/query-executor-base.js:35:45
        at #run (file:///path/to/emdash/node_modules/.pnpm/[email protected]/node_modules/kysely/dist/esm/driver/single-connection-provider.js:24:22)
        at SingleConnectionProvider.provideConnection (file:///path/to/emdash/node_modules/.pnpm/[email protected]/node_modules/kysely/dist/esm/driver/single-connection-provider.js:16:41)
        at DefaultQueryExecutor.provideConnection (file:///path/to/emdash/node_modules/.pnpm/[email protected]/node_modules/kysely/dist/esm/query-executor/default-query-executor.js:20:41)
        at DefaultQueryExecutor.executeQuery (file:///path/to/emdash/node_modules/.pnpm/[email protected]/node_modules/kysely/dist/esm/query-executor/query-executor-base.js:34:27)
        at UpdateQueryBuilder.execute (file:///path/to/emdash/node_modules/.pnpm/[email protected]/node_modules/kysely/dist/esm/query-builder/update-query-builder.js:453:51)
        at ContentRepository.syncDataColumns (/path/to/emdash/packages/core/src/database/repositories/content.ts:1096:5)
        at ContentRepository.publish (/path/to/emdash/packages/core/src/database/repositories/content.ts:951:15)
        at async file:///path/to/emdash/node_modules/.pnpm/[email protected]/node_modules/kysely/dist/esm/kysely.js:436:32
        at async DefaultConnectionProvider.provideConnection (file:///path/to/emdash/node_modules/.pnpm/[email protected]/node_modules/kysely/dist/esm/driver/default-connection-provider.js:10:20)
        at async handleContentPublish (/path/to/emdash/packages/core/src/api/handlers/content.ts:999:16)
        at async EmDashRuntime.handleContentPublish (/path/to/emdash/packages/core/src/emdash-runtime.ts:1867:18)
        at async Module.POST (/path/to/emdash/packages/core/src/astro/routes/api/content/[collection]/[id]/publish.ts:49:17)
        at async renderEndpoint (/path/to/emdash/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected]._dedb2502a3da963a245a4af4094aacf2/node_modules/astro/dist/runtime/server/endpoint.js:37:18)
        at async lastNext (/path/to/emdash/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected]._dedb2502a3da963a245a4af4094aacf2/node_modules/astro/dist/core/render-context.js:245:23)
        at async virtualAuthenticate (/path/to/emdash/packages/core/src/astro/middleware/auth.ts:258:19)
        at async renderAndFinalize (/path/to/emdash/packages/core/src/astro/middleware.ts:485:22)
        at async callMiddleware (/path/to/emdash/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected]._dedb2502a3da963a245a4af4094aacf2/node_modules/astro/dist/core/middleware/callMiddleware.js:11:10)
        at async RenderContext.render (/path/to/emdash/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected]._dedb2502a3da963a245a4af4094aacf2/node_modules/astro/dist/core/render-context.js:292:73)
        at async AstroServerApp.render (/path/to/emdash/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected]._dedb2502a3da963a245a4af4094aacf2/node_modules/astro/dist/core/app/base.js:347:20)
        at async run (/path/to/emdash/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected]._dedb2502a3da963a245a4af4094aacf2/node_modules/astro/dist/vite-plugin-app/app.js:138:26)
        at async runWithErrorHandling (/path/to/emdash/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected]._dedb2502a3da963a245a4af4094aacf2/node_modules/astro/dist/vite-plugin-astro-server/controller.js:64:5)
        at async AstroServerApp.handleRequest (/path/to/emdash/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected]._dedb2502a3da963a245a4af4094aacf2/node_modules/astro/dist/vite-plugin-app/app.js:116:5) {
      code: 'SQLITE_CORRUPT_VTAB'
    }
    
    [500] POST /_emdash/api/content/pages/:id/publish
    
  3. mahmingtea commented on Apr 21, 2026

    @mahmingtea

    Same issue, after installing 0.6.0
    even database direct change is showing this issue
    database disk image is malformed: SQLITE_CORRUPT (extended: SQLITE_CORRUPT_VTAB)
    Image

  4. contestra commented on Apr 21, 2026

    @contestra

    Adding a data point that may help triage:

    Same SQLITE_CORRUPT_VTAB reproduces on [email protected] (post-PR #313). Specifically, an UPDATE ec_posts SET deleted_at = NULL ... failed today with:

    database disk image is malformed: SQLITE_CORRUPT (extended: SQLITE_CORRUPT_VTAB) [code: 7500]
    

    Hypothesis on why PR #313 didn't fully resolve this: PR #313 removes the verifyAndRepairIndex startup INSERT that originally caused #252, which protects newly-created tenants going forward. But tenants whose FTS shadow tables were already corrupted before PR #313 landed don't get healed automatically — the corruption persists in their D1 and surfaces on the next mutation that fires an FTS trigger. The startup-time integrity-check that used to attempt the repair (and which #313 removed for being unsafe) was, paradoxically, also the only thing that would have detected and rebuilt corrupted indexes from earlier failed transactions.

    Recovery confirmed working — the FTS5-native 'rebuild' command clears the corruption with no data loss, and subsequent operations succeed:

    wrangler d1 execute <db> --remote \
      --command "INSERT INTO _emdash_fts_posts(_emdash_fts_posts) VALUES('rebuild');"

    (Replace _emdash_fts_posts with the relevant FTS table name per affected collection — _emdash_fts_answers, _emdash_fts_pages, etc.) Took ~5 seconds; the underlying ec_* content data is untouched; affected admin operations resumed working immediately.

    Suggested follow-ups (in addition to whatever's already being investigated for fresh corruption on 0.6.0):

    1. Post-upgrade migration step when bumping to 0.5.0+ that runs INSERT INTO {fts_table}({fts_table}) VALUES('rebuild') on every FTS shadow table. Would clear latent corruption from pre-fix(core): remove FTS5 integrity-check to prevent D1 shadow table corruption #313 tenants automatically.
    2. Detect SQLITE_CORRUPT_VTAB at query time and self-heal by invoking the rebuild command before retrying the operation. Avoids requiring operators to discover the recovery command via deep-dive debugging.
    3. Document the recovery procedure prominently in operator-facing docs — this is currently undocumented and operators have to trace through SQLite FTS5 internals to find the right command.

    Happy to share more diagnostic output (D1 logs, schema state of the affected FTS shadow tables before/after the rebuild) if useful for narrowing down the residual cause that's still hitting @mahmingtea on 0.6.0.

  5. mahmingtea commented on Apr 22, 2026

    @mahmingtea

    INSERT INTO _emdash_fts_pages(_emdash_fts_pages) VALUES('rebuild');
    ran this directly in my D1 studio, issue still persist.
    I have this same issue in my previous version 0.4.0. Delete everything d1, kv, r2 and fresh deployed again with 0.6.0. Also im not on paid worker so i disabled dynamic worker for plugin, no other changes.

    Right now i have only one page and that is where my issue is.
    When i enter this page from admin dashboard, all my unpublished changes were there. But when i refresh the page my published version was showing up with publish button enabled.
    Clicking publish button return
    {"error":{"code":"CONTENT_PUBLISH_ERROR","message":"Failed to publish content"}}

  6. mahmingtea commented on Apr 22, 2026

    @mahmingtea

    This is interesting!

    Now everything works after i disable the Search feature from content types

    Image
  7. jcheese1 commented on Apr 23, 2026

    @jcheese1
    Contributor

    im getting this too, and disabling search fixed it for me as well. cc @ascorbic

  8. ascorbic commented on Apr 25, 2026

    @ascorbic
    Member

    /ultrabonk can you investigate and see if you can find a root cause and propose a fix

  9. ask-bonk commented on Apr 25, 2026

    @ask-bonk
    Contributor

    @ascorbic Bonk workflow was cancelled.

    View workflow run · To retry, trigger Bonk again.

  10. ask-bonk commented on Apr 25, 2026

    @ask-bonk
    Contributor

    Created PR #768

    github run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/corebug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions