Commit 1b4c1af
authored
feat(vnext): correlate completion refresh intent (#198)
## Summary
- add an opaque completion refresh token that correlates loading
results, follow-up catalog events, and the originating completion task
- make completion tasks expose their refresh token synchronously so
CodeMirror consumers can safely latch intent before caller-controlled
reentrancy
- define precise token lifetimes for soft and terminal catalog-loading
leases, including expiry, cancellation, update, and disposal
- harden `AbortSignal` handling against reentrant and throwing
getters/listener methods without allowing an older invocation to erase
newer work
## Why
The upcoming CodeMirror adapter must refresh completion only for the
request that originally produced a loading result. Revision checks alone
cannot distinguish multiple requests at the same document revision, and
asynchronous token publication leaves a race where catalog events can
arrive before the consumer knows what to match. This contract makes that
identity explicit and keeps latest-request-wins behavior correct across
hostile caller boundaries.
## Validation
- 2,003 tests pass; 1 intentional expected failure
- changed-file coverage: 97.92% statements, 96.01% branches, 100%
functions, 98.01% lines
- all strict and loose-optional TypeScript configurations pass
- oxlint and test-integrity checks pass
- session completion benchmarks remain within budget
- two independent exact-commit adversarial reviews approved `a0522c4`
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds an opaque completion refresh token to correlate loading results,
follow-up catalog events, and the originating request.
`session.complete()` now returns a `SqlCompletionTask` that exposes the
token synchronously, and `onDidChange` events include the token when
relevant.
- **New Features**
- Introduced `SqlCompletionRefreshToken` and `SqlCompletionTask`
(`complete()` returns a task with `refreshToken`).
- `SqlSessionChangeEvent` now carries `refreshToken`:
- `catalog-availability`: always includes the exact token for the active
soft intent.
- `catalog`: includes the matching token during an active intent lease,
otherwise `null`.
- `provider-configuration`: `refreshToken` is always `null`.
- Ready results include `refreshToken` when a `catalog-loading` lease is
active; otherwise `null`.
- Hardened `AbortSignal` and timer handling to avoid reentrancy issues
and prevent stale callbacks from erasing newer work.
- **Migration**
- Update callers to use the new task:
- `const task = session.complete(...); const result = await task;`
- Use `task.refreshToken` immediately to latch intent.
- Update `onDidChange` listeners:
- Compare `event.refreshToken` to the latched `task.refreshToken` before
refreshing.
- Treat `catalog` events with `refreshToken: null` as unrelated to the
current intent.
- Adjust types:
- `complete()` now returns `SqlCompletionTask` (still awaitable).
- Handle the refined `SqlSessionChangeEvent` union with per-reason
`refreshToken` semantics.
- Do not serialize or introspect tokens; compare by identity only.
<sup>Written for commit a0522c4.
Summary will update on new commits.</sup>
<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/198?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->1 parent 0f350ef commit 1b4c1af
7 files changed
Lines changed: 1340 additions & 106 deletions
File tree
- docs/vnext
- src/vnext
- __tests__
- test/vnext-types
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
92 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
93 | 97 | | |
94 | 98 | | |
95 | 99 | | |
96 | 100 | | |
97 | | - | |
| 101 | + | |
98 | 102 | | |
99 | 103 | | |
100 | 104 | | |
| 105 | + | |
| 106 | + | |
101 | 107 | | |
102 | 108 | | |
| 109 | + | |
103 | 110 | | |
104 | 111 | | |
105 | 112 | | |
| |||
118 | 125 | | |
119 | 126 | | |
120 | 127 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
125 | 143 | | |
126 | 144 | | |
127 | 145 | | |
| |||
0 commit comments