Skip to content

fix: replace Fun.protect in transact with backtrace-free variant - #33

Merged
tiensonqin merged 1 commit into
mainfrom
fix/melange-protect
Oct 4, 2026
Merged

tiensonqin merged 1 commit into
mainfrom
fix/melange-protect

Conversation

@tiensonqin

Copy link
Copy Markdown
Contributor

Summary

impl/transact.ml wraps each transaction in Fun.protect ~finally:restore_memo. On Melange targets, Fun.protect re-raises the work exception through Printexc.raise_with_backtrace → caml_restore_raw_backtrace, which is not polyfilled — so any exception thrown inside a transaction (e.g. a schema-validation failure) surfaced as "caml_restore_raw_backtrace not polyfilled by Melange yet", masking the real error entirely.

Replace it with a local protect that keeps identical semantics — finally runs on both success and exception paths, Finally_raised still wraps a failing finally — minus backtrace preservation. Native callers lose only the original raise-site backtrace, not the exception.

Test coverage

Compiles clean (dune build impl/). Behavior-only change on the exception path; no new tests.

Link to Devin session: https://app.devin.ai/sessions/813c52cd0faf4c458fdb45ed456c0179
Open in Devin Desktop: https://app.devin.ai/desktop/session/813c52cd0faf4c458fdb45ed456c0179?variant=devin
Requested by: @tiensonqin

On Melange targets the stdlib Fun.protect re-raises the work exception
through primitives that are not polyfilled, so an exception inside a
transaction surfaced as "caml_restore_raw_backtrace not polyfilled"
instead of the real error. Use a local equivalent that keeps the same
finally/exception semantics minus backtrace preservation.
@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@tiensonqin
tiensonqin marked this pull request as ready for review October 4, 2026 10:52
@tiensonqin
tiensonqin merged commit e2bda6d into main Oct 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant