Skip to content

test: pin why the incremental compact path refuses a live segment (#230) - #239

Merged
Huxpro merged 1 commit into
new-lynxfrom
fix/lynx-incremental-compact-over-compact
Aug 30, 2026
Merged

Huxpro merged 1 commit into
new-lynxfrom
fix/lynx-incremental-compact-over-compact

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Summary

Order 3 named the state.compactHosts !== null refusal in prepareLynxCompactHandleDeltas as the thing blocking a warm container from re-entering the compact regime, and proposed teaching the incremental path to follow a live segment. I went to build that and found the refusal is not an obstacle in the way of a fix — it is holding the door shut on a silent identity loss. This PR pins that, measured rather than argued.

No product code changes.

Why

A compact host is a handle that has not been materialized yet: compactHandle (client-driver.ts:371) builds one out of the segment the first time anything observes it. So most of a shell's hosts live only in the segment. And apply() installs a staged segment by replacing the old one (client-driver.ts:1003).

Relaxing the refusal for the incremental branch therefore keeps exactly the hosts someone happened to observe first, and drops the rest. With the guard changed to (!incremental && state.compactHosts !== null) and a second segment applied at ids disjoint from the first by 10,000:

host state before the second ack after
1 observed, so materialized into handles active, same object
2 never observed — segment only null
3 never observed — segment only null

Reachability that depends on who looked, with nothing reporting it. A ref taken after the second create finds nothing, while the same code that had touched the node earlier works. That is strictly worse than the refusal, and it is why the fix cannot be a gate flip: the segment has to be preserved, not replaced.

This also kills the obvious cheap fix. Merging the new hosts into the existing dense Uint16Array would work once, but each create mints higher ids, so the array widens on every cycle and never narrows — which is the array: growth already measured as +3.15 MB of the heapMtsAfterClear drift in Order 2. A per-run segment list is the shape that survives that; the existing live === 0 retirement already drops a spent segment, which keeps the list at shell-plus-live-runs rather than one per repetition. That is the design I would build, and it is what I want your gate on.

Changes

Two tests in packages/lynx/tests/protocol.test.ts, beside the existing re-arms compact acknowledgements after the last compact host retires pin:

  • the refusal, at ids disjoint by 10,000 — every id-overlap check the incremental branch already makes passes there, so it is refused for holding a live segment at all, not for overlapping one;
  • the property any fix has to keep, written so it does not depend on how the fix is spelled: it swallows whatever the attempt does and then asks the container for hosts nobody has observed. It passes today because the attempt is refused, and must pass afterwards because the fix preserved them.

Validation

  • pnpm format:check — not run repo-wide; pnpm format:files clean on the one changed file.
  • pnpm typecheck — not run; test-only change.
  • pnpm test — not run in full.
  • targeted: packages/lynx/tests/protocol.test.ts → 49 passed (was 47).
  • full lynx project: 48 files, 730 tests, 0 failures (base 8938c1260 was 728).
  • pnpm sync clean, no generated changes.

Red-verified with the same relaxation that produced the table above:

× refuses a second compact segment over a live one, to keep the hosts nobody looked at
    AssertionError: expected [Function] to throw an error
× keeps the unobserved hosts of a live segment when a second one is attempted
    AssertionError: expected undefined to be true

The second failure is the important one — it is the identity loss itself, caught independently of whether the refusal is still there. Restored, 49/49.

Risk / follow-ups

This is the third open gate on #230 and they interact, so all three are collected in issuecomment-5462016946 and the comment following it:

  1. Ordering — Order 3 measured that E1's op does not address the create residual (the wire is already one command for create; the cost is on the receiver). This compact-regime work is where the margin is. E1 → E2 → E3 was set before that measurement.
  2. E1's addressing — a background-originated mount-program-run cannot name a resident program today, and closing that spends Main-thread-resident block programs: the optimal-Lynx first screen #163's background byte-identity promise (PR test: pin what a background-originated program mount cannot name (#230 E1) #238).
  3. This one — is the per-run segment list the shape you want, given it replaces a single compactHosts with a short list and touches ~13 read sites in client-driver.ts?

I stopped before building the segment list for the same reason I stopped before the speculative compactHosts redesign in Order 3: it is a change to handle identity, which is the part of this file least forgiving of a guess.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

Order 3 (issuecomment-5461743426) found that a root whose first commit
took the compact acknowledgement can never take an incremental one
afterwards, and read the `state.compactHosts !== null` refusal in
`prepareLynxCompactHandleDeltas` as the thing standing in the way. It is
not in the way. It is holding the door shut on a silent identity loss.

A compact host is a handle that has not been materialized yet:
`compactHandle` builds one out of the segment the first time anything
observes it. So most of a shell's hosts live only in the segment, and
`apply()` installs a staged segment by *replacing* the old one. Relaxing
the refusal for the incremental branch therefore keeps exactly the hosts
someone happened to observe first and drops the rest.

Measured, not argued. With the guard relaxed to
`(!incremental && state.compactHosts !== null)` and a second segment
applied at ids disjoint from the first by 10,000:

  host 1 (observed before the attempt)   → active, same object
  host 2 (never observed)                → null
  host 3 (never observed)                → null

Reachability that depends on who looked, with nothing reporting it. That
is worse than the refusal, and it is why the fix cannot be a gate flip:
the segment has to be preserved, not replaced.

Two tests. The first pins the refusal at disjoint ids, where every
id-overlap check the incremental branch already makes passes, so it is
refused for holding a live segment at all. The second pins the half that
has to survive any fix: it swallows whatever the attempt does and then
asks for hosts nobody has observed, so it passes today because the
attempt is refused and must pass afterwards because the fix preserved
them.

Red-verified with that same relaxation: the first fails on the missing
throw, the second on `expected undefined to be true` — the identity loss
itself, independent of the refusal.

No product code changes. Full lynx project: 48 files, 730 tests.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant