2 Commits
Author SHA1 Message Date
viettranx c8ebe9a789 refactor(comments): remove plan/phase refs from agent identity hardening code
Rewrite inline comments added during the agent identity hardening so
they explain the code as it stands today, rather than tying to internal
plan terminology (phase numbers, FR/NFR/H/M/C codes, PR references,
trap zone labels). Commit history already carries the plan archaeology.
Comments now keep the non-obvious invariants (cache boundaries, bypass
gaps, silent-nil traps, dual-tenant semantics) and drop the scaffolding.
Comment-only — no runtime behavior change.
2026-04-11 21:22:23 +07:00
viettranx c599387248 fix(router): canonicalize cache key, exact-segment match, tenant-aware IsRunning
Three related fixes to agent router identity handling:

1. Canonicalize on resolve — Router.Get now stores entries under the
   canonical tenantID:agent_key after a successful resolver call,
   regardless of whether the caller passed a UUID or agent_key. Prevents
   fragmentation where the same logical agent would occupy two cache
   slots. Callers that pass the UUID form are now un-cached and resolve
   on every call; all production callers pass agent_key today.

2. Exact-segment match — matchAgentCacheKey helper replaces HasSuffix in
   Router.Remove and Router.InvalidateAgent. Prevents substring collisions
   like "tenantX:sub-foo" being wiped when invalidating "foo". Rejects
   empty agentKey to guard against wildcard wipes.

3. Tenant-scoped IsRunning (C6) — Router.IsRunning now accepts ctx and
   uses agentCacheKey for lookup. Pre-fix, the bare r.agents[agentID]
   lookup always returned false in tenant-scoped deployments, causing
   agents.list to report every live agent as idle.

Updates the sole caller at gateway/methods/agents.go:134.

Phase 2 of agent identity hardening (TD-3).
2026-04-11 21:22:23 +07:00