Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(sync): track push and pull errors separately to stop popover flash (#1536)
miles-kt-inkeep31b3fa7a4d3d
diff --git a/.changeset/fix-sync-per-operation-errors.md b/.changeset/fix-sync-per-operation-errors.mdnew file mode 100644index 000000000..c98b0386b--- /dev/null+++ b/.changeset/fix-sync-per-operation-errors.md@@ -0,0 +1,15 @@+---+"@inkeep/open-knowledge": patch+"@inkeep/open-knowledge-core": patch+"@inkeep/open-knowledge-server": patch+"@inkeep/open-knowledge-app": patch+"@inkeep/open-knowledge-desktop": patch+---++fix(sync): track push and pull errors separately so a sync error stops flashing in the popover++The sync status popover would show a sync error (e.g. a failed push) for only a split second before it vanished. The engine stored the last failure in a single shared `error` field, so a successful fetch on the pull leg cleared a still-unresolved push error — and `trigger('sync')` runs push then pull, so the push error was wiped by the immediately-following fetch within the same "Sync now". The same alternation happened continuously under auto-sync.++Push and pull errors are now tracked independently (`pushError`/`pushErrorCode` and `pullError`/`pullErrorCode`). A success on one leg only clears that leg's error, so a real push failure stays visible until a push actually succeeds (or sync is toggled).++When both legs fail with the same root cause (e.g. an auth failure that blocks fetch and push alike) the popover collapses them into a single neutral line instead of repeating two near-identical messages. When the two legs fail for different reasons, each line is labeled "Push:" / "Pull:" so it's clear which direction failed. A lone failure renders unlabeled, with pull-specific copy for read-side auth failures.diff --git a/packages/app/src/components/SyncStatusBadge.test.ts b/packages/app/src/components/SyncStatusBadge.test.tsindex 81de9d2bd..2645d558f 100644--- a/packages/app/src/components/SyncStatusBadge.test.ts+++ b/packages/app/src/components/SyncStatusBadge.test.ts@@ -1,4 +1,5 @@import { describe, expect, test } from 'bun:test';+import { SYNC_ERROR_CODES } from '@inkeep/open-knowledge-core';describe('SyncStatusBadge module', () => {test('exports the SyncStatusBadge component', async () => {@@ -11,6 +12,9 @@ describe('SyncStatusBadge module', () => {expect(typeof mod.formatPausedReason).toBe('function');expect(typeof mod.formatPushPermissionDenied).toBe('function');expect(typeof mod.formatPushFailureCode).toBe('function');+ expect(typeof mod.formatPullFailureCode).toBe('function');+ expect(typeof mod.formatSyncFailureCode).toBe('function');+ expect(typeof mod.computeSyncErrorLines).toBe('function');expect(typeof mod.shouldDisableSyncSwitch).toBe('function');expect(typeof mod.shouldOfferSignInAgain).toBe('function');});@@ -99,6 +103,95 @@ describe('formatPushFailureCode — code-to-localized-string mapping', () => {});});+describe('formatSyncFailureCode — neutral collapsed copy', () => {+ test('every bounded enum value produces a non-empty string', async () => {+ const { formatSyncFailureCode } = await import('./SyncStatusBadge');+ for (const code of SYNC_ERROR_CODES) {+ const out = formatSyncFailureCode(code);+ expect(typeof out).toBe('string');+ expect(out.length).toBeGreaterThan(0);+ }+ });++ test('auth-403 copy is direction-agnostic (not the push-only framing)', async () => {+ const { formatSyncFailureCode, formatPushFailureCode, formatPullFailureCode } = await import(+ './SyncStatusBadge'+ );+ expect(formatSyncFailureCode('auth-403')).not.toBe(formatPushFailureCode('auth-403'));+ expect(formatSyncFailureCode('auth-403')).toBe(formatPullFailureCode('auth-403'));+ });+});++describe('computeSyncErrorLines — collapse + label truth table', () => {+ test('no errors → no lines', async () => {+ const { computeSyncErrorLines } = await import('./SyncStatusBadge');+ expect(computeSyncErrorLines({})).toEqual([]);+ });++ test('push-only → single unlabeled line with push copy', async () => {+ const { computeSyncErrorLines, formatPushFailureCode } = await import('./SyncStatusBadge');+ const lines = computeSyncErrorLines({ pushErrorCode: 'semantic-protected-branch' });+ expect(lines).toEqual([+ { key: 'push', direction: null, message: formatPushFailureCode('semantic-protected-branch') },+ ]);+ });++ test('pull-only (raw) → single unlabeled line with the raw message', async () => {+ const { computeSyncErrorLines } = await import('./SyncStatusBadge');+ const lines = computeSyncErrorLines({ pullError: 'Sync paused — local changes conflict.' });+ expect(lines).toEqual([+ { key: 'pull', direction: null, message: 'Sync paused — local changes conflict.' },+ ]);+ });++ test('same code on both legs → one collapsed, unlabeled, neutral line', async () => {+ const { computeSyncErrorLines, formatSyncFailureCode } = await import('./SyncStatusBadge');+ const lines = computeSyncErrorLines({ pushErrorCode: 'auth-401', pullErrorCode: 'auth-401' });+ expect(lines).toEqual([+ { key: 'sync', direction: null, message: formatSyncFailureCode('auth-401') },+ ]);+ });++ test('identical raw message on both legs → one collapsed line', async () => {+ const { computeSyncErrorLines } = await import('./SyncStatusBadge');+ const lines = computeSyncErrorLines({+ pushError: 'Network unreachable',+ pullError: 'Network unreachable',+ });+ expect(lines).toEqual([{ key: 'sync', direction: null, message: 'Network unreachable' }]);+ });++ test('different codes → two lines, each labeled with its direction', async () => {+ const { computeSyncErrorLines, formatPushFailureCode, formatPullFailureCode } = await import(+ './SyncStatusBadge'+ );+ const lines = computeSyncErrorLines({+ pushErrorCode: 'semantic-protected-branch',+ pullErrorCode: 'auth-403',+ });+ expect(lines).toEqual([+ {+ key: 'push',+ direction: 'push',+ message: formatPushFailureCode('semantic-protected-branch'),+ },+ { key: 'pull', direction: 'pull', message: formatPullFailureCode('auth-403') },+ ]);+ });++ test('coded push + raw pull → treated as different, both labeled', async () => {+ const { computeSyncErrorLines, formatPushFailureCode } = await import('./SyncStatusBadge');+ const lines = computeSyncErrorLines({+ pushErrorCode: 'auth-401',+ pullError: 'Could not detect conflict files',+ });+ expect(lines).toEqual([+ { key: 'push', direction: 'push', message: formatPushFailureCode('auth-401') },+ { key: 'pull', direction: 'pull', message: 'Could not detect conflict files' },+ ]);+ });+});+describe('formatPausedReason — push-permission case', () => {test('maps no-push-permission to the push-permission copy', async () => {const { formatPausedReason } = await import('./SyncStatusBadge');diff --git a/packages/app/src/components/SyncStatusBadge.tsx b/packages/app/src/components/SyncStatusBadge.tsxindex 3a3a06cc2..3b6588774 100644--- a/packages/app/src/components/SyncStatusBadge.tsx+++ b/packages/app/src/components/SyncStatusBadge.tsx@@ -1,4 +1,4 @@-import type { PushPermissionWire } from '@inkeep/open-knowledge-core';+import type { PushPermissionWire, SyncErrorCode } from '@inkeep/open-knowledge-core';import { plural, t } from '@lingui/core/macro';import { Plural, Trans, useLingui } from '@lingui/react/macro';import {@@ -161,9 +161,7 @@ export function formatPushPermissionDenied(}}-export function formatPushFailureCode(- code: 'auth-403' | 'auth-401' | 'auth-scope-mismatch' | 'semantic-protected-branch',-): string {+export function formatPushFailureCode(code: SyncErrorCode): string {switch (code) {case 'auth-403':return t`You don't have permission to push to this repo.`;@@ -178,6 +176,90 @@ export function formatPushFailureCode(}}+export function formatPullFailureCode(code: SyncErrorCode): string {+ switch (code) {+ case 'auth-403':+ return t`You don't have access to this repository.`;+ case 'auth-401':+ return t`GitHub authentication failed. Try signing in again.`;+ case 'auth-scope-mismatch':+ return t`Your GitHub token is missing required scopes. Try signing in again.`;+ default:+ return t`Fetch failed — check the server logs for details.`;+ }+}++export function formatSyncFailureCode(code: SyncErrorCode): string {+ switch (code) {+ case 'auth-403':+ return t`You don't have access to this repository.`;+ case 'auth-401':+ return t`GitHub authentication failed. Try signing in again.`;+ case 'auth-scope-mismatch':+ return t`Your GitHub token is missing required scopes. Try signing in again.`;+ case 'semantic-protected-branch':+ return t`The default branch is protected — pushes need a pull request.`;+ default:+ return t`Sync failed — check the server logs for details.`;+ }+}++type SyncErrorDirection = 'push' | 'pull';++export interface SyncErrorLine {+ key: 'sync' | 'push' | 'pull';+ direction: SyncErrorDirection | null;+ message: string;+}++export function computeSyncErrorLines(+ status: Pick<GitSyncStatus, 'pushError' | 'pushErrorCode' | 'pullError' | 'pullErrorCode'>,+): SyncErrorLine[] {+ const pushPresent = status.pushErrorCode != null || status.pushError != null;+ const pullPresent = status.pullErrorCode != null || status.pullError != null;++ if (pushPresent && pullPresent) {+ const sameRootCause =+ status.pushErrorCode != null+ ? status.pushErrorCode === status.pullErrorCode+ : status.pullErrorCode == null && status.pushError === status.pullError;+ if (sameRootCause) {+ return [+ {+ key: 'sync',+ direction: null,+ message:+ status.pushErrorCode != null+ ? formatSyncFailureCode(status.pushErrorCode)+ : (status.pushError as string),+ },+ ];+ }+ }++ const labelDirections = pushPresent && pullPresent;+ const lines: SyncErrorLine[] = [];+ if (pushPresent) {+ lines.push({+ key: 'push',+ direction: labelDirections ? 'push' : null,+ message: status.pushErrorCode+ ? formatPushFailureCode(status.pushErrorCode)+ : (status.pushError as string),+ });+ }+ if (pullPresent) {+ lines.push({+ key: 'pull',+ direction: labelDirections ? 'pull' : null,+ message: status.pullErrorCode+ ? formatPullFailureCode(status.pullErrorCode)+ : (status.pullError as string),+ });+ }+ return lines;+}+export function shouldOfferSignInAgain(pushPermission: PushPermissionWire | undefined): boolean {return (pushPermission?.checkStatus === 'unknown' && pushPermission.unknownError === 'token-invalid'@@ -255,11 +337,23 @@ function PopoverBody({ status, onSignIn, onSetIdentity }: PopoverBodyProps) {onConfirm={onConfirm}/>- {status.errorCode ? (- <p className="text-xs text-destructive">{formatPushFailureCode(status.errorCode)}</p>- ) : status.error ? (- <p className="text-xs text-destructive">{status.error}</p>- ) : null}+ {computeSyncErrorLines(status).map((line) => (+ <p key={line.key} className="text-xs text-destructive">+ {line.direction === 'push' ? (+ <>+ <span className="font-medium">{t`Push`}: </span>+ {line.message}+ </>+ ) : line.direction === 'pull' ? (+ <>+ <span className="font-medium">{t`Pull`}: </span>+ {line.message}+ </>+ ) : (+ line.message+ )}+ </p>+ ))}{status.pausedReason ? (<p className="text-xs text-muted-foreground">{formatPausedReason(status.pausedReason)}</p>) : status.pushPermission?.checkStatus === 'denied' ? (diff --git a/packages/app/src/hooks/use-git-sync-status.ts b/packages/app/src/hooks/use-git-sync-status.tsindex 81283b3e9..36975534c 100644--- a/packages/app/src/hooks/use-git-sync-status.ts+++ b/packages/app/src/hooks/use-git-sync-status.ts@@ -1,4 +1,7 @@-import type { PushPermissionWire as GitPushPermission } from '@inkeep/open-knowledge-core';+import type {+ PushPermissionWire as GitPushPermission,+ SyncErrorCode,+} from '@inkeep/open-knowledge-core';import { useEffect, useState } from 'react';import { subscribeToDocumentsChanged } from '@/lib/documents-events';@@ -24,8 +27,10 @@ export interface GitSyncStatus {syncEnabled: boolean;identityUnresolved?: boolean;remote?: { label: string; webUrl: string | null } | null;- error?: string;- errorCode?: 'auth-403' | 'auth-401' | 'auth-scope-mismatch' | 'semantic-protected-branch';+ pushError?: string;+ pushErrorCode?: SyncErrorCode;+ pullError?: string;+ pullErrorCode?: SyncErrorCode;pausedReason?: string;pushPermission?: GitPushPermission;}diff --git a/packages/app/src/locales/en/messages.json b/packages/app/src/locales/en/messages.jsonindex 099b4b59c..4036a0b60 100644--- a/packages/app/src/locales/en/messages.json+++ b/packages/app/src/locales/en/messages.json@@ -903,6 +903,7 @@"Rah7yq": ["What should the AI do? (optional)"],"RfHNf8": ["Open activity panel for ", ["tooltipName"]],"RfaEio": ["Toggle source comment"],+ "RgbKEe": ["You don't have access to this repository."],"Rj01Fz": ["Links"],"RlCInP": ["Slash commands"],"RmBY0A": ["No git remote"],@@ -1226,6 +1227,7 @@"cUK8lW": [["conflictCount", "plural", { "one": ["#", " conflict"], "other": ["#", " conflicts"] }]],+ "cUk6TF": ["Sync failed — check the server logs for details."],"cZGNlb": ["Add another pattern"],"cZI5AL": ["OK Desktop"],"cdm00A": ["No Incoming"],@@ -1254,6 +1256,7 @@"dw_dUJ": ["Failed to duplicate path"],"e0NrBM": ["Project"],"e1hptq": ["Embed a video with native player controls."],+ "e4GHWP": ["Pull"],"e6pmcJ": ["What this folder is about — give it a title, description, tags, or any properties you like, just like a doc has. This describes the folder itself; it is not copied into the docs inside it. To start new docs in this folder with a ready-made set of properties, add a template instead."],@@ -1416,6 +1419,7 @@"jRHdCz": ["Failed to load PDF"],"jSY41h": ["\"", ["docName"], "\" took too long. Check your connection."],"jTLWxh": ["Embed an external page in an inline iframe (docs, demos, Figma, CodeSandbox)."],+ "jZ_E5M": ["Fetch failed — check the server logs for details."],"jbSG8V": ["Show Files (", ["sidebarShortcutLabel"], ")"],"jdGUeI": ["Couldn't create template: ", ["error"]],"jerqF0": ["Loading branch state"],@@ -1752,6 +1756,7 @@"uH_S-u": [["loadErrorTitle"], ": ", ["message"]],"uKRYiW": ["Sync status unavailable — server error."],"uM6jnS": ["Restore failed"],+ "uO9WLl": ["Push"],"uQNW00": ["Detached HEAD — checkout a branch to resume"],"uWtdQR": ["No templates yet. Add one in this folder's Templates section, or in Settings → Templates."diff --git a/packages/app/src/locales/en/messages.po b/packages/app/src/locales/en/messages.poindex c197c11fe..f37952342 100644--- a/packages/app/src/locales/en/messages.po+++ b/packages/app/src/locales/en/messages.po@@ -2287,6 +2287,10 @@ msgstr "Failed: {loadError}"msgid "Fenced code block with monospace text."msgstr "Fenced code block with monospace text."+#: src/components/SyncStatusBadge.tsx+msgid "Fetch failed — check the server logs for details."+msgstr "Fetch failed — check the server logs for details."+#: src/components/SyncStatusBadge.tsxmsgid "Fetching"msgstr "Fetching"@@ -4328,6 +4332,10 @@ msgstr "Published"msgid "Publishing..."msgstr "Publishing..."+#: src/components/SyncStatusBadge.tsx+msgid "Pull"+msgstr "Pull"+#: src/components/SyncStatusBadge.tsxmsgid "Pulling"msgstr "Pulling"@@ -4336,6 +4344,10 @@ msgstr "Pulling"msgid "Pulls may overwrite uncommitted local file changes."msgstr "Pulls may overwrite uncommitted local file changes."+#: src/components/SyncStatusBadge.tsx+msgid "Push"+msgstr "Push"+#: src/components/SyncStatusBadge.tsxmsgid "Push failed — check the server logs for details."msgstr "Push failed — check the server logs for details."@@ -5262,6 +5274,10 @@ msgstr "Sync disabled"msgid "Sync disabled — you don't have permission to push"msgstr "Sync disabled — you don't have permission to push"+#: src/components/SyncStatusBadge.tsx+msgid "Sync failed — check the server logs for details."+msgstr "Sync failed — check the server logs for details."+#: src/components/SyncStatusBadge.tsxmsgid "Sync is off — your edits will not sync to the remote repository."msgstr "Sync is off — your edits will not sync to the remote repository."@@ -6008,6 +6024,10 @@ msgstr "You deleted <0>{filePath}</0> locally, but it was modified upstream."msgid "You don't have access to this private repo. Sign in with an account that does."msgstr "You don't have access to this private repo. Sign in with an account that does."+#: src/components/SyncStatusBadge.tsx+msgid "You don't have access to this repository."+msgstr "You don't have access to this repository."+#: src/components/SyncStatusBadge.tsxmsgid "You don't have permission to push to this repo"msgstr "You don't have permission to push to this repo"diff --git a/packages/app/src/locales/pseudo/messages.json b/packages/app/src/locales/pseudo/messages.jsonindex 933c68126..544a730b2 100644--- a/packages/app/src/locales/pseudo/messages.json+++ b/packages/app/src/locales/pseudo/messages.json@@ -903,6 +903,7 @@"Rah7yq": ["Ŵĥàţ śĥōũĺď ţĥē ÀĨ ďō? (ōƥţĩōńàĺ)"],"RfHNf8": ["Ōƥēń àćţĩvĩţŷ ƥàńēĺ ƒōŕ ", ["tooltipName"]],"RfaEio": ["Ţōĝĝĺē śōũŕćē ćōḿḿēńţ"],+ "RgbKEe": ["Ŷōũ ďōń'ţ ĥàvē àććēśś ţō ţĥĩś ŕēƥōśĩţōŕŷ."],"Rj01Fz": ["Ĺĩńķś"],"RlCInP": ["Śĺàśĥ ćōḿḿàńďś"],"RmBY0A": ["Ńō ĝĩţ ŕēḿōţē"],@@ -1226,6 +1227,7 @@"cUK8lW": [["conflictCount", "plural", { "one": ["#", " ćōńƒĺĩćţ"], "other": ["#", " ćōńƒĺĩćţś"] }]],+ "cUk6TF": ["Śŷńć ƒàĩĺēď — ćĥēćķ ţĥē śēŕvēŕ ĺōĝś ƒōŕ ďēţàĩĺś."],"cZGNlb": ["Àďď àńōţĥēŕ ƥàţţēŕń"],"cZI5AL": ["ŌĶ Ďēśķţōƥ"],"cdm00A": ["Ńō Ĩńćōḿĩńĝ"],@@ -1254,6 +1256,7 @@"dw_dUJ": ["Ƒàĩĺēď ţō ďũƥĺĩćàţē ƥàţĥ"],"e0NrBM": ["ƤŕōĴēćţ"],"e1hptq": ["Ēḿƀēď à vĩďēō ŵĩţĥ ńàţĩvē ƥĺàŷēŕ ćōńţŕōĺś."],+ "e4GHWP": ["Ƥũĺĺ"],"e6pmcJ": ["Ŵĥàţ ţĥĩś ƒōĺďēŕ ĩś àƀōũţ — ĝĩvē ĩţ à ţĩţĺē, ďēśćŕĩƥţĩōń, ţàĝś, ōŕ àńŷ ƥŕōƥēŕţĩēś ŷōũ ĺĩķē, Ĵũśţ ĺĩķē à ďōć ĥàś. Ţĥĩś ďēśćŕĩƀēś ţĥē ƒōĺďēŕ ĩţśēĺƒ; ĩţ ĩś ńōţ ćōƥĩēď ĩńţō ţĥē ďōćś ĩńśĩďē ĩţ. Ţō śţàŕţ ńēŵ ďōćś ĩń ţĥĩś ƒōĺďēŕ ŵĩţĥ à ŕēàďŷ-ḿàďē śēţ ōƒ ƥŕōƥēŕţĩēś, àďď à ţēḿƥĺàţē ĩńśţēàď."],@@ -1416,6 +1419,7 @@"jRHdCz": ["Ƒàĩĺēď ţō ĺōàď ƤĎƑ"],"jSY41h": ["\"", ["docName"], "\" ţōōķ ţōō ĺōńĝ. Ćĥēćķ ŷōũŕ ćōńńēćţĩōń."],"jTLWxh": ["Ēḿƀēď àń ēxţēŕńàĺ ƥàĝē ĩń àń ĩńĺĩńē ĩƒŕàḿē (ďōćś, ďēḿōś, Ƒĩĝḿà, ĆōďēŚàńďƀōx)."],+ "jZ_E5M": ["Ƒēţćĥ ƒàĩĺēď — ćĥēćķ ţĥē śēŕvēŕ ĺōĝś ƒōŕ ďēţàĩĺś."],"jbSG8V": ["Śĥōŵ Ƒĩĺēś (", ["sidebarShortcutLabel"], ")"],"jdGUeI": ["Ćōũĺďń'ţ ćŕēàţē ţēḿƥĺàţē: ", ["error"]],"jerqF0": ["Ĺōàďĩńĝ ƀŕàńćĥ śţàţē"],@@ -1752,6 +1756,7 @@"uH_S-u": [["loadErrorTitle"], ": ", ["message"]],"uKRYiW": ["Śŷńć śţàţũś ũńàvàĩĺàƀĺē — śēŕvēŕ ēŕŕōŕ."],"uM6jnS": ["Ŕēśţōŕē ƒàĩĺēď"],+ "uO9WLl": ["Ƥũśĥ"],"uQNW00": ["Ďēţàćĥēď ĤĒÀĎ — ćĥēćķōũţ à ƀŕàńćĥ ţō ŕēśũḿē"],"uWtdQR": ["Ńō ţēḿƥĺàţēś ŷēţ. Àďď ōńē ĩń ţĥĩś ƒōĺďēŕ'ś Ţēḿƥĺàţēś śēćţĩōń, ōŕ ĩń Śēţţĩńĝś → Ţēḿƥĺàţēś."diff --git a/packages/app/src/locales/pseudo/messages.po b/packages/app/src/locales/pseudo/messages.poindex 81e00e97a..cdf878487 100644--- a/packages/app/src/locales/pseudo/messages.po+++ b/packages/app/src/locales/pseudo/messages.po@@ -2282,6 +2282,10 @@ msgstr ""msgid "Fenced code block with monospace text."msgstr ""+#: src/components/SyncStatusBadge.tsx+msgid "Fetch failed — check the server logs for details."+msgstr ""+#: src/components/SyncStatusBadge.tsxmsgid "Fetching"msgstr ""@@ -4323,6 +4327,10 @@ msgstr ""msgid "Publishing..."msgstr ""+#: src/components/SyncStatusBadge.tsx+msgid "Pull"+msgstr ""+#: src/components/SyncStatusBadge.tsxmsgid "Pulling"msgstr ""@@ -4331,6 +4339,10 @@ msgstr ""msgid "Pulls may overwrite uncommitted local file changes."msgstr ""+#: src/components/SyncStatusBadge.tsx+msgid "Push"+msgstr ""+#: src/components/SyncStatusBadge.tsxmsgid "Push failed — check the server logs for details."msgstr ""@@ -5257,6 +5269,10 @@ msgstr ""msgid "Sync disabled — you don't have permission to push"msgstr ""+#: src/components/SyncStatusBadge.tsx+msgid "Sync failed — check the server logs for details."+msgstr ""+#: src/components/SyncStatusBadge.tsxmsgid "Sync is off — your edits will not sync to the remote repository."msgstr ""@@ -6003,6 +6019,10 @@ msgstr ""msgid "You don't have access to this private repo. Sign in with an account that does."msgstr ""+#: src/components/SyncStatusBadge.tsx+msgid "You don't have access to this repository."+msgstr ""+#: src/components/SyncStatusBadge.tsxmsgid "You don't have permission to push to this repo"msgstr ""diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 3593145e1..e24a6691b 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -714,12 +714,15 @@ export {SuggestLinksTargetSchema,type SummaryResponseField,SummaryResponseFieldSchema,+ SYNC_ERROR_CODES,type SyncAbortMergeSuccess,SyncAbortMergeSuccessSchema,type SyncConflictContentSuccess,SyncConflictContentSuccessSchema,type SyncConflictsSuccess,SyncConflictsSuccessSchema,+ type SyncErrorCode,+ SyncErrorCodeSchema,SyncRemoteSchema,type SyncRemoteWire,type SyncResolveConflictRequest,diff --git a/packages/core/src/schemas/api/sync-seed.ts b/packages/core/src/schemas/api/sync-seed.tsindex aa95b9f16..747d8c0eb 100644--- a/packages/core/src/schemas/api/sync-seed.ts+++ b/packages/core/src/schemas/api/sync-seed.ts@@ -41,6 +41,16 @@ export const PushPermissionSchema = z.discriminatedUnion('checkStatus', []) satisfies StandardSchemaV1;export type PushPermissionWire = z.infer<typeof PushPermissionSchema>;+export const SYNC_ERROR_CODES = [+ 'auth-403',+ 'auth-401',+ 'auth-scope-mismatch',+ 'semantic-protected-branch',+] as const;++export const SyncErrorCodeSchema = z.enum(SYNC_ERROR_CODES);+export type SyncErrorCode = z.infer<typeof SyncErrorCodeSchema>;+export const SyncStatusSchema = z.object({state: SyncStateSchema,@@ -55,10 +65,10 @@ export const SyncStatusSchema = zsyncEnabled: z.boolean(),identityUnresolved: z.boolean(),remote: SyncRemoteSchema.nullable().optional(),- error: z.string().optional(),- errorCode: z- .enum(['auth-403', 'auth-401', 'auth-scope-mismatch', 'semantic-protected-branch'])- .optional(),+ pushError: z.string().optional(),+ pushErrorCode: SyncErrorCodeSchema.optional(),+ pullError: z.string().optional(),+ pullErrorCode: SyncErrorCodeSchema.optional(),pausedReason: z.string().optional(),pushPermission: PushPermissionSchema.optional(),})diff --git a/packages/server/src/error-classification.ts b/packages/server/src/error-classification.tsindex 0a73c14ad..538374f97 100644--- a/packages/server/src/error-classification.ts+++ b/packages/server/src/error-classification.ts@@ -1,3 +1,5 @@+import type { SyncErrorCode } from '@inkeep/open-knowledge-core';+type NetworkSubclass = 'dns' | 'timeout' | '5xx' | '429' | 'connection-refused' | 'unknown-network';type AuthSubclass = '401' | '403' | 'expired-token' | 'scope-mismatch' | 'unknown-auth';type SemanticSubclass =@@ -13,11 +15,7 @@ type StructuralSubclass =| 'unknown-structural';type LocalSubclass = 'index-lock' | 'dirty-tree' | 'disk-full' | 'unknown-local';-export type UserFacingErrorCode =- | 'auth-403'- | 'auth-401'- | 'auth-scope-mismatch'- | 'semantic-protected-branch';+export type UserFacingErrorCode = SyncErrorCode;export type ClassifiedError =| {diff --git a/packages/server/src/sync-engine.test.ts b/packages/server/src/sync-engine.test.tsindex fd9aa3c83..57888a0f7 100644--- a/packages/server/src/sync-engine.test.ts+++ b/packages/server/src/sync-engine.test.ts@@ -504,9 +504,9 @@ describe('SyncEngine ConflictStore admission (content-only)', () => {expect(status.conflictCount).toBe(0);expect(status.state).toBe('idle');expect(status.pausedReason).toBe('non-content-merge-failure');- expect(status.error ?? '').toContain('.mcp.json');- expect(status.error ?? '').toContain('git rm <file>');- expect(status.error ?? '').toContain('git checkout');+ expect(status.pullError ?? '').toContain('.mcp.json');+ expect(status.pullError ?? '').toContain('git rm <file>');+ expect(status.pullError ?? '').toContain('git checkout');const mergeHeadPath = join(projectDir, '.git', 'MERGE_HEAD');expect(existsSync(mergeHeadPath)).toBe(false);@@ -1034,6 +1034,85 @@ describe('SyncEngine push cycle pushes existing commits when local is ahead of o});});+describe('SyncEngine per-operation error isolation', () => {+ test('a successful fetch does not clear a standing push error', async () => {+ const git = simpleGit(projectDir);+ await git.init(['--initial-branch=main']);+ await git.raw('config', 'user.name', 'Test');+ await git.raw('config', 'user.email', '[email protected]');+ writeFileSync(join(projectDir, 'README.md'), '# Test\n');+ await git.add('.');+ await git.commit('Initial');++ const bareDir = join(tmpDir, 'bare.git');+ mkdirSync(bareDir, { recursive: true });+ await simpleGit(bareDir).init(true);+ await git.addRemote('origin', bareDir);+ await git.push(['--set-upstream', 'origin', 'main']);++ await git.raw('config', 'remote.origin.pushurl', join(tmpDir, 'nonexistent-bare.git'));++ writeFileSync(join(projectDir, 'README.md'), '# Test\n\nlocal change\n');+ await git.add('.');+ await git.commit('local commit');++ const engine = makeEngine({ syncEnabled: true });+ try {+ await engine.start();+ await engine.trigger('sync');++ const status = engine.getStatus();+ expect(status.pushError ?? '').not.toBe('');+ expect(status.lastFetchUtc).not.toBeNull();+ expect(status.pullError).toBeUndefined();+ } finally {+ await engine.destroy();+ }+ });++ test('a successful push does not clear a standing pull error', async () => {+ const git = simpleGit(projectDir);+ await git.init(['--initial-branch=main']);+ await git.raw('config', 'user.name', 'Test');+ await git.raw('config', 'user.email', '[email protected]');+ writeFileSync(join(projectDir, 'README.md'), '# Test\n');+ await git.add('.');+ await git.commit('Initial');++ const bareDir = join(tmpDir, 'bare.git');+ mkdirSync(bareDir, { recursive: true });+ await simpleGit(bareDir).init(true);+ await git.addRemote('origin', bareDir);+ await git.push(['--set-upstream', 'origin', 'main']);+ await git.raw('config', 'remote.origin.url', join(tmpDir, 'nonexistent-bare.git'));+ await git.raw('config', 'remote.origin.pushurl', bareDir);++ writeFileSync(join(projectDir, 'README.md'), '# Test\n\nlocal change\n');+ await git.add('.');+ await git.commit('local commit');+ const head = (await git.revparse(['HEAD'])).trim();++ const engine = makeEngine({ syncEnabled: true });+ try {+ await engine.start();++ await engine.trigger('pull');+ const afterPull = engine.getStatus();+ expect(afterPull.pullError ?? '').not.toBe('');+ expect(afterPull.pushError).toBeUndefined();++ await engine.trigger('push');+ const afterPush = engine.getStatus();+ const remoteAfter = (await simpleGit(bareDir).revparse(['main'])).trim();+ expect(remoteAfter).toBe(head);+ expect(afterPush.lastPushedSha).toBe(head);+ expect(afterPush.pullError ?? '').not.toBe('');+ } finally {+ await engine.destroy();+ }+ });+});+describe('SyncEngine push-permission probe', () => {test('does NOT run when there is no remote', async () => {const probe = fakeProbe({ kind: 'allowed' });diff --git a/packages/server/src/sync-engine.ts b/packages/server/src/sync-engine.tsindex 6ce639be5..ecc66f825 100644--- a/packages/server/src/sync-engine.ts+++ b/packages/server/src/sync-engine.ts@@ -98,8 +98,10 @@ interface SyncStatus {syncEnabled: boolean;identityUnresolved: boolean;remote: SyncRemoteInfo | null;- error?: string;- errorCode?: UserFacingErrorCode;+ pushError?: string;+ pushErrorCode?: UserFacingErrorCode;+ pullError?: string;+ pullErrorCode?: UserFacingErrorCode;pausedReason?: string;pushPermission?: PushPermissionStatus;}@@ -206,8 +208,10 @@ export class SyncEngine {private ahead = 0;private behind = 0;private conflictCount = 0;- private error: string | undefined;- private errorCode: UserFacingErrorCode | undefined;+ private pushError: string | undefined;+ private pushErrorCode: UserFacingErrorCode | undefined;+ private pullError: string | undefined;+ private pullErrorCode: UserFacingErrorCode | undefined;private pausedReason: string | undefined;private currentBranch = 'main';@@ -411,8 +415,8 @@ export class SyncEngine {await wait(50);}this.pausedReason = undefined;- this.error = undefined;- this.errorCode = undefined;+ this.clearPushError();+ this.clearPullError();this.transitionTo(this.hasRemote ? 'disabled' : 'dormant');this.saveStateNow();return;@@ -421,8 +425,8 @@ export class SyncEngine {this.hasRemote = await this.probeRemote();this.pausedReason = undefined;- this.error = undefined;- this.errorCode = undefined;+ this.clearPushError();+ this.clearPullError();this.consecutiveFailures = 0;if (!this.hasRemote) {@@ -446,8 +450,7 @@ export class SyncEngine {this.pausedReason === 'non-content-merge-failure') {this.pausedReason = undefined;- this.error = undefined;- this.errorCode = undefined;+ this.clearPullError();}void this.probePushPermissionInternal('refresh');if (@@ -494,8 +497,10 @@ export class SyncEngine {syncEnabled: this.syncEnabled === true,identityUnresolved: this.identityUnresolved,remote: this.hasRemote ? readSyncRemoteInfo(this.projectDir) : null,- error: this.error,- ...(this.errorCode !== undefined ? { errorCode: this.errorCode } : {}),+ ...(this.pushError !== undefined ? { pushError: this.pushError } : {}),+ ...(this.pushErrorCode !== undefined ? { pushErrorCode: this.pushErrorCode } : {}),+ ...(this.pullError !== undefined ? { pullError: this.pullError } : {}),+ ...(this.pullErrorCode !== undefined ? { pullErrorCode: this.pullErrorCode } : {}),pausedReason: this.pausedReason,...(this.pushPermission !== null ? { pushPermission: this.pushPermission } : {}),};@@ -799,7 +804,7 @@ export class SyncEngine {branch = b;this.currentBranch = branch;} catch (e) {- this.handleError(classifyGitError(e instanceof Error ? e : new Error(String(e))));+ this.handleError(classifyGitError(e instanceof Error ? e : new Error(String(e))), 'pull');return;}@@ -808,11 +813,10 @@ export class SyncEngine {await handle.git.fetch('origin');this.lastFetchUtc = new Date().toISOString();this.consecutiveFailures = 0;- this.error = undefined;- this.errorCode = undefined;+ this.clearPullError();} catch (e) {const classified = classifyGitError(e instanceof Error ? e : new Error(String(e)));- this.handleError(classified);+ this.handleError(classified, 'pull');return;}@@ -842,7 +846,7 @@ export class SyncEngine {if (classified.class === 'semantic' && classified.subclass === 'merge-conflict') {await this.handleMergeConflict();} else {- this.handleError(classified);+ this.handleError(classified, 'pull');}return;} finally {@@ -909,7 +913,7 @@ export class SyncEngine {this.transitionTo('idle');return;}- this.handleError(classifyGitError(e instanceof Error ? e : new Error(String(e))));+ this.handleError(classifyGitError(e instanceof Error ? e : new Error(String(e))), 'push');return; // early exit from lock}@@ -950,6 +954,7 @@ export class SyncEngine {);this.lastPushedSha = headSha;this.lastSyncUtc = new Date().toISOString();+ this.clearPushError();this.transitionTo('idle');return;}@@ -1060,13 +1065,13 @@ export class SyncEngine {this.lastPushedSha = commitSha;this.lastSyncUtc = new Date().toISOString();this.ahead = 0;+ this.clearPushError();if (this.state === 'pushing') {this.transitionTo('idle');}if (this.pausedReason === 'dirty-tree') {this.pausedReason = undefined;- this.error = undefined;- this.errorCode = undefined;+ this.clearPullError();this.schedulePull(0);}}@@ -1100,7 +1105,7 @@ export class SyncEngine {if (mc.class === 'semantic' && mc.subclass === 'merge-conflict') {await this.handleMergeConflict();} else {- this.handleError(mc);+ this.handleError(mc, 'pull');}this.scheduleSaveState();return;@@ -1114,7 +1119,7 @@ export class SyncEngine {this.consecutiveFailures++;if (this.state === 'pushing') this.transitionTo('idle');} else {- this.handleError(classified);+ this.handleError(classified, 'push');}} finally {try {@@ -1242,8 +1247,8 @@ export class SyncEngine {if (blocking.length > 0) {const display = blocking.slice(0, 3).join(', ');const rest = blocking.length > 3 ? `, +${blocking.length - 3} more` : '';- this.errorCode = undefined;- this.error = `Sync paused — your local changes to ${display}${rest} conflict with incoming changes. Commit, stash, or discard them before syncing.`;+ this.pullErrorCode = undefined;+ this.pullError = `Sync paused — your local changes to ${display}${rest} conflict with incoming changes. Commit, stash, or discard them before syncing.`;this.pausedReason = 'external-changes-pending';this.consecutiveFailures = 0;this.transitionTo('idle');@@ -1379,8 +1384,8 @@ export class SyncEngine {} catch (abortErr) {log.warn({ err: abortErr }, '[sync] git merge --abort failed during cleanup');}- this.errorCode = undefined;- this.error = 'Failed to detect conflict files — merge aborted';+ this.pullErrorCode = undefined;+ this.pullError = 'Failed to detect conflict files — merge aborted';this.pausedReason = undefined;this.transitionTo('idle');return;@@ -1430,8 +1435,8 @@ export class SyncEngine {}const display = failedFiles.slice(0, 3).join(', ');const rest = failedFiles.length > 3 ? `, +${failedFiles.length - 3} more` : '';- this.errorCode = undefined;- this.error = `Sync paused — couldn't auto-resolve ${display}${rest}. Resolve in your terminal (e.g. \`git rm <file>\` or \`git checkout --ours/--theirs <file> && git add <file>\`), then retry sync.`;+ this.pullErrorCode = undefined;+ this.pullError = `Sync paused — couldn't auto-resolve ${display}${rest}. Resolve in your terminal (e.g. \`git rm <file>\` or \`git checkout --ours/--theirs <file> && git add <file>\`), then retry sync.`;this.pausedReason = 'non-content-merge-failure';this.consecutiveFailures = 0;this.transitionTo('idle');@@ -1509,13 +1514,31 @@ export class SyncEngine {this.scheduleSaveState();}- private handleError(classified: ClassifiedError): void {+ private clearPushError(): void {+ this.pushError = undefined;+ this.pushErrorCode = undefined;+ }++ private clearPullError(): void {+ this.pullError = undefined;+ this.pullErrorCode = undefined;+ }++ private handleError(classified: ClassifiedError, op: 'push' | 'pull'): void {if (classified.userFacingCode !== null) {- this.errorCode = classified.userFacingCode;- this.error = undefined;+ if (op === 'push') {+ this.pushErrorCode = classified.userFacingCode;+ this.pushError = undefined;+ } else {+ this.pullErrorCode = classified.userFacingCode;+ this.pullError = undefined;+ }+ } else if (op === 'push') {+ this.pushErrorCode = undefined;+ this.pushError = classified.message;} else {- this.errorCode = undefined;- this.error = classified.message;+ this.pullErrorCode = undefined;+ this.pullError = classified.message;}log.warn({