Skip to content

Commit eae0d32

Browse files
committed
Fix needsPush for sharded categories and add debug logging
1 parent 38bdf38 commit eae0d32

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/storage/repo/repo-client.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,18 @@ export class RepoStorageBackend implements StorageBackend {
103103

104104
public async getFile(path: string): Promise<string | null> {
105105
const fullPath = `${SYNC_DIR}/${path}`;
106-
const res = await this.fetchAllowNotFound(`/contents/${fullPath}`);
106+
// Add cache-bust to avoid stale GitHub API responses
107+
const cacheBust = Date.now();
108+
const res = await this.fetchAllowNotFound(`/contents/${fullPath}?cb=${String(cacheBust)}`);
107109
if (!res?.ok) return null;
108110

109111
const data = (await res.json()) as ContentFile;
110112

111113
// For files >1MB, GitHub returns empty content and provides download_url
112114
if (!data.content && data.size > 1000000) {
113115
const branch = await this.getBranch();
114-
const downloadUrl = `https://raw.githubusercontent.com/${this.owner}/${this.repo}/${branch}/${fullPath}`;
116+
// Add cache-bust to avoid stale CDN responses
117+
const downloadUrl = `https://raw.githubusercontent.com/${this.owner}/${this.repo}/${branch}/${fullPath}?cb=${String(cacheBust)}`;
115118
const downloadRes = await fetchWithRetry(
116119
downloadUrl,
117120
{

src/sync/operations/pull.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,15 @@ async function pullShardedCategoryToAcc(
115115
backend: StorageBackend,
116116
acc: PullAccumulator
117117
): Promise<void> {
118+
syncLog(`[PULL] Fetching shard: ${ref.shardFile} (itemCount: ${String(ref.itemCount)})`);
118119
const shard = await fetchCategoryShard(backend, ref.shardFile);
119-
if (!shard) return;
120+
if (!shard) {
121+
syncLog(`[PULL] ${cat}: shard file not found or empty`);
122+
return;
123+
}
124+
syncLog(
125+
`[PULL] ${cat}: shard has ${String(Object.keys(shard.items).length)} items, ${String(Object.keys(shard.tombstones).length)} tombstones`
126+
);
120127

121128
// Convert shard to ItemCategoryInfo-like structure for pullItemCategory
122129
const info: ItemCategoryInfo = {

src/sync/operations/push.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ function packItemCategoryData(
178178

179179
/**
180180
* Check if local data needs pushing by comparing checksums.
181+
* For sharded categories (sessions, messages), we skip checksum comparison
182+
* since we don't have the shard content loaded. These rely on vector clock comparison.
181183
*/
182184
export function needsPush(localData: CategoryData[], remoteManifest: Manifest | null): boolean {
183185
if (!remoteManifest) return true;
@@ -186,8 +188,11 @@ export function needsPush(localData: CategoryData[], remoteManifest: Manifest |
186188
const remoteInfo = remoteManifest.categories[catData.category];
187189

188190
if (isItemCategoryData(catData)) {
189-
// Per-item comparison
190-
if (!remoteInfo || !isItemCatInfo(remoteInfo)) return true;
191+
// Per-item comparison - but only if remote is also items type (not sharded)
192+
if (!remoteInfo) return true;
193+
// Skip comparison for sharded categories - they use vector clock comparison
194+
if (remoteInfo.type === 'sharded') continue;
195+
if (!isItemCatInfo(remoteInfo)) return true;
191196
const diff = diffItems(catData.checksums, remoteInfo.items);
192197
if (diff.toUpload.length > 0) return true;
193198
} else if (isBlobCategoryData(catData)) {

0 commit comments

Comments
 (0)