Commit 64677b0
committed
fix(os-summary): cache Darwin sw_vers product version across prompt callers (#95145)
Addresses the reviewer P1 from clawsweeper on PR #95189: resolveRuntimePromptOs()
is invoked from embedded attempt, compaction, and CLI runtime-prompt callers
on every prompt build, so the Darwin branch was synchronously spawning sw_vers
once per prompt without reuse. resolveOsSummary() already caches its full
summary by platform/release/arch tuple, but the underlying macosProductVersion()
helper spawned sw_vers unconditionally on each call — so resolveRuntimePromptOs's
direct call to macosProductVersion() bypassed the existing cache entirely.
Add a module-level cachedMacosProductVersionByRelease map keyed by os.release().
The macOS marketing product version is stable for the life of a process for a
given kernel release; once resolved, both resolveOsSummary() and
resolveRuntimePromptOs() reuse the cached string and no longer re-spawn
sw_vers. Non-Darwin output is unchanged.
Also export a test-only __resetOsSummaryCachesForTests() helper that clears
both module-level caches, and wire beforeEach() hooks into the existing test
file. Without the reset, the new cache exposes a pre-existing test-isolation
gap — the 'falls back to os.release on darwin when sw_vers returns blank' case
reuses kernel release 25.5.0 from an earlier case that already cached
'26.5.1', so the cache would return the earlier mock and the fallback case
would never exercise its fallback. The reset hook makes each test case
authoritative for its own mock.
Two new cache regression tests:
- reuses cached macOS product version across repeated calls (asserts
spawnSync is called exactly once across 3 invocations)
- runtime-prompt and os-summary share the cached Darwin product version
(asserts resolveRuntimePromptOs called after resolveOsSummary for the
same kernel release does not re-spawn sw_vers — the two helpers share
the module-level cache)
Verification:
- node scripts/run-vitest.mjs src/infra/os-summary.test.ts
src/agents/system-prompt.test.ts
src/agents/embedded-agent-runner/run/attempt-system-prompt.test.ts
→ all 3 shards pass (11 + 1 + 4 tests)
- pnpm tsgo:core → clean
- pnpm tsgo:core:test → clean1 parent 8b3cb34 commit 64677b0
2 files changed
Lines changed: 111 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
| |||
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
26 | 33 | | |
27 | 34 | | |
28 | 35 | | |
| |||
106 | 113 | | |
107 | 114 | | |
108 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
109 | 119 | | |
110 | 120 | | |
111 | 121 | | |
| |||
166 | 176 | | |
167 | 177 | | |
168 | 178 | | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
15 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
16 | 32 | | |
17 | 33 | | |
18 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
19 | 48 | | |
20 | 49 | | |
21 | 50 | | |
| |||
0 commit comments