model-writtenrun 767 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Andrzej Doros reported production crashes when a PL/Python set-returning function was invalidated mid-iteration, tracing the use-after-free to saved arguments allocated in the deleted procedure context #1.
- Matheus Alcantara reproduced the problem and submitted a patch moving saved arguments into the SRF memory context, but also found recursive calls could lose their call depth, argument stack, and globals when the procedure was replaced #2.
- Tom Lane explained that active executions must retain their original function body and state, recommending reference counting; when Matheus identified the difficulty of preserving references between ValuePerCall invocations, Tom pointed to SQL-language functions as the model #4 #5 #6.
- Matheus replaced the narrow allocation fix with a funccache.c conversion that stores a per-call-site cache in fn_extra, retains the procedure through a memory-context callback, and manages SRF iteration and expression shutdown explicitly #7.
- Tom raised the choice between PostgreSQL 20, PostgreSQL 19 during beta, and backpatching; Heikki Linnakangas supported inclusion in PostgreSQL 19, Nathan Bossart and Melanie Plageman agreed, and Tom chose that target while opposing stable-branch backpatching on risk grounds #8 #10 #11 #12 #13.
- Tom's detailed review found procedure lookup outside PG_TRY could leave the execution-context stack unbalanced, and requested less trigger-classification refactoring, consistent cache-pointer names, and better comments #14.
- Matheus addressed those concerns, added a self-invalidating SRF regression test, and fixed a Python-reference leak he found during self-review by making the memory-context callback clean up interrupted SRFs during error aborts #15.
- Tom committed the revised patch as 9bcb8a694b, with local lifetime and reference-management changes, reorganized cleanup code and comments, and LIMIT tests covering early termination; the commit targets master only because the invasive fix depends on infrastructure unavailable before PostgreSQL 18 #16.
- Matheus acknowledged the final review and thanked Tom for committing, leaving the development-branch fix complete with no further patch pending in the thread #17.