Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
381 changes: 381 additions & 0 deletions data/auto_parse/level_freeze/frozen/idx_14.jsonl

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion data/auto_parse/level_freeze/state.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
10,
11,
12,
13
13,
14
],
"history": [
{
Expand Down Expand Up @@ -219,6 +220,12 @@
"action": "freeze",
"idx": 13,
"n_records": 47
},
{
"ts": "2026-05-17T09:31:29",
"action": "freeze",
"idx": 14,
"n_records": 381
}
]
}
21 changes: 21 additions & 0 deletions scripts/parse_doc2dict_with_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,27 @@ def _apply_scope_rule(rows: list[dict[str, Any]]) -> list[dict[str, Any]]:
first_child_title = children[0]["title"] if children else None
if _is_real_subdoc_title(r.get("title"), r.get("cls"), r.get("is_envelope", False), first_child_title):
real_subdoc_ids.add(r["node_id"])
else:
# Secondary-agreement carrier: a node whose own subdoc_penalty
# is 0 but whose direct children carry subdoc_penalty>=1.
# The depth-walker sets this when a non-subdoc-class section has
# a title matching the AGREEMENT|PLAN structural-level-0 pattern
# and the primary L0 has already been emitted (see walk_sections'
# is_secondary_agreement branch). Structurally this IS an
# attached subdocument (it has its own subtree with its own
# depth penalty) even though doc2dict didn't tag its cls as
# exhibit/schedule/appendix/annex. Treat it as a real subdoc
# for scope purposes so the post-sig walk-up doesn't strand it
# in trailer (and bring genuine attached subdoc content with
# it). The check is purely structural: subdoc_penalty arithmetic
# comes from the tree walk, not phrase matching.
if (
not r.get("is_envelope")
and (r.get("subdoc_penalty", 0) or 0) == 0
and children
and any((c.get("subdoc_penalty", 0) or 0) > 0 for c in children)
):
Comment on lines +603 to +608

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current logic for identifying secondary-agreement carriers is too broad and contradicts the documented scope rule in task_rules/scope_rule.md.

According to the scope rule, bare identifiers (e.g., "EXHIBIT A" with no descriptive text) are NOT real subdocuments and should be excluded from the JSONL if they appear after the signature block. However, because walk_sections increments the subdoc_penalty for any node with a subdoc class (line 954), a bare exhibit will satisfy the condition (penalty == 0 and children penalty > 0). This causes bare exhibits to be added to real_subdoc_ids, protecting them and their descendants from being marked as trailer scope.

To align with the intent of recovering only secondary agreements (as noted in your comment on lines 590-602), you should ensure the node does not belong to a subdoc class.

Suggested change
if (
not r.get("is_envelope")
and (r.get("subdoc_penalty", 0) or 0) == 0
and children
and any((c.get("subdoc_penalty", 0) or 0) > 0 for c in children)
):
if (
not r.get("is_envelope")
and r.get("cls") not in _SUBDOC_CLASSES
and (r.get("subdoc_penalty", 0) or 0) == 0
and children
and any((c.get("subdoc_penalty", 0) or 0) > 0 for c in children)
):
References
  1. A section is out of scope if it appears after the signature block and is not a descendant of a real subdocument. Real subdocuments must have descriptive text beyond a bare identifier.

real_subdoc_ids.add(r["node_id"])
Comment on lines +589 to +609

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial | 💤 Low value

Consider using elif to reduce indentation.

The static analysis tool correctly identifies that the else: if pattern can be simplified to elif. This improves readability without changing behavior.

♻️ Suggested refactor
-        else:
-            # Secondary-agreement carrier: a node whose own subdoc_penalty
-            # is 0 but whose direct children carry subdoc_penalty>=1.
-            # The depth-walker sets this when a non-subdoc-class section has
-            # a title matching the AGREEMENT|PLAN structural-level-0 pattern
-            # and the primary L0 has already been emitted (see walk_sections'
-            # is_secondary_agreement branch). Structurally this IS an
-            # attached subdocument (it has its own subtree with its own
-            # depth penalty) even though doc2dict didn't tag its cls as
-            # exhibit/schedule/appendix/annex. Treat it as a real subdoc
-            # for scope purposes so the post-sig walk-up doesn't strand it
-            # in trailer (and bring genuine attached subdoc content with
-            # it). The check is purely structural: subdoc_penalty arithmetic
-            # comes from the tree walk, not phrase matching.
-            if (
-                not r.get("is_envelope")
-                and (r.get("subdoc_penalty", 0) or 0) == 0
-                and children
-                and any((c.get("subdoc_penalty", 0) or 0) > 0 for c in children)
-            ):
-                real_subdoc_ids.add(r["node_id"])
+        # Secondary-agreement carrier: a node whose own subdoc_penalty
+        # is 0 but whose direct children carry subdoc_penalty>=1.
+        # The depth-walker sets this when a non-subdoc-class section has
+        # a title matching the AGREEMENT|PLAN structural-level-0 pattern
+        # and the primary L0 has already been emitted (see walk_sections'
+        # is_secondary_agreement branch). Structurally this IS an
+        # attached subdocument (it has its own subtree with its own
+        # depth penalty) even though doc2dict didn't tag its cls as
+        # exhibit/schedule/appendix/annex. Treat it as a real subdoc
+        # for scope purposes so the post-sig walk-up doesn't strand it
+        # in trailer (and bring genuine attached subdoc content with
+        # it). The check is purely structural: subdoc_penalty arithmetic
+        # comes from the tree walk, not phrase matching.
+        elif (
+            not r.get("is_envelope")
+            and (r.get("subdoc_penalty", 0) or 0) == 0
+            and children
+            and any((c.get("subdoc_penalty", 0) or 0) > 0 for c in children)
+        ):
+            real_subdoc_ids.add(r["node_id"])
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
else:
# Secondary-agreement carrier: a node whose own subdoc_penalty
# is 0 but whose direct children carry subdoc_penalty>=1.
# The depth-walker sets this when a non-subdoc-class section has
# a title matching the AGREEMENT|PLAN structural-level-0 pattern
# and the primary L0 has already been emitted (see walk_sections'
# is_secondary_agreement branch). Structurally this IS an
# attached subdocument (it has its own subtree with its own
# depth penalty) even though doc2dict didn't tag its cls as
# exhibit/schedule/appendix/annex. Treat it as a real subdoc
# for scope purposes so the post-sig walk-up doesn't strand it
# in trailer (and bring genuine attached subdoc content with
# it). The check is purely structural: subdoc_penalty arithmetic
# comes from the tree walk, not phrase matching.
if (
not r.get("is_envelope")
and (r.get("subdoc_penalty", 0) or 0) == 0
and children
and any((c.get("subdoc_penalty", 0) or 0) > 0 for c in children)
):
real_subdoc_ids.add(r["node_id"])
# Secondary-agreement carrier: a node whose own subdoc_penalty
# is 0 but whose direct children carry subdoc_penalty>=1.
# The depth-walker sets this when a non-subdoc-class section has
# a title matching the AGREEMENT|PLAN structural-level-0 pattern
# and the primary L0 has already been emitted (see walk_sections'
# is_secondary_agreement branch). Structurally this IS an
# attached subdocument (it has its own subtree with its own
# depth penalty) even though doc2dict didn't tag its cls as
# exhibit/schedule/appendix/annex. Treat it as a real subdoc
# for scope purposes so the post-sig walk-up doesn't strand it
# in trailer (and bring genuine attached subdoc content with
# it). The check is purely structural: subdoc_penalty arithmetic
# comes from the tree walk, not phrase matching.
elif (
not r.get("is_envelope")
and (r.get("subdoc_penalty", 0) or 0) == 0
and children
and any((c.get("subdoc_penalty", 0) or 0) > 0 for c in children)
):
real_subdoc_ids.add(r["node_id"])
🧰 Tools
🪛 Ruff (0.15.12)

[warning] 589-603: Use elif instead of else then if, to reduce indentation

Convert to elif

(PLR5501)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/parse_doc2dict_with_config.py` around lines 589 - 609, Replace the
"else:" followed by "if" block with a single "elif" condition to reduce
indentation and improve readability while preserving behavior: change the branch
that checks r (the record), subdoc_penalty, children, and the any(...) child
check and then adds r["node_id"] to real_subdoc_ids so the logic around the
is_envelope check, (r.get("subdoc_penalty", 0) or 0) == 0, children truthiness,
and any((c.get("subdoc_penalty", 0) or 0) > 0 for c in children) remains
identical; update the control flow where the original else and nested if occur
so only an elif with the same combined condition is used.


def _is_descendant_of_subdoc(row: dict[str, Any]) -> bool:
current_id = row.get("parent_node_id")
Expand Down