Skip to content

The agent that grows with you

fix(onboarding): a refused build pick names every too-long label with its length

alt-glitchb3aa3b4ef9b1
diff --git a/agent/onboarding_first_tasks.py b/agent/onboarding_first_tasks.py
index 214949b9389..16e4901bedd 100644
--- a/agent/onboarding_first_tasks.py
+++ b/agent/onboarding_first_tasks.py
@@ -266,27 +266,32 @@ def _option_error(option: Any, eligible: set[str], seen: set[str]) -> str | None
if option["id"] in seen:
return f"{option['id']!r} is picked twice"
label = option.get("label")
- if not isinstance(label, str) or not label.strip() or len(label) > MAX_LABEL:
- return f"the label for {option['id']} must be 1 to {MAX_LABEL} characters"
+ if not isinstance(label, str) or not label.strip():
+ return f"the label for {option['id']} is empty"
+ if len(label) > MAX_LABEL:
+ return f'"{label}" is {len(label)} characters; the limit is {MAX_LABEL}. Shorten it'
return None
def pick_error(options: Any, facts: Facts, picks: Mapping[str, Any]) -> str | None:
"""Why the model's build picks are refused, naming the eligible ids; None when they are valid."""
eligible = [task.id for task in eligible_tasks(facts, picks)]
- problem = None
+ problems: list[str] = []
if not isinstance(options, list) or not options:
- problem = "options is required"
+ problems.append("options is required")
elif len(options) > MAX_PICKS:
- problem = f"pick at most {MAX_PICKS}"
+ problems.append(f"pick at most {MAX_PICKS}")
else:
+ # Every bad option is named at once, so one retry can fix them all.
seen: set[str] = set()
for option in options:
if problem := _option_error(option, set(eligible), seen):
- break
- seen.add(option["id"])
- if problem is None:
+ problems.append(problem)
+ elif isinstance(option, Mapping):
+ seen.add(option["id"])
+ if not problems:
return None
+ problem = "; ".join(problems)
return (f'{problem}. Call setup_beat(beat="build", options=[{{"id": ..., "label": ...}}]) with up to '
f"{MAX_PICKS} of these ids: {', '.join(eligible)}.")
diff --git a/tests/agent/test_onboarding_first_tasks.py b/tests/agent/test_onboarding_first_tasks.py
index 064186fdc31..65475cc0baa 100644
--- a/tests/agent/test_onboarding_first_tasks.py
+++ b/tests/agent/test_onboarding_first_tasks.py
@@ -4,7 +4,7 @@ from __future__ import annotations
import pytest
-from agent.onboarding_first_tasks import FIRST_TASKS, eligible_tasks
+from agent.onboarding_first_tasks import FIRST_TASKS, eligible_tasks, pick_error
from agent.onboarding_flow import Facts, new_record
from agent.onboarding_text import reminder
@@ -90,3 +90,11 @@ def test_the_app_tasks_carry_the_connectors_playbook_and_the_menu_lists_only_eli
assert "connectors__" not in reminder("build_site", new_record(PC), PC)
menu = reminder("tour_skip", new_record(MAC), MAC)
assert "- mac (Set up my Mac helpers)" in menu and "keep its energy" in menu and "- brief" not in menu and "- hermes" not in menu
+
+
+def test_every_too_long_label_is_named_with_its_length_in_one_refusal():
+ long_a, long_b = "Today's brief from Linear and Slack", "My whole week laid out on one page"
+ error = pick_error([{"id": "brief", "label": long_a}, {"id": "week", "label": long_b},
+ {"id": "repo", "label": "Map one of my repos"}], MAC, {"connected": ["slack"]})
+ assert f'"{long_a}" is {len(long_a)} characters; the limit is 32' in error
+ assert f'"{long_b}" is {len(long_b)} characters' in error