Skip to content

0.6.1: maintenance — decompose complexity hotspots, dedup dispatch, drop dead exports#255

Merged
bbopen merged 10 commits into
mainfrom
refactor/0.6.1
May 31, 2026
Merged

0.6.1: maintenance — decompose complexity hotspots, dedup dispatch, drop dead exports#255
bbopen merged 10 commits into
mainfrom
refactor/0.6.1

Conversation

@bbopen

@bbopen bbopen commented May 31, 2026

Copy link
Copy Markdown
Owner

0.6.1 — maintenance patch (invisible)

The 0.6.1 cleanup slice from the ts-fx review. No API, behavior, or wire-protocol changes — purely internal. Built as a stacked agent workflow (9 scopes), each characterization-gated (snapshot before/after, assert identical) and verified.

What changed

  • Removed 2 dead exports (emitTypeTestsForModule, redundant export default tywrap) — neither on the public surface.
  • Decomposed the 11 worst remaining complexity hotspots, output-preserved: generateKey (cache), validateTypeHints (validation), the dev.ts watch/reload trio, flushWriteQueue (subprocess transport), discovery dependency/path helpers, normalizePath/resolvePythonExecutable (utils), parseTypingFactoryName (annotation parser).
  • Factored the duplicated request/response dispatch in bridge-codec and rpc-client into one path (the cross-bridge call/instantiate merge was deliberately left alone as too risky for a patch).

Result

  • fx actionable complexity: 14 → 3 — the remaining three (generate cog 91, fetchPythonIr cog 27 → 0.7.0; splitTopLevel → intentionally irreducible) are deferred.
  • typecheck ✓ · build ✓ · lint 0 errors ✓ · tsd ✓ · full suite 1232 passed / 0 failed / 130 skipped (identical to 0.6.0 — behavior preserved).

Carries the version bump + human CHANGELOG so the merge cuts 0.6.1 via publish_from_main.

bbopen added 10 commits May 31, 2026 14:36
…port

emitTypeTestsForModule was a dev aid with no consumers in src/test/test-d
and was not re-exported from the public surface. The module-level
'export default tywrap' was likewise unused: src/index.ts imports the named
tywrap and re-exports its own default, so nothing depended on the tywrap.ts
default. Both removed; the named tywrap export is retained.
Decompose three cognitive-complexity hotspots in src/dev.ts without
changing reload/watch behavior, ordering, or side effects:

- resolveWatchTargets (cognitive 28 -> resolved): extract the invariant
  Python resolution script to a module constant and split out
  resolveWatchPythonEnv, resolveWatchTargetPayload,
  resolvePackageWatchTargets, resolveFileWatchTarget, and
  resolveModuleWatchTargets helpers.
- collectWatchDirectories (cognitive 19 -> resolved): extract
  isWatchableDirectory and listChildDirectories from the BFS loop.
- runReload (cognitive 25 -> 13, no longer actionable): introduce a
  ReloadState object plus prepareReload, activateReloadBridge, and
  disposeReloadFailure helpers, preserving the exact closed-checkpoint
  abort semantics and emit ordering.

No public API, behavior, or wire-protocol change.
Extract rejectAllQueuedWrites and processQueuedWrite helpers from
flushWriteQueue to drop its cognitive complexity below threshold
(23 -> below 15). The write-drain ordering, backpressure handling,
queue-timeout fallback, and synchronous-error rejection semantics
are preserved exactly; the loop now dispatches on a status returned
by processQueuedWrite (continue / backpressure / error).
Maintenance release: dead-export removal, 11 complexity-hotspot decompositions
(output-preserved), and codec/RPC-client dispatch dedup. No API/behavior/wire
changes. Actionable complexity 14 -> 3.
@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Version 0.6.1 maintenance release refactoring internal code organization: consolidating duplicated request/response decoding in the runtime codec and RPC client, extracting complexity hotspots in core modules and dev watch system into smaller focused helpers, and removing two dead exports. No public API changes or behavior modifications.

Changes

0.6.1 Maintenance Release

Layer / File(s) Summary
Version and changelog update
CHANGELOG.md, package.json, src/version.ts
Package version bumped to 0.6.1; changelog describes maintenance release with internal refactorings, dead export removals, and complexity reductions.
Dead export removal
src/tywrap.ts
Default export and emitTypeTestsForModule function removed; consumers must use named exports.
Core parsing helpers extraction
src/core/annotation-parser.ts, src/core/discovery.ts
Annotation-parser delegates quoted-argument extraction to extractQuotedFactoryArg helper; discovery refactors module-path resolution into resolveViaInterpreter/resolveViaSearchPaths and import extraction into extractImportedModule.
Type validation engine refactoring
src/core/validation.ts
ValidationEngine.validateTypeHints split into focused helpers: reportMissingType, checkReturnTypeHint, checkParameterTypeHint, checkParameterTypeStructure, checkReturnTypeStructure to centralize missing-type detection and strict-mode validation.
Runtime message pipeline consolidation
src/runtime/bridge-codec.ts, src/runtime/rpc-client.ts
BridgeCodec refactored with parseResponseResult and assertNoSpecialFloats helpers; RpcClient consolidated send logic via sendVia and stampMessage helpers, eliminating duplicated decode paths and protocol stamping across sync/async methods.
Subprocess stdin queue management
src/runtime/subprocess-transport.ts
Write queue refactored with rejectAllQueuedWrites and processQueuedWrite helpers to centralize timeout, backpressure, and error handling in flushWriteQueue.
Development watch and reload system refactoring
src/dev.ts
Watch-directory discovery extracted into listChildDirectories/isWatchableDirectory helpers; watch-target resolution restructured with embedded Python script and payload types; reload execution reorganized around ReloadState/PreparedReload with dedicated prepareReload and activateReloadBridge functions.
Utility module helper extraction
src/utils/cache.ts, src/utils/python.ts, src/utils/runtime.ts
Cache key generation uses encodeKeyInput/stringifyKeyInput; Python resolution delegates to usesDefaultPython/resolveVenvPython; path normalization uses applyPathSegment helper.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • bbopen/tywrap#251: RPC client refactoring centralizing request stamping and send pipeline via shared helpers directly overlaps with this PR's sendVia/stampMessage consolidation.
  • bbopen/tywrap#225: Prior changes to startNodeWatchSession watch-path/reload-scheduling logic in same file as this PR's large dev.ts watch/reload system refactoring.
  • bbopen/tywrap#224: Related refactoring of dev watch/reload and bridge-activation internals in src/dev.ts that this PR significantly restructures.

Suggested labels

enhancement, refactor, area:core, area:runtime, area:codec, area:dev, priority:p2

Poem

🐰 A tidy warren builds with care,

Helpers split and logic spare,

Duplication fades away,

Cleaner paths to code each day! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the three main changes: removing dead exports, decomposing complexity hotspots, and deduplicating dispatch logic. It accurately reflects the primary objectives of this maintenance release.
Description check ✅ Passed The description comprehensively details the PR's maintenance scope, lists specific files and refactorings, documents the complexity reduction results, and confirms all tests pass with identical behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/0.6.1

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot added enhancement New feature or request area:runtime-node Area: Node runtime bridge area:codec Area: codecs and serialization area:tooling Area: tooling and CLI priority:p2 Priority P2 (medium) labels May 31, 2026
@bbopen bbopen merged commit 790dbfb into main May 31, 2026
21 of 22 checks passed
@bbopen bbopen deleted the refactor/0.6.1 branch May 31, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:codec Area: codecs and serialization area:codegen area:docs Area: documentation area:runtime area:runtime-node Area: Node runtime bridge area:tooling Area: tooling and CLI enhancement New feature or request priority:p2 Priority P2 (medium)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant