Commit e211beb
fix(router): remove persisted route_config key on SemanticRouter.delete() (#635)
## Motivation
A `SemanticRouter` persists its configuration as a standalone JSON key,
`{name}:route_config`, written when the router is constructed and
rewritten on every route change. `delete()`, however, only drops the
router's search index — it never removes that key. The index is built
over hash documents, and `FT.DROPINDEX ... DD` deletes only the
documents the index actually tracks, so the JSON config key falls
outside its reach and survives every call to `delete()`.
The immediate consequence is orphaned `:route_config` keys accumulating
in Redis. The subtler one is a correctness gap: `from_existing()` loads
a router straight from that key, so a router that was supposedly deleted
can be silently resurrected from stale config. It also leaves residue
behind in the test suite, where it contributed to the broader
Redis-backed isolation problems tracked in #546.
## Fix
`delete()` now removes `{name}:route_config` explicitly after dropping
the index, so deleting a router fully clears its state. The change is
confined to `SemanticRouter.delete()`; there is no async router variant
to mirror.
A regression test constructs a router, confirms the config key exists,
calls `delete()`, and then asserts both that the key is gone and that
`from_existing()` on the same name raises rather than reloading stale
config — locking in the behaviour described above.
Closes #634.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Small lifecycle fix in router teardown with a focused regression test;
no changes to routing, auth, or data semantics beyond complete cleanup
on delete.
>
> **Overview**
> **`SemanticRouter.delete()`** now drops the search index and
explicitly deletes the standalone Redis JSON key `{name}:route_config`,
which is not removed by `FT.DROPINDEX` because it sits outside the
index.
>
> This prevents orphaned config keys and stops **`from_existing()`**
from reloading a router that was supposed to be deleted.
>
> An integration test asserts the config key is gone after
**`delete()`** and that **`from_existing()`** raises when no valid
config remains.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
23805cff1c06371b2377abeee442b09dd1b09a74. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent a1f2891 commit e211beb
2 files changed
Lines changed: 32 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
577 | 577 | | |
578 | 578 | | |
579 | 579 | | |
580 | | - | |
| 580 | + | |
581 | 581 | | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
582 | 585 | | |
583 | 586 | | |
584 | 587 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
685 | 685 | | |
686 | 686 | | |
687 | 687 | | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
688 | 716 | | |
689 | 717 | | |
690 | 718 | | |
| |||
0 commit comments