Share the `CompactOnRequest` toolset with its per-run copies so durable engines accept it
Written by Claude Code on behalf of @DouweM.
Part of #14403
Why we make these changes
CompactOnRequest.get_toolset built a new FunctionToolset on every call, and for_run returned replace(self), so each run contributed a toolset leaf the durable engine never registered. BaseDurabilityCapability._reject_runtime_toolsets matches leaves by identity against the construction-time toolsets. It refuses the unregistered leaf on every engine whose spec lists 'function' in unsupported_runtime_toolset_kinds: Temporal, Prefect, and the harness engines Lambda, Absurd, pgtask, Azure and Render. DBOS is unaffected.
The capability now builds its toolset once and hands that instance to each per-run copy, following the Planning pattern. Because replace() resets init=False fields, for_run sets the field on the copy explicitly. Each copy still resets its pending request and its max_per_run count. The fix goes through the existing engine-spec contract, without checking engine names.
This is only part of #14403:
- On Temporal, the strategy also needs
deferred_capability_idsto work inside an activity. #14874 makes that change. - The planned compaction rework (A2) turns
CompactOnRequestinto a pure trigger and removes itscompactdurable operation. This fix still holds after A2, because a trigger still contributes itscompact_contexttool throughget_toolset.
New public surface
none
Verification
test_runs_under_a_durable_engine_that_refuses_runtime_function_toolsetsruns a JSON-codec recording engine that declaresunsupported_runtime_toolset_kinds={'function'}. It does two runs withmax_per_run=1and asserts that compaction ran in both and that the second request in run one was refused. It does not assert durable operation names, which A2 will change. Without the fix it fails withFunctionToolset 'compact_on_request' cannot be added at runtime with recording.- Manual check on the Lambda fake (
FakeDurableContext): a run followed by a journal replay failed onmainand passes with the fix, with no steps re-invoked. The existingCompactOnRequestunit tests and the DBOS durable test still pass. - A Temporal run + replay test comes once #14874 lands, or as part of A2.
What changes for existing users
CompactOnRequest is no longer refused by durable engines that reject runtime function toolsets. Nothing changes outside durable execution.
Decisions
- Pre-push review (call 1 of 3) at
24687e634a: no blocking findings. Its one optional finding concerned the_capability_loads.pyhunk, which is now dropped. 5f55894d29only removes lines from the reviewed tree: the_capability_loads.pyhunk (it belongs to #14874), the Temporal test, and an assertion on the durable operation name. Because the new commit adds nothing to the reviewed tree, it needed no new pre-push review.- #15347 also edits
test_compact_on_request.pyand adds the sameRecordingDurabilityimport, so expect a trivial conflict in the import block. - douwebot round at
5f55894d29(2026-11-30 20:33 CST):6718165d6dis test-only. It movesFunctionToolsetRejectingDurabilityintotests/harness/_recording_durability.pyand drops the copies in the planning and memory tests. It had no pre-push review: the delta is exempt as test code only, chaining from the reviewed24687e634a. The line-211 finding was declined; douwebot itself refuted it.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.