Skip to content

state: expose a JSON-safe summary of pending registration cache entries (#2714) - #3411

Open
MsfPablo wants to merge 1 commit into
juanfont:mainfrom
MsfPablo:fix/registration-cache-debug-entries
Open

state: expose a JSON-safe summary of pending registration cache entries (#2714)#3411
MsfPablo wants to merge 1 commit into
juanfont:mainfrom
MsfPablo:fix/registration-cache-debug-entries

Conversation

@MsfPablo

@MsfPablo MsfPablo commented Aug 5, 2026

Copy link
Copy Markdown

Context

#2714 originally reported that DebugRegistrationCache panicked/errored on JSON marshaling because it returned raw types.AuthRequest values, which carry an unexported chan AuthVerdict field.

That literal panic no longer reproduces on current mainDebugRegistrationCache already stopped returning the raw entries. But in doing so it also stopped saying anything about the individual pending entries, so the issue's stated "Expected Behavior" (being able to inspect what's actually in the registration cache) is still unmet: the debug endpoint currently only reports cache-level metadata (size, expiration, max entries), not what's in it.

What this does

Adds a small per-entry summary to DebugRegistrationCache's output — an auth_id and a type (plain / registration / ssh-check, derived from AuthRequest.IsRegistration() / IsSSHCheck(), which never touch the unexported channel field). Peek is used instead of Get so inspecting the cache for debugging doesn't itself perturb LRU recency/eviction order.

I also found the existing TestDebugRegistrationCache in debug_test.go didn't actually exercise State.DebugRegistrationCache at all — it exercised NodeStore.DebugString, an unrelated type that happens to share a similarly-named debug method. Renamed that test to TestNodeStoreDebugRegistrationCache to reflect what it actually covers, and added TestStateDebugRegistrationCache for real regression coverage of this method (empty cache, plus one entry of each flow type).

Note on scope

I noticed AGENTS.md asks contributors to check in about scope on ambiguous issues before implementing. #2714's original literal bug is already fixed, so I want to be upfront that this is a proposal for closing the gap between "bug fixed" and the issue's stated expected behavior — not a claim that this is the only or definitive way to do that. Happy to adjust the shape of the debug output (e.g. more/fewer fields) or close this if there's a different intended direction.

Testing

  • go build ./...
  • go test ./hscontrol/state/... (full package, passing)
  • go test ./hscontrol/state/... -run DebugRegistrationCache -v (both new/renamed tests passing)
  • gofmt -l clean on both changed files
  • golangci-lint run clean on both changed files

Closes #2714 if this shape is acceptable — otherwise happy to iterate.

DebugRegistrationCache() already stopped marshaling raw AuthRequest
values (fixing the reported chan-in-JSON panic), but it also stopped
saying anything about individual entries, leaving unmet the issue's
stated expectation of being able to "display the current registration
cache".

AuthRequest carries unexported fields backed by a channel, so it can't
be marshaled directly. Add a per-entry summary (auth_id, flow type:
registration/ssh-check/plain) built from AuthRequest's existing public
accessors (IsRegistration/IsSSHCheck), which never touch the channel.
Peek is used instead of Get so inspecting the cache for debugging
doesn't itself affect LRU recency/eviction order.

Renamed the existing TestDebugRegistrationCache, which actually
exercised NodeStore.DebugString (a different type), to
TestNodeStoreDebugRegistrationCache, and added
TestStateDebugRegistrationCache to cover State.DebugRegistrationCache
itself.

Relates to juanfont#2714
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.

[Bug] Internal server error on /debug/registration-cache

1 participant