Skip to content

refactor(session-bridge): simplify session_bridge.py without changing behavior - #14390

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14345-42569665920-1
Nov 9, 2026
Merged

melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14345-42569665920-1

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14345

Summary

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

Simplified lib/session-bridge/session_bridge.py while keeping its behavior: the loopback watcher and the channel relay now share one Transport._listener_view instead of two copies of the listening/reading/idle logic, token_ok and watch_token_ok share one header compare, read_session and kept_port reuse read_json, the channel server resolves data_dir in one helper, and the awkward wrapping a formatter left behind is unwrapped (ruff.toml selects no line-length rule). view-bridge.sh is unchanged: it is already 16 lines, and test_view_bridge.py:315 fakes a Python by matching the probe's text, so rewording the probe would break that test for no gain. The five generated plugin copies were regenerated with sync-shared-copies.

Not verified

  • Python test suites lib/session-bridge/test_session_bridge.py and test_view_bridge.py were not run: this lane has no wrapper for a test runner, so they are left to the PR's CI
  • ci-status green on the PR: left to the PR's CI
  • tidy skipped: the change touches lib/ (a listed shared path) and spans 4 areas (lib, plugins/planning, plugins/review, plugins/work-items), over the 1-area cutoff
  • lib/session-bridge/view-bridge.sh left unchanged: there is nothing to simplify that keeps test_view_bridge.py:315, which matches the probe text, passing

Fix

  • lib/session-bridge/session_bridge.py: added Transport._listener_view, which both listener() implementations call; added LoopbackHandler._header_token_is behind token_ok and watch_token_ok; read_session and kept_port read the session file through read_json; added ChannelServer._data_dir; unwrapped…
  • plugins/planning/shared/session_bridge.py: regenerated copy
  • plugins/planning/surface/session_bridge.py: regenerated copy
  • plugins/planning/view-bridge/session_bridge.py: regenerated copy
  • plugins/review/view-bridge/session_bridge.py: regenerated copy
  • plugins/work-items/view-bridge/session_bridge.py: regenerated copy
  • .changes/planning/work-resolve-issue-issue-14345-42569665920-1-03b2d6c4.md: patch fragment
  • .changes/work-items/work-resolve-issue-issue-14345-42569665920-1-0352f93c.md: patch fragment
  • .changes/review/work-resolve-issue-issue-14345-42569665920-1-f3592338.md: patch fragment

Verification

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

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

The run reports:

  • sync-shared-copies: regenerated the 5 plugin copies of session_bridge.py, exit 0
  • new-changelog-fragment --carriers-of lib/session-bridge/session_bridge.py patch: created the planning, work-items and review fragments
  • check-changelog-fragments: all 7 fragments under .changes/ are valid
  • check-changed-skills: no changed skills under plugins/*/skills/, nothing to gate
  • check-affected: 13 passed, 6 skipped (shellcheck: no changed shell; typos: not installed; three validate-plugins sub-checks that run code from the checked tree; changed-skills: no skill change) over 9 changed files
  • git-read diff --numstat HEAD: 189 changed lines in the one hand-edited source file, plus 3 fragments and 5 generated copies; within the issue's 400-line and 15-file limits
  • fresh-context review subagent, checking each hunk against the old code (non-dict JSON, empty dict, missing keys, exceptions, call order, lookup of names defined later in the module): no findings; noted only a hook-call order change inside listener() with no observable effect, and an unreachable…
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42569665920

Left out: the items under Not verified.

Related

#14345

Merge-Risk: max=HIGH demote=true head=a48bcfba5b8ebfc62f138698e869d6fbfd21590e rubric=8.1.2 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 reviewed a48bcfba5b8ebfc62f138698e869d6fbfd21590e: read 9 of 9 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #14390 (refactor of session_bridge.py)

No security issues found.

critical-findings: 0

What was reviewed

  • lib/session-bridge/session_bridge.py (the hand-edited source). I read the whole change.
  • plugins/planning/shared/session_bridge.py. I read the whole change. It matches the lib change line for line, two lines further down the file. Its four copies (plugins/planning/surface/, plugins/planning/view-bridge/, plugins/review/view-bridge/ and plugins/work-items/view-bridge/session_bridge.py) are identical changes. None of them sits at a hook, workflow, settings or manifest path, so the same content does not act differently at any of them.
  • .changes/planning/...03b2d6c4.md. This is a changelog fragment with no security surface. Its two copies are identical.

No changed file matches a TRUSTED PATHS glob. The PR changes no plugin manifest, workflow or trust control.

Security-relevant hunks checked

  • Token checks. token_ok and watch_token_ok now both call the new LoopbackHandler._header_token_is. It still reads only the X-<Name>-Token header (or "") and still compares with secrets.compare_digest against hub.token or hub.watch_token. Which check guards which route has not moved: /api/lease uses the watcher token and the other POST routes use the main token. Authorization is unchanged.
  • Session-file reads. read_session and kept_port now go through read_json (head L1051-L1056). It catches OSError and ValueError and returns None for anything that is not a dict, the same failure handling as before. kept_port still checks that the port is an integer (not a bool) between 1 and 65535. A non-dict or missing port still gives None and no exception.
  • Channel server data_dir. The new ChannelServer._data_dir resolves the path exactly as both of its earlier inline copies did. The check that the env file exists is unchanged; only the error-message variable is new. The arguments-must-be-a-dict check in tools/call is the same logic, rewritten.
  • listener(). Both transports now share Transport._listener_view. It only reports state (state, waiters, idleFor, timestamps, lease) and controls no access. The channel relay's lease is still None once it is stopped.
  • The rest of the diff only reformats lines or comments.

Other notes

  • The PR context file contains no embedded instructions aimed at this lane.
  • No spend or billing effect.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

claude-review reviewed a48bcfba5b8ebfc62f138698e869d6fbfd21590e: read 9 of 9 changed file(s); 0 finding(s), 0 as inline comments.

Code review: no findings

This pull request refactors lib/session-bridge/session_bridge.py and regenerates its five plugin copies. I read every change in the source file and in one generated copy and checked each one against the old code. I found no change in behavior.

  • Shared listener code. Both listener() methods now call one helper, Transport._listener_view, which gives the same output as the two copies it replaces. ChannelRelay passes int(self.waiting), so waiters > 0 behaves like the old truthiness check, and waiters is still an int. The lease is worked out the same way as before. One small difference: LoopbackWatcher.lease_view() now runs just before _listener_view reads the clock instead of just after. Each takes its own time.time(), so nothing outside can see the difference.
  • Session-file readers. read_session and kept_port now use read_json (L1051), which catches OSError and ValueError and returns None when the file isn't a JSON object.
    • The old KeyError and TypeError cases in kept_port now become .get("port") returning None, so the function still returns None.
    • In read_session, an empty dict now fails the s and check where it used to pass isinstance and then fail on .get("port"). Both give None.
  • Token checks. _header_token_is runs the same compare_digest on the same header, with the same "" fallback.
  • ChannelServer. _data_dir contains the same expression as before. The new local env in tool_watch doesn't shadow anything used later in the method. The rewritten args handling gives the same result.
  • Line unwrapping. The rest of the diff only joins wrapped lines back together. ruff.toml selects only the E4, E7, E9 and F rules, and I found no ruff format check in the workflows.

Closing issue #14345, acceptance criteria:

  • Behavior is unchanged: met as far as I can tell by reading the code. Nothing is renamed or removed, and view-bridge.sh is untouched. lib/session-bridge/test_session_bridge.py covers listener(), idleFor, kept_port and read_session, so the existing tests can catch a regression.
  • The diff edits only the listed files and changelog fragments: met. It changes one hand-edited source file, five generated copies (identical to each other) and three fragments.
  • At most 400 changed lines: met. The source file has about 189 changed lines.
  • ci-status is green: not checked by this lane.
  • sync-shared-copies.sh is run: the copies are consistent: the five plugin copies match each other and carry the same changes as the source. That the script was run is the author's claim, not something I verified.

The PR says the Python test suites were not run. I could not run them either, because this lane has no shell, so the tests are unverified.

I read the planning fragment and the plugins/planning/shared copy and skipped their identical copies. All of those copies sit at paths of the same kind (plugin copies of session_bridge.py, or .changes/<plugin>/ fragments), so none behaves differently because of where it sits. Each fragment's bump: patch fits a refactor that doesn't change behavior.

No hold applies, and the change adds no spend.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Unattended merge: native auto-merge leaves this pull request unarmed at head a48bcfba5b8ebfc62f138698e869d6fbfd21590e. The lanes clear this reason on their own; the next scheduled run judges it again.

pr-merge's gate refuses its verifier verdict (verify:missing)

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for a48bcfb

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-14390-a48bcfba5b8ebfc62f138698e869d6fbfd21590e, 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 dec94f1 Nov 9, 2026
75 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14345-42569665920-1 branch November 9, 2026 08:02
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit dec94f1273433cca85b8a4f26eb2bddaf5edb7bc; 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 session-bridge shared lib source (1 of 2)

0 participants