powersync-js icon indicating copy to clipboard operation
powersync-js copied to clipboard

Could not apply pending checkpoint even after completed upload

Open ivanvolti opened this issue 5 months ago • 5 comments

I've recently started seeing the following warning: "Could not apply pending checkpoint even after completed upload." It appears every time I update any row in the database.

Simplified example of how I perform writes:

export async function markProjectsAsDeleted(ids: string[]) {
  await drizzleDb
    .update(projects)
    .set({ isDeleted: true, updatedAt: sql`datetime('now')` })
    .where(inArray(projects.id, ids));
}

Log:

[PowerSyncDatabase[powersync25.db]] Validated and applied checkpoint
connector.ts:65 op {
  "op_id": 21,
  "op": "PATCH",
  "type": "projects",
  "id": "ba3679b6-106f-463d-9688-80162ef7d8b8",
  "tx_id": 21,
  "data": {
    "is_deleted": 1,
    "updated_at": "2025-07-23 12:56:23"
  }
}
bundle.mjs:85 [PowerSyncDatabase[powersync25.db]] Could not apply checkpoint due to local data. Will retry at completed upload or next checkpoint.
bundle.mjs:85 [PowerSyncDatabase[powersync25.db]] Created write checkpoint: 20
bundle.mjs:85 [PowerSyncDatabase[powersync25.db]] Updating target write checkpoint to 20
hook.js:608 [PowerSyncDatabase[powersync25.db]] Could not apply pending checkpoint even after completed upload
... [PowerSyncDatabase[powersync25.db]] Validated and applied checkpoint

Simplified example of how I read data:

function useDrizzleQuery<T>(
  query: {
    execute: () => Promise<unknown>;
    toSQL: () => { sql: string; params: unknown[] };
  },
  schema: z.ZodSchema<T>,
) {
  const { data, ...rest } = useQuery(toCompilableQuery(query));
  return { data: data?.map((record) => schema.parse(record)), ...rest };
}

export function useActiveProjects() {
  const query = drizzleDb
    .select()
    .from(projects)
    .where(and(...activeProjectConditions))
    .orderBy(desc(projects.createdAt));
  return useDrizzleQuery(query, projectSelectSchema);
}

ivanvolti avatar Jul 23 '25 12:07 ivanvolti

Thanks for the report! Does this happen all the time with local writes or just sometimes? And does the stream recover reliably? How much time is there between "Could not apply pending checkpoint even after upload" and the subsequent "Validated and applied checkpoint"?

simolus3 avatar Jul 23 '25 17:07 simolus3

Does this happen all the time with local writes or just sometimes? It happens all the time with local writes. But it doesn’t happen when I directly change rows in the database—but everything stays in sync in both cases.

And does the stream recover reliably? I’m not sure what you mean by "stream," but all changes go through fine and everything stays in sync.

How much time is there between "Could not apply pending checkpoint even after upload" and the subsequent "Validated and applied checkpoint"? About a second or less.

ivanvolti avatar Jul 25 '25 09:07 ivanvolti

Thanks! And is this with supabase or a custom connector / backend?

simolus3 avatar Jul 30 '25 13:07 simolus3

With supabase.

ivanvolti avatar Jul 30 '25 17:07 ivanvolti

Thanks! Are there any triggers in your local database or things in Supabase that might asynchronously cause subsequent writes apart from the one being uploaded? I've tried to reproduce the issue in one of our sample projects (also using drizzle for updates), but that worked perfectly fine. For reference, this is the output I get when debugging the sync worker:

Image

simolus3 avatar Jul 31 '25 08:07 simolus3