Skip to content

refactor: full rewrite of Chrome Free AI with base session caching, reusable sessions, and better response and abort signals - #33

Open
iamaamir wants to merge 9 commits into
mainfrom
feat/refactor-chrome-ai
Open

refactor: full rewrite of Chrome Free AI with base session caching, reusable sessions, and better response and abort signals#33
iamaamir wants to merge 9 commits into
mainfrom
feat/refactor-chrome-ai

Conversation

@iamaamir

@iamaamir iamaamir commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • Per-tab cancellation of stale grammar checks using AbortController registry in grammar.js
  • Base session caching per cascade level with clone-per-check isolation to reduce LanguageModel.create() calls
  • 5-minute TTL on base sessions with lazy expiry and destroySessions cleanup
  • Race-safe provider cache invalidation with generation tokens
  • Settings verification one-shot (skipSessionCache) to avoid pinning base sessions
  • Tab-removal listener aborts in-flight checks on tab close

Test Plan

  • 147 unit tests passing (ChromeFreeAIProvider, cascade signal propagation, session lifecycle)
  • 7 e2e tests passing (E2E-CFAI-001 through 007)
  • Manual Chrome Prompt API validation completed
  • Benchmark: 1 base create for 5 rapid cancels (B) and 3 sequential checks (C)

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@iamaamir iamaamir changed the title ✨ feat: per-tab cancellation, base session caching, clone-per-check, and TTL for Chrome Free AI feat: per-tab cancellation, base session caching, clone-per-check, and TTL for Chrome Free AI Jun 2, 2026
iamaamir added 8 commits June 2, 2026 21:27
- base.clone() is async (returns Promise) in real Prompt API but mock
  was synchronous — session received a Promise object, not a session,
  causing 'c.prompt is not a function' and 'c.destroy is not a function'
- Added await base.clone() in _runWithSession
- Made mock clone() async to match real API surface
- Wrapped session.destroy() in try/catch in finally block to prevent
  destroy errors from masking successful prompt results
…ation tests

Adds 42 tests covering ChromeFreeAIProvider session lifecycle:
  - isAvailable / getStatus / ensureModel
  - Base session creation, caching, reuse, concurrent dedup
  - destroySessions with generation invalidation
  - _runWithSession clone-per-check and skipSessionCache paths
  - AbortError handling and availability gates
  - Session metrics lifecycle tracking

Adds 6 cascade signal propagation tests:
  - Pre-aborted signal rejected before level attempt
  - Mid-flight abort increments aborted counter
  - AbortError stops cascade (no level 2 attempt)
  - Cache not updated on mid-flight abort
  - Unknown providerOptions passed through to _doCorrectGrammar

Modifies CascadeProvider test helper to accept _options
parameter for accurate signaling passthrough.
Remove baseSessionGenerationByLevel.delete() from TTL expiry path
which caused an extra session create on retry. Clear
_baseSessionCreatedAt in destroySessions for consistency.

Add 3 TTL unit tests (reuse within TTL, expire after TTL,
cross-level isolation) and E2E-CFAI-007 tab-removal e2e test
(close tab during in-flight check, verify abort + no crash).
@iamaamir
iamaamir force-pushed the feat/refactor-chrome-ai branch from 17f84a6 to 6e60d96 Compare June 2, 2026 15:57
@iamaamir iamaamir changed the title feat: per-tab cancellation, base session caching, clone-per-check, and TTL for Chrome Free AI feat: full re-write of Chrome Free AI with base session caching, reuseable sessions and better reponse signals Jun 2, 2026
@iamaamir iamaamir changed the title feat: full re-write of Chrome Free AI with base session caching, reuseable sessions and better reponse signals feat: full rewrite of Chrome Free AI with base session caching, reusable sessions, and better response and abort signals Jun 2, 2026
@iamaamir iamaamir changed the title feat: full rewrite of Chrome Free AI with base session caching, reusable sessions, and better response and abort signals refactor: full rewrite of Chrome Free AI with base session caching, reusable sessions, and better response and abort signals Jun 2, 2026
@sonarqubecloud

sonarqubecloud Bot commented Jun 2, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots
6.6% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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