Stop rebuilding the active-capability set for every deferred capability on every hook
- Closes #13538
Before each hook, every deferred capability (each skill from Skills, for example) asked whether it was active by rebuilding the run's whole active-capability set, so N skills meant N rebuilds of an N-item set per hook. A new private RunContext._is_deferred_capability_dispatch_active answers that for one id by looking it up in the load records, and both the hook gate and is_tool_available use it.
What this gets you
20-step run with Skills | main | this PR |
|---|---|---|
| 30 skills | 149 ms | 45 ms |
| 100 skills | 1,108 ms | 80 ms |
| 300 skills | 10,069 ms | 170 ms |
Measured with a standalone script: FunctionModel, N local skills, one load_capability then tool calls, best of 3 runs.
No behaviour change: the benchmark's messages and instructions are identical on main and this PR at every size, and the old and new answers matched on all 9,248 gate checks made while running the deferred-loading, tool-availability, combine, hooks and Skills tests. No new test: dropping either half of the lookup fails existing deferred-loading and tool-availability tests (5 and 15 failures).
gpt-6.2-sol review: no major findings. It raised a hypothetical RunContext subclass that overrides active_capability_ids to drop a loaded capability; no supported subclass does that (DurableRunContext's snapshot always includes the loaded ids).
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.
Summary by cubic
Speeds up hook dispatch for runs with many deferred capabilities by answering each capability's active check with a direct lookup instead of rebuilding the full active-capability set per capability per hook.
A new private RunContext._is_deferred_capability_dispatch_active checks one capability id against the load records, replacing the set rebuilds in the hook gate and is_tool_available. No behavior change: benchmark messages and instructions are identical to main, and the old and new answers matched on all 9,248 gate checks across the deferred-loading and tool-availability tests. No unit test pins the lookup directly, since those existing tests fail if either half of the check breaks.
20-step run with Skills | main | this PR |
|---|---|---|
| 30 skills | 149 ms | 45 ms |
| 100 skills | 1,108 ms | 80 ms |
| 300 skills | 10,069 ms | 170 ms |