From ae2befa7cb89335e99e03ed2f4064d3140a3c1be Mon Sep 17 00:00:00 2001 From: matheusPavaneli Date: Sun, 27 Sep 2026 00:54:51 -0300 Subject: [PATCH] feat: plan first when a ticket names code in a critical zone BN-4 cost 6.7x plain in the 9abd3c9 run. Its fix touched user data, so wb finish sent it to the standard route after the change was made, and both sessions then reverted a working fix to plan it from scratch. wb start now reads the identifiers the ticket spells (in backticks, snake_case or CamelCase, at most six), finds where each is defined at HEAD, and starts the ticket on the standard route when that file is in a critical zone, saying which name and which zone. When wb finish does move a ticket, it says to keep the change and plan around it, and plan-change says the same. Closing this ticket with wb finish took the standard route for a false reason: the billing zone matches the word plan in any path, so skills/plan-change/SKILL.md read as billing. WB-60 records it. --- .workflow/tasks/WB-58.json | 4 ++-- .workflow/tasks/WB-60.json | 16 +++++++++++++ lib/workbench/cli/finish.py | 5 ++-- lib/workbench/cli/start.py | 8 ++++--- lib/workbench/light.py | 46 +++++++++++++++++++++++++++++++++++-- skills/plan-change/SKILL.md | 3 +++ tests/test_light.py | 29 +++++++++++++++++++++++ 7 files changed, 102 insertions(+), 9 deletions(-) create mode 100644 .workflow/tasks/WB-60.json diff --git a/.workflow/tasks/WB-58.json b/.workflow/tasks/WB-58.json index 1146b40..905f7cb 100644 --- a/.workflow/tasks/WB-58.json +++ b/.workflow/tasks/WB-58.json @@ -2,10 +2,10 @@ "key": "WB-58", "title": "Critical-zone and misleading tickets still cost 3-7x a plain session", "type": "chore", - "status": "open", + "status": "done", "desc": "The clean bench run (bench/results/2026-09-27-9abd3c9) met WB-53's 2x target on BN-7 and on BN-3's wall time and cost, not elsewhere. BN-4 (bug in shop/users.py, user-data zone) cost 6.7x tokens: wb finish only learns the change is in a critical zone after it is made, sends it to the standard route, and the session discarded its working fix to re-plan it. BN-6 cost 2.8x, spent tracing the live code path that plain skipped.\n\nACCEPTANCE:\n- a ticket whose change lands in a critical zone keeps the change it already made when it moves to the standard route, and the plan starts from that diff instead of from scratch\n- wb start says up front when the ticket's likely files are in a critical zone, so the session plans first instead of finishing twice\n- the bench's BN-4 ratio is measured again and the README table updated", "created": "2026-09-27T03:04:45Z", - "updated": "2026-09-27T03:04:45Z", + "updated": "2026-09-27T03:48:20Z", "comments": [], "linked": [ { diff --git a/.workflow/tasks/WB-60.json b/.workflow/tasks/WB-60.json new file mode 100644 index 0000000..581de58 --- /dev/null +++ b/.workflow/tasks/WB-60.json @@ -0,0 +1,16 @@ +{ + "key": "WB-60", + "title": "The billing zone matches any path containing plan", + "type": "bug", + "status": "open", + "desc": "profile.CRITICAL_ZONES['billing'] is billing|payment|invoice|subscription|checkout|stripe|paddle|quota|plan, matched anywhere in a path. skills/plan-change/SKILL.md, planner.py or explanation.md read as billing and are held to the critical bar; wb finish sent WB-58 to the standard route for it.\n\nACCEPTANCE:\n- plan matches a pricing plan (plans/, plan_limits, subscription_plan) and not plan-change, planner or explanation\n- a test pins both sides; plans already audited with the old zones re-audit cleanly or say why", + "created": "2026-09-27T03:48:12Z", + "updated": "2026-09-27T03:48:12Z", + "comments": [], + "linked": [ + { + "key": "WB-58", + "type": "relates" + } + ] +} diff --git a/lib/workbench/cli/finish.py b/lib/workbench/cli/finish.py index 3ed3a56..620e7de 100644 --- a/lib/workbench/cli/finish.py +++ b/lib/workbench/cli/finish.py @@ -50,9 +50,10 @@ def run(args: argparse.Namespace) -> int: if result.outgrew: light.unmark(key, root) raise WbError( - f"{key} outgrew the light path: {result.outgrew}. It now takes the standard route; the change stays", + f"{key} outgrew the light path: {result.outgrew}. It now takes the standard route. " + "Keep the change on disk and do not revert it: the plan cites the code at HEAD, so plan around it", code=EXIT_AUDIT, - fix=[f"plan it: (plan-change) then wb sdd audit {key}"], + fix=[f"plan it: (plan-change) then wb sdd audit {key}, then wb impl verify {key} on the change already made"], ) if not result.ok: raise WbError(f"{key}: " + "; ".join(result.blocked), code=EXIT_AUDIT, fix=result.fix) diff --git a/lib/workbench/cli/start.py b/lib/workbench/cli/start.py index 07cf6d3..7ba1e27 100644 --- a/lib/workbench/cli/start.py +++ b/lib/workbench/cli/start.py @@ -59,7 +59,7 @@ def run(args: argparse.Namespace) -> int: print("triage already read (--refresh to read it again)") print(f"branch {where}") - _choose_path(key, kind, root) + _choose_path(key, kind, root, f"{title}\n{triage.get('desc') or ''}") tier, reason, steps = route_cli.compute(key, root) print(f"route {tier}: {', '.join(name for name, _, _ in steps)} ({reason})") if light.marker(key, root) is not None: @@ -73,7 +73,7 @@ def run(args: argparse.Namespace) -> int: return 0 -def _choose_path(key: str, kind: str, root: Path) -> None: +def _choose_path(key: str, kind: str, root: Path, text: str = "") -> None: """Put eligible work on the light path, once, before anything is planned. A ticket that already has a plan keeps it: the path is chosen at the start, @@ -86,9 +86,11 @@ def _choose_path(key: str, kind: str, root: Path) -> None: if not light.enabled(root): light.unmark(key, root) return - allowed, _ = light.eligible(key, kind, root) + allowed, reason = light.eligible(key, kind, root, text) if allowed: light.mark(key, root) + elif "zone" in reason: + print(f"light no: {reason}") def _triage(key: str, root: Path, *, refresh: bool) -> tuple[dict, bool]: diff --git a/lib/workbench/light.py b/lib/workbench/light.py index ad950b8..bdc44a8 100644 --- a/lib/workbench/light.py +++ b/lib/workbench/light.py @@ -31,6 +31,7 @@ from __future__ import annotations import json +import re import shlex from dataclasses import dataclass, field from pathlib import Path @@ -64,8 +65,14 @@ def enabled(root: Path) -> bool: return profile.repo_config(root).get(CONFIG_KEY) is not False -def eligible(key: str, kind: str, root: Path) -> tuple[bool, str]: - """Whether a ticket may start on the light path, and why (not).""" +def eligible(key: str, kind: str, root: Path, text: str = "") -> tuple[bool, str]: + """Whether a ticket may start on the light path, and why (not). + + ``text`` is the ticket's own words. A function it names that is defined in + a critical zone sends it to the standard route before any change is made: + found out at wb finish instead, the zone cost a finished fix and a second + pass (WB-58). + """ if not enabled(root): return False, f'"{CONFIG_KEY}": false in .workflow/config.json' if key.startswith(("incident-", "idea-")): @@ -75,9 +82,44 @@ def eligible(key: str, kind: str, root: Path) -> tuple[bool, str]: return False, f"{lowered} work owes a product frame" if lowered in AUDIENCE: return False, f"{lowered} work has a reader outside engineering" + zoned = zone_named(text, root) if text else None + if zoned: + name, path, zone = zoned + return False, f"the ticket names {name}, defined in {path}, which is in the {zone} zone: plan it first" return True, "no plan up front; wb finish holds the change to the floor" +# Names worth looking up: in backticks, snake_case or CamelCase. A plain word +# ("total", "name") would match half the repo and predict nothing. +_NAMED = re.compile( + r"`([A-Za-z_][A-Za-z0-9_]*)(?:\(\))?`|\b([a-z][a-z0-9]*_[a-z0-9_]+)\b|\b([A-Z][a-z0-9]+[A-Z][A-Za-z0-9]*)\b" +) +MAX_NAMES = 6 +DEFINERS = ("def {name}(", "class {name}", "function {name}(") + + +def names(text: str) -> list[str]: + """Identifiers the ticket names, first mention first, at most MAX_NAMES.""" + found: list[str] = [] + for match in _NAMED.finditer(text): + name = next(group for group in match.groups() if group) + if name not in found: + found.append(name) + return found[:MAX_NAMES] + + +def zone_named(text: str, root: Path) -> tuple[str, str, str] | None: + """(name, file, zone) for the first name the ticket gives that is defined in a critical zone.""" + for name in names(text): + for definer in DEFINERS: + files = gitctx.grep_files(root, "HEAD", definer.format(name=name), []) or [] + zones = profile.critical_zones(files) + if zones: + zone = sorted(zones)[0] + return name, zones[zone][0], zone + return None + + def marker(key: str, root: Path) -> dict | None: """The light record for ``key``, or ``None`` when it is not on this path.""" path = artifacts.ticket_dir(key, root) / MARKER diff --git a/skills/plan-change/SKILL.md b/skills/plan-change/SKILL.md index 0548e43..3b889c7 100644 --- a/skills/plan-change/SKILL.md +++ b/skills/plan-change/SKILL.md @@ -26,6 +26,9 @@ python "${CLAUDE_PLUGIN_ROOT}/lib/wb.py" 3. **Pick a persona** from `references/personas.md`. It shapes what counts as done, not the format. + A change already on disk (a light-path ticket `finish` moved here) stays: + plan around it, never revert it to plan from scratch. + 4. **Confirm everything in the code.** Assume nothing. Every claim about this codebase needs a `file:line` and the text of that line, because the audit in step 7 reopens each one. A claim you cannot cite is a question, not a fact — diff --git a/tests/test_light.py b/tests/test_light.py index f68dfb1..8223f74 100644 --- a/tests/test_light.py +++ b/tests/test_light.py @@ -153,6 +153,7 @@ def test_a_change_past_the_bound_leaves_the_path_for_a_plan(self) -> None: self.assertEqual(EXIT_AUDIT, code) self.assertIn("outgrew the light path", err) self.assertIn("plan-change", err) + self.assertIn("do not revert it", err) self.assertIsNone(light.marker("ABC-1", self.root)) _, nxt, _ = run("next", "ABC-1") self.assertIn("plan", nxt) @@ -238,6 +239,34 @@ def test_a_bug_s_regression_test_is_proven(self) -> None: self.assertIn("1 regression test(s) proven", out) +class ZoneNamed(LightPath): + """WB-58: a ticket naming a function in a critical zone plans first, instead of finishing twice.""" + + KIND = "bug" + + def test_a_named_function_in_a_critical_zone_starts_on_the_standard_route(self) -> None: + self.write("shop/billing/__init__.py", "") + self.write("shop/billing/charge.py", "def charge_card(total):" + chr(10) + " return total" + chr(10)) + self.git("add", "-A") + self.git("commit", "-q", "-m", "chore: billing") + code, out, err = run("task", "new", "Cards are charged twice", "--type", "bug", + "--desc", "charge_card runs twice on a retry.", "--key", "ABC-2") + self.assertEqual(0, code, out + err) + code, out, err = run("start", "ABC-2") + self.assertEqual(0, code, out + err) + self.assertIsNone(light.marker("ABC-2", self.root)) + self.assertIn("names charge_card, defined in shop/billing/charge.py, which is in the billing zone", out) + self.assertIn("standard", out) + + def test_a_named_function_outside_every_zone_keeps_the_light_path(self) -> None: + run("start", "ABC-1") + self.assertIsNotNone(light.marker("ABC-1", self.root), "format_money lives in shop/money.py, no zone") + + def test_names_are_the_identifiers_a_ticket_spells_not_its_plain_words(self) -> None: + text = "display_name keeps stray whitespace; `in_stock` and ChargeError, the total and the name." + self.assertEqual(["display_name", "in_stock", "ChargeError"], light.names(text)) + + class Feature(LightPath): KIND = "feature"