Awesome Reviewers

Null/undefined checks, optional chaining, and non-null assertions must reflect the actual type contract and runtime invariants — not an assumed one.

Example:

// Bad: type already guarantees `provider` is defined — this check is dead and misleading
const failingModel = message.provider !== undefined && registry.find(message.provider);

// Good: trust the type, let `find()` signal "not resolvable" via its own return value
const failingModel = registry.find(message.provider);

// Bad: asserts an invariant that doesn't hold on every call path
async #ensureLoaded(): Promise<void> {
  this.#indexLoadPromise ??= this.#loadIndex(this.#persist!.indexPath);
}

// Good: guard for the case where the invariant doesn't apply
async #ensureLoaded(): Promise<void> {
  if (!this.#persist) return;
  this.#indexLoadPromise ??= this.#loadIndex(this.#persist.indexPath);
}