Skip to content

Add adaptive translation reliability and diagnostics - #3

Merged
Yipxiyi merged 1 commit into
mainfrom
agent/adaptive-translation-reliability
Jul 22, 2026
Merged

Yipxiyi merged 1 commit into
mainfrom
agent/adaptive-translation-reliability

Conversation

@Yipxiyi

@Yipxiyi Yipxiyi commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • make adaptive processing the default while keeping advanced controls in Settings
  • stream uploads and prepare source files asynchronously with format-wide actionable diagnostics
  • split oversized or failing translation batches safely and preserve resumable progress
  • serialize per-job starts to prevent duplicate invalid requests from corrupting a running job's state
  • clean temporary uploads when the handoff into a job workspace fails

Validation

  • PYTHONPATH=src:tests python -m unittest discover -s tests (82 passed)
  • npm test (8 passed)
  • npm run build
  • python -m compileall -q src tests
  • git diff --check

@Yipxiyi
Yipxiyi marked this pull request as ready for review July 22, 2026 07:02
@Yipxiyi
Yipxiyi merged commit b9fa7df into main Jul 22, 2026
3 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 78bf233efc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread README.md
Comment on lines +33 to +34
- Analyzes each uploaded book and adaptively chooses batch size, concurrency, timeout, and retries; advanced overrides remain available in Settings.
- Splits timeout/context-limited batches and simple oversized paragraphs into smaller translation requests, then resumes from valid output.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Record these user-visible changes in the changelog

This adds and documents user-visible adaptive processing and fallback behavior, but CHANGELOG.md is not included in the commit. Add a release-note entry so users upgrading Babel can discover the changed Web/API processing semantics.

AGENTS.md reference: AGENTS.md:L34-L34

Useful? React with 👍 / 👎.

Comment thread src/babel_epub/jobs.py
Comment on lines +1170 to +1172
split_worthy = (
is_provider_safety_rejection(exc)
or is_retryable_translation_output_error(exc)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Split batches after validation-invalid provider output

When a provider returns parseable rows that are nevertheless incomplete or structurally invalid (for example, a context-truncated multi-row response), the error is raised later by validate_translation_rows in _translate_batch_with_retries. It therefore only retries the same full batch and never reaches this split_worthy path, so it ultimately fails instead of applying the advertised smaller-batch fallback. Validate provider results inside _translate_rows_with_safety_fallback, or route that later validation error back through the fallback.

Useful? React with 👍 / 👎.

Comment thread src/babel_epub/jobs.py
Comment on lines +311 to +312
adaptive_enabled=bool(data.get("adaptive_enabled", True)),
adaptive_plan=dict(data.get("adaptive_plan") or {}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve manual execution settings for pre-adaptive jobs

Jobs persisted before this change have neither adaptive_enabled nor adaptive_plan; this default turns both into an enabled adaptive job with an empty plan. On the next resume, resolve_execution_plan replaces the settings supplied by the user with the generic 3-worker/480-second/2-retry defaults, so previously prepared jobs can unexpectedly ignore deliberately conservative concurrency, timeout, and retry settings. Treat missing adaptive fields as legacy custom mode, or derive and persist a plan during migration.

Useful? React with 👍 / 👎.

Comment thread src/babel_epub/jobs.py
Comment on lines +1148 to +1151
translated_text = " ".join(
element_text(parse_snippet(str(part.get("translated_html", ""))))
for part in translated_parts
).strip()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve whitespace when merging split source rows

For an oversized leaf element whose formatting depends on whitespace, such as xml:space="preserve" or a white-space: pre/pre-wrap CSS rule, element_text normalizes every whitespace run and the join inserts ordinary spaces. The merged translated_html therefore loses newlines, tabs, and repeated spaces even when every split response is valid, changing the rendered EPUB layout. Retain the translated text nodes' whitespace when reassembling the original row.

AGENTS.md reference: AGENTS.md:L16-L16

Useful? React with 👍 / 👎.

Yipxiyi added a commit that referenced this pull request Jul 24, 2026
Address unresolved review feedback from #3 and add regression coverage.
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