Skip to content

refactor(planning): simplify shared share.py and tunnel.py - #14773

Merged
melodic-automation-lanes[bot] merged 2 commits into
mainfrom
work-resolve-issue/issue-14683-42645215007-1
Nov 9, 2026
Merged

melodic-automation-lanes[bot] merged 2 commits into
mainfrom
work-resolve-issue/issue-14683-42645215007-1

Conversation

@melodic-automation-lanes

@melodic-automation-lanes melodic-automation-lanes Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Closes #14683

Summary

Opened by the work-resolve-issue lane. The run's own summary:

Simplified plugins/planning/shared/share.py and tunnel.py without changing behavior. tunnel.py now reads its JSON records through one private _load helper and checks records with one private _has_pid helper, replacing nine copies of the same isinstance pair. In share.py, cmd_status and cmd_list read the session mapping once, cmd_status builds its fixed keys in their original order from a key tuple, summarize folds repeats under one if, and main uses a membership test. share.sh is a 16-line probe loop with nothing worth removing, so it is unchanged. A fresh-context review found two edge-case behavior differences in my first draft (dropping src.exists() in creation(), and removing the second bridge.running ping in cmd_stop), so both were reverted.

Not verified

  • The planning shared Python test suites (plugins/planning/shared/tests/test_share.py, test_server.py) were not run: this lane cannot run an interpreter. Left to the PR's CI.
  • ci-status green is a PR CI check, left to the PR's CI
  • tidy-diff passes 4 and 5 (write-for-humans, ai-slop) were skipped on the changelog fragment because the issue fixes its body word for word; passes 1-3 ran and found nothing to change
  • tunnel.py is 4 lines longer than before (two helper definitions with docstrings) even though it removes nine copies of the same check; share.py is 2 lines shorter
  • share.sh unchanged: its probe loop has no redundant step to remove without changing which interpreter it picks

Fix

  • plugins/planning/shared/tunnel.py: added private _load(path) and _has_pid(rec) helpers; read, read_live, fall_back, retired, sweep, stop, _server, tunnel_running and end_live use them in place of repeated try/json.loads and isinstance checks
  • plugins/planning/shared/share.py: cmd_status and cmd_list read doc['session'] once; cmd_status builds its None keys with dict.fromkeys and its server-status keys with a comprehension, both in the original key order; stopped_lives uses a dict comprehension; summarize folds a fault's repeats under…
  • .changes/planning/work-resolve-issue-issue-14683-42645215007-1-e0679773.md: patch fragment, ### Changed / - Internal simplification, no behavior change.

Verification

The runner ran each check from the base copy against f129941:

  • scripts/check-changelog-fragments.sh --check: passed
  • scripts/check-changed-skills.sh --merge-base: passed

The run reports:

  • check-changelog-fragments: all 2 fragments valid
  • check-changed-skills: no changed skills, nothing to gate
  • check-affected: 13 passed, 6 skipped (shellcheck: no changed shell; typos not installed; three validate-plugins steps that run code from the checked tree; changed-skills), over 3 changed files
  • fresh-context review subagent compared every hunk against the pre-change copies: it confirmed the same JSON key order, KeyError order and return values for status, list, summarize, main and every tunnel.py function. It found two differences (creation() swallowing a non-ENOENT error from exists(),…
  • grep of plugins/planning for callers: no module-level name was removed or renamed; tests call share_cli.bring_up and tunnel.* public functions, all unchanged
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42645215007

Left out: the items under Not verified.

Related

#14683

Merge-Risk: max=MEDIUM demote=false head=e68c5082f0672f28884e7cf8be3aac13ef244cb5 rubric=8.1.6 rater=claude-opus-5-5 checker=claude-opus-5-5

Lane-Activity: work-resolve-issue/resolve-issue
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review needs no new review of e68c5082f0672f28884e7cf8be3aac13ef244cb5: no file of this pull request changed since the review of f129941.

Security review: no security issues found

I read every hunk of all 3 changed files: plugins/planning/shared/share.py, plugins/planning/shared/tunnel.py and the changelog fragment. None of them matches a trusted-path glob, and none touches a trust control, merge hold, token scope, kill switch or plugin manifest.

This is a behavior-preserving refactor. The checks below confirm it doesn't change anything security-relevant:

  • Shared helpers in tunnel.py:
    • _load(path) catches the same OSError and ValueError as the try/except blocks it replaces in read and read_live.
    • _has_pid(rec) (isinstance(rec, dict) and isinstance(rec.get("pid"), int)) is exactly the pair it replaces in fall_back, retired, sweep, stop, _server and end_live.
    • In tunnel_running, the old isinstance((rec or {}).get("pid"), int) and the new _has_pid(rec) agree for None and for any dict. A truthy non-dict was not a dict before either, so the old form would have raised and the new one returns False. That is fail-closed and never reached, since callers pass read_live results, which are always dicts.
    • Process stop and liveness checks (detached.stop, detached.alive) still run only on records that pass the same validation as before.
  • share.py:
    • Reading the session mapping once, dict.fromkeys, the key comprehension and the membership test in main return the same values and keys, in the same order. A missing key still raises KeyError in the same order.
    • The summarize fold under if g["fp"]: matches the two conditional expressions it replaces.
    • The data-dir existence guard in main still exempts only ensure-running and list.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

claude-review needs no new review of e68c5082f0672f28884e7cf8be3aac13ef244cb5: no file of this pull request changed since the review of f129941.

Code review: no findings

I read every hunk of all 3 changed files. None of them match a trusted-path glob.

Behavior equivalence. I checked each change by hand against the base code. I ran no code or tests myself.

  • share.py cmd_status, stopped branch: session is read once. doc is already known to be a dict there, because doc.get("rounds") ran on it before. dict.fromkeys(...) is unpacked in the same place as the four None keys it replaces, so the JSON key order stays the same. Any AttributeError from a session value that is not a dict still comes from the guestUrl entry, as before.
  • cmd_status, running branch: the comprehension reads st[k] in the original key order, so a missing key raises the same KeyError at the same point.
  • cmd_list, stopped_lives, main: same results.
  • summarize: when fp is falsy, the old code added 0 to the integer count and set lastSeen to itself. Folding both lines under if g["fp"]: changes nothing.
  • tunnel.py: _has_pid is the same isinstance(dict) and isinstance(pid, int) pair at every place it replaces. _load keeps the same OSError / ValueError handling. One case can now differ: tunnel_running(rec) given a truthy value that is not a dict used to raise AttributeError and now returns False. No caller can hit it. The calls at tunnel.py:585, tunnel.py:622, share.py:727 and server.py:457 / server.py:508 all pass dicts from read_live or the live records, and the tests pass dicts too.

Closing issue #14683, acceptance criteria:

  • "Behavior is unchanged": met, as above. The existing test_tunnel.py, test_server_live.py and test_share.py suites call these functions.
  • "The diff edits only the listed files … and changelog fragments": met.
  • Size limit (400 lines / 15 files): met. The diff touches 3 files and well under 400 lines.
  • "ci-status is green": the PR's CI decides this. I could not check it here.
  • Fragment for planning with ### Changed / "Internal simplification, no behavior change.": met, bump: patch.

These checks are claimed by the author and I did not verify them: the test suites were not run by the lane, and the changelog / changed-skills checks the PR body reports.

No plugin manifest changed. No paved-path, settled-thread or prior-finding items apply, and the PR context holds no embedded directives.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head e68c5082f0672f28884e7cf8be3aac13ef244cb5, the head its arming checks judged.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for e68c508

The verifier passed this head. The capture artifact holds the capture summary, which says whether the capture ran, and any screenshot or video that passed the mask check; this comment uploads no file.

Capture artifact: pr-capture-14773-e68c5082f0672f28884e7cf8be3aac13ef244cb5, expires on 2026-12-09.

One comment per pull request, updated in place for each new head.

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Nov 9, 2026
Merged via the queue into main with commit dad7850 Nov 9, 2026
57 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14683-42645215007-1 branch November 9, 2026 19:14
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit dad78506cd7d24a260eecfb495e7443e1b31235b; later checks count it verified from this comment.

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.

Simplify the shared planning plugin code (2 of 2)

1 participant