Cap remote verified repair turns

ober

636b95b89e18264e79aa41270467cc4af793fbe4

diff --git a/src/jcode/core/verified-run.ss b/src/jcode/core/verified-run.ss
index f0a3a0b..aef1187 100644
--- a/src/jcode/core/verified-run.ss
+++ b/src/jcode/core/verified-run.ss
@@ -43,6 +43,7 @@
 (def default-local-verified-history-keep-batches 2)
 (def default-local-verified-max-completion-tokens 8192)
 (def default-local-verified-repair-max-completion-tokens 4096)
+(def default-verified-repair-max-completion-tokens 8192)
 
 (def (opt-get o key) (let ((p (assoc key o))) (and p (cdr p))))
 
@@ -434,17 +435,22 @@
                    (make-provider-backend
                      provider chat-with-expert-via-stream))))
     (lambda (messages tool-specs step)
+      (let ((repair-turn?
+              (or (current-after-failed-verify?)
+                  (and (current-rejected-ss-draft)
+                       (> (current-rejected-draft-inspections) 0))
+                  (> (current-successful-edit-count) 0))))
       (parameterize
         ((current-defer-truncated-escalation
            (current-verified-local-model?))
          (current-max-tokens-cap
-           (if (and (current-verified-local-model?)
-                    (or (current-after-failed-verify?)
-                        (and (current-rejected-ss-draft)
-                             (> (current-rejected-draft-inspections) 0))
-                        (> (current-successful-edit-count) 0)))
-             default-local-verified-repair-max-completion-tokens
-             (current-max-tokens-cap))))
+           (cond
+             ((and (current-verified-local-model?) repair-turn?)
+              default-local-verified-repair-max-completion-tokens)
+             (repair-turn?
+              default-verified-repair-max-completion-tokens)
+             (else
+              (current-max-tokens-cap)))))
         (if (procedure? provider)
           (let* ((specs (verified-provider-tool-specs tool-specs))
                  (forced-choice (and (not (current-verified-local-model?))
@@ -483,7 +489,7 @@
 	                    (backend messages
 	                             (forced-first-edit-specs specs forced-choice)
 	                             #f)
-	                    forced-choice))))))))))
+	                    forced-choice)))))))))))
 
 ;; ── verify oracle ──────────────────────────────────────────────────────
 (def (tail-lines s n)
diff --git a/test/run.ss b/test/run.ss
index e26713a..0f32e40 100644
--- a/test/run.ss
+++ b/test/run.ss
@@ -3805,6 +3805,42 @@
 	  (safe-delete-test-file! target-path))
 
 	(let* ([vr-dir "/tmp"]
+	       [target "jcode-remote-repair-cap.txt"]
+	       [target-path (string-append vr-dir "/" target)]
+	       [calls 0]
+	       [caps '()]
+	       [responder
+	         (lambda (_messages _tools _step)
+	           (set! calls (+ calls 1))
+	           (set! caps (cons (current-max-tokens-cap) caps))
+	           (case calls
+	             [(1) (list (make-wtool-call "verify" '() #f))]
+	             [(2) (list (make-wtool-call "edit"
+	                         (list (cons "path" target)
+	                               (cons "content" "remote repaired\n")) #f))]
+	             [(3) (list (make-wtool-call "verify" '() #f))]
+	             [(4) (list (make-wtool-call "done"
+	                          '(("summary" . "remote-repair-cap-ok"))
+	                          #f))]
+	             [else (error 'test "unexpected remote repair cap provider call")]))])
+	  (safe-delete-test-file! target-path)
+	  (let ([result
+	          (verified-run responder "repair with a smaller remote completion cap"
+	            (list
+	              (cons 'cwd vr-dir)
+	              (cons 'verify-command (string-append "grep -q 'remote repaired' " target))
+	              (cons 'write-scope (parse-write-scope target))
+	              (cons 'max-iterations 8)))])
+	    (check! "verified-run: remote repair cap still verifies"
+	            result "VERIFIED: exit 0\n"))
+	  (let ([observed (reverse caps)])
+	    (check! "verified-run: remote first-draft completion cap is unchanged"
+	            (car observed) #f)
+	    (check! "verified-run: remote post-verifier repair cap is 8k"
+	            (cadr observed) 8192))
+	  (safe-delete-test-file! target-path))
+
+	(let* ([vr-dir "/tmp"]
 	       [target "jcode-remote-auto-verify.txt"]
 	       [target-path (string-append vr-dir "/" target)]
 	       [calls 0]