fix(spreadsheetbench)+optimizer: fix verify-feedback bloat, drop optimizer-side truncation, soft-disable gate

A. SpreadsheetBench verification-feedback bloat
   - rollout.py _auto_verify_output: use official _compare_cell_value (was
     repr() equality, which falsely flagged 5 vs 5.0 / None vs ""); collapse
     correct-and-empty cells into a count so large sparse answer ranges no
     longer flood feedback with MBs of None=None noise.
   - codegen_agent.py _build_eval_feedback: only list WRONG cells, collapse
     correct ones into a count.
   Scoring is unaffected (evaluate() is independent); this only fixes the
   target model's multi-turn solving feedback.

B. Remove optimizer-side truncation (bloat source now fixed)
   - reflect.py: drop _MAX_TRAJ_CHARS cap and all per-field clips.
   - update_modes.py / clip.py / lr_autonomous.py: describe_item /
     short_item_summary no longer truncate; raise ranking/lr token budget.
   - trainer.py _format_step_buffer: full task_ids / target.
   - slow_update.py: full comparison samples.

C. Soft-disable gate
   - config.py / trainer.py: use_gate=false no longer raises; validation still
     runs but candidates are force-accepted (new force_accept branch + log).

Misc: aggregate.py merge token budget 4096 -> 16384.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Cuzyoung
2026-06-01 11:23:08 +00:00
parent f64a41397c
commit 372fd56c1e
10 changed files with 138 additions and 94 deletions
+2 -2
View File
@@ -46,7 +46,7 @@ def _merge_batch(
response, _ = chat_optimizer(
system=system_prompt,
user=user,
max_completion_tokens=64000 if is_full_rewrite_minibatch_mode(update_mode) else 4096,
max_completion_tokens=64000 if is_full_rewrite_minibatch_mode(update_mode) else 16384,
retries=3,
stage="merge",
)
@@ -231,7 +231,7 @@ def merge_patches(
response, _ = chat_optimizer(
system=merge_final_prompt,
user=user,
max_completion_tokens=64000 if is_full_rewrite_minibatch_mode(update_mode) else 4096,
max_completion_tokens=64000 if is_full_rewrite_minibatch_mode(update_mode) else 16384,
retries=3,
stage="merge",
)
+22 -25
View File
@@ -43,19 +43,21 @@ from skillopt.utils import extract_json
# ── Trajectory formatting ────────────────────────────────────────────────────
_MAX_TRAJ_CHARS = 12_000
def _clip_text(value, limit: int | None = None) -> str:
"""Render optional trajectory fields. Truncation is disabled: the optimizer
is given the full content so it can see exactly what the agent saw/did.
def _clip_text(value, limit: int) -> str:
"""Render optional trajectory fields safely before truncation."""
``limit`` is accepted for backward compatibility but ignored.
"""
if value is None:
return ""
return str(value)[:limit]
return str(value)
def fmt_trajectory(
conversation: list[dict],
max_chars: int = _MAX_TRAJ_CHARS,
max_chars: int | None = None,
) -> str:
"""Format a conversation list into analyst-readable text.
@@ -69,37 +71,32 @@ def fmt_trajectory(
lines: list[str] = []
for item in conversation:
if not isinstance(item, dict):
lines.append(f"[agent] {_clip_text(item, 500)}")
lines.append(f"[agent] {_clip_text(item)}")
continue
if item.get("type") == "tool_call":
cmd = _clip_text(item.get("cmd"), 500)
obs = _clip_text(item.get("obs"), 800)
cmd = _clip_text(item.get("cmd"))
obs = _clip_text(item.get("obs"))
lines.append(f"[action] {cmd}")
lines.append(f"[obs] {obs}")
elif "action" in item and "env_feedback" in item:
step = item.get("step", "?")
reasoning = _clip_text(item.get("reasoning"), 300)
action = _clip_text(item.get("action"), 200)
feedback = _clip_text(item.get("env_feedback"), 500)
reasoning = _clip_text(item.get("reasoning"))
action = _clip_text(item.get("action"))
feedback = _clip_text(item.get("env_feedback"))
if reasoning:
lines.append(f"[step {step} think] {reasoning}")
lines.append(f"[step {step} action] {action}")
lines.append(f"[step {step} obs] {feedback}")
elif item.get("role") == "system":
# Post-execution verification / enrichment info
msg = _clip_text(item.get("content"), 2000)
msg = _clip_text(item.get("content"))
lines.append(f"[verification] {msg}")
else:
msg = _clip_text(item.get("content"), 500)
msg = _clip_text(item.get("content"))
role = item.get("role", "agent")
lines.append(f"[{role}] {msg}")
text = "\n".join(lines)
if len(text) > max_chars:
head = text[: max_chars // 2]
tail = text[-max_chars // 2 :]
text = head + "\n...[middle truncated]...\n" + tail
return text
return "\n".join(lines)
# ── Minibatch trajectory formatting ──────────────────────────────────────────
@@ -157,7 +154,7 @@ def fmt_minibatch_trajectories(
if reference_text:
header += (
f"\n#### Hidden Reference\n"
f"{reference_text[:4000]}\n"
f"{reference_text}\n"
)
# ── Append target context (what the agent saw) ──────────────
@@ -170,7 +167,7 @@ def fmt_minibatch_trajectories(
if target_prompt:
header += (
f"\n#### Target System Prompt\n"
f"{target_prompt[:3000]}\n"
f"{target_prompt}\n"
)
user_prompt = item.get("target_user_prompt", "")
@@ -182,7 +179,7 @@ def fmt_minibatch_trajectories(
if user_prompt:
header += (
f"\n#### Target User Prompt\n"
f"{user_prompt[:3000]}\n"
f"{user_prompt}\n"
)
if os.environ.get("REFLACT_CODEX_TRACE_TO_OPTIMIZER", "0") == "1":
@@ -214,7 +211,7 @@ def fmt_minibatch_trajectories(
if preview:
header += (
f"\n#### Spreadsheet Preview\n"
f"{preview[:3000]}\n"
f"{preview}\n"
)
parts.append(header + "\n" + traj_text)
@@ -323,7 +320,7 @@ def run_error_analyst_minibatch(
try:
response, _ = chat_optimizer(
system=actual_system, user=user,
max_completion_tokens=64000 if is_full_rewrite_minibatch_mode(mode) else 4096,
max_completion_tokens=64000 if is_full_rewrite_minibatch_mode(mode) else 16384,
retries=3,
stage="analyst",
)
@@ -398,7 +395,7 @@ def run_success_analyst_minibatch(
try:
response, _ = chat_optimizer(
system=actual_system, user=user,
max_completion_tokens=64000 if is_full_rewrite_minibatch_mode(mode) else 4096,
max_completion_tokens=64000 if is_full_rewrite_minibatch_mode(mode) else 16384,
retries=3,
stage="analyst",
)