Skip to content

feat: edit routes and groups as resources, and let the dry run say which route it used - #44

Merged
fylorn merged 2 commits into
mainfrom
feat/routes-api
Sep 19, 2026
Merged

fylorn merged 2 commits into
mainfrom
feat/routes-api

Conversation

@fylorn

@fylorn fylorn commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Why

Routing could only be changed through the generic config patch, which can append and remove but not insert or move. The desktop UI therefore appended every new rule after the catch-all, where its forward or deny can never be chosen, while the config stayed perfectly valid. Rules could not be edited in place either, and the dry run silently fell back to the first key in the file, so it could answer for a different route than the one the user had in mind.

This is the core half of the routing page redesign in ThinkWatch-Lite.

What

Routes and groups are resources, like providers and proxies:

  • POST /routes, PUT /routes/{name} — one whole route per write, rules in the order given. Renaming moves the keys that use it and default_route in the same version. keys sets exactly which keys use the route; keys moved out fall back to the default route. route_probes sets the chosen assistant request classes to route in the same write, since an intent condition never matches classes that are answered locally or passed through.
  • DELETE /routes/{name}?reassign_to= — the keys that use it move to the route the user picked, or to the default route. The default route cannot be deleted.
  • PUT /default_route — moving the default away from the synthesised route writes that route into the file first, so it stays as an ordinary route.
  • POST /groups, PUT/DELETE /groups/{name} — renaming moves the rules that forward to the group; a group still referenced cannot be deleted; the built-in group cannot be edited.
  • GET /models — every model the gateway can serve and which upstreams serve it (same catalog as /v1/models), for suggestions.

Engine and views:

  • The built-in "all upstreams" group (__all__) exists whenever there are upstreams, not only while the default route is synthesised. Writing the default route into the file used to make its own catch-all invalid.
  • The synthesised catch-all rule is called 兜底; names starting with __ are reserved; duplicate group names are rejected.
  • A rule that only adds a guard is valid (it was rejected as having no effect).
  • When::is_catch_all now accounts for intent.
  • The overview gives every rule in full (conditions, target, deny reason, rewrite, guard) plus catch_all / phase_two / shadowed, marks the synthesised route and group as builtin, reports routes without a catch-all, and judges cache risk per group, so a sticky round robin is no longer flagged.

Dry run: evaluates a key's route, a named route, or an unsaved draft, and refuses rather than guessing when given none. The result names the route it used, and each matching rule says whether it decided the outcome, added something, or had no effect. It also stops reporting a numeric condition that held as the mismatch, and treats assistant_internal as any assistant request when explaining one.

Breaking changes

RuleView.deny is now the reason (Option<String>) instead of a flag, and /dryrun returns 400 without client, route or draft. The desktop app is the only consumer and moves in lockstep.

Checks

cargo fmt --check, cargo clippy --workspace --all-targets -D warnings, cargo test --workspace and scripts/smoke.sh (49 passed, 0 failed) pass locally. New tests: tests/routes.rs (19), new cases in tests/dryrun.rs, engine and config unit tests.

🤖 Generated with Claude Code

fylorn and others added 2 commits September 19, 2026 11:30
…ich route it used

Routing could only be changed through generic patches, which can append and
remove but not insert or move. The UI therefore appended every new rule after
the catch-all, where its forward or deny can never be chosen, while the config
stayed perfectly valid.

Routes and groups are now resources, like providers and proxies:

- POST /routes, PUT /routes/{name}: a whole route per write, rules in the
  order given. Renaming moves the keys that use it and default_route in the
  same version. `keys` sets exactly which keys use the route; keys moved out
  fall back to the default route.
- DELETE /routes/{name}?reassign_to=: the keys that use it move to the route
  the user picked, or to the default route. The default route cannot be
  deleted.
- PUT /default_route. Moving the default away from the synthesised one
  writes that route into the file first, so it stays as an ordinary route.
- POST /groups, PUT/DELETE /groups/{name}: renaming moves the rules that
  forward to the group; a group still referenced cannot be deleted.
- GET /models: every model the gateway can serve and which upstreams serve it.

The engine and the views change to match:

- The built-in "all upstreams" group (__all__) exists whenever there are
  upstreams, not only while the default route is synthesised. Writing the
  default route into the file used to make its own catch-all invalid.
- The synthesised catch-all rule is called 兜底; names starting with __ are
  reserved; duplicate group names are rejected.
- A rule that only adds a guard is valid.
- The overview gives every rule in full (conditions, target, deny reason,
  rewrite, guard) plus catch_all / phase_two / shadowed, marks the
  synthesised route and group as builtin, reports routes without a
  catch-all, and judges cache risk per group, so a sticky round robin is no
  longer flagged.

The dry run no longer falls back to the first key in the file: it evaluates
a key's route, a named route, or an unsaved draft, returns the route it
used, and says for each matching rule whether it decided, added something,
or had no effect. It also stops blaming a numeric condition that held, and
treats assistant_internal as any assistant request when explaining a miss.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ch to the router

A rule's intent condition only ever matches requests whose class is set to
route; the rest are answered locally or passed through before routing and
carry no class. route_probes sets the chosen classes to route in the same
write as the route, so a new intent rule does not silently never match.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Thanks for the PR. One thing before review: this targets main, and it should target dev.

main is a release-only line — branch-protected, linear history, and every commit on it is a tagged release snapshot. Routine work lands on dev and reaches main with the next release. GitHub pre-filled main here because it is the default branch, so this is our defaults being unhelpful rather than anything you did wrong.

No need to close and reopen: click Edit next to the PR title and change the base branch to dev. The commits and the discussion carry over.

See CONTRIBUTING.md and CONTRIBUTING.md for the branch contract.

@fylorn
fylorn merged commit 3c140bf into main Sep 19, 2026
2 checks passed
@fylorn
fylorn deleted the feat/routes-api branch September 19, 2026 04:47
@fylorn fylorn mentioned this pull request Sep 19, 2026
fylorn added a commit that referenced this pull request Sep 19, 2026
Routes and groups are edited as resources (#44): a whole route per write with
rules in the order given, keys and the default route moved along on rename,
and the keys of a deleted route sent where the user picked. The built-in
all-upstreams group stays once the default route is written down, a rule may
carry only a guard, and the dry run evaluates a key's route, a named route or
an unsaved draft and says which route it used.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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