Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 3 files.
1 file is newly checked for coverage.
Full summary · PHP report · JS report Coverage check overridden by
Covered by non-unit tests
|
7c012ed to
59ce146
Compare
On WordPress.com Simple the locale follows the logged-in user through wp-admin and the REST calls it makes, so `get_locale()` there answers with the reader's language rather than the site's. A French blog read by an Italian admin reported Italian, and both halves of the language split inherited it: the copy written into new pages, and the language the prompt told the model to write the drafts in. The launchpad chrome was right and the site's own content was wrong — the exact inversion the split exists to prevent. `get_blog_lang_code()` is the blog's own `lang_id` setting and is what Simple means by the site language; the coming-soon page already resolves it this way for the same reason. Atomic and self-hosted do not define that function and keep `get_locale()`, so their behaviour is unchanged — verified live. The stub the suite uses returns '' by default, which is both what a blog with no language set returns and what keeps every other test on the non-Simple path.
The wizard fires a full tailoring whenever the user pauses for more than a second and a half, so an answer is ready the moment they press Finish. That part earns its tokens. Persisting it does not: every speculative run was written to the server, and only the last one could ever be used. Those writes are far from inert. PUT /tailored stores the output as the site's `ai_output`, which is what decides whether the launchpad opens on the wizard or on the task list — so a user who paused mid-sentence and then closed the tab came back to a checklist built from a half-typed description, with no route back to the wizard. The same write clears the skipped and completed options and re-baselines completion reporting, and logs a `tailored` record, so the analytics plane counted one tailoring per typing pause rather than one per user. Splitting the call leaves the prewarm doing the expensive part and none of the writing: prepareTailoring() produces the output, commitTailoring() persists it and moves the Tracks context onto the run that produced it, and only Finish commits. tailor() is the two back to back, so the path without a prewarm behaves as before. The commit half lives in its own module because tailor.ts imports the JWT client, which the type-stripping test runner cannot load; split off, the persist and fall-back-on-rejection logic is finally testable. One reporting change rides along: `duration_ms` now measures the tailoring alone rather than tailoring plus the PUT, and for a prewarmed run it is that background call's own latency — which is what the number was always meant to describe.
59ce146 to
af6920b
Compare
Part of DOTOBRD-474
Proposed changes
Two follow-ups to #52485, both found while testing that work rather than reading it.
1. The site language on WordPress.com Simple
Found on a Simple site whose account language and site language differ.
get_locale()there answers with the reader's language rather than the site's. A French blog read by an Italian admin reported Italian.get_blog_lang_code()is the blog's ownlang_idsetting and is what Simple means by the site language. The coming-soon page in this same package already resolves it this way, for the same reason.Atomic and self-hosted do not define that function and keep
get_locale(), so their behaviour is unchanged — verified live on an Atomic site before and after.2. The prewarm was persisting every speculative run
The wizard fires a full tailoring whenever the user pauses for more than 1.5s, so an answer is ready the moment they press Finish. That part earns its tokens — this PR does not change it, and the prewarm still costs one AI call per distinct pause. What it changes is that the speculative run was also being written, and only the last one could ever be used.
Those writes are not inert:
PUT /tailoredstores the output as the site'sai_output, which is whatdecideInitialView()reads to choose between the wizard and the task list. A user who paused mid-sentence and then closed the tab came back to a checklist built from a half-typed description, with no route back to the wizard.tailoredLogstash record, so the analytics plane counted one tailoring per typing pause rather than one per user — inflating the count and dragging the duration average toward the fastest calls.tailor()is split in two:prepareTailoring()produces the output and writes nothing,commitTailoring()persists it and points the Tracks context at the run that produced it. The prewarm stops at prepare; only Finish commits.tailor()is now the two back to back, so the path without a prewarm behaves exactly as before.The commit half is its own module because
tailor.tsimports the JWT client, which the type-stripping test runner cannot load — split off, the persist-and-fall-back-on-rejection logic is finally under test (4 new cases, including the 422-rejects-the-AI-output path that previously had none).One reporting change rides along:
duration_msnow measures the tailoring alone rather than tailoring plus the PUT, and for a prewarmed run it is that background call's own latency, which is what the number was always meant to describe.Related product discussion/links
Does this pull request change what data or activity we track or use?
The
tailoredLogstash record now fires once per completed wizard instead of once per typing pause, and itsduration_msno longer includes the PUT round-trip. No new fields, no new events.Testing instructions
The site language (needs a Simple site)
Needs a Simple site with the AI Launchpad enabled, where the account language and the site language differ — say account Italian, site French.
await wp.apiFetch( { path: '/wpcom/v2/ai-launchpad' } )—site.languageshould be the site's language (fr), whileuser_languagestays the account's (it). Before this change both came backit.Then confirm nothing moved on Atomic:
site.languageshould still equalget_locale()there.site.languageand in the AI-written drafts regardless.The prewarm (either platform)
jetpack-ai-querycall fire (that is the prewarm, as before) and noPUT /ai-launchpad/tailored. On trunk the PUT fires here.PUT /ai-launchpad/tailoredshould fire, and the list should render from it — the pause before Finish should make it land noticeably faster than a cold run, confirming the prewarm is still being reused.🤖 Generated with Claude Code