EVA-10283: auto-refresh the tools schema cache (login hook + 1h TTL at startup)#11
Conversation
…-10283) The dynamic-command registry previously only refreshed when the user manually ran 'tools refresh' — with near-daily server-side tool changes the CLI silently drifted stale. Now the cache refreshes at two targeted moments: right after 'auth login' succeeds, and at startup when the cache is over 1h old (TTL lowered from 24h) via a 3s best-effort probe that falls back to the stale cache on failure. Silent fallback is narrowed to be honest: --no-cache failures and missing-cache failures propagate as transport errors instead of degrading to 'unknown command'. Static commands (help, version, auth, tools, completion, cobra __complete) never trigger a fetch, preserving offline/pre-auth behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR reduces the tools schema cache TTL to 1 hour, adds a bounded startup freshness probe that conditionally refreshes tools/list for dynamic commands (with non-interactive token handling and --no-cache semantics), triggers a best-effort post-login cache refresh, enhances tests to cover these flows, and updates docs. ChangesSchema Caching and Startup Freshness Probe
Sequence DiagramsequenceDiagram
participant CLI as CLI Startup
participant Cache as Schema Cache
participant Creds as Credentials
participant Server as Schema Server
participant Tools as Tool Registration
CLI->>Cache: Check if cache exists and fresh (< 1h)
Cache-->>CLI: Cache state (fresh/stale/missing)
alt Cache fresh and --no-cache not set
CLI->>Tools: Register tools from cache
else Need refresh (stale/missing or --no-cache)
CLI->>Creds: Check for stored credentials
alt No stored credentials
CLI->>Tools: Use existing cache or fail
else Credentials available
CLI->>Server: LoadOrFetch with timeout (3s)
alt Fetch succeeds
Server-->>Cache: Update schema cache
Cache-->>Tools: Register updated tools
else Fetch fails
alt Stale cache exists and --no-cache not set
Cache-->>Tools: Silently use stale cache
else No fallback available
Server-->>CLI: Return transport error
end
end
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
📊 Code Quality Score: 52/100
Was this score accurate? 👍 Yes · 👎 No Scored by GitVelocity · How are scores calculated? |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cmd/startup_test.go (1)
125-129: ⚡ Quick winAssert unexpected
ensureFreshSchema()errors in success-path tests.Line 125, Line 199, Line 228, Line 252, Line 277, Line 292, and Line 305 call
ensureFreshSchema()without checkingerr. That can mask regressions with false-positive passes when the function fails before the side-effect assertion.Suggested pattern
- ensureFreshSchema() + if err := ensureFreshSchema(); err != nil { + t.Fatalf("ensureFreshSchema: %v", err) + }Also applies to: 199-203, 228-232, 252-256, 277-281, 292-296, 305-309
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cmd/startup_test.go` around lines 125 - 129, The tests call ensureFreshSchema() but ignore its error return, which can hide failures; update each call (e.g., in the tests around ensureFreshSchema() followed by f.calls() assertions) to capture and assert the error like: err := ensureFreshSchema(); if err != nil { t.Fatalf("ensureFreshSchema failed: %v", err) } before continuing with the side-effect assertions (such as using f.calls()), and apply this change to all occurrences referenced in the comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@cmd/startup_test.go`:
- Around line 125-129: The tests call ensureFreshSchema() but ignore its error
return, which can hide failures; update each call (e.g., in the tests around
ensureFreshSchema() followed by f.calls() assertions) to capture and assert the
error like: err := ensureFreshSchema(); if err != nil {
t.Fatalf("ensureFreshSchema failed: %v", err) } before continuing with the
side-effect assertions (such as using f.calls()), and apply this change to all
occurrences referenced in the comment.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e7d25a0d-56a0-4441-99ee-83b01c9781e2
📒 Files selected for processing (8)
CLAUDE.mdREADME.mdcmd/auth.gocmd/dynamic.gocmd/integration_test.gocmd/root.gocmd/startup_test.godocs/agents.md
CodeRabbit quick win: seven call sites discarded the error return, which could mask regressions with false-positive passes when the function fails before the side-effect assertion. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
✅ Addressed CodeRabbit's nitpick: all seven success-path |
📊 Code Quality Score: 51/100
Was this score accurate? 👍 Yes · 👎 No Scored by GitVelocity · How are scores calculated? |
Summary
Linear: EVA-10283
The dynamic-command registry previously only refreshed when the user manually ran
tools refresh; with near-daily server-side MCP tool changes, the CLI silently drifted stale (the 24h TTL was never honored by the startup path, only bytools list/tools refresh). This PR makes the cache self-maintaining:auth loginrefreshes the tool list in the same invocation ("Cached N tools." on stderr); refresh failure warns but never fails the login.--no-cache(bare or=true, pre- or post-subcommand) + fetch failure, or a missing cache with nothing to fall back to, exit with a transport-coded error (7) instead of silently lying or degrading tounknown command.--help,version,auth *,tools *,completion, and cobra's hidden__complete/__completeNoDescnever trigger a startup fetch; leading persistent flags (--pretty,-q) are scanned past correctly.SEARCHLIGHT_TOKENis set, else the just-saved OAuth tokens) — a rejected token fails silently/warns instead of launching the browser.tools refreshis now an optional escape hatch.Test plan
--no-cacheforms, rejected pre-minted token (asserts no interactive fallback), post-login principal selection, exit-code pinning (transport=7).go vet, golangci-lint, gosec clean;-racegreen.auth loginagainst production (browser flow) — checklist item for reviewer/author.Design notes
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Improvements
Documentation
Tests