Skip to content

Let the repository's configuration reach the router - #13

Merged
datacas merged 4 commits into
mainfrom
feat/config-routing
Sep 21, 2026
Merged

datacas merged 4 commits into
mainfrom
feat/config-routing

Conversation

@datacas

@datacas datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner

Why this is before the canary

CycleRecorder routed with profiles=None, so code_cycle.profiles in .code-cycle.yml never reached route(). load_profiles() already existed and already knew how to overlay a repository's declaration on the defaults — nothing called it on the production path.

The consequence only matters now: the first productive rows are about to be treated as data, and a run could have recorded a routing policy nobody declared. That is the one contamination worth a small PR to avoid.

The split

The driver loads configuration; the recorder receives what was resolved.

run_cycle.py → .code-cycle.yml → repository.selector + load_profiles(config)
             → CycleRecorder(..., profiles=profiles) → route(..., profiles=self.profiles)

CycleRecorder does not look for YAML itself, and a test asserts its source mentions neither the file name nor load_profiles. A component that reads configuration on its own can disagree with its caller about what the configuration says, and both would be writing rows.

Decisions

Repository precedence is --repo, then code_cycle.repository.selector, then an error. No inference from git remote: there is already an explicit contract, and a second resolution path would make the recorded repo_id ambiguous in exactly the dataset this is protecting.

A configuration that exists and cannot be read stops the run, rather than falling back to the defaults. Falling back is the quiet failure — it produces a row describing a policy nobody chose. --no-config asks for the defaults deliberately, and contradicting it with --config is refused.

An unknown profile name stops the run before anything is dispatched. Learning that after a stage has run means paying for a cycle to discover a typo.

PyYAML is imported only when there is a file to parse. A repository without configuration still needs nothing beyond the standard library, which is what the rest of this toolkit assumes; when a file is there and the parser is not, the error says so instead of silently using defaults.

Tests

Twelve new, of which two fail against the previous wiring (verified by reverting the one line in cycle.py: FAILED (failures=2), OK with it):

  • a declared cheap_coder.primary = claude:anthropic/claude-sonnet-5 high actually runs on Claude, and Codex is never dispatched;
  • a reroute uses the configured fallback, claude-opus-5, not the built-in one.

The rest: defaults untouched when nothing is declared; --repo wins over the selector; the selector is used when --repo is absent; neither is an error; an unknown profile name, malformed YAML, a named file that is not there, and --config with --no-config are each refused; --no-config returns the built-in profiles with a file present; and CycleRecorder given profiles routes with them while looking for no file of its own.

Verification

  • python3 -m unittest discover -s tests — Ran 358 tests ... OK (was 344).
  • python3 scripts/validate-package.py — VALID.

After this

The canary: one real cycle, then telemetry.sqlite inspected by hand. It will then demonstrate installation, real configuration, configured routing, real dispatch, recorder and SQLite in a single pass.

CycleRecorder routed with profiles=None, so code_cycle.profiles in
.code-cycle.yml never reached route(). load_profiles() existed and knew how to
overlay a repository's declaration on the defaults; nothing called it on the
production path. Every run used the built-in profiles whatever the repository
declared, and the telemetry row would have described a policy nobody chose --
which matters now precisely because those rows are about to be treated as data.

The split is the one the configuration deserves: the driver loads, the recorder
receives. run_cycle.py reads the file, resolves the repository and the profiles,
and hands the recorder something already decided. CycleRecorder does not look
for YAML itself, asserted by a test, because a component that reads
configuration on its own can disagree with its caller about what it says and
both would be writing rows.

Repository precedence is --repo, then code_cycle.repository.selector, then an
error. No inference from git remote: there is already an explicit contract and
a second resolution path would make the recorded repo_id ambiguous.

A configuration that exists and cannot be read stops the run instead of falling
back to the defaults, and an unknown profile name stops it before anything is
dispatched -- learning that afterwards means paying for a cycle to find a typo.
--no-config asks for the defaults deliberately. PyYAML is imported only when
there is a file to parse, so a repository without configuration still needs
nothing beyond the standard library.

Twelve tests, two of which fail against the previous wiring: a declared
cheap_coder lands on Claude rather than the default Codex, and a reroute uses
the configured fallback rather than the built-in one.
CI has no PyYAML and this machine does, so twelve configuration tests passed
locally and failed on every runner. Third time this session that an assumption
about the environment reached CI as a green local suite.

Both jobs now install PyYAML before running the suite, so the configuration
path is exercised rather than skipped, and the tests skip only where the parser
genuinely is not available. README and CHANGELOG name it as the runtime's one
optional dependency: needed to read .code-cycle.yml, needed for nothing else.
@datacas

datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner Author

Code Cycle Review

Status: CHANGES_REQUESTED

Reviewed the accumulated diff from origin/main...db96bf3c07597fbb320e49f8489984707f5fa1aa.

Findings

[REV-001] · medium · - · valid · blocks:yes — Validate the repository selector before dispatch

Location: scripts/run_cycle.py:104-108

repository_of() accepts any non-empty string and plan() returns it directly. run_cycle() then composes the executor prompt and dispatches the first stage; only afterward does telemetry validate repo_id in CycleRecorder._record(). With code_cycle.repository.selector: "bad selector", I reproduced plan() accepting the value, the fake Codex adapter being called once, and only then a TelemetryError for the invalid identifier. A credential-shaped selector would likewise reach the executor prompt before the telemetry guard rejects it.

Please validate the configured selector during planning, using the same repository identifier/credential rules as telemetry (ideally through a shared validator), and add coverage proving invalid and credential-shaped selectors fail with zero adapter dispatches.

[REV-002] · medium · - · valid · blocks:yes — Reject malformed nested configuration with a driver error

Location: scripts/run_cycle.py:104-108

The loader only validates the top-level YAML value. A valid YAML document such as code_cycle: not-a-mapping reaches repository_of(), whose unconditional .get() call raises AttributeError: 'str' object has no attribute 'get'. Because main() catches only CycleDriverError, the CLI emits a traceback instead of the documented configuration error and does not provide a controlled refusal. The same problem applies to other non-mapping code_cycle values.

Please validate code_cycle and repository as mappings (or make repository_of() tolerate invalid shapes and raise CycleDriverError) and add a valid-YAML malformed-shape test.

Verification

  • python3 scripts/validate-package.py — passed.
  • python3 -m unittest discover -s tests -v — 358 tests passed.
  • git diff --check — passed.
  • GitHub checks — all four required checks passed.
  • Security triage — completed; yaml.safe_load is used and no additional confirmed security finding was identified.

plan() returned whatever the configuration said. A selector of "bad selector"
was accepted, the prompt was composed, Codex was dispatched once, and only then
did telemetry refuse the identifier -- so the stage ran, was paid for, and its
row could not be written. The run happened and left no trace of having happened,
which is the one outcome this instrument cannot tolerate. A credential-shaped
selector reached the executor prompt the same way.

The repository and the work item are now checked during planning through
telemetry.validate_reference: the store's own rule, exported rather than copied,
because two validators agree until one of them is edited. The work item is
included because it is the same defect at the same cost, one line away.

Second finding, same commit: the loader validated only the top level, so the
valid document `code_cycle: not-a-mapping` reached repository_of() and raised
AttributeError from its own .get -- a traceback where a stated refusal belongs,
and load_profiles would have done the same. code_cycle, code_cycle.repository
and code_cycle.profiles must now be mappings, checked when the file is read, and
the load_profiles wrapper catches RouterError rather than every exception, so a
real bug is no longer reported as a configuration problem.

Both reproduced first: plan() returned 'bad selector' with the adapter
dispatched once, and `code_cycle: not-a-mapping` raised AttributeError. Six new
tests, of which eight checks fail against the previous code.
@datacas

datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner Author

Resolution summary

Both findings reproduced against db96bf3 before any edit, fixed in b0a31b6.

[REV-001] · medium · resolved · valid · blocks:yes — Validate the repository selector before dispatch

Valid, and the consequence is worse than a late error. Reproduced exactly as described: with selector: "bad selector", plan() returned 'bad selector', the fake Codex adapter was dispatched once, and only then did TelemetryError fire. So the stage ran, was paid for, and its row could not be written — the run happened and left no trace of having happened, which is the single outcome this instrument exists to prevent.

plan() now checks the repository through telemetry.validate_reference(), which is _checked exported rather than a second copy of the rules: two validators agree until one of them is edited. A TelemetryError becomes a CycleDriverError, so the CLI refuses through parser.error like every other configuration problem.

The work item is checked with it. --task had the identical defect at the identical cost and was one line away; leaving it would have meant fixing the reported instance of a bug and knowingly shipping its twin.

Verified after: 'bad selector' → 'repo_id' is not a reference: … contains whitespace or characters a repository, work item or model name does not use; ghp_000000000000000000 → 'repo_id' starts with 'ghp_', a published credential prefix; --task "API 7" → the same refusal on task_id. Zero dispatches and zero rows in each case.

[REV-002] · medium · resolved · valid · blocks:yes — Reject malformed nested configuration with a driver error

Valid. One correction to the record, which does not change the outcome: the traceback needs the repository to come from configuration. With --repo given, args.repo or repository_of(config) short-circuits and repository_of is never called — my first reproduction attempt passed --repo and saw a controlled error. Without it, code_cycle: not-a-mapping raised AttributeError: 'str' object has no attribute 'get', exactly as reported. load_profiles would have raised the same way on config.get("code_cycle", {}).get("profiles", …).

load_config() now validates the shape when the file is read: code_cycle, code_cycle.repository and code_cycle.profiles must be mappings when present, each refused by name and type. repository_of() no longer assumes a mapping either, so it is safe independently of its caller.

Also narrowed while in there: the load_profiles call was wrapped in except Exception, which turned any bug inside the router into a message saying the configuration was wrong. It now catches RouterError.

Verified after: code_cycle: not-a-mapping → code_cycle must be a mapping, not str; repository: nope and profiles: nope → the same refusal naming the section.

Regression tests

Six new in tests/test_run_cycle.py: a selector the store would refuse, a credential-shaped selector, an explicit --repo checked the same way, the work item checked too, nothing dispatched and no rows when planning refuses, and the three malformed shapes as a table.

Checked against the previous code, not only the new one: with scripts/run_cycle.py restored from db96bf3, Ran 26 tests … FAILED (failures=6, errors=2). Against b0a31b6, OK.

Verification

  • python3 -m unittest discover -s tests — Ran 364 tests ... OK (was 358).
  • python3 scripts/validate-package.py — VALID.
  • CI on b0a31b6 — all four checks pass, none pending, failed, cancelled or skipped.

Sensitivity triage

The diff moves a credential check earlier, from after a dispatch to before one, and adds type checks on parsed configuration. Nothing new is executed and no new data crosses a boundary. Agreeing with the review's triage: no audit finding, and the credential-prefix rejection is now reached before any prompt is composed rather than after.

Residual risks

validate_reference enforces the store's rule, which is a shape and a published-prefix list — not proof that an arbitrary reference is not a secret. That limit was documented when the rule was written and is unchanged here; what changed is when it is applied.

Status: RESOLVED — REV-001 and REV-002 closed at b0a31b6.

@datacas

datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner Author

Code Cycle Re-review

Status: CHANGES_REQUESTED

Reviewed the complete accumulated diff against origin/main, including the fix commit b0a31b60e0e120f3b4d97364ec6b953f4de158f8. Previous review head: db96bf3c07597fbb320e49f8489984707f5fa1aa.

Changes since the previous review

The fix adds a shared pre-dispatch reference validator, validates the nested configuration section shapes, narrows router error handling, and adds regression coverage. The accumulated change now touches 10 files.

Previous findings

[REV-001] · medium · resolved · blocks:yes — Validate the repository selector before dispatch

Location: scripts/run_cycle.py:364-373

Resolved and verified by execution. plan() now applies the telemetry validator before run_cycle() can dispatch. The original selector: "bad selector" reproduction now raises CycleDriverError before any executor call; the credential-shaped ghp_... selector is also refused before prompt composition. The added regression test confirms no adapter dispatch and no telemetry rows when planning refuses.

[REV-002] · medium · resolved · blocks:yes — Reject malformed nested configuration with a driver error

Location: scripts/run_cycle.py:107-120

Resolved and verified by execution. Valid YAML with scalar code_cycle, code_cycle.repository, or code_cycle.profiles values now raises a named CycleDriverError instead of reaching an unchecked .get() call or a traceback. The added table-driven regression test covers all three shapes.

New finding

[REV-003] · medium · open · blocks:yes — Validate each profile entry before loading it

Location: scripts/run_cycle.py:375-378

load_config() validates that code_cycle.profiles is a mapping, but it does not validate each profile value. A valid configuration such as cheap_coder: nope reaches load_profiles(); its {**spec, **(declared.get(name) or {})} merge raises TypeError: 'str' object is not a mapping. plan() catches only RouterError, and main() catches only CycleDriverError, so the CLI exits 1 with a traceback rather than reporting a controlled configuration refusal. Other non-mapping target values can similarly survive planning and fail later during routing.

Please validate every declared profile spec and its primary/fallback target shapes, or convert these malformed-input failures into RouterError before dispatch. Add regression coverage for a scalar profile entry and non-string targets.

Verification and current checks

  • python3 scripts/validate-package.py — passed.
  • python3 -m unittest discover -s tests -v — 364 tests passed.
  • git diff --check — passed.
  • GitHub checks at b0a31b6 — all four required checks passed; none pending, failed, cancelled, or skipped.
  • Original reproductions for REV-001 and REV-002 — passed with the fixes.
  • New REV-003 reproduction — still fails with an unhandled TypeError and traceback.

Security triage and verdict

This remains a sensitive change because repository configuration controls executor routing and reference values cross into prompts and telemetry. The security audit ran: yaml.safe_load is used, the new reference check occurs before dispatch, and no additional confirmed security vulnerability was found. No separate service or browser verification is defined by the repository; the validator, full unit suite, original reproductions, and current CI gates were available and executed.

The current verdict is CHANGES_REQUESTED until malformed individual profile entries are refused through the same controlled configuration path.

load_profiles validated the names and nothing under them. A declared
`cheap_coder: nope` reached the merge and raised TypeError past plan()'s
RouterError handler and main()'s CycleDriverError handler, so the CLI printed a
traceback where a stated refusal belongs.

The quieter half was worse and was not reported: `primary: 3` was accepted. The
loader carried a non-string target through untouched -- `parse_target(x) if
isinstance(x, str) else x` -- so a Profile could hold the integer 3 as its
target, and only something trying to route with it ever found out, after
planning had approved the run.

Every declared profile must now be a mapping, and every primary and fallback a
non-empty target string, each refused by name as a RouterError, which the driver
already converts. The isinstance escape hatch is gone: a target is parsed or it
is refused. load_profiles also refuses a code_cycle section that is not a
mapping rather than quietly reading the defaults out of a broken file -- the
driver already refused that shape, but the function is used on its own too.

Eleven tests across both layers, of which nine checks fail against the previous
router. One of them caught a weak test of my own while it was being written: two
of the new cases asserted only that CycleDriverError was raised, and the error
they actually got was the missing repository, not the malformed profile.
@datacas

datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner Author

Resolution summary — round 2

Reproduced against b0a31b6 before editing, fixed in d26da52.

[REV-001] · medium · resolved · valid · blocks:no — Validate the repository selector before dispatch

Closed in the previous round at b0a31b6 and confirmed by the re-review. No change since.

[REV-002] · medium · resolved · valid · blocks:no — Reject malformed nested configuration with a driver error

Closed in the previous round at b0a31b6 and confirmed by the re-review. No change since.

[REV-003] · medium · resolved · valid · blocks:yes — Validate each profile entry before loading it

Valid, and the reproduction matched: cheap_coder: nope reached {**spec, **declared.get(name)} and raised TypeError: 'str' object is not a mapping — past plan()'s RouterError handler and past main()'s CycleDriverError handler, so the CLI printed a traceback where a stated refusal belongs.

The quieter half is worse and was not in the finding. While reproducing I checked the neighbouring shapes:

scalar profile entry -> UNCONTROLLED TypeError 'str' object is not a mapping
non-string primary   -> accepted; cheap_coder.primary = 3
non-string fallback  -> accepted; cheap_coder.primary = Target(...)

primary: 3 was accepted. The loader carried a non-string target through untouched — parse_target(x) if isinstance(x, str) else x — so a Profile could hold the integer 3 as its target and planning would approve the run. Only something trying to route with it would ever find out, after the cycle had started. A crash is loud; this one was not.

Fixed in load_profiles, which is where the shapes below the name belong — the driver's check is about the file, the router's is about profiles, and fixing it here covers every caller rather than this one CLI:

  • every declared profile must be a mapping, refused by name;
  • every primary and fallback must be a non-empty target string;
  • the isinstance escape hatch is gone: a target is parsed or it is refused, so parse_target's own RouterError covers malformed strings as before.

load_profiles also now refuses a code_cycle section that is not a mapping instead of quietly reading the defaults out of a broken file. load_config already refused that shape, but the function is used on its own, and reading the defaults from a file that says otherwise is the precise failure this PR exists to prevent.

Verified after: each of the six shapes — scalar entry, non-string primary, non-string fallback, whitespace-only target, malformed target string, and a healthy declaration — now refuses by name or loads, with no uncontrolled exception.

Regression tests

Eleven across both layers. Six in tests/test_router.py (non-mapping profile, three non-string target shapes as a table, empty target, malformed target string, healthy declaration, broken code_cycle section) and two in tests/test_run_cycle.py reaching the same refusals through plan().

Checked against the previous code: with scripts/router.py restored from b0a31b6, Ran 65 tests … FAILED (failures=6, errors=3). Against d26da52, OK.

One of them caught a weak test of my own. Two new cases initially asserted only that CycleDriverError was raised — and it was, but for the missing repository, not the malformed profile. They now pass a repository and assert the message names the profile. Worth recording: a test that passes for the wrong reason is how a fix gets believed without being verified.

Verification

  • python3 -m unittest discover -s tests — Ran 372 tests ... OK (was 364).
  • python3 scripts/validate-package.py — VALID.
  • CI on d26da52 — all four checks pass, none pending, failed, cancelled or skipped.

Sensitivity triage

Unchanged and narrower: the diff adds type checks to parsed configuration, executes nothing new, and passes no new data anywhere. No audit finding.

Residual risks

The configuration surface is now checked for shape at both layers, but .code-cycle.yml has other consumers in the skills that read it as prose rather than through load_profiles; nothing here changes those. Unchanged from the previous round: validate_reference enforces a shape and a published-prefix list, not proof that an arbitrary reference is not a secret.

Status: RESOLVED — REV-003 closed at d26da52; REV-001 and REV-002 remain closed at b0a31b6.

@datacas

datacas commented Sep 21, 2026

Copy link
Copy Markdown
Owner Author

Code Cycle Re-review

Status: APPROVED

Reviewed the complete accumulated diff against origin/main at d26da524170e3b1de76e4a1a9f0613504dc0cbf2. Previous rereview head: b0a31b60e0e120f3b4d97364ec6b953f4de158f8.

Changes since the previous rereview

The router now validates each declared profile mapping and its primary/fallback target types before creating Profile objects. It also validates standalone load_profiles() configuration sections and adds router- and driver-level regression coverage for malformed shapes.

Previous findings

[REV-001] · medium · resolved · blocks:no — Validate the repository selector before dispatch

Location: scripts/run_cycle.py:364-373

Reproduced with an invalid selector and a credential-shaped selector. Both now raise CycleDriverError during planning, before prompt composition or executor dispatch. The regression suite also confirms zero adapter dispatches and zero telemetry rows when planning refuses.

[REV-002] · medium · resolved · blocks:no — Reject malformed nested configuration with a driver error

Location: scripts/run_cycle.py:107-120

Reproduced scalar code_cycle, code_cycle.repository, and code_cycle.profiles values. Each now produces a named CycleDriverError rather than an unchecked attribute error or traceback.

[REV-003] · medium · resolved · blocks:no — Validate each profile entry before loading it

Location: scripts/router.py:227-250

Reproduced a scalar profile entry, an integer primary, and a list fallback. Each now produces a named RouterError converted to CycleDriverError by the driver. A valid configured target still loads and routes correctly.

Verification and current checks

  • python3 scripts/validate-package.py — passed.
  • python3 -m unittest discover -s tests -v — 372 tests passed.
  • git diff --check — passed.
  • GitHub checks at d26da52 — all four required checks passed; none pending, failed, cancelled, or skipped.
  • Original reproductions for REV-001, REV-002, and REV-003 — all passed after the fixes.
  • No separate service or browser verification is defined by this repository; no required verification remained unrun.

Security triage and residual risk

This remains a sensitive configuration and executor-routing change. The security audit ran: yaml.safe_load is used, reference and profile validation occur before dispatch, and no additional confirmed security vulnerability was identified. The remaining documented limitation is unchanged: reference validation rejects known credential prefixes and invalid shapes, but cannot prove that every arbitrary caller-supplied reference is not a secret.

Final verdict: APPROVED. All recovered findings are resolved, the current head was fully rereviewed, and no open blocking finding remains.

@datacas
datacas merged commit b449b36 into main Sep 21, 2026
4 checks passed
@datacas
datacas deleted the feat/config-routing branch September 21, 2026 21:07
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.

1 participant