Skip to content

Validate model names against effective configuration (#26) - #32

Merged
datacas merged 3 commits into
mainfrom
issue-26-effective-model-telemetry
Sep 23, 2026
Merged

datacas merged 3 commits into
mainfrom
issue-26-effective-model-telemetry

Conversation

@datacas

@datacas datacas commented Sep 22, 2026

Copy link
Copy Markdown
Owner

Summary

  • Accept models declared in the effective repository profiles without weakening the closed validation set.
  • Keep configured model additions scoped to each Telemetry instance.
  • Record the four closed model-resolution states and retain rows when an executor reports an unrecognised model.
  • Count unrecognised mismatches in model drift without persisting the reported unknown name.
  • Document the requested-versus-resolved model contract.

No adapter behavior was changed.

Verification

  • python -m unittest discover -s tests -p "test_*.py" -q — 462 passed.
  • python -m compileall -q scripts tests — passed.
  • python scripts/validate-package.py — passed.
  • git diff --check — passed.
  • Post-change code review — no P0/P1 findings.
  • Security review — no confirmed vulnerabilities.

Closes #26

@datacas

datacas commented Sep 22, 2026

Copy link
Copy Markdown
Owner Author

Initial review — CHANGES_REQUESTED

Reviewed the accumulated diff from the merge base 8a802ae to head
562af4a0ef294830d9aeb2b8bdf42c2ebac8060b, not only the last commit:
scripts/telemetry.py, scripts/router.py, scripts/cycle.py,
docs/instrumentation.md, and the three test files.

The design is sound and well argued: configuration stays with the caller,
models_from_profiles is a clean projection, the per-instance set keeps two
repositories apart, and the four closed model_resolution states are a better
contract than the old two-column comparison. The added tests cover every new
path. What is missing is the old path: this store is append-only and
long-lived, and one of the changes silently reinterprets rows that are already
in it.

Conventions applied: CONTRIBUTING.md (validator plus full unittest run before
a pull request); no AGENTS.md or CLAUDE.md in this repository.


Findings

[REV-001] · high · open · blocks:yes — model_drift silently drops every row written before this change

Affects scripts/telemetry.py:627-633 (model_drift), with
summary()["model_drift"] downstream.

model_drift no longer compares the model_requested and model_resolved
columns; it now requires payload["model_resolution"] to be
mismatch_known or mismatch_unrecognized. No row written by a previous
version of this module carries that key — its payload is {} — so every
historical drift observation disappears from both model_drift() and
summary(). SCHEMA_VERSION is unchanged at 1 and there is no migration or
backfill, so nothing marks the discontinuity either.

This is precisely the failure the surrounding code argues against in its own
comments: a row that says nothing is being read as agreement, and the drift
count goes to zero without anything having drifted. Given the file's stated
purpose — telling a change in the work apart from a change in the instrument
months later — losing the prior campaigns' drift is the expensive direction of
the error.

Reproduced at runtime. A row written by the pre-PR telemetry.py (from
8a802ae), then read back by the head revision against the same database file:

OLD model_drift: [{'task_id': '42', 'role': 'implement',
                   'requested': 'claude-sonnet-5', 'resolved': 'claude-opus-5'}]
NEW model_drift on the same DB: []
NEW summary: 0 of 1 stages
row columns still hold the drift: claude-sonnet-5 -> claude-opus-5 | payload: {}
schema_version of that row: 1 | current SCHEMA_VERSION: 1

The columns still hold the evidence; only the reader stopped looking at it.
A fallback in model_drift for rows with no model_resolution — comparing the
two columns as before — would preserve the history without weakening the new
token. Bumping SCHEMA_VERSION and reading the older version through the old
rule would do the same more explicitly. Either way, a test that writes a row
without the token and asserts it is still reported would have caught this.

[REV-002] · medium · open · blocks:no — CycleRecorder mutates a caller-owned Telemetry, so a shared store leaks one repository's models into another's

Affects scripts/cycle.py:146-147 and scripts/telemetry.py:427-443.

Telemetry.__init__ documents the intent plainly: "They are deliberately per
instance: two repositories in one process must not share their additions."

CycleRecorder.__init__ then calls telemetry.add_known_models(...) on an
instance it does not own. The isolation therefore holds only when each
repository also gets its own Telemetry object. Nothing in the constructor
signature or the type says so, and Telemetry is otherwise reusable — it is
keyed by repo_id per call, not per instance.

Verified at runtime on one store:

store.add_known_models({"private-model-a"})     # repository A's configuration
store.record_stage("owner/repo-b", "7", "implement",
                   model_requested="private-model-a")   # accepted -> row 1

test_configured_models_are_scoped_to_the_telemetry_instance covers two
separate instances, which is the case that already worked; the shared instance
is the one that breaks the stated invariant. Passing the models at
construction from the same caller that loads the profiles, or scoping the
additions by repo_id, would make the guarantee match its wording.

[REV-003] · medium · open · blocks:no — validate_reference and record_stage now disagree about model_requested

Affects scripts/telemetry.py:330-341 and scripts/telemetry.py:509-511.

validate_reference is exported so a caller can refuse a value before
paying for a dispatch, and its docstring commits to being the same check:
"It is deliberately the same function rather than a second copy of the rules.
Two validators agree until one of them is edited."
After this change the
module-level path falls back to known_models() — the toolkit defaults alone —
while Telemetry._checked uses the effective set. For a model declared only in
.code-cycle.yml, the pre-check refuses what the store would accept:

validate_reference: REFUSED -> 'model_requested' must name a model this toolkit
knows, not 'private-model-a'. ...

No caller is affected today: scripts/run_cycle.py only pre-checks repo_id,
task_id, and status. The finding is that the divergence the docstring warns
about now exists and is invisible, so the first caller to pre-check a model
name inherits a false refusal. Either make the exported entry point take the
effective set, or state in its docstring that model fields are out of its
scope.

[REV-004] · low · open · blocks:no — model_resolution is absent, not unreported, when the caller omits model_resolved

Affects scripts/telemetry.py:472-478 and docs/instrumentation.md.

The token is computed only under if "model_resolved" in fields. A
record_stage call that never mentions the key — a plain stage row rather than
a dispatch — stores payload: {}, so the row carries no model_resolution at
all rather than unreported. Confirmed:

record_stage(..., model_requested="claude-sonnet-5")   # no model_resolved
payload without model_resolved: {}

record_dispatch always passes the keyword, so the practical effect is small.
But the documentation now states that the payload carries the closed token,
and any consumer reading model_resolution has to handle a fifth state,
missing, that the closed set does not name. This is the same distinction
REV-001 turns on, which is why it is worth closing rather than leaving implicit.

[REV-005] · low · open · blocks:no — no CHANGELOG.md entry for a documented contract change

CONTRIBUTING.md does not require one, so this is the repository's practice
rather than a rule: 8a802ae, 8f9bfaf, and b4fdda5 each updated
CHANGELOG.md, 54e1ee0 did not. This change adds a stored field and alters
the meaning of model_drift, which is the kind of thing the changelog has been
recording. Advisory only.


Security triage and audit

Triage flagged the change as sensitive: it edits an input-validation path and
widens a closed allowlist using values that come from repository configuration.
The cc-security-review pass was therefore run over the diff and the trust
boundary it crosses.

No confirmed vulnerabilities. The widening is narrower than it first looks.
Every model value still passes the full _checked identifier pipeline before
the closed-set test — type, MAX_IDENTIFIER_LENGTH, IDENTIFIER_PATTERN, and
the CREDENTIAL_PREFIXES scan — so .code-cycle.yml cannot use the wider set
to smuggle prose or a credential-shaped secret into the store. What the
allowlist now guarantees is "a name this repository declared" rather than "a
name this toolkit ships", which is a data-quality property, not a trust
boundary. models_from_profiles also reads only profiles already parsed by
parse_target, so the shape is enforced upstream too.

Two potential risks, neither exploitable as written:

  • The closed-set check for model_resolved moved out of _checked and into
    Telemetry._model_observation, a single call site in record_stage. Today
    record_stage is the only insert path, so the gate holds. It is now
    defence in one place instead of in the shared validator — the same concern
    REV-003 raises from the other direction.
  • add_known_models accepts any iterable of strings with no validation at
    injection time. Values only face the identifier rules when a row is written,
    so a malformed configured name fails late, at the write, rather than when it
    is accepted.

Executed commands and observed results

Command Result
python -m unittest discover -s tests -p "test_*.py" -q OK — 462 tests, 9.2s
python scripts/validate-package.py VALID — 12 skills, shared sections in sync, manifests aligned
git diff --check clean
Legacy-row reproduction (pre-PR writer, head reader, one database) REV-001 confirmed — drift [1 row] → []
Shared-instance reproduction on one Telemetry REV-002 confirmed — repo B accepted repo A's model
validate_reference("model_requested", <configured model>) REV-003 confirmed — refused
record_stage without model_resolved REV-004 confirmed — payload: {}

The preflight succeeded: the suite is pure Python with no services, database, or
ports to own, so execution-backed verification ran in full. Every finding above
was observed at runtime, not inferred from reading the diff.

Not verified

  • The behaviour of a real executor dispatch reporting a resolved model. Both
    passes exercise record_dispatch through test doubles; no actual Claude or
    Codex dispatch was performed, so result.model_resolved was never observed
    coming from a live receipt.
  • Windows behaviour, beyond what the PowerShell CI job covers.

CI

All four check runs on this head are green:

Check Workflow State
Skills, manifests, and Bash installer Validate package SUCCESS
PowerShell installer Validate package SUCCESS
Skills, manifests, and Bash installer Validate package (second run) SUCCESS
PowerShell installer Validate package (second run) SUCCESS

gh pr checks 32 reports 4 passed, 0 failed, 0 pending, none skipped. Validate package is the only workflow this repository defines for pull requests, and it
ran; no expected gate is missing. The PR is not a draft and carries no labels,
so no label-driven suite was skipped.

Worth noting that green CI is consistent with REV-001: the regression is in how
existing data is read, and the suite only ever reads rows it wrote itself in the
same process.

Residual risk

  • Any telemetry database already in use loses its accumulated drift history the
    moment this merges, and nothing in the schema records that it happened
    (REV-001). The rows survive; the question stops being answerable from them.
  • The per-instance model scope is an invariant held by convention at the call
    site rather than by the type (REV-002).
  • Whether an executor ever reports a model outside the effective set — the case
    mismatch_unrecognized exists for — remains untested against a live
    dispatch.

Verdict

CHANGES_REQUESTED. REV-001 blocks approval: it is a silent regression on
data this store exists to accumulate, and a fallback of a few lines closes it.
REV-002 through REV-005 are worth addressing in the same pass but do not block
on their own.

@datacas

datacas commented Sep 22, 2026

Copy link
Copy Markdown
Owner Author

PR 32 targeted resolution

Reviewed head: 562af4a0ef294830d9aeb2b8bdf42c2ebac8060b
Fix commits: a120b59, 0c5d900

All review findings are resolved:

[REV-001] · high · resolved · blocks:yes — model_drift silently drops every row written before this change

  • model_drift now falls back to the historical model_requested and model_resolved columns when model_resolution is absent.
  • Added a regression test that removes the token from a stored row and verifies the mismatch remains visible.
  • This preserves drift from rows written before the new token contract.

[REV-002] · medium · resolved · blocks:no — CycleRecorder mutates a caller-owned Telemetry, so a shared store leaks one repository model set into another

  • Effective profile models are now stored by repo_id in the shared telemetry instance.
  • The repository-specific model set is used for requested-model validation and resolved-model classification.
  • Added a shared-store isolation test covering acceptance in one repository and rejection in another.

[REV-003] · medium · resolved · blocks:no — validate_reference and record_stage disagree about model_requested

  • Exported validate_reference now accepts the already-resolved effective model set through model_names.
  • Its contract documents that repository configuration must be injected by the caller, keeping it aligned with record_stage without reading configuration itself.
  • Added coverage for an injected repository model.

[REV-004] · low · resolved · blocks:no — model_resolution is absent, not unreported, when model_resolved is omitted

  • A row with model_requested but no model_resolved now records model_resolution: unreported.
  • Added a regression test for the omitted field case.

[REV-005] · low · resolved · blocks:no — no CHANGELOG.md entry for the documented contract change

  • Added the effective-model and resolution-token contract to the Unreleased changelog.

Verification:

  • Focused telemetry suite: 61 tests passed.
  • Full suite: 466 tests passed.
  • Python compilation, package validation, and git diff --check passed.
  • GitHub checks: 4/4 passed on head 0c5d900, including both Bash and PowerShell installers.

Post-change review:

  • Accumulated diff reviewed against origin/main; no P0/P1 correctness or regression findings remain.
  • Security review found no confirmed vulnerabilities. The effective model set remains closed, unrecognized executor observations are not persisted, and database writes remain parameterized.
  • Residual risk is limited to the existing boundary that effective profile models must be supplied by the configuration-loading caller; no live provider execution was introduced by this change.

No approval or merge was performed.

@datacas

datacas commented Sep 23, 2026

Copy link
Copy Markdown
Owner Author

Rereview — APPROVED

Previous reviewed head: 562af4a0ef294830d9aeb2b8bdf42c2ebac8060b
Current head: 0c5d900395a13b8c2405b44ccb27b1b7f4f06a34
Merge base: 8a802ae

I reviewed the full accumulated diff against origin/main, not just the fix commits. It touches 8 files (+291/−24): scripts/telemetry.py, scripts/router.py, scripts/cycle.py, docs/instrumentation.md, CHANGELOG.md, and three test files.

Conventions applied: CONTRIBUTING.md, which asks for the validator and a full unittest run. There is no AGENTS.md or CLAUDE.md.

Changes since the previous review

Two commits landed after the last review: a120b59 and 0c5d900.

  • Legacy rows in model_drift. A row with no model_resolution token now falls back to comparing the model_requested and model_resolved columns.
  • Per-repository models. Telemetry.add_known_models(repo_id, models) now stores configured models separately for each repository. _model_names(repo_id) and _model_observation look them up by repo_id, and CycleRecorder passes its own repo_id.
  • Injected model set. validate_reference(..., model_names=...) now accepts a model set supplied by the caller.
  • unreported token. record_stage now writes model_resolution: unreported when model_requested is present and model_resolved is omitted.
  • Changelog and docs. There is a new CHANGELOG.md entry under Unreleased, and docs/instrumentation.md now describes the legacy fallback.
  • Tests. Four new tests: shared-store isolation, the injected set, a legacy row, and an omitted resolved model.

Previous findings

[REV-001] · high · resolved · blocks:yes — model_drift silently drops every row written before this change

Fixed and verified by running it. I wrote rows to one SQLite file with the pre-PR scripts/telemetry.py, taken from a temporary worktree at 8a802ae. I then read that file back with the head revision:

old writer / old reader: [{'task_id': '42', 'requested': 'claude-sonnet-5', 'resolved': 'claude-opus-5', ...}]
new reader:              [{'task_id': '42', 'requested': 'claude-sonnet-5', 'resolved': 'claude-opus-5', ...}] | summary: 1 | payloads: [{}, {}, {}]

Two edge cases also behave as before. A legacy row with model_resolved=None is still excluded, and a legacy row whose two models match is not counted as drift. Rows written by the new code always carry the token whenever a model field is present, so the fallback only ever applies to genuinely old rows.

[REV-002] · medium · resolved · blocks:no — CycleRecorder mutates a caller-owned Telemetry, so a shared store leaks one repository's models into another's

Fixed and verified by running it. I used one shared Telemetry and called add_known_models("owner/repo-a", {"private-model-a"}):

repo-a model_requested=private-model-a  -> accepted
repo-b model_requested=private-model-a  -> refused
repo-b model_resolved=private-model-a   -> {'model_resolution': 'mismatch_unrecognized'}, column None

Both the requested-model check and the resolved-model classification are now scoped by repository.

[REV-003] · medium · resolved · blocks:no — validate_reference and record_stage disagree about model_requested

Fixed and verified by running it for the case that was reported. A model declared only in configuration used to be refused by the pre-check. It is now accepted when the caller injects it:

validate_reference("model_requested", "private-model-a", model_names={"private-model-a"}) -> 'private-model-a'

The injected set replaces the built-in models instead of adding to them. That leaves a narrower gap, which I've raised separately as REV-006 because the root cause and the fix are different.

[REV-004] · low · resolved · blocks:no — model_resolution is absent, not unreported, when the caller omits model_resolved

Fixed and verified by running it. record_stage(..., model_requested="claude-sonnet-5") now stores {'model_resolution': 'unreported'}. A row with neither model field still stores {}, which is correct: it is not a dispatch observation.

[REV-005] · low · resolved · blocks:no — no CHANGELOG.md entry for a documented contract change

Fixed. The Unreleased entry covers per-repository injection, the closed requested-model set, the four resolution tokens, and the preserved historical drift.


New findings

[REV-006] · low · open · blocks:no — validate_reference(model_names=...) replaces the built-in models instead of adding to them

Affects scripts/telemetry.py:330-346 and scripts/telemetry.py:410-417.

record_stage accepts a model_requested from the built-in models plus the constructor's models plus that repository's models. validate_reference passes model_names straight through as the entire permitted set. The docstring still promises "The same check record_stage would make", and says configured names "must be supplied through model_names". A caller reading that would naturally pass models_from_profiles(effective_profiles). If the repository overrides a default profile's model, that set drops the built-in model the override replaced, and the pre-check then refuses it. I confirmed this at runtime on one store:

validate_reference("model_requested", "claude-sonnet-5", model_names={"private-model-a"}) -> REFUSED
validate_reference("model_requested", "claude-sonnet-5")                                 -> 'claude-sonnet-5'
store.record_stage("owner/repo-a", ..., model_requested="claude-sonnet-5")               -> accepted (row 3)

This is advisory. No caller passes model_names today: scripts/run_cycle.py only pre-checks status and non-model references. It is the same trap REV-003 described, moved one parameter over. There are two ways to close it:

  • have validate_reference combine model_names with known_models(), the way Telemetry._model_names does;
  • or document that model_names is the complete permitted set, and add a test that fixes those semantics.

Security triage and audit

Triage marked this change as sensitive because it still edits an input-validation path and a closed allowlist fed by repository configuration. I ran the cc-security-review checks inline as part of this rereview, not as a separately invoked pass.

No confirmed vulnerabilities.

  • Every model value still goes through the identifier pipeline before the allowlist check: type, MAX_IDENTIFIER_LENGTH, IDENTIFIER_PATTERN, and CREDENTIAL_PREFIXES. That includes values validated against the per-repository and injected sets.
  • repo_id is used only as a dictionary key in _configured_models_by_repo and is validated before the row is written.
  • The configured model sets are now isolated per repository, so REV-002 is closed at the trust boundary too.
  • An unrecognised model_resolved is still never persisted; it is replaced by None plus mismatch_unrecognized.
  • SQL stays parameterised. The only new raw SQL is a test-only UPDATE.

One potential risk, carried over and not exploitable: add_known_models and validate_reference(model_names=...) accept any iterable of strings without checking it when the set is supplied. A malformed name fails later, at write time, not at injection.

Verification

Command Result
python -m unittest discover -s tests -p "test_*.py" -q OK: 466 tests
python -m compileall -q scripts tests OK
python scripts/validate-package.py VALID: 12 skills, shared sections in sync, manifests aligned
git diff --check origin/main...HEAD clean
Legacy database: pre-PR writer, head reader REV-001 resolved: drift kept, summary 1
Shared-store isolation (requested and resolved) REV-002 resolved
validate_reference with injected configured model REV-003 resolved
validate_reference with injected set plus a built-in model REV-006 confirmed: refused, while record_stage accepts it
record_stage without model_resolved REV-004 resolved: unreported

Not verified:

  • A live executor dispatch reporting a resolved model. record_dispatch is only exercised through test doubles.
  • Windows behaviour beyond what the PowerShell CI job covers.

CI

gh pr checks 32: 4 passed, 0 failed, 0 pending, 0 skipped, on head 0c5d900.

Check State
Skills, manifests, and Bash installer (×2) SUCCESS
PowerShell installer (×2) SUCCESS

Validate package is the only workflow this repository defines for pull requests, and it ran. The PR is not a draft and has no labels, so no suite was skipped by policy.

Residual risk

  • REV-006: the first caller that pre-checks a model with an injected set may be refused a built-in model the store would accept.
  • The requested/resolved contract has not been exercised against a real dispatch.
  • SCHEMA_VERSION is still 1. Old and new rows are told apart by whether the payload token is present, not by the schema version. This works because new rows always carry the token whenever a model field is present.

Verdict

APPROVED. All five previous findings were fixed and verified by running them. The one new finding, REV-006, is low severity and does not block approval. Every CI check passed on the reviewed head. No merge was performed.

@datacas
datacas merged commit 525fdfd into main Sep 23, 2026
4 checks passed
@datacas
datacas deleted the issue-26-effective-model-telemetry branch September 24, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate model names against the effective configuration

1 participant