Skip to content

AI Launchpad: read the site language from the blog, and stop the prewarm from persisting - #52569

Open
Copons wants to merge 3 commits into
trunkfrom
mag-16-ai-launchpad-simple-site-locale
Open

Copons wants to merge 3 commits into
trunkfrom
mag-16-ai-launchpad-simple-site-locale

Conversation

@Copons

@Copons Copons commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

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.

  • On 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.
  • Both halves of AI Launchpad: internationalize the wizard, the created pages, and the AI output #52485's language split then inherited it: the copy written into newly created pages, and the language the prompt tells the model to write the drafts and page intros in. The launchpad chrome was correctly in the reader's language 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 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 /tailored stores the output as the site's ai_output, which is what decideInitialView() 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.
  • The same write clears the skipped and completed options and re-baselines completion reporting.
  • It logs a tailored Logstash 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.
  • It moved the Tracks context onto a run that was about to be thrown away, so wizard events fired after a pause were attributed to it.

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.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 under test (4 new cases, including the 422-rejects-the-AI-output path that previously had none).

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.

Related product discussion/links

  • DOTOBRD-474

Does this pull request change what data or activity we track or use?

The tailored Logstash record now fires once per completed wizard instead of once per typing pause, and its duration_ms no 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.

  1. Open Site Setup and run the wizard.
  2. In the console, await wp.apiFetch( { path: '/wpcom/v2/ai-launchpad' } )site.language should be the site's language (fr), while user_language stays the account's (it). Before this change both came back it.
  3. The task list chrome and the task subtitles should be Italian; the generated first post and About page drafts should be French.
  4. Click a page task's CTA — the created page's title and heading come from the server in the site language.

Then confirm nothing moved on Atomic: site.language should still equal get_locale() there.

⚠️ Much of the created-page copy still reads English on both platforms: those are new PHP originals that GlotPress only picked up when #52485 merged. What this PR changes is which language is asked for, which is visible in site.language and in the AI-written drafts regardless.

The prewarm (either platform)

  1. Reset the launchpad so the wizard shows, open it, and pick a goal.
  2. On step 2, type a name and a partial description, then stop typing for a few seconds — watch the Network tab. You should see the jetpack-ai-query call fire (that is the prewarm, as before) and no PUT /ai-launchpad/tailored. On trunk the PUT fires here.
  3. Without pressing Finish, close the tab and reopen Site Setup. You should get the wizard again. On trunk you land on a task list tailored to the half-typed description.
  4. Now run the wizard through to Finish. Exactly one PUT /ai-launchpad/tailored should 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

@Copons Copons self-assigned this Sep 21, 2026
@github-actions

github-actions Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (WordPress.com Site Helper), and enable the mag-16-ai-launchpad-simple-site-locale branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack-mu-wpcom-plugin mag-16-ai-launchpad-simple-site-locale

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

github-actions Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Sep 21, 2026
@jp-launch-control

jp-launch-control Bot commented Sep 21, 2026

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 3 files.

File Coverage Δ% Δ Uncovered
projects/packages/jetpack-mu-wpcom/src/features/ai-launchpad/js/lib/prewarm.ts 0/107 (0.00%) 0.00% 4 💔
projects/packages/jetpack-mu-wpcom/src/features/ai-launchpad/helpers.php 112/198 (56.57%) 0.84% 1 ❤️‍🩹
projects/packages/jetpack-mu-wpcom/src/features/ai-launchpad/js/lib/tailor.ts 0/189 (0.00%) 0.00% -33 💚

1 file is newly checked for coverage.

File Coverage
projects/packages/jetpack-mu-wpcom/src/features/ai-launchpad/js/lib/commit-tailoring.ts 85/85 (100.00%) 💚

Full summary · PHP report · JS report

Coverage check overridden by Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code .

@Copons
Copons force-pushed the mag-16-ai-launchpad-simple-site-locale branch from 7c012ed to 59ce146 Compare September 21, 2026 18:08
@Copons Copons changed the title AI Launchpad: read the site language from the blog, not from the request AI Launchpad: read the site language from the blog, and stop the prewarm from persisting Sep 21, 2026
@Copons Copons added Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Sep 21, 2026
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.
@Copons
Copons force-pushed the mag-16-ai-launchpad-simple-site-locale branch from 59ce146 to af6920b Compare September 22, 2026 13:06
@Copons
Copons marked this pull request as ready for review September 22, 2026 13:23

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code [mu wpcom Feature] Ai Launchpad [Package] Jetpack mu wpcom WordPress.com Features [Status] In Progress [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant