ep: Fix teacher prompt formatting (#47172)

Oleksiy Syvokon created

Release Notes:

- N/A

Change summary

crates/edit_prediction_cli/src/format_prompt.rs  | 4 ++--
crates/edit_prediction_cli/src/main.rs           | 8 ++++++--
crates/edit_prediction_cli/src/teacher.prompt.md | 4 ++++
3 files changed, 12 insertions(+), 4 deletions(-)

Detailed changes

crates/edit_prediction_cli/src/format_prompt.rs 🔗

@@ -295,9 +295,9 @@ impl TeacherPrompt {
 
     fn extract_editable_region(text: &str) -> String {
         let start = text
-            .find(Self::EDITABLE_REGION_START)
+            .rfind(Self::EDITABLE_REGION_START)
             .map_or(0, |pos| pos + Self::EDITABLE_REGION_START.len());
-        let end = text.find(Self::EDITABLE_REGION_END).unwrap_or(text.len());
+        let end = text.rfind(Self::EDITABLE_REGION_END).unwrap_or(text.len());
 
         let region = &text[start..end];
         let region = region.strip_suffix('\n').unwrap_or(region);

crates/edit_prediction_cli/src/main.rs 🔗

@@ -364,8 +364,12 @@ async fn load_examples(
         }
     }
 
-    if let Some(path) = output_path {
-        resume_from_output(path, &mut examples);
+    // Skip resume logic for --in-place since input and output are the same file,
+    // which would incorrectly treat all input examples as already processed.
+    if !args.in_place {
+        if let Some(path) = output_path {
+            resume_from_output(path, &mut examples);
+        }
     }
 
     Progress::global().set_total_examples(examples.len());