Skip to content

feat: add lookup resources debugging behavior#682

Open
tstirrat15 wants to merge 2 commits intomainfrom
tstirrat/lookup-resources-debugging
Open

feat: add lookup resources debugging behavior#682
tstirrat15 wants to merge 2 commits intomainfrom
tstirrat/lookup-resources-debugging

Conversation

@tstirrat15
Copy link
Copy Markdown
Contributor

@tstirrat15 tstirrat15 commented Apr 25, 2026

Description

Zed counterpart to authzed/spicedb#3070. This does the work of submitting the debug arg and then interpreting the trace held in the error message.

What the output looks like

Cycle found in data:
	user:someuser#...	<-- Original subject
	folder:a#viewer
	folder:a#view	<-- Cycle start
	folder:b#view
	folder:a#view	<-- Cycle end

Changes

Will annotate.

Testing

Review. go work this together with the code in authzed/spicedb#3070 and run the tests. Note that this is blocked on that PR, so tests will fail until that SHA is pulled into this PR.

You can also use the schema and relationships from the tests for a running example - do go run ./cmd/spicedb/... serve-testing in one window and then go-run the lookup-resources call with --debug to see the output.

Copy link
Copy Markdown
Contributor Author

@tstirrat15 tstirrat15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

lookupResourcesCmd.Flags().Uint32("page-limit", 0, "limit of relations returned per page")
lookupResourcesCmd.Flags().String("cursor", "", "resume pagination from a specific cursor token")
lookupResourcesCmd.Flags().Bool("show-cursor", true, "display the cursor token after pagination")
lookupResourcesCmd.Flags().Bool("debug", false, "send debug header to spicedb. useful for debugging recursion depth errors")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd welcome bikeshedding on this flag. It feels like it's different from --explain because it's about getting more context out of an exception rather than showing the path taken on a successful request.

ctx := cmd.Context()
if cobrautil.MustGetBool(cmd, "debug") {
log.Info().Msg("debugging requested on LookupResources")
ctx = requestmeta.AddRequestHeaders(ctx, requestmeta.RequestDebugInformation)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also welcome bikeshedding on this point - I reached for a header by reflex but it may not be how we want to do things.


// handleLookupResourcesErr does any additional handling of LR errors.
// Primarily used to print a traceback when in debug mode.
func handleLookupResourcesErr(err error) error {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it might be worth pushing up into authzed-go - unpacking errors always feels like a pain point of gRPC.

@tstirrat15 tstirrat15 force-pushed the tstirrat/lookup-resources-debugging branch from 0999a40 to b51489b Compare April 25, 2026 15:14
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.

1 participant