Probe suggestion status before catching up a waiting frame
Stacked on #5827
This follows the bill-suggestion catch-up logic in #5827. It stays a draft until #5827 lands, then should be retargeted to refactor/ai-plumbing.
Problem
The waiting frame navigated to #show as soon as the ActionCable subscription reported connected, guarded by a sessionStorage key written once per suggestion id. That key was never cleared, so a still-pending answer could navigate before the result was stored, and a later open could trust a flag left by an earlier session.
Behaviour
- The Stimulus controller asks
#showfor{ status }when the cable subscribes (on connect, or on theconnectedmutation) and navigates the frame only for a terminal status —complete,failedorcancelled. A pending answer leaves the waiting frame in place for the broadcast. #showin both suggestion controllers answers JSON with only the suggestion status. The stored proposal and rationale are not part of that response.- The one-shot
sessionStorageflag is gone; a reopened dialog always checks the current status.
Validation
- Full Rails suite on this branch: 19,330 runs / 212,938 assertions / 0 failures / 0 errors / 32 skips.
- JS controller test (
node --test test/javascript/ai_suggestion_controller_test.mjs): 5 tests, 5 pass. - Focused controller tests: 30 runs / 189 assertions / 0 failures / 0 errors.
- Biome check, erb_lint and RuboCop are clean.
Summary by cubic
Changes how the AI suggestion waiting frame catches up and enforces that model calls run inside jobs, not on web threads.
The waiting frame now asks #show for the stored status when the cable subscribes and navigates only for a terminal status (complete, failed, cancelled), replacing the sticky one-shot sessionStorage flag. A pending answer leaves the waiting frame up for the broadcast, and a reopened dialog always rechecks the server. #show returns JSON with only the status, hiding the stored proposal and rationale.
Every transport call (generate, judge, embed, ocr, probe) now runs Ai::Capsule.check!, which raises outside a job or capsule in development and test. Web requests and non-AI jobs that call a transport directly fail; tests that call the plumbing directly opt in via ai_capsule!.
New enforcement
- Framework feature requesters, tool calls, and document imports hand work to worker jobs instead of calling transports on the web thread.
- Only evals may call a model outside a job:
Eval::GenerationClientandlib/tasks/evals.rakewrap runs inAi::Capsule.outside. - New
Sure/AiOutsideCapsuleRuboCop cop flags opt-outs outsideapp/models/eval/**andlib/tasks/evals.rake. - Architecture tests cover the capsule boundary and that a replayed or redelivered step never reports a generation batch or run ending twice.
Summary by CodeRabbit
- Bug Fixes
- Suggestion dialogs now update reliably when a suggestion finishes, fails, or is cancelled, including when the connection is established late.
- Pending suggestions and unsuccessful status checks no longer trigger an unexpected navigation.
- Status requests return only the suggestion’s status, without including stored details such as bill names or rationale.