Share the `CompactOnRequest` toolset with its per-run copies so durable engines accept it

Merged
DO
3d ago
+53-18

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_ids to work inside an activity. #14874 makes that change.
  • The planned compaction rework (A2) turns CompactOnRequest into a pure trigger and removes its compact durable operation. This fix still holds after A2, because a trigger still contributes its compact_context tool through get_toolset.

New public surface

none

Verification

  • test_runs_under_a_durable_engine_that_refuses_runtime_function_toolsets runs a JSON-codec recording engine that declares unsupported_runtime_toolset_kinds={'function'}. It does two runs with max_per_run=1 and 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 with FunctionToolset '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 on main and passes with the fix, with no steps re-invoked. The existing CompactOnRequest unit 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.py hunk, which is now dropped.
  • 5f55894d29 only removes lines from the reviewed tree: the _capability_loads.py hunk (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.py and adds the same RecordingDurability import, so expect a trivial conflict in the import block.
  • douwebot round at 5f55894d29 (2026-11-30 20:33 CST): 6718165d6d is test-only. It moves FunctionToolsetRejectingDurability into tests/harness/_recording_durability.py and 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 reviewed 24687e634a. 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.