fix(omo-senpi): freeze the shared models.json parse and type it deeply readonly
Merged
SU
1mo ago+44+44+01234567890123456789-3-3-0123456789
Summary
readModelsJsoncached one parsedmodels.jsonper process and returned the same object to every caller (todaycustomModelProvidersand the credential-rotation policy reader). The return type wasunknown, so a future caller could narrow it and write into it, silently changing what every other reader in the process sees. This is the #11034 follow-up to #10485 / #10493; both current callers only read, so nothing is broken today.- The parse is now deep-frozen before it enters the cache, and the return type is a deeply readonly JSON type, so a write attempt fails to typecheck and also throws at runtime. The issue accepts either prong; this PR does both because the freeze also protects callers that bypass the types.
- Cache behavior is unchanged: one parse while the file's mtime and size are unchanged, an edited file is re-read, a removed file returns null.
Changes
packages/omo-senpi/src/components/model-profile/models-json.ts: new exportedModelsJsonValue(deeply readonly JSON type) as the return type;deepFreezewalks a fresh parse once before it is cached; a parse that yields no value is normalized tonull, which the two callers already treat the same as the previousundefinedcase.packages/omo-senpi/src/components/model-profile/models-json.test.ts: one new test that writes into the returned parse through a mutable view and asserts both writes throw and a later read still returns the original content.changes/unreleased/11034.md: changelog fragment.
QA & Evidence
- What was tested: the new mutation test in
models-json.test.ts, before and after the fix.
Observed result: before the fix the writes succeeded silently and the test failed; after the fix, the wholemodel-profilesuite (9 files, including both callers' tests) passes 140/140, and the pre-existing cache tests still pin the same-object, edited-file, and removed-file behavior.
Artifact:.omo/evidence/20261029-models-json-immutable/red-models-json-test.txt,.omo/evidence/20261029-models-json-immutable/green-tests-typecheck.txt(local only, per repo policy)
Why sufficient: the runtime prong is proven by the failing-then-passing test, and cache behavior is pinned by the unchanged pre-existing tests. - What was tested: the type prong, with a temporary probe file (deleted after the run) that attempts an index write and an array
pushthrough the public return type, plus the package typecheck without the probe.
Observed result: with the probe,tsgoreportserror TS2542: Index signature in type '{ readonly [key: string]: ModelsJsonValue; }' only permits readinganderror TS2339: Property 'push' does not exist on type 'readonly ModelsJsonValue[]'; without it,tsgo --noEmit -p packages/omo-senpi/tsconfig.jsonexits 0 with no diagnostics, so both existing callers compile against the readonly type unchanged.
Artifact:.omo/evidence/20261029-models-json-immutable/typecheck-probe.txt,.omo/evidence/20261029-models-json-immutable/green-tests-typecheck.txt
Why sufficient: the acceptance criterion is exactly that a writing caller fails to typecheck; the probe is that caller, and the clean package typecheck shows no legitimate caller needed changes.
sha256sum .omo/evidence/20261029-models-json-immutable/red-models-json-test.txt
cef988ed20706012b060451185d761e09aef7831867aee3cec4e49c667f9b63f
sha256sum .omo/evidence/20261029-models-json-immutable/green-tests-typecheck.txt
85186b960bb1ed48056cadfb6b19f6706c0207ec6152d6cd3993d828ce6c010f
sha256sum .omo/evidence/20261029-models-json-immutable/typecheck-probe.txt
8611290a454832f38730a8a5b82f123eb8f522f5ef4153eba91cdc8bc6ccb2a8
Risks & Residuals
- A caller somewhere outside this package that relied on mutating the returned value would now throw. Mitigated: a repo-wide search shows the only readers are the two callers in this component, both read-only, and their tests pass. Accepted residual: none known.
- The full
test:senpigate (build + stage + whole package suite) was not run locally; the component suite and the package typecheck were. Residual risk is covered by CI.
Automated Checks
bun test packages/omo-senpi/src/components/model-profile/
tsgo --noEmit -p packages/omo-senpi/tsconfig.json
Related Issues
Closes #11034
Summary by cubic
readModelsJson now deep-freezes the cached models.json parse before sharing it and returns a deeply readonly JSON type (closes #11034). A caller that writes into the returned value fails to typecheck and throws at runtime, instead of silently changing what every other reader in the process sees.
- Both existing callers in the component only read, so no call sites need changes; cache behavior is unchanged (one parse per unchanged stamp, re-read after edits,
nullfor a missing file). - Adds a test asserting writes throw and that the cached value keeps its original content.