Skip to content

feat(vnext): correlate completion refresh intent - #198

Merged
Light2Dark merged 1 commit into
dev-refactorfrom
codex/vnext-refresh-contract
Jul 25, 2026
Merged

feat(vnext): correlate completion refresh intent#198
Light2Dark merged 1 commit into
dev-refactorfrom
codex/vnext-refresh-contract

Conversation

@Light2Dark

@Light2Dark Light2Dark commented Jul 25, 2026

Copy link
Copy Markdown
Member

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

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.

Written for commit a0522c4. Summary will update on new commits.

Review in cubic

@github-actions

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 98.01% (🎯 91%) 741 / 756
🔵 Statements 97.92% (🎯 91%) 754 / 770
🔵 Functions 100% (🎯 90%) 65 / 65
🔵 Branches 96.01% (🎯 85%) 578 / 602
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/vnext/index.ts 0% 0% 0% 0%
src/vnext/relation-completion-types.ts 100% 100% 100% 100%
src/vnext/session.ts 97.88% 96.01% 100% 97.97% 146, 624, 667, 889, 927, 1009, 1336-1339, 1367-1371, 1471-1474, 1483-1489, 1496-1499, 1503-1507, 1575-1578, 2080-2083
src/vnext/types.ts 100% 100% 100% 100%
Generated in workflow #756 for commit a0522c4 by the Vitest Coverage Report Action

@Light2Dark
Light2Dark marked this pull request as ready for review July 25, 2026 17:06
@Light2Dark
Light2Dark merged commit 1b4c1af into dev-refactor Jul 25, 2026
9 checks passed
@Light2Dark
Light2Dark deleted the codex/vnext-refresh-contract branch July 25, 2026 17:06
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.

1 participant