Skip to content

Commit 257b251

Browse files
fix(docs): continue partial i18n batches after file errors (#91642)
Summary: - This PR passes the existing docs-i18n `--allow-partial` flag into sequential and parallel doc-mode schedulin ... ion as terminal, adds regression tests, and removes one non-null assertion in Microsoft Foundry onboarding. - PR surface: Source 0, Other +286. Total +286 across 3 files. - Reproducibility: yes. at source level: current main returns from sequential doc mode on the first `processFi ... d not run Go tests because this review is read-only, but the PR adds direct regression cases for that path. Automerge notes: - PR branch already contained follow-up commit before automerge: fix(docs): continue partial i18n batches after file errors - PR branch already contained follow-up commit before automerge: fix(clawsweeper): address review for automerge-openclaw-openclaw-9164… Validation: - ClawSweeper review passed for head b66c098. - Required merge gates passed before the squash merge. Prepared head SHA: b66c098 Review: #91642 (comment) Co-authored-by: Mason Huang <masonxhuang@tencent.com> Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com> Co-authored-by: clawsweeper[bot] <274271284+clawsweeper[bot]@users.noreply.github.com> Approved-by: hxy91819 Co-authored-by: hxy91819 <8814856+hxy91819@users.noreply.github.com>
1 parent c517162 commit 257b251

3 files changed

Lines changed: 295 additions & 9 deletions

File tree

extensions/microsoft-foundry/onboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export async function selectFoundryDeployment(
212212
})),
213213
});
214214
const selected =
215-
supported.find((deployment) => deployment.name === selectedDeploymentName) ?? supported[0]!;
215+
supported.find((deployment) => deployment.name === selectedDeploymentName) ?? supported[0];
216216
return { selected, supported };
217217
}
218218

scripts/docs-i18n/main.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"errors"
56
"flag"
67
"fmt"
78
"log"
@@ -136,7 +137,7 @@ func runDocsI18N(ctx context.Context, cfg runConfig, files []string, newTranslat
136137
switch cfg.mode {
137138
case "doc":
138139
if parallel > 1 {
139-
proc, skip, outputs, err := runDocParallel(ctx, ordered, resolvedDocsRoot, cfg.sourceLang, cfg.targetLang, cfg.overwrite, parallel, glossary, cfg.thinking, newTranslator)
140+
proc, skip, outputs, err := runDocParallel(ctx, ordered, resolvedDocsRoot, cfg.sourceLang, cfg.targetLang, cfg.overwrite, cfg.allowPartial, parallel, glossary, cfg.thinking, newTranslator)
140141
processed += proc
141142
skipped += skip
142143
localizedFiles = append(localizedFiles, outputs...)
@@ -149,7 +150,7 @@ func runDocsI18N(ctx context.Context, cfg runConfig, files []string, newTranslat
149150
return err
150151
}
151152
defer translator.Close()
152-
proc, skip, outputs, err := runDocSequential(ctx, ordered, translator, resolvedDocsRoot, cfg.sourceLang, cfg.targetLang, cfg.overwrite)
153+
proc, skip, outputs, err := runDocSequential(ctx, ordered, translator, resolvedDocsRoot, cfg.sourceLang, cfg.targetLang, cfg.overwrite, cfg.allowPartial)
153154
processed += proc
154155
skipped += skip
155156
localizedFiles = append(localizedFiles, outputs...)
@@ -185,23 +186,34 @@ func runDocsI18N(ctx context.Context, cfg runConfig, files []string, newTranslat
185186
elapsed := time.Since(start).Round(time.Millisecond)
186187
log.Printf("docs-i18n: completed processed=%d skipped=%d elapsed=%s", processed, skipped, elapsed)
187188
if translationErr != nil && cfg.allowPartial && cfg.mode == "doc" && processed > 0 {
189+
if ctx.Err() != nil || errors.Is(translationErr, context.Canceled) || errors.Is(translationErr, context.DeadlineExceeded) {
190+
return translationErr
191+
}
188192
log.Printf("docs-i18n: allowing partial doc output after translation error: %v", translationErr)
189193
return nil
190194
}
191195
return translationErr
192196
}
193197

194-
func runDocSequential(ctx context.Context, ordered []string, translator docsTranslator, docsRoot, srcLang, tgtLang string, overwrite bool) (int, int, []string, error) {
198+
func runDocSequential(ctx context.Context, ordered []string, translator docsTranslator, docsRoot, srcLang, tgtLang string, overwrite, allowPartial bool) (int, int, []string, error) {
195199
processed := 0
196200
skipped := 0
197201
outputs := []string{}
202+
var firstErr error
198203
for index, file := range ordered {
199204
relPath := resolveRelPath(docsRoot, file)
200205
log.Printf("docs-i18n: [%d/%d] start %s", index+1, len(ordered), relPath)
201206
start := time.Now()
202207
skip, outputPath, err := processFileDoc(ctx, translator, docsRoot, file, srcLang, tgtLang, overwrite)
203208
if err != nil {
204-
return processed, skipped, outputs, err
209+
if shouldStopDocRun(ctx, err, allowPartial) {
210+
return processed, skipped, outputs, err
211+
}
212+
if firstErr == nil {
213+
firstErr = err
214+
}
215+
log.Printf("docs-i18n: [%d/%d] failed %s (%s): %v", index+1, len(ordered), relPath, time.Since(start).Round(time.Millisecond), err)
216+
continue
205217
}
206218
if skip {
207219
skipped++
@@ -212,10 +224,10 @@ func runDocSequential(ctx context.Context, ordered []string, translator docsTran
212224
log.Printf("docs-i18n: [%d/%d] done %s (%s)", index+1, len(ordered), relPath, time.Since(start).Round(time.Millisecond))
213225
}
214226
}
215-
return processed, skipped, outputs, nil
227+
return processed, skipped, outputs, firstErr
216228
}
217229

218-
func runDocParallel(ctx context.Context, ordered []string, docsRoot, srcLang, tgtLang string, overwrite bool, parallel int, glossary []GlossaryEntry, thinking string, newTranslator docsTranslatorFactory) (int, int, []string, error) {
230+
func runDocParallel(ctx context.Context, ordered []string, docsRoot, srcLang, tgtLang string, overwrite, allowPartial bool, parallel int, glossary []GlossaryEntry, thinking string, newTranslator docsTranslatorFactory) (int, int, []string, error) {
219231
jobs := make(chan docJob)
220232
results := make(chan docResult, len(ordered))
221233
ctx, cancel := context.WithCancel(ctx)
@@ -247,7 +259,7 @@ func runDocParallel(ctx context.Context, ordered []string, docsRoot, srcLang, tg
247259
skipped: skip,
248260
err: err,
249261
}
250-
if err != nil {
262+
if err != nil && shouldStopDocRun(ctx, err, allowPartial) {
251263
cancel()
252264
return
253265
}
@@ -283,6 +295,8 @@ func runDocParallel(ctx context.Context, ordered []string, docsRoot, srcLang, tg
283295
if result.skipped {
284296
skipped++
285297
log.Printf("docs-i18n: [w* %d/%d] skipped %s (%s)", result.index, len(ordered), result.rel, result.duration.Round(time.Millisecond))
298+
} else if result.err != nil {
299+
log.Printf("docs-i18n: [w* %d/%d] failed %s (%s): %v", result.index, len(ordered), result.rel, result.duration.Round(time.Millisecond), result.err)
286300
} else if result.err == nil {
287301
processed++
288302
outputs = append(outputs, result.output)
@@ -292,6 +306,13 @@ func runDocParallel(ctx context.Context, ordered []string, docsRoot, srcLang, tg
292306
return processed, skipped, outputs, firstErr
293307
}
294308

309+
func shouldStopDocRun(ctx context.Context, err error, allowPartial bool) bool {
310+
if !allowPartial {
311+
return true
312+
}
313+
return ctx.Err() != nil || errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded)
314+
}
315+
295316
func runSegmentSequential(ctx context.Context, ordered []string, translator docsTranslator, tm *TranslationMemory, docsRoot, srcLang, tgtLang string) (int, []string, error) {
296317
processed := 0
297318
outputs := []string{}

0 commit comments

Comments
 (0)