{"record":{"id":"55a365b05ede7f06","repo":"tursodatabase/turso","slug":"invalid-cell-payload","errorCode":null,"errorMessage":"invalid cell payload","messagePattern":"invalid cell payload","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"core/storage/btree.rs","lineNumber":6786,"sourceCode":"                                    )?;\n                                }\n                            }\n                            _ => unreachable!(\"Expected table leaf cell\"),\n                        }\n                        (cell_payload, leaf_cell_idx)\n                    };\n\n                    let leaf_page = self.stack.top_ref();\n\n                    self.pager.add_dirty(page)?;\n                    self.pager.add_dirty(leaf_page)?;\n\n                    // Step 2: Replace the cell in the parent (interior) page.\n                    {\n                        let parent_contents = page.get_contents();\n                        let parent_page_id = page.get().id;\n                        let left_child_page = u32::from_be_bytes(\n                            cell_payload[..4].try_into().expect(\"invalid cell payload\"),\n                        );\n                        turso_assert!(\n                            left_child_page as usize != parent_page_id,\n                            \"corrupt: current page and left child page are the same\",\n                            { \"left_child_page\": left_child_page, \"parent_page_id\": parent_page_id }\n                        );\n\n                        // First, drop the old cell that is being replaced.\n                        drop_cell(parent_contents, cell_idx, usable_space)?;\n                        // Then, insert the new cell (the predecessor) in its place.\n                        insert_into_cell(parent_contents, &cell_payload, cell_idx, usable_space)?;\n                    }\n\n                    // Step 3: Delete the predecessor cell from the leaf page.\n                    {\n                        let leaf_contents = leaf_page.get_contents();\n                        drop_cell(leaf_contents, leaf_cell_idx, usable_space)?;\n                    }","sourceCodeStart":6768,"sourceCodeEnd":6804,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/core/storage/btree.rs#L6768-L6804","documentation":"After building the replacement interior cell payload (4-byte big-endian left-child pointer followed by the key), the parent update parses cell_payload[..4] back into a page number with try_into().expect(\"invalid cell payload\"). The panic fires when the freshly built payload is shorter than 4 bytes, which the builders (child_pointer.to_be_bytes() extension) should never produce.","triggerScenarios":"Interior-node replacement on DELETE where the payload Vec came out empty or truncated - a logic bug in the payload construction arms (TableLeafCell / IndexLeafCell rewriting) or an allocation failure swallowed earlier in the chain.","commonSituations":"Engine regressions in cell serialization, corrupted cell metadata producing zero-length writes, allocation-failure paths in with_btree_allocation_site! macros.","solutions":["Report to Turso with the exact DELETE statement and a copy of the database - payload construction cannot legitimately produce <4 bytes","Run PRAGMA integrity_check to rule out corruption","Retry the operation on a fresh connection; pre-commit disk state is unaffected","Upgrade the engine - the cell-building code paths are under active development"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let result = std::panic::catch_unwind(AssertUnwindSafe(|| {\n    conn.execute(\"DELETE FROM idx_t ON ...\", ())  // any delete touching interior cells\n}));\nif result.is_err() { conn.close().ok(); /* reopen, verify, report */ }","preventionTips":["Run PRAGMA integrity_check after abnormal terminations before further writes","Test upgrades against delete-heavy datasets to catch serialization regressions early","Use transactions around deletes so partial effects are never committed after a panic","Report minimal reproductions upstream"],"tags":["btree","cell-payload","delete","panic"],"backgroundTag":"corrupt-btree-cell","analyzedSha":"6c7252267988c76e632af00a671e4b9788dfae13","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}