@@ -2945,6 +2945,115 @@ TEST(pipeline_incremental_repoints_call_reference_without_stale_edge) {
29452945 PASS();
29462946}
29472947
2948+ /* #1419: every index publishes through a private staging DB in WAL mode that
2949+ * cbm_store_seal_for_atomic_publish() checkpoints at synchronous=FULL and
2950+ * switches to DELETE mode before the atomic rename. A crash before that rename
2951+ * discards the stage, so a WAL commit at FULL only adds an fsync per
2952+ * transaction without protecting anything; SQLite documents NORMAL as
2953+ * corruption-safe under WAL. The probe reads the EFFECTIVE synchronous level
2954+ * of the committing handle from a WAL hook on every connection the run opens.
2955+ *
2956+ * SQLite installs its default autocheckpoint WAL hook after auto-extensions
2957+ * run, so the auto-extension installs a statement trace and the trace installs
2958+ * the probe once the connection is fully open. The probe keeps SQLite's
2959+ * default 1000-frame autocheckpoint, so it does not change what the run
2960+ * writes. */
2961+ enum { I1419_SYNC_FULL = 2, I1419_DEFAULT_AUTOCHECKPOINT = 1000 };
2962+ static atomic_int g_i1419_wal_commits;
2963+ static atomic_int g_i1419_full_sync_commits;
2964+
2965+ static int i1419_wal_probe(void *arg, sqlite3 *db, const char *db_name, int wal_frames) {
2966+ (void)arg;
2967+ atomic_fetch_add(&g_i1419_wal_commits, 1);
2968+ sqlite3_stmt *stmt = NULL;
2969+ if (sqlite3_prepare_v2(db, "PRAGMA synchronous;", -1, &stmt, NULL) == SQLITE_OK &&
2970+ sqlite3_step(stmt) == SQLITE_ROW && sqlite3_column_int(stmt, 0) >= I1419_SYNC_FULL) {
2971+ atomic_fetch_add(&g_i1419_full_sync_commits, 1);
2972+ }
2973+ sqlite3_finalize(stmt);
2974+ if (wal_frames >= I1419_DEFAULT_AUTOCHECKPOINT) {
2975+ (void)sqlite3_wal_checkpoint(db, db_name);
2976+ }
2977+ return SQLITE_OK;
2978+ }
2979+
2980+ static int i1419_trace(unsigned type, void *ctx, void *stmt, void *sql) {
2981+ (void)type;
2982+ (void)ctx;
2983+ (void)sql;
2984+ (void)sqlite3_wal_hook(sqlite3_db_handle((sqlite3_stmt *)stmt), i1419_wal_probe, NULL);
2985+ return 0;
2986+ }
2987+
2988+ static int i1419_install_probe(sqlite3 *db, char **errmsg, const sqlite3_api_routines *api) {
2989+ (void)errmsg;
2990+ (void)api;
2991+ return sqlite3_trace_v2(db, SQLITE_TRACE_STMT, i1419_trace, NULL);
2992+ }
2993+
2994+ static int i1419_index(const char *repo, const char *db_path) {
2995+ cbm_pipeline_t *p = cbm_pipeline_new(repo, db_path, CBM_MODE_FULL);
2996+ if (!p) {
2997+ return -1;
2998+ }
2999+ int rc = cbm_pipeline_run(p);
3000+ cbm_pipeline_free(p);
3001+ return rc;
3002+ }
3003+
3004+ TEST(pipeline_staged_publish_commits_below_full_sync_issue1419) {
3005+ char tmp[256];
3006+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_i1419_XXXXXX");
3007+ if (!cbm_mkdtemp(tmp)) {
3008+ FAIL("tmpdir");
3009+ }
3010+ /* Equal lengths + equal mtimes: the second run must route on content
3011+ * bytes to the closure-repair (delta) publish, not a full rebuild. */
3012+ static const char initial_source[] =
3013+ "package syncprobe\n"
3014+ "func alphaSyncTarget() {}\n"
3015+ "func bravoSyncTarget() {}\n"
3016+ "func syncProbeAccept(callback func()) {}\n"
3017+ "func syncProbeSite() { syncProbeAccept(alphaSyncTarget) }\n";
3018+ static const char replacement_source[] =
3019+ "package syncprobe\n"
3020+ "func alphaSyncTarget() {}\n"
3021+ "func bravoSyncTarget() {}\n"
3022+ "func syncProbeAccept(callback func()) {}\n"
3023+ "func syncProbeSite() { syncProbeAccept(bravoSyncTarget) }\n";
3024+ ASSERT_EQ(sizeof(initial_source), sizeof(replacement_source));
3025+ write_temp_file(tmp, "probe.go", initial_source);
3026+ char source_path[512];
3027+ snprintf(source_path, sizeof(source_path), "%s/probe.go", tmp);
3028+ const time_t fixed_mtime = 1700000000;
3029+ ASSERT_EQ(pipeline_test_set_mtime(source_path, fixed_mtime, 123456789L), 0);
3030+ char db_path[512];
3031+ snprintf(db_path, sizeof(db_path), "%s/i1419.db", tmp);
3032+
3033+ atomic_store(&g_i1419_wal_commits, 0);
3034+ atomic_store(&g_i1419_full_sync_commits, 0);
3035+ ASSERT_EQ(sqlite3_auto_extension((void (*)(void))i1419_install_probe), SQLITE_OK);
3036+ /* Both publish routes run before any assertion, so the probe is always
3037+ * unregistered again even when a run fails. */
3038+ int full_rc = i1419_index(tmp, db_path);
3039+ write_temp_file(tmp, "probe.go", replacement_source);
3040+ int mtime_rc = pipeline_test_set_mtime(source_path, fixed_mtime, 123456789L);
3041+ cbm_pipeline_incremental_test_reset_faults();
3042+ int delta_rc = i1419_index(tmp, db_path);
3043+ cbm_incremental_route_t delta_route = cbm_pipeline_incremental_test_last_route();
3044+ (void)sqlite3_cancel_auto_extension((void (*)(void))i1419_install_probe);
3045+ th_rmtree(tmp);
3046+
3047+ ASSERT_EQ(full_rc, 0);
3048+ ASSERT_EQ(mtime_rc, 0);
3049+ ASSERT_EQ(delta_rc, 0);
3050+ ASSERT_EQ(delta_route, CBM_INCREMENTAL_ROUTE_CLOSURE_REPAIR);
3051+ /* Non-vacuous: both publishes commit through the WAL. */
3052+ ASSERT_GT(atomic_load(&g_i1419_wal_commits), 0);
3053+ ASSERT_EQ(atomic_load(&g_i1419_full_sync_commits), 0);
3054+ PASS();
3055+ }
3056+
29483057/* SQL DDL becomes first-class Table/View nodes wired into FROM/JOIN lineage,
29493058 * while the shared name registry must NOT leak those relations into other
29503059 * languages' textual resolution: a Python call or identifier sharing the
@@ -17292,6 +17401,7 @@ SUITE(pipeline) {
1729217401SUITE(pipeline_semantic_manifest_repro) {
1729317402 RUN_TEST(incremental_downgrade_preserves_scope_and_artifact_across_change_noop_delete);
1729417403 RUN_TEST(pipeline_incremental_repoints_call_reference_without_stale_edge);
17404+ RUN_TEST(pipeline_staged_publish_commits_below_full_sync_issue1419);
1729517405 RUN_TEST(pipeline_sql_lineage_and_relation_isolation);
1729617406 RUN_TEST(pipeline_incremental_sql_table_rename_drops_stale_lineage);
1729717407 RUN_TEST(pipeline_dbt_jinja_lineage);
0 commit comments