Skip to content

Commit f48f17a

Browse files
cdeustclaude
andcommitted
fix(scripts): undo only the ADR-0200 promotion, keep every other global row
Review finding on #613: classify() cleared is_global on any resolved row the detector did not confirm, so a row made global by an explicit act was lost. A row now loses global scope only when it carries the defect signature, a decision written under an agent context. Other global rows are kept, listed under unexplained_global_ids, and the owner can clear one by id through clear_global_ids. An id cannot be both kept and cleared. Rerun on a fresh restore of the same archive: 93 changes, 0 on the second pass, 67 globals retained (46 unresolved, 6 left to the owner), row count unchanged. The validation record carries the new figures and no longer mentions unrelated private plans. Refs #611 Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NLvPnrr8Ab6cKPK1Kt3K7f Signed-off-by: cdeust <[email protected]>
1 parent b78d993 commit f48f17a

3 files changed

Lines changed: 91 additions & 12 deletions

File tree

‎docs/validation/issue-611-team-scope.md‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,37 @@ as requested by the reclassification plan.
103103
6. Run both acceptance hooks from the updated installed plugin. Require
104104
4353879 absent in anthropic-partnership and present in japonais-2027, and
105105
no japonais-2027 row in the parent's Team Decisions block. Do not claim
106-
the issue fixed in a release or publish the LinkedIn draft before this.
106+
the issue fixed in a release before this.
107+
108+
## Rerun after review (2026-09-17)
109+
110+
The review of #613 found that `classify()` cleared `is_global` on any resolved
111+
row the detector did not confirm, including rows the ADR-0200 promotion could
112+
not have produced (no agent context, or no decision content). Those rows were
113+
made global by an explicit act the script cannot see. The rule is now narrower:
114+
only a decision written under an agent context loses global scope. Every other
115+
global row is kept and listed under `unexplained_global_ids`, and the owner can
116+
clear one through `clear_global_ids` in the mappings file.
117+
118+
The figures above predate that change. The same archive was restored into a
119+
fresh database and the whole sequence repeated with the approved mapping of
120+
4353879 supplied from the first pass:
121+
122+
| Measurement | Result |
123+
| --- | --- |
124+
| Global candidates | 160 |
125+
| Dry-run changes | 93 |
126+
| Applied changes | 93 |
127+
| Changes proposed on the second run | 0 |
128+
| Retained globals | 67 |
129+
| of which unresolved project | 46 |
130+
| of which kept as not produced by the defect | 6 |
131+
| Non-benchmark rows before and after | 47,041 |
132+
133+
The six kept rows are 4349818, 4353551, 4353795, 4353809, 4353915 and 4361406.
134+
Each has an agent context and content the decision cue does not match, so the
135+
script leaves the call to the owner. The apply step refused to run until the
136+
`is_team_decision` column existed on the restored copy, as designed.
107137

108138
## Python compatibility
109139

@@ -127,5 +157,4 @@ uses its concrete class as a postponed return annotation, with no new dependency
127157
| Transaction rollback and marker refusal | real PostgreSQL and SQLite script tests |
128158
| Missing/invalid backup, missing table data, full decode | script backup validation tests and full archive restore |
129159

130-
No merge, release, production reclassification, LinkedIn publication, or
131-
message to Denis is performed by this change. Task B is a separate session.
160+
No merge, release or production reclassification is performed by this change.

‎scripts/reclassify_team_scope.py‎

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class ScopeMappings:
4444
domains: dict[str, str]
4545
memories: dict[str, str]
4646
keep_global_ids: frozenset[int]
47+
clear_global_ids: frozenset[int] = frozenset()
4748

4849

4950
def load_mappings(path: Path | None) -> ScopeMappings:
@@ -52,8 +53,11 @@ def load_mappings(path: Path | None) -> ScopeMappings:
5253
"domains",
5354
"memories",
5455
"keep_global_ids",
56+
"clear_global_ids",
5557
}:
56-
raise ValueError("mappings require domains, memories and/or keep_global_ids")
58+
raise ValueError(
59+
"mappings accept domains, memories, keep_global_ids, clear_global_ids"
60+
)
5761
domains, memories = data.get("domains", {}), data.get("memories", {})
5862
for mapping in (domains, memories):
5963
if not isinstance(mapping, dict):
@@ -70,10 +74,15 @@ def load_mappings(path: Path | None) -> ScopeMappings:
7074
raise ValueError(f"project directory must be canonical: {directory}")
7175
if any(not key.isdecimal() for key in memories):
7276
raise ValueError("memory mapping keys must be decimal IDs")
73-
keep = data.get("keep_global_ids", [])
74-
if not isinstance(keep, list) or any(type(item) is not int for item in keep):
75-
raise ValueError("keep_global_ids must be a list of integers")
76-
return ScopeMappings(domains, memories, frozenset(keep))
77+
id_lists = []
78+
for key in ("keep_global_ids", "clear_global_ids"):
79+
ids = data.get(key, [])
80+
if not isinstance(ids, list) or any(type(item) is not int for item in ids):
81+
raise ValueError(f"{key} must be a list of integers")
82+
id_lists.append(frozenset(ids))
83+
if id_lists[0] & id_lists[1]:
84+
raise ValueError("an id cannot be both kept and cleared")
85+
return ScopeMappings(domains, memories, id_lists[0], id_lists[1])
7786

7887

7988
def classify(row: ScopeRow, mappings: ScopeMappings) -> ScopeChange:
@@ -90,10 +99,16 @@ def classify(row: ScopeRow, mappings: ScopeMappings) -> ScopeChange:
9099
row.id, "", row.is_global, row.is_team_decision, "unresolved_project"
91100
)
92101
detected, _, _ = detect_global(row.content, row.tags)
93-
global_scope = row.id in mappings.keep_global_ids or detected
94-
team = row.is_team_decision or (
95-
bool(row.agent_context) and is_decision_content(row.content)
96-
)
102+
# Only the ADR-0200 promotion is undone: a decision written under an agent
103+
# context. Any other global row was made global by an explicit act this
104+
# script cannot see, so it stays global. source: ADR-1083
105+
promoted = bool(row.agent_context) and is_decision_content(row.content)
106+
kept = row.id in mappings.keep_global_ids or detected
107+
cleared = row.id in mappings.clear_global_ids # the owner's explicit call
108+
global_scope = kept or (row.is_global and not promoted and not cleared)
109+
team = row.is_team_decision or promoted
110+
if global_scope and not kept:
111+
reason = "global_origin_not_the_defect"
97112
return ScopeChange(row.id, directory, global_scope, team, reason)
98113

99114

@@ -120,6 +135,11 @@ def make_report(rows: list[ScopeRow], mappings: ScopeMappings) -> dict:
120135
change.id for change in changes if change.reason == "unresolved_project"
121136
],
122137
"retained_global_ids": [change.id for change in changes if change.is_global],
138+
"unexplained_global_ids": [
139+
change.id
140+
for change in changes
141+
if change.reason == "global_origin_not_the_defect"
142+
],
123143
"changes": [asdict(change) for change in updates],
124144
}
125145

‎tests_py/scripts/test_reclassify_team_scope.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,36 @@ def test_nondecision_and_existing_marker(row, mappings):
8080
assert not classify(replace(row, agent_context=""), mappings).is_team_decision
8181

8282

83+
def test_a_global_row_the_defect_could_not_have_produced_stays_global(row, mappings):
84+
"""ADR-0200 promoted decisions written under an agent context. A global
85+
row with no agent context, or with non-decision content, was made global
86+
by an explicit act: clearing it would lose the owner's intent (#611)."""
87+
explicit = replace(
88+
row, content="The parser uses XML.", agent_context="", is_global=True
89+
)
90+
kept = classify(explicit, mappings)
91+
assert kept.is_global
92+
assert kept.reason == "global_origin_not_the_defect"
93+
no_agent = classify(replace(row, agent_context="", is_global=True), mappings)
94+
assert no_agent.is_global
95+
promoted = classify(replace(row, is_global=True), mappings)
96+
assert not promoted.is_global
97+
assert promoted.is_team_decision
98+
99+
100+
def test_the_owner_can_clear_a_global_the_script_would_keep(row):
101+
explicit = replace(row, content="The parser uses XML.", is_global=True)
102+
owner = ScopeMappings({}, {}, frozenset(), frozenset({1}))
103+
assert not classify(explicit, owner).is_global
104+
105+
106+
def test_an_id_cannot_be_both_kept_and_cleared(tmp_path):
107+
file = tmp_path / "mappings.json"
108+
file.write_text(json.dumps({"keep_global_ids": [7], "clear_global_ids": [7]}))
109+
with pytest.raises(ValueError, match="both kept and cleared"):
110+
load_mappings(file)
111+
112+
83113
def test_mapping_validation(tmp_path):
84114
file = tmp_path / "mappings.json"
85115
file.write_text(

0 commit comments

Comments
 (0)