Skip to content

Plugin extensible xblock services - #927

Open
felipemontoya wants to merge 3 commits into
openedx:masterfrom
eduNEXT:fmo/extensible-services
Open

felipemontoya wants to merge 3 commits into
openedx:masterfrom
eduNEXT:fmo/extensible-services

Conversation

@felipemontoya

Copy link
Copy Markdown
Member

This PR adds the capability for openedx plugins to add services to the xblock_runtime. This is needed to be able to offer xblocks (e.g: ORA) capabilities from inside a platform plugin (e.g: openedx-ai-extensions) in a way that does not create a dependency hell and lets the xblock respond gracefully when the service is not present.

References:

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Jun 10, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @felipemontoya!

This repository is currently maintained by @openedx/axim-engineering.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@felipemontoya

Copy link
Copy Markdown
Member Author

@bradenmacdonald @symbolist @pdpinch as fellow maintainers of the xblock library, what do you think about this?

@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Jun 11, 2026

@Henrrypg Henrrypg left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey folks, i was playing a bit with this implementation and i like it!

Here we have an example of how it could work with ora :) a quick test only adding suggestions as a raw text, but we definitively can go deeper

Screencast.from.12-06-26.17.08.11.webm

Comment on lines +130 to +134
**Why the ``needs``/``wants`` gate stays in front.** The declaration check
runs before any entry-point lookup, so a plugin-provided service is only ever
handed to blocks that explicitly asked for it. ``wants`` gives blocks a
portable soft-dependency: the same block works on installs with and without
the providing package, enabling features conditionally.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can understand why we have a needs declaration (to show an appropriate error when a required service is not available). But I never understood the point of declaring wants. It just seems like pointless boilerplate.

"We don't allow XBlocks to access a service unless they declare it with needs/wants, because if they don't declare it, ___" What? It would still work totally fine if every XBlock implicitly wants every service, without having to declare them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradenmacdonald Remind me-- do XBlocks break in a loud way upon system startup if they're missing the 'needs' declaration? Or only when someone calls the service function?

If it's only when someone calls the service function, it does seem nearly useless. The only advantage I could think of is that you'd never be handling a None when using the service function, but I'm not sure throwing an exception is exactly better.

If it's upon system startup, or when trying to invoke the block at all, it could at least surface dependency issues early.

@mphilbrick211 mphilbrick211 moved this from Ready for Review to In Eng Review in Contributions Jul 13, 2026
@mphilbrick211

Copy link
Copy Markdown

Hi @felipemontoya! Is this still in progress?

@felipemontoya

Copy link
Copy Markdown
Member Author

@mphilbrick211 yes it is. It is just slowly simmering for a while waiting for any more comments while I start working on this again. I'm a core contributor to this repo so I could update and merge but I dont have immediate pressure as it will probably be 2~4 weeks before I come back to this initiative.

@Henrrypg

Henrrypg commented Dec 2, 2026 •

Copy link
Copy Markdown

Hello everyone, we're working with WGU team on integrate xblock-ai-evaluation with openedx-ai-extensions framework. It would be so helpful to get this PR merged for that effort.

As i see this PR needs an approval from one more maintainer

@felipemontoya may you rebase this PR please?

Hi @Kelketek, can somebody from your team help us with a review here please?

felipemontoya and others added 3 commits December 2, 2026 17:52
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@felipemontoya
felipemontoya force-pushed the fmo/extensible-services branch from a47654f to d23091d Compare December 2, 2026 22:53
@felipemontoya

Copy link
Copy Markdown
Member Author

Rebased. Happy to see other use cases for this extension point. I was planning to push this when I start working on ORA2 and the AI connection but I'm happy to start with your case.

@Kelketek Kelketek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to look into the code part later, but I had a few questions/things to consider about the proposal as it stands.

service still gets ``NoSuchServiceError``.
2. Return the runtime-provided service from ``_services`` if present
(unchanged).
3. **New:** if the runtime has nothing, try

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we make deliberately installed plugin services priority? While this means extensions could potentially collide with officially supported services, the alternative is that the default services can never be overwritten, when it might be useful to do so.

3. **New:** if the runtime has nothing, try
``_load_service_from_entry_point(block, service_name)``, which loads the
provider class from the ``xblock.service.v1`` group and instantiates it as
``provider_class(runtime=self, xblock=block)``.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure this is a sufficient number of arguments for instantiating an XBlock service? Several services require the user to be specified. Some others use custom functions, such as the replace_urls service taking an optional lookup_asset_url argument which some runtimes provide and others do not.

Placing the lookup after the ``_services`` miss, inside the one method every
runtime inherits, gives complete coverage (all Open edX runtimes, the
workbench, third-party runtimes that don't override ``service()``) for a
single small change, and gives a hard guarantee: *runtime-provided services

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the advantage of being able to override core services may be worth a few more lines of code.

Currently there's no way to do this. I will concede that I know of no one in particular trying to do this, but we could expect that teams might want to run an experimental iteration on top of a service without running a custom fork of the platform, or a service might get 'promoted' to core and change the semantics of a service for a team who isn't ready to move yet, and is still installing the originating plugin.

fallback is one dict lookup); loud ``AmbiguousPluginError`` when two installed
packages claim the same service name, instead of last-write-wins — the exact
failure mode that makes monkey-patching unacceptable; a sanctioned override
path (``xblock.service.v1.overrides``) when replacing a default implementation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to imply that, yes, we are allowing overriding of default implementations. But that's in contradiction to the earlier statement that plugins won't be able to override the base service, and it would also imply that the existing services would need to be converted to plugins somehow. That would be a significant refactoring.

is intentional; and ``register_temp_plugin`` for tests.

**Why ``provider_class(runtime=…, xblock=…)``.** This mirrors the
constructor of the reference ``Service`` class, gives the provider the two

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the first I've heard of the reference Service class. I've never seen it used, nor do I know of any real service that accepts the runtime as an initialization argument. In the platform, all the services accept individual, specific arguments, and they are never the runtime.

The omission is glaring enough that I have to imagine it was intentional-- the idea being that each service should be completely separate and not depend on calling another service, which would be the most probable use of using the runtime directly.

Comment on lines +130 to +134
**Why the ``needs``/``wants`` gate stays in front.** The declaration check
runs before any entry-point lookup, so a plugin-provided service is only ever
handed to blocks that explicitly asked for it. ``wants`` gives blocks a
portable soft-dependency: the same block works on installs with and without
the providing package, enabling features conditionally.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradenmacdonald Remind me-- do XBlocks break in a loud way upon system startup if they're missing the 'needs' declaration? Or only when someone calls the service function?

If it's only when someone calls the service function, it does seem nearly useless. The only advantage I could think of is that you'd never be handling a None when using the service function, but I'm not sure throwing an exception is exactly better.

If it's upon system startup, or when trying to invoke the block at all, it could at least surface dependency issues early.

************

* Installed packages can provide named runtime services to consenting blocks
on any runtime that uses the default resolution path; no host-application

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only host application that matters is the platform. The only other consumer of XBlocks I know of is the workbench, and I've already got a plan to deprecate it. Attempts to get other teams to use XBlocks have failed and they are in practice dependent on openedx-platform's implementation.

We don't have to be fearful of making changes in the host-application in fear of screwing up other environments.

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

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: In Eng Review

Development

Successfully merging this pull request may close these issues.

6 participants