Page MenuHomePhabricator

editSaved generic instrumentation doesn't handle edits made through other editors
Open, HighPublic5 Estimated Story Points

Description

@Catrope in this Slack thread:

Is it known/expected that the reusable instrumentation for edit_saved events in editSaved.js is incomplete, and does not capture edits that were not made through VisualEditor? Is a server-side version of this instrument available? (I'm guessing it was implemented client-side so that it could be used for edge-unique experiments too, but I'm doing an mw-user experiment so I can log events server-side.)
…
To make the JS instrument work correctly, we probably need to set an mw.config var or query string param on the page the user lands on after submitting an edit through the old wikitext editor

That is, currently editSaved only sends edit_saved events when these two hooks fire:

  • ve.newTarget (save specifically)
  • mobileFrontend.sourceEditor.saveComplete

Proposed solution

  1. Update mediawiki.action.view.postEdit.fireHook() / .fireHookOnPageReload() signatures
  2. Update the existing calls to .fireHook() and .fireHookOnPageReload()
  3. Update the editSaved generic instrumentation to handle the postEdit hook
  4. [Bonus] Update existing postEdit hook handlers to get the action from the payload rather than mw.config.get( 'wgPostEdit' )

AC

  • postEdit hook optional data includes:
    • revision ID of the corresponding edit
    • namespace ID of the corresponding edit
    • self-identified editing interface name (following some conventions)
    • additional contextual data object
  • Changes are compatible with existing postEdit evokers (source editor, VE, mobile editor) and downstream subscribers
  • Popular editing interfaces integrate the updated postEdit hook and self-identify (name) (see legacy/editattemptstep for reference)
    • VisualEditor (visualeditor?)
    • Mobile editor (mobile_editor or mobile_visualeditor?)
    • Wikitext source editor (wikitext?)
  • editSaved subscribes to the new postEdit hook and uses the accompanying data to fill out:
    • revision ID => page.revision_id
    • editing interface => action_source
    • interface-specific contextual data object => JSON.stringify() => action_context

Event Timeline

@mpopov what are your thoughts on whether the generic instrumentation should support edits made through different editors?

Handling all types of editors could bring in questions like whether we need a non-cache-splitting version of the instrumentation and a cache-splitting version which can handle all sources of edits.

Why does cache-splitting-ness matter here? When a user saves an edit, they make a POST request, which always bypasses caching. I could see how edge-unique vs mw-user could matter, because we can't log server-side events for edge-unique experiments, but we might be able to work around that by adding something to the response that indicates an edit happened and picking that up in JS. I believe this response should currently always be uncached because the user is logged in at that point (to an autocreated temp account); I'm not completely sure of that, or how that will change when we start caching page views for logged-in users, but it seems to me that we should be able to find a way to make the first post-edit page view uncacheable.

what are your thoughts on whether the generic instrumentation should support edits made through different editors?

I think ideally yes it should support all the major editing interfaces, to the extent possible and reasonable.

Is a server-side version of this instrument available? (I'm guessing it was implemented client-side so that it could be used for edge-unique experiments too, but I'm doing an mw-user experiment so I can log events server-side.)

It is not currently available, and offering reusable instruments via PHP SDK would be considerable effort (see @phuedx's excellent write-up in T435202: [DE1.2.2] [Spike] Could/should PHP SDK offer #use() like JS SDK?). So for now if you want to produce edit_saved events from server-side, you will have to do that for each individual experiment.

JVanderhoop-WMF set the point value for this task to 5.
JVanderhoop-WMF moved this task from Incoming to Backlog on the Test Kitchen board.
JVanderhoop-WMF added a project: OKR-Work.
JVanderhoop-WMF subscribed.

Proposed implementation: follow the same pattern in T439137: editSaved should record editing interface: create a client-side hook that fires when an edit is successfully published via wikitext editor, and editSaved should pick that up.

Ensure that the new hook includes the revisionID of the edit that was saved.

Proposed implementation: follow the same pattern in T439137: editSaved should record editing interface: create a client-side hook that fires when an edit is successfully published via wikitext editor, and editSaved should pick that up.

I looked into this because… well… Who doesn't spend their evenings walking through MediaWiki Code?!

There's already a client-side hook that fires after an edit is saved, the postEdit hook, which is already wired for all the editors that are used in production. As the source code for that hook notes, it's not the easiest hook to use:

  • It doesn't fire with the action that triggered the hook (created, published, restored, saved)
  • It doesn't fire with the revision ID of the page
  • It doesn't fire with the editor that was used to make the edit
  • It does fire with a message whose key includes the action and whose parameters include the revision ID of the page
  • It does fire with an Plain Ol' JavaScript Object, which can be modified without breaking existing uses

I'm going to amend my handwavy proposal above with the following slightly-less-handwavy proposal:

  1. Update mediawiki.action.view.postEdit.fireHook() / .fireHookOnPageReload() signatures to
type PostEditAction = "created" | "published" | "restored" | "saved";
type PostEditEditorName = … // TODO: Bikeshed!

function fireHook( action: PostEditAction, tempUserCreated: boolean, editorName: PostEditEditorName, newRevisionId: number ): void;
function fireHookOnPageReload( action: PostEditAction, tempUserCreated: boolean, editorName: PostEditEditorName, newRevisionId: number ): void;

and fire with

{
  // Existing properties
  message: …,
  tempUserCreated: …,

  // New properties
  action,
  editorName,
  newRevisionId
}
  1. Update the existing calls to .fireHook() and .fireHookOnPageReload()
  2. Update the editSaved generic instrumentation to handle the postEdit hook
  3. [Bonus] Update existing postEdit hook handlers to get the action from the payload rather than mw.config.get( 'wgPostEdit' )

Updated task per proposal from @phuedx and our discussion offline.

@KReid-WMF: Might need re-estimation?

mpopov added a subscriber: DLynch.

@DLynch: Does it make sense to add Discussion Tools to the integration AC?

It probably should, just because otherwise there's a weird split where some edits to talk pages (made in a source editor) count, while others (made in DT) don't.

Change #1360374 had a related patch set uploaded (by Phuedx; author: Phuedx):

[mediawiki/core@master] mediawiki.action.view.postEdit: Update fireHook() and fireHookOnPageReload()

https://gerrit.wikimedia.org/r/1360374

Change #1360428 had a related patch set uploaded (by Phuedx; author: Phuedx):

[mediawiki/extensions/ProofreadPage@master] ext.proofreadpage.page.editinsequence: Use fireHook() API

https://gerrit.wikimedia.org/r/1360428

Change #1361730 had a related patch set uploaded (by Phuedx; author: Phuedx):

[mediawiki/extensions/WikimediaEvents@master] ext.wikimediaEvents: Update editSaved to use postEdit hook payload...

https://gerrit.wikimedia.org/r/1361730

Being bold and moving this into review while I noodle on the updates to codebases firing the hook.

Change #1368711 had a related patch set uploaded (by Phuedx; author: Phuedx):

[mediawiki/extensions/DiscussionTools@master] ext.discussionTools.init: Use fireHook() API

https://gerrit.wikimedia.org/r/1368711

And now onto the postEdit hook handlers. For each of the following, we need to check whether the handler is looking at config variables that are set around the postEdit hook firing (e.g. wgPostEdit) that are now included in the payload parameter and, if so, update them: