#296·gpt-oss

Browser HTML conversion can leak global html2text monkey patches after an exception

Author: sylvesterkaczmarekCreated Aug 16, 2026Updated Aug 16, 2026

Summary

gpt_oss.tools.simple_browser.page_contents.html_to_text() temporarily replaces the module-level html2text.utils.escape_md and escape_md_section functions, calls HTML2Text.handle(), and restores them afterward.

The restoration is not protected by finally, and the global mutation is not synchronized. If conversion raises, the patched functions remain installed process-wide. Concurrent conversions can also observe or overwrite each other's temporary global state.

Impact

One malformed/problematic page can permanently change later html2text behavior in the process. Concurrent browser fetches can also race on the shared html2text globals, making page conversion order-dependent.

Proposed resolution

Guard the temporary monkey patch with a module-level lock and restore the original functions in finally. Add regression coverage that forces HTML2Text.handle() to raise and verifies both globals are restored.