pi: apply omp patches via prePatch (bun2nix.hook overrides patchPhase)

`bun2nix.hook` (used by upstream omp's package.nix) sets

  patchPhase = bunPatchPhase

at the end of its setup-hook unless `dontUseBunPatch` is already set.
`bunPatchPhase` only runs `patchShebangs` plus a HOME mktemp; it never
iterates over `$patches`. The standard nixpkgs `patches` attribute
therefore went into the derivation env but was silently ignored at
build time, leaving the deployed omp binary unpatched.

Switch to applying the two patches via `prePatch` (which `bunPatchPhase`
does call). Verified with strings(1) over the rebuilt binary that both
patch hunks land:

  /wrong_api_format|...|invalid tool parameters/  (patch 0001)
  stubsReasoningContent ... thinkingFormat == "openrouter"  (patch 0002)
This commit is contained in:
2026-04-25 18:18:20 -04:00
parent 318373c09c
commit 450b77140b

View File

@@ -37,17 +37,21 @@ let
in
{
home.packages = [
# `bun2nix.hook` sets `patchPhase = bunPatchPhase`, which only runs `patchShebangs` and
# silently ignores the standard `patches` attribute. Apply patches via `prePatch` instead
# so they actually take effect. Tracking: nothing upstream yet.
(inputs.llm-agents.packages.${pkgs.stdenv.hostPlatform.system}.omp.overrideAttrs (old: {
patches = (old.patches or [ ]) ++ [
# Retry without strict tools when DeepSeek (via OpenRouter) rejects strict-mode `anyOf`
# nullable unions with `Invalid tool parameters schema : field \`anyOf\`: missing field \`type\``.
# Upstream PR: pending; applies cleanly against v14.2.1.
../../patches/omp/0001-openai-completions-retry-without-strict-on-deepseek-openrouter.patch
# Stub `reasoning_content` on tool-call assistant messages for OpenRouter reasoning models.
# Fixes DeepSeek V4 Pro et al. rejecting follow-up requests with `400 The \`reasoning_content\`
# in the thinking mode must be passed back to the API`. Mirrors the existing Kimi handling.
../../patches/omp/0002-openai-completions-stub-reasoning-content-for-openrouter.patch
];
prePatch =
(old.prePatch or "")
+ ''
# 0001 retry without strict tools when DeepSeek (via OpenRouter) rejects strict-mode
# `anyOf` nullable unions with `Invalid tool parameters schema : field \`anyOf\`:
# missing field \`type\``.
patch -p1 < ${../../patches/omp/0001-openai-completions-retry-without-strict-on-deepseek-openrouter.patch}
# 0002 require `reasoning_content` for OpenRouter reasoning models so DeepSeek V4 Pro
# et al. accept follow-up requests in thinking mode.
patch -p1 < ${../../patches/omp/0002-openai-completions-stub-reasoning-content-for-openrouter.patch}
'';
}))
];