Files
PaperClipAI/server
Dotta 86927d4933 feat(cloud-trial): enable fast responses by default with starter inference key (#23556)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Fast responses send a brief acknowledgement in the agent's voice
while the full agent run starts.
> - During Cloud starter-inference onboarding (`free_inference_1`),
users start chatting immediately before connecting their own model
provider, so no `company_fast_responses` connection exists yet.
> - Without a default fast-response path, the first chat waits silently
while the Runner starts up and thinks.
> - This pull request enables fast responses by default while Cloud
starter inference is active, routing acknowledgements through the
server-held OpenRouter starter key with `$1` quota and `llmBlocked` gate
enforcement.
> - The benefit is immediate, responsive first-chat acknowledgements out
of the box with a clean handoff once the user connects their own model
provider.

## Linked Issues or Issue Description

Refs #23401, #23427

**Summary**
Enable fast-response acknowledgements by default for companies running
on active Cloud starter inference (`free_inference_1`), using the
existing server-side OpenRouter starter inference key.

**Problem Statement**
Fast responses currently require both the experimental
`enableFastResponses` instance flag and an explicit shared API
connection in `company_fast_responses`. New Cloud starter-inference
workspaces have no saved API connection yet, so users do not get fast
acknowledgements during their initial onboarding chat.

**Proposed Solution**
Fall back to the server-side Cloud starter inference OpenRouter key
(`FAST_RESPONSE_DEFAULT_MODEL`, `openai/gpt-oss-120b`) when a company
has no `company_fast_responses` row and is actively on trial-only
inference without a blocked gate. Respect explicit company
configuration/opt-out, enforce `responsibleUserId` and `issue:read`
authorization, disallow sponsored webhooks on the starter key, mark the
trial exhausted on HTTP 402/limit errors, and stop using the starter key
automatically once the user connects their own model provider.

## What Changed

- `server/src/services/cloud-trial-proxy.ts` &
`server/src/services/cloud-trial-inference.ts`: Added
`isCloudTrialFastResponseEligible` and `prepareCloudTrialFastResponse`.
Keeps the raw OpenRouter key strictly in server process memory, enforces
`isCompanyOnTrialOnlyInference`, the `$1` quota, and the
`work_requires_model` / `exhausted` gates, wraps `fetch` to call
`markExhausted` immediately on HTTP 402/limit responses, and probes
usage on cleanup.
- `server/src/services/fast-responses.ts`: Updated
`enqueueFastResponse`, `fastResponseSourceCurrent`, `settings`,
`availability`, `resolve`, `process`, and `history` to use Cloud starter
inference by default when no `company_fast_responses` row exists and
starter inference is active and unblocked. Explicit
`company_fast_responses` rows (including opt-out `enabled: false`)
always take precedence, and connecting a user model provider cleanly
ends starter-key usage.
- `packages/shared/src/fast-response.ts`: Added optional
`usingCloudTrialDefault?: boolean` to `FastResponseSettings`.
- `server/src/__tests__/fast-responses.test.ts`: Added regression tests
covering starter-inference default fast responses (even when
`enableFastResponses` is `false`), raw key non-leakage,
`work_requires_model` gate blocking, HTTP 402 exhaustion, explicit
opt-out, and clean handoff after connecting a user model provider.

## Verification

- `pnpm --filter @paperclipai/shared typecheck` — passed (0 errors).
- `pnpm --filter @paperclipai/server typecheck` — passed (0 errors).
- `pnpm --filter @paperclipai/server exec vitest run
src/__tests__/fast-responses.test.ts
src/__tests__/cloud-trial-inference.test.ts` — passed (44/44 tests).

## Risks

- Low risk. No database schema migration is required
(`fast_response_requests.connection_id` and `grant_id` are already
nullable). Self-hosted instances and `baseline` Cloud stacks are
unaffected because `trialInferenceEnabled` is `false`. Companies that
explicitly configure or disable `company_fast_responses` or connect
their own AI provider never fall back to the starter key.

## Model Used

- Google Gemini (Antigravity agentic runtime, thinking mode with tool
use and local code execution).

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-12-02 16:29:41 -06:00
..