Skip to content

chore(portal): wave-4 dead-code removal and logic simplifications#45

Merged
dzhelezov merged 1 commit into
mainfrom
chore/wave4-dead-code-simplification
Jul 5, 2026
Merged

chore(portal): wave-4 dead-code removal and logic simplifications#45
dzhelezov merged 1 commit into
mainfrom
chore/wave4-dead-code-simplification

Conversation

@mo4islona

@mo4islona mo4islona commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Restacked onto main#44 merged (main 458dc8c), so this now rebases cleanly to a single commit (chore(portal): wave-4 dead-code removal and simplifications) on top of main; the diff is exactly this PR's own changes. The stale harness/compat/analyze.test.ts importer of the deleted portal/config.ts (the repo-tests red) is fixed per the triage below — its sole withPortal case is dropped with the module. All checks green.

Summary

Removes the code the wave-4 review verified as dead (every deletion grep-verified for zero importers) and applies the flagged logic simplifications. Net −469 lines; no behavior change on any production path.

Deletions

  • portal/realtime.ts (259 lines) + realtime.test.ts (105) — the RPC endpoint-probe module: zero runtime importers, yet grafted and shipped in the published npm artifact.
  • portal/config.ts (43 lines) — the pre-wiring-patch injection path; sync-upstream.sh already annotated it "(deleted)" and excluded it from the graft. Its sole remaining importer — harness/compat/analyze.test.ts's withPortal case — is dropped with it (getPortalDataset/withPortal were used only there), keeping the repo-root node --test harness/compat/*.test.ts job green.
  • StateDiff/toStateDiff + the statediffs.json fixture — no producer or consumer anywhere.
  • DiscoveryState.status — written on every transition, read by nothing (planDiscovery ignored it), and wrong as telemetry (a predecessor completing set idle while a chained successor still scanned).
  • checksEnabled/checksStrict — unreferenced invariant-mode helpers.
  • rankTraces' strict INV-5 assert — the rank is the forEach counter of a monotonically walked array, strictly increasing by construction; the assert could never fire (the same rationale INV-2 documents for its deliberately-omitted per-row assert). INVARIANTS.md "Checked at (runtime)" cell updated.

Simplifications

  • reconcile() / portalRealtimeEvents' anchor is now required — the optional legacy mode preserved exactly the blind-append hole INV-10 was amended to close, and production (the wire) always passed an anchor. Startup is now always anchored.
  • FinalizedHead collapses to { number, hash? } — the bare-number variant was test-only; drops the typeof branching in the finalize poll.
  • streamHotBlocks' inline field-projection fallbacks are replaced by the shared BLOCK_FIELDS/LOG_FIELDS constants — the exact duplication the wire's own header comment disclaims.
  • traceSafeChunkBlocks loses its "compat" re-export in portal-transform (an internal fork module has no external compat surface) and its env-reading default parameter (INV-14: env is parsed once into PortalConfig; the shell always passes cfg.traceChunkBlocks).
  • STREAM_REALTIME drops the always-true Boolean(chain.portal) conjunct (the constructor is only selected for portal chains).
  • Doc drift: portal-invariant.ts header now says INV-1…INV-16; PUBLISHING.md drops the config.ts mention; sync-upstream.sh copy comment updated.

Test plan

  • scripts/sync-upstream.sh 0.16.6 --test green — 15 files, 205 tests (incl. portal-realtime/portal-realtime-wire/portal-shell, which cover the anchor-required change against the merged fix(portal): wave-4 review — five medium fixes (store parity, monotonic head, schema-degradation bounds, bounded realtime probe) #44)
  • scripts/sync-upstream.sh 0.15.17 --test green — 15 files, 205 tests
  • repo-root node --test harness/compat/*.test.ts green — 6 tests (the withPortal case dropped with config.ts)
  • CI green on the restacked head: repo-tests, fork-seam (0.16.6), fork-seam (0.15.17), versions
  • The anchor-required change is covered by the existing reconcile/anchor matrix (all reconcile unit tests pass an explicit anchor; the depth-1-fork test keeps a non-matching-anchor gap assertion); every portalRealtimeEvents test supplies a startup anchor consistent with its stream
  • The graft copy glob (realtime*.ts) still matches realtime-standardize.test.ts, so the standardize suite keeps running

🤖 Generated with Claude Code

@dzhelezov

Copy link
Copy Markdown
Collaborator

CI triage — the repo-tests job is red with a precise root cause:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '.../portal/config.ts'
imported from harness/compat/analyze.test.ts

harness/compat/analyze.test.ts:3 imports getPortalDataset/withPortal from the deleted portal/config.ts, and its withPortal test (line ~97) still exercises the helper. The zero-importers grep held for the grafted tree (sync-upstream already excluded config.ts), but the repo-level node --test harness/compat/*.test.ts job runs from the repo root, where the compat suite is a live importer.

Since the module really is outside the graft, the consistent fix is to take its last test with it: drop the import and the withPortal: extracts portal into registry… block from analyze.test.ts (getPortalDataset is only used inside that block). Alternatively keep config.ts — but that contradicts the PR's own rationale.

The fork-seam gates (0.16.6 + 0.15.17) are green on this head, so the graft-side deletions look clean. Will give this the full review once #44 settles and the stack collapses to its own diff.

@dzhelezov

Copy link
Copy Markdown
Collaborator

#44 is merged (main 458dc8c) — this can restack onto main now; the stacked commits should collapse to just the dead-code/simplification diff. The repo-tests red is still the harness/compat/analyze.test.ts import of the deleted portal/config.ts (fix per the triage comment above: drop the import + the withPortal test block). Happy to give it the full review pass as soon as it restacks.

Removes the verified-dead code and never-fire machinery from the wave-4
review; no behavior change on any production path.

Deletions (grep-verified zero importers):
- portal/realtime.ts + realtime.test.ts — the RPC endpoint-probe module;
  nothing imported it and it shipped in the published npm artifact.
- portal/config.ts — the pre-wiring-patch injection path; sync-upstream.sh
  already annotated it "(deleted)" and excluded it from the graft. Its sole
  remaining importer, harness/compat/analyze.test.ts's withPortal case, is
  dropped with it (getPortalDataset/withPortal were used only there) so the
  repo-root `node --test harness/compat/*.test.ts` job stays green.
- StateDiff/toStateDiff + statediffs.json fixture — no producer or consumer.
- DiscoveryState.status — written on every transition, read by nothing
  (and wrong as telemetry under chained extensions).
- checksEnabled/checksStrict — unreferenced invariant-mode helpers.
- rankTraces' strict INV-5 assert — ranks are strictly increasing by
  construction (the forEach counter); same rationale as INV-2's
  deliberately-omitted per-row assert. INVARIANTS.md cell updated.

Simplifications:
- reconcile()/portalRealtimeEvents' anchor is REQUIRED — the optional
  legacy mode preserved exactly the blind-append hole INV-10 closed, and
  production always passed an anchor.
- FinalizedHead collapses to { number, hash? } (the bare-number variant
  was test-only).
- streamHotBlocks' inline field-projection fallbacks are replaced by the
  shared BLOCK_FIELDS/LOG_FIELDS constants (single source, no drift).
- traceSafeChunkBlocks loses its "compat" re-export in portal-transform
  and its env-reading default parameter (INV-14: env is parsed once into
  PortalConfig; the shell always passes cfg.traceChunkBlocks).
- STREAM_REALTIME drops the always-true Boolean(chain.portal) conjunct.

Graft suite green on 0.16.6 and 0.15.17 (15 files, 205 tests each);
harness/compat green (6 tests, the withPortal case dropped with config.ts).
Portal-layer coverage +1.0 stmts (the dead module leaves the denominator).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mo4islona
mo4islona force-pushed the chore/wave4-dead-code-simplification branch from 1c48841 to 9eadd50 Compare July 5, 2026 08:48
@mo4islona

Copy link
Copy Markdown
Collaborator Author

Restacked onto main and the repo-tests red is fixed — ready for the full review pass.

All four checks (repo-tests, fork-seam (0.16.6), fork-seam (0.15.17), versions) are green on the restacked head.

@dzhelezov

Copy link
Copy Markdown
Collaborator

Merge-gate evidence (the fork's gated standard) — APPROVE on head 9eadd50

Three independent verification fronts, plus green CI on both runs:

1. Reference + gate verification (independent pass): every deleted export traced to zero remaining references at head — including string-level refs: the realtime*.ts graft glob in sync-upstream.sh still matches realtime-standardize.test.ts, so the copy can't fail empty. Both version gates green at head: 0.16.6 exit 0 (205 tests), 0.15.17 exit 0 (205), vs main's 211/211 — the −6 delta maps exactly to tests of deleted code (5 realtime.ts probe tests + 1 toStateDiff/statediffs.json fixture test; the removed withPortal test is node:test-side, not vitest-counted). portal-realtime.test.ts stays 34/34. Biome error-level clean; per-hunk equivalence confirmed for every simplification.

2. Adversarial review (cross-model): correctly flagged that three removals are not behavior-neutral over the exported functions' full input domain — reconcile/portalRealtimeEvents without an anchor, bare-number FinalizedHead, and traceSafeChunkBlocks' env-reading default (+ its portal-transform re-export). Disposition: all three modes were production-dead — the sole production caller (portal-realtime-wire.ts) always passes a populated anchor, an object-form head probe, and the validated cfg.traceChunkBlocks cap; the env default was exactly the silent-NaN shape INV-14 exists to kill — and each removal is disclosed in the diff's own comments. Accepted as the point of the PR, not a regression.

3. Call-site diff read: both wiring patches select createPortalHistoricalSync only under params.chain.portal, so the dropped Boolean(chain.portal) conjunct was a constant; LOG_FIELDS equals the old inline literal exactly; the wire passes all three field constants explicitly, so the widened BLOCK_FIELDS fallback default is unreachable in production; the discovery status field was write-only (nothing reads it at head); checksEnabled/checksStrict have zero refs; INV-16 exists in INVARIANTS.md, so the comment bump is correct.

Non-blocking follow-ups (we'll fold these into the next portal PR — no need for another round here):

  • portal-realtime.test.ts (~L441, ~L887) still passes bare-number finalizedHead stubs (async () => 673). Observable outcome is unchanged either way (both paths end in "no finalize", and the tests don't assert finalization), but they should be object-form now that the type is narrowed.
  • .agents/skills/pr-quality-gate/SKILL.md still lists realtime.ts as a source↔test pair (L26) and statediffs.json as a fixture (L62).
  • harness/euler-multichain/probe.mjs header still says it mirrors portal/realtime.ts (unit-tested) — the module it mirrored is gone, so the comment (and the "unit-tested" claim) needs a rewrite.

Merging. Thanks for the clean restack + the analyze.test.ts import fix.

@dzhelezov
dzhelezov merged commit e2185c8 into main Jul 5, 2026
8 checks passed
@dzhelezov
dzhelezov deleted the chore/wave4-dead-code-simplification branch July 5, 2026 09:10
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