Skip to content

bug(python): external_handler deadlocks when callback re-enters same Bash instance #1320

@chaliy

Description

@chaliy

Split from #1312.

Summary

In Python bindings, using external_handler with Bash(python=True, external_functions=[...]) can deadlock if the handler callback calls back into the same Bash instance, e.g. via bash.read_file(...) or bash.fs().

This is related to #1312 as motivation, but it is a separate issue from exposing persistent custom builtins on Bash/BashTool.

Repro

from bashkit import Bash

async def read_memory(ctx) -> str:
    return ctx["bash"].read_file("/workspace/memory.md")

actions = {"read__memory": read_memory}

bash = Bash(
    python=True,
    external_functions=["read__memory"],
    external_handler=handler,
)

async def handler(fn_name: str, _args: list, kwargs: dict):
    ctx = {"bash": bash}
    method = actions[fn_name]
    return await method(ctx)

Calling the external function from python3 -c ... deadlocks when the callback reaches back into the same Bash instance.

Expected

One of:

  • this pattern is explicitly documented as unsupported, with guidance for the intended workflow
  • or the Python binding prevents/rejects the re-entrant call cleanly instead of deadlocking
  • or the underlying re-entrancy issue is fixed

Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions