fix(publish): prevent stuck publish queue and duplicate posting
Desktop Client Build / Resolve Build Metadata (push) Successful in 41s
Backend CI / Backend (push) Failing after 7m14s
Desktop Client Build / Build Desktop Client (push) Successful in 23m46s
Desktop Client Build / Publish Client Artifacts to NAS (push) Successful in 56s

The desktop publish queue could stall for a long time and end users assumed
the software was broken. Root cause: a hung adapter held its execution slot
with no wall-clock timeout while auto-renewing its lease forever, so the
server never reclaimed it and every queued task behind it stayed 等待发布.
Auto-recovery also risked silently re-posting a non-idempotent article.

Client (Electron):
- per-task wall-clock deadline + abort; progress-gated lease renewal that
  stops and aborts a stalled task instead of renewing it forever
- decouple the concurrency cap from CDP-induced CPU/memory pressure
  (admission gate instead of self-throttling collapse); 15s watchdog pump
- all adapter network I/O now has fetch timeouts and honors context.signal;
  bounded image-upload concurrency with per-image timeout
- surface live adapter progress, elapsed time, queue position and a
  working-vs-queued distinction in the publish view

Server (tenant-api):
- publish lease-recovery worker (every 3m) + supporting index: reclaim
  expired in_progress publish leases, requeue (<3 attempts) or terminal-fail
- 3-minute lease TTL with client-presence-gated extension; max 3 attempts

Idempotency (production-grade core):
- durable publish_submit_started_at marker, set before the irreversible
  platform submit POST; recovery and abort route a maybe-submitted task to
  unknown (manual reconcile, kept in the dedup set) instead of re-posting
- desktop UI requires explicit confirmation before retrying a possibly-
  already-published task

Verified: go build/vet/test (incl. resolvePublishRecoveryOutcome), vue-tsc,
vitest 141/141, gofmt all clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-30 19:52:17 +08:00
parent 9d6181260a
commit fa51a3455f
41 changed files with 2124 additions and 358 deletions
+17 -6
View File
@@ -168,6 +168,7 @@ async function fetchAccount(context: PublishAdapterContext): Promise<ZolAccount
credentials: 'include',
headers: await zolHeaders(context),
},
{ signal: context.signal },
).catch(() => null)
const user = response?.data
@@ -217,6 +218,7 @@ async function createDraftId(context: PublishAdapterContext, form: FormData): Pr
headers: await zolHeaders(context),
body: form,
},
{ signal: context.signal },
).catch(
(error): ZolDraftResponse => ({
errcode: -1,
@@ -254,6 +256,7 @@ async function uploadCoverVariant(
headers: await zolHeaders(context),
body: form,
},
{ signal: context.signal },
).catch(
(error): ZolImageUploadResponse => ({
errcode: -1,
@@ -281,7 +284,7 @@ async function uploadCover(
context: PublishAdapterContext,
sourceUrl: string,
): Promise<ZolCoverImage[] | null> {
const source = await fetchImageAssetBlob(sourceUrl)
const source = await fetchImageAssetBlob(sourceUrl, { signal: context.signal })
if (!source) {
throw new Error('zol_cover_fetch_failed')
}
@@ -327,6 +330,7 @@ async function uploadContentImageByNetworkPic(
headers: await zolHeaders(context),
body: form,
},
{ signal: context.signal },
).catch(() => null)
const uploaded = zolUploadedImageUrl(response)
@@ -345,7 +349,7 @@ async function uploadContentImageByFile(
context: PublishAdapterContext,
sourceUrl: string,
): Promise<string | null> {
const image = await fetchImageAssetBlob(sourceUrl)
const image = await fetchImageAssetBlob(sourceUrl, { signal: context.signal })
if (!image) {
throw new Error(
`zol_content_image_upload_failed:${sourceUrl.slice(0, 160)}:source_fetch_failed`,
@@ -367,6 +371,7 @@ async function uploadContentImageByFile(
headers: await zolHeaders(context),
body: form,
},
{ signal: context.signal },
).catch(
(error): ZolImageUploadResponse => ({
errcode: -1,
@@ -421,10 +426,15 @@ async function applyRecommendSubjects(
url.searchParams.set('keyword', '')
url.searchParams.set('page', '1')
const response = await sessionFetchJson<ZolSubjectListResponse>(context.session, url.toString(), {
credentials: 'include',
headers: await zolHeaders(context),
}).catch(() => null)
const response = await sessionFetchJson<ZolSubjectListResponse>(
context.session,
url.toString(),
{
credentials: 'include',
headers: await zolHeaders(context),
},
{ signal: context.signal },
).catch(() => null)
const subjects = (response?.data?.list ?? [])
.filter((item) => item.subjectId != null && item.subjectName?.trim())
@@ -598,6 +608,7 @@ export const zolAdapter: PublishAdapter = {
headers: await zolHeaders(context),
body: form,
},
{ signal: context.signal },
).catch(
(error): ZolPublishResponse => ({
errcode: -1,