Skip to content

fix(ai): benchmark uncached vision requests - #172

Merged
scotej merged 1 commit into
mainfrom
agent/fix-ai-session-startup
Aug 3, 2026
Merged

fix(ai): benchmark uncached vision requests#172
scotej merged 1 commit into
mainfrom
agent/fix-ai-session-startup

Conversation

@scotej

@scotej scotej commented Aug 3, 2026

Copy link
Copy Markdown
Owner

What changed and why

AI sampling on the reported Windows CPU setup aborted every live vision request at 90 seconds. The saved benchmark looked fast only because its warmup and three measured passes reused one byte-identical prompt; llama-server's prompt cache skipped both image encodes after the discarded warmup, recording a ~12.6 s p95 even though changing live frames needed roughly 127–148 seconds.

This change disables prompt caching for benchmark requests, fingerprints the cache-cold benchmark protocol, refuses to use stale timing data for cadence/timeout decisions, and gives unmeasured or stale models the existing five-minute upper bound. The old contaminated benchmark is preserved for display as stale and can be replaced normally by re-benchmarking.

Closes #171

Manual test

  • npm run tauri dev launched and the changed surface behaves as described
    n-a: the reporter's Windows/Gemma CPU environment was not available; the 130-second live-request path is covered by a fake-clock regression test
  • Checked in both themes and at reduced-motion
    n-a: no visual styling or motion changed

Compatibility surfaces

No wire, identity, database, updater, or persisted-store shape changed. Existing benchmark records are preserved, but records from the old benchmark protocol are intentionally treated as stale until re-measured.

  • SQLite schema / src-tauri/src/db/migrations/
  • Peer wire format (trystero payloads, session/pomodoro/AI-alert messages)
  • Identity derivation (BIP39 → ed25519/x25519, pair links, contact links)
  • Persisted settings shape / store keys
  • Updater manifest or release artifact names

Gates

  • npm run build && npm run lint && npm run test
  • npm run check-tokens && npm run check-strings && npm run check-contrast
  • npm run check-migrations && npm run check-stories
  • npm run build-storybook && npm run check-a11y
  • cd src-tauri && cargo fmt --check && cargo clippy && cargo test
  • cd src-tauri && cargo deny check

Also checked version lockstep and diff whitespace. Local results: 1,068 frontend tests, 316 Storybook accessibility tests, and 117 native tests passed.

Merge style

  • Squash
  • Merge commit

Summary by CodeRabbit

  • AI Model Reliability

    • Increased the fallback request timeout for unbenchmarked models to five minutes.
    • Stale or unavailable benchmark data no longer influences timeout, slowdown, or sampling decisions.
    • Models with stale benchmarks cannot be enabled until current performance data is available.
    • Benchmark-based speed and sampling information is hidden when results are outdated.
  • Performance

    • Benchmarking now measures cache-cold requests to better reflect live inference performance.
    • Existing measurements using the previous protocol are treated as outdated.

Copilot AI review requested due to automatic review settings August 3, 2026 07:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7ce916b5-7f6b-479f-afd4-56d399caa974

📥 Commits

Reviewing files that changed from the base of the PR and between 027844c and aa5f3d2.

📒 Files selected for processing (12)
  • ARCHITECTURE.md
  • PLAN.md
  • README.md
  • src/features/ai/ModelGuide.tsx
  • src/features/ai/ModelPickerContainer.tsx
  • src/features/ai/benchmark.ts
  • src/features/ai/benchmarkGate.ts
  • src/features/ai/sampleLoop.ts
  • src/features/settings/categories/AiCategory.tsx
  • tests/unit/ai-benchmark-gate.test.ts
  • tests/unit/ai-benchmark.test.ts
  • tests/unit/ai-sample-loop.test.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (6)
  • GitHub Check: Installer (macOS)
  • GitHub Check: Installer (Windows)
  • GitHub Check: Analyze (rust)
  • GitHub Check: Rust (macOS)
  • GitHub Check: Rust (Windows)
  • GitHub Check: Frontend
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx,rs}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,rs}: Never add telemetry; the application is local-only. Never instruct users to paste model files or BIP39 mnemonics into an AI chat service.
Add comments only when the reason is non-obvious; identifiers should carry the meaning and code should read top-to-bottom.
Maintain scope discipline: do not refactor adjacent code while implementing a feature, add abstractions for hypothetical needs, or expand a bug fix beyond the bug.

Files:

  • tests/unit/ai-benchmark-gate.test.ts
  • src/features/ai/ModelGuide.tsx
  • src/features/settings/categories/AiCategory.tsx
  • src/features/ai/benchmarkGate.ts
  • src/features/ai/ModelPickerContainer.tsx
  • src/features/ai/benchmark.ts
  • tests/unit/ai-benchmark.test.ts
  • tests/unit/ai-sample-loop.test.ts
  • src/features/ai/sampleLoop.ts
tests/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use Vitest for unit and integration tests; component tests are not currently supported because the harness uses node-env without RTL/jsdom, so component behavior belongs in Storybook and axe-core checks.

Files:

  • tests/unit/ai-benchmark-gate.test.ts
  • tests/unit/ai-benchmark.test.ts
  • tests/unit/ai-sample-loop.test.ts
**/*

📄 CodeRabbit inference engine (CLAUDE.md)

Use one focused change per commit, with a Conventional Commit subject such as feat:, fix:, chore:, docs:, or ci:; PRs are squash-merged.

Files:

  • tests/unit/ai-benchmark-gate.test.ts
  • README.md
  • src/features/ai/ModelGuide.tsx
  • src/features/settings/categories/AiCategory.tsx
  • src/features/ai/benchmarkGate.ts
  • src/features/ai/ModelPickerContainer.tsx
  • src/features/ai/benchmark.ts
  • ARCHITECTURE.md
  • PLAN.md
  • tests/unit/ai-benchmark.test.ts
  • tests/unit/ai-sample-loop.test.ts
  • src/features/ai/sampleLoop.ts
**/*.md

📄 CodeRabbit inference engine (CLAUDE.md)

Do not create new documentation files unless explicitly requested; update canonical documentation, CHANGELOG.md, or ISSUES.md when justified.

Files:

  • README.md
  • ARCHITECTURE.md
  • PLAN.md
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

src/**/*.{ts,tsx}: All design-token values—colors, spacing, fonts, radii, shadows, motion, and z-indexes—must come from src/design/tokens.ts; do not use raw hex values, arbitrary px, or inline cubic-bezier values.
User-facing toast and notification copy must live in src/strings.ts; prefer centralized strings for JSX text and aria-label values.
Maintain WCAG AA contrast for every text/background pairing in both themes, do not convey information by color alone, and honor the global reduced-motion kill switch; new motion must be gated by default.
Treat peer wire formats and identity derivation as cross-version contracts; coordinate changes so older builds and existing stored data remain compatible.
Every component and feature component must have a Storybook story.

Files:

  • src/features/ai/ModelGuide.tsx
  • src/features/settings/categories/AiCategory.tsx
  • src/features/ai/benchmarkGate.ts
  • src/features/ai/ModelPickerContainer.tsx
  • src/features/ai/benchmark.ts
  • src/features/ai/sampleLoop.ts
🔇 Additional comments (33)
src/features/ai/benchmark.ts (5)

2-5: LGTM!


45-56: LGTM!


77-80: LGTM!


124-131: LGTM!


327-348: LGTM!

tests/unit/ai-benchmark.test.ts (3)

117-135: LGTM!


214-217: LGTM!


238-241: LGTM!

ARCHITECTURE.md (2)

428-430: LGTM!


457-457: LGTM!

src/features/ai/benchmarkGate.ts (2)

2-2: LGTM!


22-24: LGTM!

src/features/ai/ModelPickerContainer.tsx (2)

33-37: LGTM!


526-529: LGTM!

src/features/ai/ModelGuide.tsx (2)

16-16: LGTM!


31-31: LGTM!

src/features/ai/sampleLoop.ts (6)

68-68: LGTM!


82-83: LGTM!


95-98: LGTM!


142-151: LGTM!


1351-1373: LGTM!


1385-1386: LGTM!

src/features/settings/categories/AiCategory.tsx (2)

37-37: LGTM!


103-109: LGTM!

PLAN.md (2)

87-87: LGTM!


147-147: LGTM!

README.md (1)

174-174: LGTM!

tests/unit/ai-benchmark-gate.test.ts (1)

94-111: LGTM!

tests/unit/ai-sample-loop.test.ts (5)

15-15: LGTM!


155-155: LGTM!


1277-1337: LGTM!


1354-1354: LGTM!


2008-2011: LGTM!


📝 Walkthrough

Walkthrough

The AI benchmark now measures cache-cold inference requests. Stale or missing benchmarks are excluded from readiness, cadence, displayed speeds, and timeout decisions. Unbenchmarked models use a five-minute request timeout, with updated documentation and regression tests.

Changes

AI benchmark freshness

Layer / File(s) Summary
Cache-cold benchmark protocol
src/features/ai/benchmark.ts, tests/unit/ai-benchmark.test.ts, ARCHITECTURE.md
Benchmark requests disable prompt caching. The engine fingerprint invalidates previous cache-warm measurements. Stale timings are unavailable for runtime decisions.
Runtime benchmark decisions
src/features/ai/benchmarkGate.ts, src/features/ai/ModelPickerContainer.tsx, src/features/ai/ModelGuide.tsx, src/features/ai/sampleLoop.ts, src/features/settings/categories/AiCategory.tsx
Stale or missing benchmarks block activation, hide measured speeds, use fallback cadence, and select the five-minute maximum timeout.
Fallback documentation and lifecycle validation
ARCHITECTURE.md, PLAN.md, README.md, tests/unit/ai-benchmark-gate.test.ts, tests/unit/ai-sample-loop.test.ts
Documentation describes the five-minute fallback. Tests cover stale fingerprints, cache-disabled requests, readiness, and 130-second inference.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant ModelPickerContainer
  participant benchmarkGate
  participant sampleLoop
  User->>ModelPickerContainer: Enable AI
  ModelPickerContainer->>benchmarkGate: Check active model readiness
  benchmarkGate-->>ModelPickerContainer: Return ready or unbenchmarked
  ModelPickerContainer->>sampleLoop: Start model sampling
  sampleLoop->>sampleLoop: Select current benchmark or five-minute fallback timeout
Loading

Possibly related PRs

Suggested reviewers: copilot, claude

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: benchmarking uncached vision requests.
Description check ✅ Passed The description covers the change, rationale, testing status, compatibility surfaces, gates, and merge style.
Linked Issues check ✅ Passed The changes address issue #171 by preventing premature AI vision request timeouts during session activation.
Out of Scope Changes check ✅ Passed The documentation, implementation, and regression tests are directly related to the benchmarking and timeout objectives.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch agent/fix-ai-session-startup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@scotej
scotej merged commit 4f26de0 into main Aug 3, 2026
20 checks passed
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.

Ai failure

2 participants