Skip to content

feat(i18n-isr): persist bot-path auto-translations to registry backend#264

Draft
snomiao wants to merge 2 commits into
sno-i18n-isrfrom
sno-i18n-persist-translations
Draft

feat(i18n-isr): persist bot-path auto-translations to registry backend#264
snomiao wants to merge 2 commits into
sno-i18n-isrfrom
sno-i18n-persist-translations

Conversation

@snomiao
Copy link
Copy Markdown
Contributor

@snomiao snomiao commented May 12, 2026

Summary

After the bot path's OpenAI auto-translation succeeds, fire-and-forget a POST /nodes/{id}/translations to the registry backend so subsequent ISR builds (and the human path) read the stored translation instead of re-calling OpenAI.

Unblocks #258.

Why this PR exists

Today (after #257), the bot path generates translations via OpenAI every time the ISR cache cold-misses. Without persistence:

  • OpenAI gets called once per (node, locale, region) per hour — paid every cycle, not once.
  • The human path (/nodes/[id]) never sees the auto-translation because nothing writes it back.

This PR persists the result, which:

  • Bounds OpenAI cost to one call per (node, locale) for the entire history of the translation (until a publisher overrides via PR feat: add node translation editor for i18n management #179 or the source changes).
  • Eventually converges the human and bot paths — humans see a Japanese meta description once a bot has crawled.
  • Costs the request ~0ms (fire-and-forget; awaited would re-introduce the blocking-render problem the bot/human split was designed to avoid).

Dependencies

Operational config

  • New env: COMFY_REGISTRY_ADMIN_SECRETserver-only (NOT NEXT_PUBLIC_*). Same value as backend's AdminAPISecret. Add to Vercel project env (production + preview as desired).
  • Without the env set, the persistence call no-ops — safe to deploy before the backend lands.

Changes

  • src/hooks/i18n/persistNodeTranslation.tsnew helper. Validates content source is "auto", uses 10s AbortController timeout, logs but never throws.
  • src/hooks/i18n/nodeStaticProps.ts — call persistNodeTranslation (fire-and-forget) when blocking: true and the loader generated a new "auto" translation. Awaiting is deliberately avoided.
  • .env — placeholder for COMFY_REGISTRY_ADMIN_SECRET matching the existing GITHUB_CLIENT_ID pattern.
  • docs/i18n-isr-implementation.md — Key Decisions §4a documents the persistence path and the dependency on the backend PR.

Test plan

  • With COMFY_REGISTRY_ADMIN_SECRET unset: no behavior change, no warnings (Decision: silently no-op).
  • With COMFY_REGISTRY_ADMIN_SECRET set but backend unupdated: persistence call returns 401, warning logged, page still renders translated content.
  • After backend PR lands: first bot hit on a fresh (node, locale) writes node.translations[locale]; second hit returns source: "stored" (no OpenAI call); human path on the same (node, locale) now also returns the translated description.
  • Confirm fire-and-forget — TTFB on bot ISR cold miss does not regress vs. PR feat: ISR with auto-translated content i18n for node pages #257.

Out of scope

  • Migrating from shared secret to a scoped GCP service account / Workload Identity Federation. Acceptable follow-up once write path is stable.
  • Backfilling existing translations — relies on natural crawl traffic to populate. A one-off backfill cron is a separate PR if desired.

🤖 Generated with Claude Code

…ckend

After the bot path's OpenAI translation succeeds, fire-and-forget
POST /nodes/{id}/translations with X-Comfy-Admin-Secret so subsequent
ISR builds (and the human path) read the stored translation instead
of re-calling OpenAI.

- New persistNodeTranslation helper (server-only). No-ops unless both
  COMFY_REGISTRY_ADMIN_SECRET and NEXT_PUBLIC_BACKEND_URL are set and
  the translation came from OpenAI (source: "auto"). Failures are
  logged, never thrown — page render must not depend on the write.
- loadNodeStaticProps calls it only when blocking: true and a new
  auto-translation was generated.
- Doc update in i18n-isr-implementation.md with the new env var.

Depends on Comfy-Org/cloud#3641 (backend attaches APISecretMiddleware
to the translations route). Without that PR the backend will return
401 and the persistence call will simply be ignored.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
registry-web Ready Ready Preview, Comment May 12, 2026 3:47am

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant