没有不值得去解决的问题,也没有不值得去学习的技术!

A Tour of Go Chinese Translation Second Batch Run: From Inline Code Order Misjudgment to Historical Response Revalidation

Figure 2: flowcontrol/6 final Chinese page, return and v swap positions entirely to adapt to natural Chinese word order

作者:

在

,

Today I continued advancing the Simplified Chinese translation of the go-tour-i18n project.

After the previous representative page validation and the completion of the first batch of regular page automated trial runs, the entire workflow of translation, structure protection, and automated validation has gradually stabilized. Therefore, this time I continued to select the next batch of 10 regular pending pages for formal translation.

I originally thought this batch would be fairly smooth, and the actual results were indeed quite good: most of the earlier pages successfully entered ready.

However, the last flowcontrol/6 failed 3 times in a row and ultimately entered blocked.

After further analysis, I discovered a very interesting problem:

GLM-5.2 did not lose Protected Tokens, nor did it break the inline code. What really went wrong was the project’s own restoration rules.

This issue was ultimately fixed, and it also prompted the project to add a highly valuable new capability:

After fixing the protection, restoration, or validation logic, previously successful model responses can be directly revalidated without needing to call the large model API again.

This troubleshooting process was fairly comprehensive, so I am recording it separately.

1. Continuing with the second batch of 10 regular pages

The current project still uses the “complete course page” as the minimum translation unit.

The overall workflow is:

Plaintext
Complete course page
→ GLM-5.2 full-page translation
→ Save Candidate
→ Automated structure and page validation
├─ Pass → ready
└─ Fail → Limited full-page retry → blocked

The 10 pages selected this time are:

Plaintext
basics/14
basics/15
basics/16
basics/17
flowcontrol/1
flowcontrol/2
flowcontrol/3
flowcontrol/4
flowcontrol/5
flowcontrol/6

Formal translation passed via:

Bash
go run -mod=readonly ./cmd/tour-i18n translate run \
    --locale zh-CN \
    --id <page_id>

Currently, --id only accepts one page at a time, so during batch execution, a Shell loop is used in the outer layer to call them sequentially page by page.

2. 9 pages enter ready, flowcontrol/6 fails 3 times in a row

After the first round of execution completed, the results were as follows:

PageStatusAttempts
basics/14ready1
basics/15ready1
basics/16ready1
basics/17ready1
flowcontrol/1ready1
flowcontrol/2ready1
flowcontrol/3ready3
flowcontrol/4ready1
flowcontrol/5ready1
flowcontrol/6blocked3

Among them, although flowcontrol/3 used 3 Attempts, it ultimately entered ready normally.

The one that truly needs further analysis is flowcontrol/6.

It still failed after the 3rd formal Attempt:

Plaintext
status: blocked
attempts: 3
token_valid: false
present_valid: false

The final error was:

Plaintext
inline code sentinel 5 opening marker missing
Figure 1: flowcontrol/6 enters blocked after 3 consecutive translations due to Inline Code Sentinel validation failure
Figure 1: flowcontrol/6 enters blocked after 3 consecutive translations due to Inline Code Sentinel validation failure

Looking at the error name, it is easy to initially form a judgment:

Did GLM-5.2 delete the 5th Inline Code Opening Marker?

But after further checking the original model response, I found that this was not the case.

3. flowcontrol/6 itself does not have a complex structure

The upstream course page corresponding to flowcontrol/6 is:

Plaintext
* If with a short statement

Like `for`, the `if` statement can start with a short statement to execute before the condition.

Variables declared by the statement are only in scope until the end of the `if`.

(Try using `v` in the last `return` statement.)

.play flowcontrol/if-with-a-short-statement.go

The Present structure of this page is actually very simple:

  • A regular title;
  • A regular paragraph;
  • 5 inline codes;
  • 1 .play Directive.

The 5 inline codes in order are:

Plaintext
for
if
if
v
return

The sentence that actually triggered the problem is the last one:

Plaintext
(Try using `v` in the last `return` statement.)

According to the order of appearance in the English source code, the two inline codes are:

Plaintext
v → return

4. GLM-5.2 did not lose Tokens at all

After checking attempt-001, attempt-002, and attempt-003, I found that the key sentences in the three model outputs were basically identical.

The natural Chinese expression is:

(Try using return in the last v statement.)

Thus, the order of appearance of the two complete Inline Code Pairs became:

Plaintext
return → v

While the English original is:

Plaintext
v → return

In other words, what the model did was:

Plaintext
English:
v → return

Chinese:
return → v

Most importantly, the model did not:

  • Delete the Opening Marker of return;
  • Delete the Closing Marker of return;
  • Modify return;
  • Delete v;
  • Modify v;
  • Add backtick code on its own.

Both Inline Code Pairs are complete.

What actually happened was merely:

The two complete Inline Code Pairs swapped positions entirely to adapt to the natural Chinese word order.

5. The Chinese result in the browser actually proves this transposition is reasonable

After fixing and restoring the page, viewing the final Chinese page in the browser allows you to intuitively see this sentence:

(Try using return in the last v statement.)

Figure 2: flowcontrol/6 final Chinese page, return and v swap positions entirely to adapt to natural Chinese word order
Figure 2: flowcontrol/6 final Chinese page, return and v swap positions entirely to adapt to natural Chinese word order

This screenshot is actually very illustrative of the problem.

If merely to maintain the English source code’s:

Plaintext
v → return

And force Chinese to use the same order, it would likely require deliberately rewriting the Chinese into an unnatural expression.

Whereas:

Use v in the last return statement

Is obviously the normal Chinese word order.

Therefore, what truly needs to be considered this time is not:

How to make GLM never adjust the Token order?

But rather:

Which orders belong to structures that must be protected, and which orders should be allowed to change naturally with the target language?

6. The real problem lies in Restore’s Source Order assumption

The problem was ultimately located in validateInlinePairs().

The old implementation performed a one-way scan according to the Inline Pair order in the source code.

The original order was:

Plaintext
for
→ if
→ if
→ v
→ return

The model output was:

Plaintext
for
→ if
→ if
→ return
→ v

The old logic first looked for v according to the source code order.

After finding v, it continued to look for return in the subsequent text.

The problem is:

return had already been moved entirely in front of v due to the natural Chinese word order.

So the program naturally couldn’t find the 5th Pair’s Opening Marker after v.

Ultimately producing:

Plaintext
inline code sentinel 5 opening marker missing

In fact, this error message is also somewhat misleading.

The Marker was not missing.

The real problem was merely:

The old restorer assumed that different Inline Pairs must continue to maintain Source Order.

7. Structure protection cannot in turn destroy natural language

Ultimately, I chose not to further strengthen the Prompt to require GLM-5.2 to:

All Inline Code Pairs must strictly maintain the original English order.

Because doing so, while it might let the old validator pass, would introduce another problem:

Sacrificing the natural expression of the target language for the convenience of program validation.

This does not conform to the translation goals established at the very beginning of this project.

What structure protection should strictly guarantee is:

  • Opening Marker cannot be missing;
  • Closing Marker cannot be missing;
  • Pairs cannot be split;
  • The code content within a Pair cannot be changed;
  • Pairs cannot be duplicated;
  • Pairs cannot be forged;
  • Pairs cannot cross;
  • Pairs cannot be nested;
  • The model cannot add new backtick code outside of Tokens.

However:

Two separate, complete, and semantically independent Inline Code Pairs do not need to be prohibited from swapping positions entirely with the target language’s word order just because their English order of appearance differs.

8. Modifying the Inline Pair restoration rules

Therefore, what was ultimately fixed was the Restore, rather than forcing the model to change the Chinese.

The new validateInlinePairs() no longer performs a one-way scan based on the Source Order of different Pairs.

It now separately locates each Pair’s own:

Plaintext
Opening Marker
Original Payload
Closing Marker

And then strictly validates:

  • Opening Marker must exist;
  • Closing Marker must exist;
  • Opening must be located before the corresponding Closing;
  • The Payload within the Pair must be byte-for-byte identical;
  • Pairs cannot cross;
  • Pairs cannot be nested.

But it allows different complete Pairs to swap positions entirely.

Therefore:

Plaintext
Source:

v → return

Translated as:

Plaintext
Translation:

return → v

Is now considered legal behavior.

The prerequisite remains that both Pairs themselves are completely intact.

9. The final Validator originally allowed this transposition

After further review, I also discovered a very important issue.

The final Candidate Validator originally used an unordered protected content comparison for Inline Codes.

It strictly validates:

  • Inline Code count;
  • Inline Code Payload;
  • Inline Code Multiset.

But it does not require different Inline Codes to always maintain Source Order.

So there was actually an internal rule conflict:

Plaintext
Restore:
Requires different Inline Pairs to maintain Source Order

Final Validator:
Allows complete Inline Codes to swap positions entirely based on natural language

flowcontrol/6 was the first to stably expose this contradiction.

After the fix, the two layers of rules are finally unified:

Strict inside a single Inline Code Pair; natural word order transposition is allowed between different complete Pairs.

10. Why not request GLM again after fixing it?

After Restore was fixed, another problem arose.

At this point, flowcontrol/6 had officially entered:

Plaintext
blocked

In formal status, the regular:

Plaintext
translate run

Will not continue running Blocked pages.

Although development mode can continue to request the model, doing so would create a new Attempt and consume GLM Tokens again.

The problem is, there was no need to retranslate at all this time.

Because it had already been confirmed that:

  • The 3rd API request succeeded;
  • finish_reason=stop;
  • The model Content was complete;
  • Protected Tokens were complete;
  • The Inline Code content was not modified;
  • What really failed was the old Restore.

So if I fixed the project’s own bug but then required the model to translate again, I would actually be wasting the valid results already obtained.

A more reasonable workflow should be:

Plaintext
Fix Restore
→ Read the already saved historical model response
→ Use the new Restore to restore
→ Revalidate using the current Validator

Rather than:

Plaintext
Fix Restore
→ Call GLM again

11. recover-network cannot solve this problem

The project previously already had:

Plaintext
translate recover-network

But it has a very clear responsibility:

Recover Attempts that truly failed due to network failures and did not actually receive a valid model response.

It requires the historical Attempt to belong to:

Plaintext
api_success=false
network failure
no valid model content

Whereas flowcontrol/6 was the exact opposite:

Plaintext
api_success=true
has complete response
has complete content

Only the old Restore failed.

Therefore, for convenience, I could not directly reuse recover-network.

Different types of failures should retain clear, independent recovery semantics.

12. Adding translate revalidate-response

To solve this type of problem, a formal CLI was added this time:

Bash
go run -mod=readonly ./cmd/tour-i18n translate revalidate-response \
    --locale zh-CN \
    --id flowcontrol/6 \
    --attempt 3

It solves:

Historical model responses that were successful, but because the protection, restoration, or validation logic was subsequently fixed, need to be revalidated according to the current rules.

The entire workflow is:

Plaintext
Read historical successful Response
→ Use current protectTranslation()
→ Use current restore()
→ Use current ValidateCandidate()
→ All pass
→ Write formal Candidate
→ blocked → ready

During this entire process, it will not:

  • Call GLM;
  • Create a new Translation Attempt;
  • Increase Retry Quota;
  • Modify the historical Response;
  • Modify the historical Request;
  • Overwrite the historical Validation.

13. Revalidation must still Fail Closed

After adding the historical response revalidation capability, it also cannot be allowed to become a backdoor that bypasses the formal state machine.

Therefore, revalidate-response will strictly check:

  • Page ID exists;
  • Locale is valid;
  • Current Source Hash matches;
  • Current status must be blocked;
  • The specified Attempt must exist;
  • Request, Response, and Validation audits must be complete;
  • The historical Request’s Page ID, Locale, and Source Hash must all match;
  • The historical API request must have succeeded;
  • finish_reason must be stop;
  • Content cannot be empty.

Afterwards, it must still execute the complete:

Plaintext
protect
→ restore
→ ValidateCandidate

If any step fails:

Plaintext
status

It still remains:

Plaintext
blocked

It will never be directly promoted to ready just because the historical Response was once an HTTP success.

14. First successful real historical response revalidation

After the feature was completed and tested, I formally executed the following on the 3rd historical response of flowcontrol/6:

Bash
go run -mod=readonly ./cmd/tour-i18n translate revalidate-response \
    --locale zh-CN \
    --id flowcontrol/6 \
    --attempt 3

Final result:

Plaintext
source_attempt: 3
attempts: 3
status: ready

token_valid: true
present_valid: true
passed: true
Figure 3: Reusing historical attempt-003 for successful revalidation, flowcontrol/6 recovers from blocked to ready
Figure 3: Reusing historical attempt-003 for successful revalidation, flowcontrol/6 recovers from blocked to ready

What is most noteworthy in this screenshot is actually not:

Plaintext
status: ready

But rather:

Plaintext
source_attempt: 3
attempts: 3

That is, there was no:

Plaintext
attempt-004

GLM-5.2 was also not called again.

This proves from a real data perspective:

The 3rd model output itself was usable. What truly failed previously was the project’s own Restore rules.

15. Historical Attempts cannot be rewritten just because they later succeeded

flowcontrol/6 already had:

Plaintext
attempt-001
attempt-002
attempt-003

These historical Attempts are all retained and will not be modified.

The revalidation will separately generate:

Plaintext
revalidation-001.json

Therefore, the final audit chain expresses:

Plaintext
attempt-003:
Failed validation according to the Restore rules at the time

↓
Fix Restore

↓
revalidation-001:
Using the same historical Response,
successfully validated according to the new Restore + Validator

Rather than rewriting past failure records into successes.

This is very important for long-term maintenance.

If a failure occurred, the true failure record from that time should be preserved.

Subsequent code fixes and revalidations are then appended as new audit events.

16. Fixing absolute paths in audit files along the way

After generating revalidation-001.json for the first time, another small issue was found during the final review.

In the audit data:

Plaintext
response_path
validation_path

What was originally saved was the local absolute path.

For example:

Plaintext
/home/wangqiang/code/go-tour-i18n/...

Although there was no functional problem, if this data were to enter the Git repository long-term, it would be tied to the current machine and directory structure.

If in the future:

  • I change computers;
  • Change my username;
  • Change the repository directory;

These absolute paths would lose portability.

Therefore, the source paths in the Revalidation audit were ultimately changed to repository-relative paths:

Plaintext
data/translation-runs/zh-CN/flowcontrol/6/sources/.../attempt-003/response.json

And tests were added to ensure that local absolute paths would not be written to such audit fields again in the future.

17. After committing, I discovered another outdated TestCommittedStatus

After this batch of translations and the Revalidation feature were completed, I first created a commit:

Plaintext
b7de0e0 feat(i18n): 支持历史响应复验并完成第二批页面翻译

But after committing, rerunning:

Bash
go test ./internal/i18n
go test ./...

Still produced a failure:

Plaintext
basics/4: ready, attempts=7

At first, it looked like this commit had caused some status anomaly.

But after further analysis, I found:

This test had actually already failed before this commit.

The problem was that TestCommittedStatus itself could no longer keep up with the current project workflow.

18. The old TestCommittedStatus is essentially a Ready page whitelist

In addition to running the basic CheckStatus(), the old test also maintained a Page ID whitelist.

A few historically manually confirmed pages were allowed to be:

Plaintext
ready

While pages that had not entered this switch whitelist were all required by default to be:

Plaintext
pending
attempts=0
CandidatePath=""

This design was very reasonable in the early stages of the project.

Because at that time, only a few representative pages had entered ready, and the test could use this to prevent unconfirmed runtime statuses from accidentally entering Git.

But the project has now entered a normal batch translation phase.

Every time a batch of pages is completed, new ones will naturally appear as:

Plaintext
ready

If the old design were still used, then every time 10 pages were completed in the future, 10 Page IDs would have to be manually added to the test file.

This is obviously no longer reasonable.

19. Why did it only report basics/4 first?

Currently, the entire project already has quite a few ready pages.

But the test first only showed:

Plaintext
basics/4: ready, attempts=7

This did not mean that only basics/4 had a problem.

It was just that the test immediately Fatal upon encountering the first failure.

basics/4 happened to be the first one encountered that:

Had not entered the old whitelist, but had already legally become a ready page.

The other new Ready pages after it would actually encounter the same problem.

20. attempts=7 does not mean 7 formal retries are allowed

Another special point about basics/4 is:

Plaintext
attempts=7

This number, at first glance, seems to exceed the limited number of retries in the project’s formal phase.

But what is actually recorded here is:

The monotonically increasing Attempt number throughout the page’s entire development history.

basics/4 early on experienced:

  • Infrastructure network failures;
  • Network Recovery;
  • Formal model response structure failures;
  • Continued validation during the development calibration phase;
  • Ultimately generating a legal Candidate.

Therefore, the historical number ultimately reached 7.

It is not equivalent to:

The formal production workflow allows 7 consecutive automatic retries.

The current Retry Window and the historical Attempt number are actually two different concepts.

So I cannot, just to make the test green, forcibly reduce:

Plaintext
attempts=7

Doing so would actually destroy the true audit history.

21. Changing the static whitelist to a general status invariant

Ultimately, I did not continue to expand the Ready page whitelist.

Instead, I changed TestCommittedStatus to truly validate “whether a committed status is legal.”

For pending:

  • Candidate Path must be empty;
  • attempts=0 is not strictly required, to be compatible with the legal situation where an Attempt has occurred during the development phase but the status still remains Pending.

For blocked:

  • attempts > 0;
  • Candidate Path must be empty;
  • Do not use incorrect limits like attempts <= 3.

For:

Plaintext
ready
candidate
published

The requirements are:

  • attempts > 0;
  • Candidate Path must be the standard path derived from the Page ID;
  • The Candidate file must actually exist;
  • The Candidate must pass the current ValidateCandidateForLocale().

Thus, the question the test focuses on becomes:

Does this status satisfy the invariants that the state machine should uphold long-term?

And no longer:

Has this Page ID been written into the test whitelist in advance?

This way, when new Ready pages are added in the future, there is no need to constantly modify the Page ID list in the tests.

22. Precise assertions with real historical value are retained

In the original tests, some special historical pages also had precise assertions for fields such as:

  • Attempts;
  • Source Hash;
  • Candidate Path;
  • UpdatedAt;
  • Note;

These were not all simply deleted.

If certain pages do carry regression value for historical migrations, recoveries, or special calibration behavior, it still makes sense to continue locking their metadata.

Ultimately, the two responsibilities were simply separated:

Plaintext
General status legality

And:

Plaintext
Regression of specific important historical behaviors

No longer letting a single historical whitelist bear the status legality judgment for all future pages.

23. The complete test suite finally passes again

After adjusting the tests, I reran:

Bash
go test ./internal/i18n

Passed.

Subsequently:

Bash
go test ./cmd/tour-i18n
go test ./...

Also all passed.

Status check:

Bash
go run -mod=readonly ./cmd/tour-i18n status check \
    --locale zh-CN

Result:

Plaintext
status OK: 103 pages for zh-CN

Finally, I created a separate commit:

Plaintext
13ec759 test(i18n): 修正已提交翻译状态校验

I did not Amend it into the previous feature commit.

So this ultimately produced two commits with very clear responsibilities:

Plaintext
b7de0e0
feat(i18n): 支持历史响应复验并完成第二批页面翻译

13ec759
test(i18n): 修正已提交翻译状态校验

The two commits were then pushed together to origin/main.

Both local and remote are ultimately:

Plaintext
13ec759

The working tree remains clean.

24. The final result of the second batch is 10/10 Ready

When the automated translation just finished, this batch was at one point:

Plaintext
9 ready
1 blocked

But after troubleshooting the issue and fixing Restore, flowcontrol/6 directly reused the previous attempt-003 original model response and successfully revalidated it.

So the final result of the second batch was actually:

Plaintext
10 / 10 ready

As of the completion of this commit, the status of the entire project has reached:

Plaintext
ready=35
pending=68
blocked=0

Total number of pages:

Plaintext
103

Status checks and complete tests have all passed.

25. The biggest gain this time was not translating 10 more pages

Looking just at the numbers, this time only added 10 Ready pages.

But from an engineering perspective, I feel what was more important this time was exposing and solving three problems.

The first is:

Strict protection of Protected Tokens should not be equivalent to strictly maintaining English word order.

As long as an Inline Code Pair itself remains intact, it can entirely move with the semantic unit of the target language.

The second is:

Model translation failures and validator false rejections must be strictly distinguished.

If the historical Response itself is fine, and it is only later discovered that the old Restore or Validator had a flaw, then after the code is fixed, priority should be given to reusing the existing model response rather than spending another API Token.

This is also the greatest value of the newly added:

Plaintext
translate revalidate-response

The third is:

The tests themselves also need to evolve with the project workflow.

In the early stages of the project:

Plaintext
Only a few specified pages are allowed to be ready

Could have been a very valuable protection rule.

But when the project truly enters the batch translation phase, the long-term invariant should become:

Plaintext
Any ready page,
must have a legal Candidate,
and pass the unified Validator.

Rather than continuing to maintain an ever-growing Page ID whitelist.

26. Next steps: continuing to advance in small batches

Currently, there are still:

Plaintext
pending=68

And:

Plaintext
blocked=0

I still will not directly translate all the remaining 68 pages at once.

The next step will continue to use:

Plaintext
10 pages per batch

to advance.

Today’s experience also proves again that what really needs to be observed during the batch translation phase is not just the success rate.

More importantly:

Will each new batch of course pages produce structural combinations not previously covered by the representative pages and existing batches?

If things continue to be stable later, I will then consider whether to increase the number of pages per batch.

If a new blocked appears again, I will continue to handle it according to the process that has gradually taken shape:

Plaintext
Retain complete Attempt
→ Check original model Response
→ Determine if it's a model issue or a toolchain issue
→ Minimal fix
→ Revalidate using the unified validation chain

Rather than simply to make the page pass, continuously adding Prompt restrictions or repeatedly calling the model.

The second batch of 10 regular pages is officially complete here.

Compared to merely adding 10 more Ready pages, I feel that the real outcomes left behind by this batch are actually two new engineering capabilities:

Plaintext
Complete Inline Code Pairs support natural word order transposition

And:

Plaintext
Historical successful model responses can be revalidated

These two points should be more valuable than mere page numbers for the automated translation of the remaining 68 pages.

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系