feat(k8s): cache-aware kubectl pods/services + impact-scored discover - #3725
Open
wussh wants to merge 1 commit into
Open
feat(k8s): cache-aware kubectl pods/services + impact-scored discover#3725wussh wants to merge 1 commit into
wussh wants to merge 1 commit into
Conversation
kubectl get pods/services is the single biggest token sink (90.7M tokens over 16K calls in real usage) — the existing JSON-summary filter already compresses aggressively, so the actual gap is call frequency, not filter quality. - Cache the hash of the already-filtered summary (not raw JSON, so volatile fields like resourceVersion never matter). Repeated polls of unchanged cluster state collapse to one line within a 15s sliding TTL window; --force bypasses for guaranteed fresh detail. Still runs the real kubectl/oc call every time — never skips the query itself. - discover's "TOP UNHANDLED COMMANDS" list was sorted by raw call count only. Add an impact score (count x avg output tokens for a guessed category) and a Priority column so a rare-but-huge command isn't buried under a frequent tiny one. Verified: cargo test (full suite green), manual run against a live cluster (tbs-dev) confirming collapse/--force/services behavior, and discover against this repo's own 30-day session history.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In real-world agent usage,
kubectl get podsis by far the largest single token sink — 16,092 calls / ~90.7M tokens saved over 30 days in my own history. But the existingformat_kubectl_podsfilter already compresses aggressively (counts + capped issue list). The filter isn't the gap; call frequency is. An agent polling a stable cluster gets the same summary re-sent dozens of times in a row.Separately,
rtk discover's "TOP UNHANDLED COMMANDS" table sorts by raw call count, so a rare-but-huge command is buried under a frequent tiny one — no signal about which is actually worth filing an issue for.Changes
Two independent, separately-reviewable changes:
1. Result-diff caching for
kubectl/ocget pods/services (src/core/k8s_cache.rs)Hashes the already-filtered summary text (not raw JSON) keyed by tool+resource+args. When a repeat call produces an identical summary within a 15s sliding poll-gap window, output collapses to one line instead of the full summary.
--forcebypasses it.Hashing post-filter output rather than raw JSON sidesteps normalizing volatile fields (
resourceVersion,managedFields, timestamps) out of an open-ended schema — those never surface in the summary by construction.2. Impact-scored
rtk discover(src/discover/)Adds
impact = call_frequency × avg_output_tokens_for_categoryand aPrioritycolumn, replacing the raw-count sort on the unhandled-commands table. Reuses the existingcategory_avg_tokenstable via a newguess_unsupported_categoryhelper, so unhandled commands get the same per-category estimate as handled ones.Design philosophy compliance
kubectl/occommand still executes on every call; only the re-printing of an unchanged result is skipped, never the query itself. Stale cluster state shown to an agent debugging a live rollout would be far worse than the token cost.--forceis the flag-aware escape hatch for explicitly-requested full detail.7 pods: 7) and names its own escape hatch. No new format for the normal (uncached) path.never_worsevia the existingrunner::run_filteredpath, thedirs::data_local_dir()/RTK_DATA_DIRstorage convention fromcore/tracking.rs, anddiscover's existing category tables. No new storage layer, no new UI concept.Testing
k8s_cache.rs(first call, unchanged repeat, changed state,--force, flag extraction)cargo clippy --all-targetsclean,cargo fmt --checkclean.rtk discover --allagainst 275 real sessions / 13,091 commands — new Priority column reorders the unhandled table sensibly.Notes / out of scope
discovernow surfaces (sshpass,python3,export, …) — happy to file those as separate issues per the contribution norms.--forceis added only to thekubectl pods/servicesshorthand subcommands, notoc— theocvariants passfalseand behave exactly as before.kubectl get pods -Aon a large cluster exceeds the 10 MiB filter-input cap and falls back to raw. Not touched here; mentioning in case it's of interest.