Skip to content

Delete surplus exports and dead helpers, and gate dead code in JavaScript and Python - #2326

Merged
max-sixty merged 15 commits into
mainfrom
dead-code-gates
Oct 11, 2026
Merged

max-sixty merged 15 commits into
mainfrom
dead-code-gates

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

Removing a caller never flagged its callees, so exports, application trampolines and Python helpers kept outliving their last use (#2020 and #1808 left several). This deletes them and adds two gates, so the next orphan fails in the change that creates it.

Gates

  • tests/test_unused_exports.py fails on any JavaScript or TypeScript export that no other tracked file names as a word. A default export counts as read where another file names its module's file name, since tools such as eslint and Pi load those modules by path. A JavaScript comment or a stylesheet counts as no reader, apart from a JSDoc import("…").Name; code, Python strings, pages and contract prose do. It runs over the whole tree rather than through knip because the browser tests import runtime modules inside Python strings and the render gate calls probes by name. Committed bundles are skipped, and the build/ inputs of third-party bundles are skipped as exporters, since the bundled dependency reads their exports. A name that collides with another word can hide an unused export.
  • vulture runs as a pre-commit hook over every Python tree (build, dev, hooks, skills, tests, worker), configured in [tool.vulture]. A function a framework calls is excluded by the decorator that registers it (click commands, pytest fixtures, atexit.register, jsonschema format checks) or by the name the framework's protocol fixes (do_*, pytest_*, uvicorn's main_loop, and so on), never one dead name at a time.

Deleted or narrowed

  • application.js loses the trampolines nothing imports (approvalBlockingQuestions, beginRead, midComposition, receiveState, startFeed, unaccountedGesture, undoable, undoLast). Pure helpers stop routing through the mounted application: widget-api.js re-exports watchReports from reports.js, and leaf.js imports beginRead and approvalBlockingQuestions from theirs. The mount drops the unread updateFab and the feed dependency bag, which repeated state, and the six openPageThread forward references share one forwarder. The mounted object lists the members boot reads instead of spreading the projection commands and engagement into it, so undoable, undoLast, retainReversal, unaccountedGesture, dispatchWidget, refreshAnnotationInventory and receiveState leave it.
  • export comes off every symbol only its own module uses, across the runtime, the default package, the browser framework's types, eslint.config.mjs, the Worker and the rust-sort example. widget-api.js stops re-exporting submitBindings and submitLabel, which no package uses. history.js and banner-toolbar.js use focus.js's drawn instead of their own copies, context.js loses the unread events and activity getters and shares one live-revision test, pointed-place.js names its function pointInto instead of aliasing rowIn, geometry.js loses the uncalled documentPoint, and composing/input.js gets its contract comment as a header.
  • Python: events.current_anchors, anchored_ids and anchored_parts, tasks.canonical_tasks, log_tasks_open, OUTCOMES and the ENDS_BY_* constants, PageTransaction.voice, and the test-only wrappers unattended_pages and layer_generation, whose tests now call what production calls. task_error reads the task's owner directly, which is what the ends comparison meant; the ends field itself stays. Test helpers xfail_browser_problem and draft_owner had no callers; a fixture requested only for its effect moves to usefixtures, and protocol overrides collect arguments they ignore in underscore-named * or ** parameters.
  • Behavior changed in tests: five visual-part tests in test_interact_anchors.py asserted that a version may drop a part a detached, moved, resolved, reopened or bare-reaction thread had pointed at. Since Clarify navigation and keep decided pages editable #2020 no thread blocks that removal, so each passed without its premise; test_a_removed_visual_part_moves_its_thread_to_the_surviving_section keeps the live-thread case.

Rule

skills/leaf/assets/AGENTS.md gains "Facts both runtimes know": a fact Python and the browser both use is owned by one language and consumed as data, or generated from the registry, and a new parity fixture or source-scanning test is a review flag asking why it is not generated. /developing-leaf points reviewers at it.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 5 commits October 10, 2026 17:31
# Conflicts:
#	skills/leaf/assets/runtime/thread/landing.js
…lication's members

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	skills/leaf/assets/vendor/browser-runtime.js
leaf-agent
leaf-agent previously approved these changes Oct 11, 2026
max-sixty and others added 2 commits October 10, 2026 19:19
# Conflicts:
#	skills/leaf/assets/runtime/standing-target.js
#	skills/leaf/scripts/leaf/tasks.py
…er merging main

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The new gate misses default exports. exported_names() returns an empty set for export default function lfUnusedDefaultExportReviewProbe() {}, so deleting that export's last reader leaves a green gate. This is a live export form in the tree (hooks/pi.ts), and the PR describes the gate as covering any JavaScript or TypeScript export. Please cover default exports or state why they are outside the gate and how their orphans are caught.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The new gate fails on the current merged tree: uv run pytest tests/test_unused_exports.py -q -n0 reports GRADE_SCHEMA in evals/ui-review-detection/grade.mjs and BROWSER_SCHEMA in provider.mjs as unread. The lint job also fails vulture on list_directory in dev/leaf_dev/review_detection_eval.py and codex_cli in tests/test_eval.py. These files arrived on main after this branch diverged; the branch needs to account for them before the new gates can pass.

Comment thread tests/test_unused_exports.py Resolved
leaf-agent
leaf-agent previously approved these changes Oct 11, 2026
max-sixty and others added 2 commits October 10, 2026 22:52
# Conflicts:
#	skills/leaf/assets/runtime/application.js
#	skills/leaf/assets/runtime/widget-api.js
#	skills/leaf/scripts/leaf/service.py
leaf-agent
leaf-agent previously approved these changes Oct 11, 2026
# Conflicts:
#	skills/leaf/assets/leaf.js
#	skills/leaf/assets/runtime/application.js
#	skills/leaf/assets/runtime/queues.js
#	skills/leaf/assets/runtime/widget-api.js
leaf-agent
leaf-agent previously approved these changes Oct 11, 2026
# Conflicts:
#	skills/leaf/assets/runtime/application.js
#	skills/leaf/assets/runtime/keeps.js
#	skills/leaf/assets/runtime/pointed-place.js
@max-sixty
max-sixty enabled auto-merge (squash) October 11, 2026 09:36
@max-sixty
max-sixty merged commit 4dab767 into main Oct 11, 2026
4 of 5 checks passed
@max-sixty
max-sixty deleted the dead-code-gates branch October 11, 2026 10:00
max-sixty added a commit that referenced this pull request Nov 2, 2026
The JavaScript export check (`tests/journeys/test_unused_exports.py`)
ran only in the daily `journeys` tier. That run has failed every day
this week, with over a hundred failures each time, so an orphaned export
reached main and stayed until Tend triaged the daily report: #4724 and
#4873 left seven on 30 and 31 October, and #5014 removed them on 1
November. Vulture, its Python counterpart, runs as a pre-commit hook,
which both landing paths (a pull request's lint step and `wt merge`'s
pre-merge) run over the whole tree, so the change that orphans a Python
definition is the one told.

This moves the export check beside vulture:

- `leaf-dev unused-exports` holds the check, unchanged, with the test's
docstring as its module header. It takes about two seconds.
- `.pre-commit-config.yaml` runs it as `unused-exports`, woken locally
by the file kinds that export or read (`.js`, `.mjs`, `.ts`, `.py`,
`.html`, `.md`, `worker/wrangler.toml`). CI runs every hook on every
file.

It also removes what #5014's deletion of `since-seen.js` left behind:

- the `keepalive` option of `deliverBookkeeping` and `postEvent`, which
only the departing `seen` send set, and `runtime.seen`, which only
`since-seen.js` read;
- the six arrival tests skipped while `since-seen.js` was unmounted. The
module, renamed `test_changes_in_place.py`, keeps the comparison and
at-work tests;
- the prose in `change-walk.js`, `events.md`, `read_state.py`,
`agent_state.py` and `browser/AGENTS.md` that described the turned-off
marking. The server's reading of `seen` events is unchanged, and no tab
posts one.

And it drops the `uuid` devDependency, which no module imports. A
one-off knip scan of dependencies flagged 33; the other 32 are bundled
from `build/entries`, loaded by evals or `tests/*.mjs`, or resolved as
types and peers. As #2326 and #3423 found for exports, knip would need
more configuration than it saves, so it is not added as a gate.

Validation: `leaf-dev unused-exports` and every pre-commit hook pass on
the changed files; `pnpm run check:browser`, the 737 runtime tests, and
the browser test for comparison bars and the `h` walk pass.

> _This was written by Claude Code on behalf of max-sixty_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants