translate: VICTORY_FAIL_DUMP samples stay distinct across files #336

Closed
JordanFableFur wants to merge 2 commits from upstream-pr/336 into main
JordanFableFur commented 2026-11-24 23:34:58 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by JordanFableFur on 2026-11-24T23:34:58Z.


What

The first-3-containers-per-reason limit counted per worker and per file: the counters live in each worker's Tally, and before is read per file. Two files whose first failure has the same reason each wrote <reason>_0.cdxil, and the second replaced the first.

Sample slots are now tracked for the whole run, keyed by reason (SAMPLED), and a container takes the next slot the run has not written yet. That also keeps samples distinct when two different reason strings sanitize to the same file stem.

Fixes #247.

Testing

cargo check --all-targets and clippy -D warnings cross-checked for the Windows target (clean). The write path sits behind VICTORY_FAIL_DUMP inside the worker scope; the slot bookkeeping is exercised by the change itself (old block with two same-reason failures wrote one file, the new logic takes slot 1 for the second).

AI use: written with Codex and Claude Code (GPT-5.2 Codex); reviewed and posted with my approval. No game files were used.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6593600578 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/336). Originally posted by [JordanFableFur](https://github.com/JordanFableFur) on 2026-11-24T23:34:58Z. --- ## What The first-3-containers-per-reason limit counted per worker and per file: the counters live in each worker's `Tally`, and `before` is read per file. Two files whose first failure has the same reason each wrote `<reason>_0.cdxil`, and the second replaced the first. Sample slots are now tracked for the whole run, keyed by reason (`SAMPLED`), and a container takes the next slot the run has not written yet. That also keeps samples distinct when two different reason strings sanitize to the same file stem. Fixes #247. ## Testing `cargo check --all-targets` and clippy `-D warnings` cross-checked for the Windows target (clean). The write path sits behind `VICTORY_FAIL_DUMP` inside the worker scope; the slot bookkeeping is exercised by the change itself (old block with two same-reason failures wrote one file, the new logic takes slot 1 for the second). **AI use:** written with Codex and Claude Code (GPT-5.2 Codex); reviewed and posted with my approval. No game files were used.
chatgpt-codex-connector[bot commented 2026-11-25 00:09:52 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:38:09Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eeeb39e2ea

ℹ️ 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".

<!-- greyfinch-sync:fxceless/victory-fork:review:6049167927 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/336#pullrequestreview-6049167927). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:38:09Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `eeeb39e2ea` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). 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". </details>
chatgpt-codex-connector[bot commented 2026-11-25 00:10:09 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:35:07Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T23:38:16.007189Z eeeb39e PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7147566273 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/336#issuecomment-7147566273). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:35:07Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"eeeb39e2eaeb1693bf88b71a9d82c9f71757e9c0","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T23:38:16.007189Z">2026-11-24T23:38:16.007189Z</relative-time> | `eeeb39e` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
chatgpt-codex-connector[bot commented 2026-11-25 00:10:13 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:38:09Z.

Code review location: apps/victory/src/translate.rs; line 401

@@ -377,17 +383,26 @@ fn translate(
         Err(e) => return t.fail(e.to_string(), example),
     };
     // `VICTORY_FAIL_DUMP=<dir>`: the first 3 containers of each failure reason, as the title
-    // has them (`.cdxil`), to work on a translator gap offline
+    // has them (`.cdxil`), to work on a translator gap offline. Sample counts are per run,
+    // not per file: two files whose first failure has the same reason must not both write
+    // `<reason>_0.cdxil`.
     let dump = std::env::var_os("VICTORY_FAIL_DUMP");
     let before: Option<BTreeMap<String, usize>> = dump.as_ref().map(|_| t.failed.iter().map(|(k, v)| (k.clone(), v.0)).collect());
     translate_programs(&container, programs, &example, t, checks);
     if let (Some(dir), Some(before)) = (dump, before) {
         for (reason, (n, _)) in &t.failed {
             let was = before.get(reason).copied().unwrap_or(0);
-            if *n > was && was < 3 {
+            if *n > was {
+                let mut sampled = SAMPLED.lock().unwrap_or_else(|e| e.into_inner());
+                let taken = sampled.entry(reason.clone()).or_default();
                 let stem: String = reason.chars().map(|c| if c.is_ascii_alphanumeric() { c } else { '_' }).take(60).collect();
-                let _ = std::fs::create_dir_all(&dir);
-                let _ = std::fs::write(std::path::Path::new(&dir).join(format!("{stem}_{was}.cdxil")), &bytes[..]);
+                // Even when two sanitized reason strings collide, the next slot is one
+                // this run has not written yet.
+                let slot = (was..3).find(|i| taken.insert(*i));

P2 Badge Consume sample slots only after successful writes

If the first three dump attempts for a reason fail because the output directory is temporarily unwritable, this insertion still fills SAMPLED even though no container was saved. Once the directory becomes writable, failures in later input files are silently skipped because all slots are already marked taken; previously those files retried the write. Mark a slot as taken only after std::fs::write succeeds, or release it on error, so a transient filesystem error cannot suppress that reason's dumps for the remainder of the run.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:fxceless/victory-fork:review-comment:4688064514 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/336#discussion_r4688064514). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:38:09Z. **Code review location:** `apps/victory/src/translate.rs`; line 401 ~~~~diff @@ -377,17 +383,26 @@ fn translate( Err(e) => return t.fail(e.to_string(), example), }; // `VICTORY_FAIL_DUMP=<dir>`: the first 3 containers of each failure reason, as the title - // has them (`.cdxil`), to work on a translator gap offline + // has them (`.cdxil`), to work on a translator gap offline. Sample counts are per run, + // not per file: two files whose first failure has the same reason must not both write + // `<reason>_0.cdxil`. let dump = std::env::var_os("VICTORY_FAIL_DUMP"); let before: Option<BTreeMap<String, usize>> = dump.as_ref().map(|_| t.failed.iter().map(|(k, v)| (k.clone(), v.0)).collect()); translate_programs(&container, programs, &example, t, checks); if let (Some(dir), Some(before)) = (dump, before) { for (reason, (n, _)) in &t.failed { let was = before.get(reason).copied().unwrap_or(0); - if *n > was && was < 3 { + if *n > was { + let mut sampled = SAMPLED.lock().unwrap_or_else(|e| e.into_inner()); + let taken = sampled.entry(reason.clone()).or_default(); let stem: String = reason.chars().map(|c| if c.is_ascii_alphanumeric() { c } else { '_' }).take(60).collect(); - let _ = std::fs::create_dir_all(&dir); - let _ = std::fs::write(std::path::Path::new(&dir).join(format!("{stem}_{was}.cdxil")), &bytes[..]); + // Even when two sanitized reason strings collide, the next slot is one + // this run has not written yet. + let slot = (was..3).find(|i| taken.insert(*i)); ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Consume sample slots only after successful writes** If the first three dump attempts for a reason fail because the output directory is temporarily unwritable, this insertion still fills `SAMPLED` even though no container was saved. Once the directory becomes writable, failures in later input files are silently skipped because all slots are already marked taken; previously those files retried the write. Mark a slot as taken only after `std::fs::write` succeeds, or release it on error, so a transient filesystem error cannot suppress that reason's dumps for the remainder of the run. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
JordanFableFur commented 2026-11-25 01:12:01 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by JordanFableFur on 2026-11-25T00:32:55Z.


Addressed in 24dfcec: a slot is marked taken only after fs::write succeeds, so a transient write failure (an unwritable directory) leaves the slot for the next failure of that reason.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7148622476 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/336#issuecomment-7148622476). Originally posted by [JordanFableFur](https://github.com/JordanFableFur) on 2026-11-25T00:32:55Z. --- Addressed in 24dfcec: a slot is marked taken only after `fs::write` succeeds, so a transient write failure (an unwritable directory) leaves the slot for the next failure of that reason.
upstream-sync closed this pull request 2026-11-25 02:09:26 +00:00
kaayzouee commented 2026-11-25 02:10:06 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by kaayzouee on 2026-11-25T01:20:27Z.


Duplicate of #292?

<!-- greyfinch-sync:fxceless/victory-fork:comment:7149447045 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/336#issuecomment-7149447045). Originally posted by [kaayzouee](https://github.com/kaayzouee) on 2026-11-25T01:20:27Z. --- Duplicate of #292?
JordanFableFur commented 2026-11-25 02:10:10 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by JordanFableFur on 2026-11-25T01:46:15Z.


Closing — #292 fixes the same issue (#247) and was opened first. Thanks for flagging.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7149936260 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/336#issuecomment-7149936260). Originally posted by [JordanFableFur](https://github.com/JordanFableFur) on 2026-11-25T01:46:15Z. --- Closing — #292 fixes the same issue (#247) and was opened first. Thanks for flagging.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!336
No description provided.