Skip to content

Conversation

@akshayka
Copy link
Contributor

@akshayka akshayka commented Jan 18, 2026

fix: UI element interactions when defs are overridden

This change fixes a bug in which cells run as a consequence of UI
element interactions did not respect overridden definitions in
embedded apps.

This fix adds internal APIs:

  • check if the current runtime is embedded
  • get overrides of an app

This fix also fixes a bug in which nested contexts had isolated
AppKernelRunner registries. With this change, contexts now share
their parent's registry to make sure runner retrieval can happen at runtime,
in a nested context. The registries are still isolated across run sessions.

Finally, it fixes a bug in App.clone, in which CellImpls were shallow copied even though they have mutable state.

Fixes #7685

This change fixes a bug in which cells run as a consequence of UI
element interactions did not respect overriden definitions in
embedded apps.

This fix adds internal APIs:
* check if the current runtime is embedded
* get cells overriden by the passed-in definititions

This fix also fixes a bug in which nested contexts had isolated
AppKernelRunner registries; instead, contexts now share
their parents registry to ensure that the registry to make sure
runner retrieval can happen at runtime, in a nested context.

The registries are still isolated across run sessions.
@akshayka akshayka requested a review from dmadisetti as a code owner January 18, 2026 17:32
@vercel
Copy link

vercel bot commented Jan 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
marimo-docs Ready Ready Preview, Comment Jan 19, 2026 3:27pm

Request Review

@akshayka
Copy link
Contributor Author

@yairchu I believe this change fixes your minimal example, thank you for debugging and brainstorming with me. Could you try this change out and see if it feels correct? I am not sure if it fixes the "locking" in your original app, I haven't tried that out

@akshayka akshayka added the bug Something isn't working label Jan 18, 2026
@akshayka akshayka changed the title fix: fix: UI element interaction should respect overriden defs in embedded apps Jan 18, 2026
@yairchu
Copy link
Contributor

yairchu commented Jan 18, 2026

@akshayka this does solve the problem of overridden defs!

However a problem of strangely resetting sliders does remain in this example:

embed_test_a.py:

import marimo

__generated_with = "0.19.4"
app = marimo.App(width="full")


@app.cell
def _():
    import marimo as mo
    return


@app.cell
def _():
    import embed_test_b
    return (embed_test_b,)


@app.cell
def _(embed_test_b):
    clone_a = embed_test_b.app.clone()
    return (clone_a,)


@app.cell
async def _(clone_a):
    embed_a = await clone_a.embed()
    embed_a.output
    return (embed_a,)


@app.cell
def _(embed_test_b):
    clone_b = embed_test_b.app.clone()
    return (clone_b,)


@app.cell
async def _(clone_b, embed_a):
    (
        await clone_b.embed(
            defs={
                "slider": None,
                "value": embed_a.defs["value"],
                "label": "their",
                "kind": "warn",
            }
        )
    ).output
    return


@app.cell
def _():
    return


if __name__ == "__main__":
    app.run()

embed_test_b.py:

import marimo

__generated_with = "0.19.2"
app = marimo.App(width="full")


@app.cell
def _():
    import marimo as mo
    import time
    return (mo,)


@app.cell
def _():
    state = None
    return (state,)


@app.cell
def _(mo):
    slider = mo.ui.slider(0, 10, 1, 3, label="A slider")
    return (slider,)


@app.cell
def _(slider):
    slider
    return


@app.cell
def _(slider, state):
    value = slider.value if state is None else state()
    label = "our"
    return label, value


@app.cell
def _():
    kind = "info"
    return (kind,)


@app.cell
def _(kind, label, mo, value):
    mo.callout(
        mo.md(f"""
        The value of *{label}* slider is **{value}**!
        """), kind
    )
    return


@app.cell
def _():
    return


if __name__ == "__main__":
    app.run()

The slider seems to be "reseting" or recreating constantly when moved. Try to move the slider and notice how the value jumps between the dragging value and the initial value of 3.

@akshayka
Copy link
Contributor Author

Thanks so much @yairchu for trying it out, and for sharing this example — it's very helpful.

I can see the incorrect behavior in the underlying code (slider in embed_test_a is recreated when it's interacted with, causing it to reset) but I'm not sure why it's happening. If I comment out the slider overriding in the second embed call, it's not recreated. Hopefully the bug unravels as I pull on this thread.

@yairchu
Copy link
Contributor

yairchu commented Jan 19, 2026

@akshayka, if it helps, I think that it is somehow related to the undisplayed slider being recreated in the second instance of embed_test_b.

What leads me to think this:

  • If I cp embed_test_b.py embed_test_c.py and change the second instance to be an embed of embed_test_c rather than a second instance of embed_test_b, then the problem vanishes
  • The workaround I previously found, which makes the cell not run at all, still appears to solve the issue
This fixes a bug in app.clone() in which the CellImpl was shallow
copied; CellImpl has mutable state, and should not be shallow copied.
@akshayka
Copy link
Contributor Author

@yairchu, thanks so much! I pushed up additional changes, and the slider no longer resets. Want to give it one more try?

cloned_embed.mp4
@akshayka akshayka changed the title fix: UI element interaction should respect overriden defs in embedded apps Jan 19, 2026
@yairchu
Copy link
Contributor

yairchu commented Jan 19, 2026

@akshayka works great now!

@akshayka akshayka merged commit 998e900 into main Jan 19, 2026
51 of 53 checks passed
@akshayka akshayka deleted the aka/fix-embed-defs-ui-element-interaction branch January 19, 2026 16:35
@github-actions
Copy link

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.19.5-dev18

mscolnick pushed a commit that referenced this pull request Jan 19, 2026
…d apps (#7889)

fix: UI element interactions when defs are overridden

This change fixes a bug in which cells run as a consequence of UI
element interactions did not respect overridden definitions in
embedded apps.

This fix adds internal APIs:
* check if the current runtime is embedded
* get overrides of an app

This fix also fixes a bug in which nested contexts had isolated
`AppKernelRunner` registries. With this change, contexts now share
their parent's registry to make sure runner retrieval can happen at
runtime,
in a nested context. The registries are still isolated across run
sessions.

Finally, it fixes a bug in `App.clone`, in which `CellImpl`s were
shallow copied even though they have mutable state.

Fixes #7685
botterYosuke pushed a commit to botterYosuke/marimo that referenced this pull request Jan 20, 2026
…d apps (marimo-team#7889)

fix: UI element interactions when defs are overridden

This change fixes a bug in which cells run as a consequence of UI
element interactions did not respect overridden definitions in
embedded apps.

This fix adds internal APIs:
* check if the current runtime is embedded
* get overrides of an app

This fix also fixes a bug in which nested contexts had isolated
`AppKernelRunner` registries. With this change, contexts now share
their parent's registry to make sure runner retrieval can happen at
runtime,
in a nested context. The registries are still isolated across run
sessions.

Finally, it fixes a bug in `App.clone`, in which `CellImpl`s were
shallow copied even though they have mutable state.

Fixes marimo-team#7685
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

3 participants