Repository navigation
Add background job for ai hint request - #1135
Conversation
Clearing input when either sucessfully completed or failed getting Ai hint.
This controller will replace the existing controller, FriendlyErrorMessagesController, once polling is enabled in editor-ui and deployed.
Test coverage94.23% line coverage reported by SimpleCov. |
ApprovabilityVerdict: Needs Human Approval Macroscope's review found this PR requires human approval — The new AI-hint flow is feature-gated and clears processed inputs, but also changes shared worker concurrency and database pooling. Confirm deployed connection headroom and overrides, plus the intended retention policy for newly persisted code/error inputs. Needs human approval because:
You can add or adjust custom eligibility rules. Learn more. |
zetter-rpf
left a comment
There was a problem hiding this comment.
Run below script:
heroku config:set -a editor-api-staging
WORKER_DB_POOL=8
GOOD_JOB_QUEUES='create_students_job:1;import_schools_job:1;salesforce_sync:2;default:1;ai_hints:2'
We normally configure env vars using terraform
That's a good idea since we have separate logging in place and don't need to keep them. Maybe we have a weekly job that runs with Good Job cron that deletes hint rows older than a day? |
zetter-rpf
left a comment
There was a problem hiding this comment.
Nice one, I've added a couple of suggestions
|
@cocomarine please can you put |
> [!WARNING] > Merge after [the editor-api PR](RaspberryPiFoundation/editor-api#1135) is merged. ## Status - Part of RaspberryPiFoundation/digital-editor-issues#1932 - Depends on RaspberryPiFoundation/editor-api#1135 (must be merged first) Switches AI hints to the new async endpoints. The client creates a hint, then polls until it's ready, instead of holding one request open while inference runs. ## What's changed? - Added new endpoints `createAiHint` (`POST /api/ai_hints`) and `getAiHint` (`GET /api/ai_hints/:id`), each with a 5s timeout, and removes `getAiErrorHint`. - Added `pollAiHint` helper: - Polls every 1s for up to 30s, in step with [`MAX_QUEUE_WAIT` in editor-api](https://github.com/RaspberryPiFoundation/editor-api/pull/1135/changes#diff-08d4a8b75698c6d53065036fc5ea482e3e12bf9125b38829a5aef5d451ba3969). - Resolves with the hint, or rejects with an `AiHintPollError` whose `reason` is `failed`, `timeout` or `aborted`. - A 4xx client error fails straight away whereas network errors and 5xx are retried. - `AiErrorMessage`: - Uses create-and-poll. It's aborted when the error changes or the component unmounts, so polling stops instead of carrying on in the background.
Status
Moves AI hint generation off the request thread.
editor-ui PR: RaspberryPiFoundation/editor-ui#1790
The client creates a hint, gets an ID straight away, and polls until the hint is ready.
Performance considerations
🤖 Generated with help of Claude Code
What's changed?
inputis cleared once the hint completes or fails.GenerateAiHintJobruns on a new ai_hints GoodJob queue with 5 threads. It callsFriendlyErrorMessagesInferenceClientand marks the hint completed or failed.DB_POOLfirst and falls back to RAILS_MAX_THREADS. The worker in the Procfile sets DB_POOL=25 so the extra queue threads don't run out of connections.Relationship to existing
FriendlyErrorMessagesControllerAiHintsControllerfor the similar job of running the inference in the background will eventually replace it.TODO before merging
Steps to perform after deploying to production
FriendlyErrorMessagesControllerand its routes and specs.