Skip to content

Import helpers called inside a spread; back off failing streams - #164

Merged
tiavision merged 2 commits into
mainfrom
ccr-015aee2d-1l96zz
Dec 6, 2026
Merged

tiavision merged 2 commits into
mainfrom
ccr-015aee2d-1l96zz

Conversation

@tiavision

Copy link
Copy Markdown
Member

Two fixes from a stability review.

A helper called only inside a spread is imported

The compiler's "is this name used" pattern, (?<[\w$.])name, skipped any name after a .. That includes the last dot of a spread's ..., so data-sn-text="[...pick(n)].length" compiled to a call of pick with no import { pick }, and the binding failed in the browser.

One shared guard, NAME_START in src/compiler/code-text.ts, now refuses only a member's . and ?.. It replaces the same pattern in:

  • namesIn, which decides the page module's and the early script's imports
  • the built-in formatter checks in early-parts.ts
  • the impure-helper check for row programs in prerender.ts
  • reads in expr-queries.ts
  • the early $k guard in index.ts

test/compiler/helper-spread.test.ts covers array spread, object spread and a namespace member, and checks that an unused helper still isn't imported. Three of its four tests fail on main. It also passes under SN_LINK_AUDIT and SN_FROM_WALK_AUDIT.

Streams back off instead of reconnecting in a loop

src/sse.ts had two loops:

  1. A 2xx session probe opened the stream immediately, and only wait() grew the backoff. A stream endpoint that kept failing while the probe succeeded (a proxy answering 502) looped probe and connect as fast as round trips allowed.
  2. Every open reset the backoff. A server that accepted and then closed at once looped every second without a probe, and with no delay at all with one.

Now:

  • A drop reconnects at once only if the connection had opened and no other quick reconnect happened in the last 10 s.
  • Anything else waits its backoff (1 s doubling to 30 s), then probes.
  • The backoff resets only after a connection has stayed open for 10 s.

A working connection that drops still reconnects at once, as before, and the existing stream tests pass unchanged. Three new tests in test/behaviour/sync.test.ts cover a stream failing while the probe succeeds, a server that accepts and closes at once (with and without the probe), and the reset after a stable connection. All three fail on main. docs/sync.md (connection rules) and CHANGELOG.md are updated.

Checks

  • npm run typecheck passes.
  • npm test: 360 files, 3,607 tests pass, 1 skipped.

Generated by Claude Code

The identifier guard `(?<![\w$.])` took any name after a `.` for a member's property,
including the last dot of a spread's `...`: `[...pick(x)]` compiled to a call of `pick`
with no import of it. One shared guard, NAME_START, now refuses only a member's `.`
(and `?.`); it replaces the same pattern in namesIn (the page module's and the early
script's imports), the built-in formatter checks, the impure-helper check of row
programs, `reads` and the early `$k` guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AjKzdxiisqN9crUQ7XSyca
A 2xx probe opened the stream at once and only wait() grew the backoff, so a stream
endpoint that failed while the session probe succeeded looped probe + connect as
fast as round trips allowed; and since every open reset the backoff, a server that
accepted and closed at once looped every second (at once, with the probe).

Now a drop reconnects at once only when the connection had opened and no other
quick reconnect happened in the last 10 s; anything else waits its backoff (then
probes), and the backoff resets only once a connection has stayed open 10 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AjKzdxiisqN9crUQ7XSyca
@tiavision
tiavision merged commit 1cd70b6 into main Dec 6, 2026
22 checks passed
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