The question, in the user's words: "A user's credentials come back in the wrong order. The PRIORITY column of the CREDENTIAL table looks wrong. What writes it?"

What you get at the end: every method that reads, writes or deletes the table, the methods that set the field, and the routes and callers that reach them. Then, for a value that arrives as a message, who publishes it and who handles it.

Words used on this page:

The steps

1. Which stores does the code use?

niro ask list_data_resources limit=15

67 data resource(s):
  sql          table       USER_ENTITY                  20 use(s)
  sql          table       REALM                        10 use(s)
  ...
  sql          table       CREDENTIAL                   7 use(s)

2. Who reads, writes and deletes that table?

niro ask get_data_resource_usage resource_fqn=CREDENTIAL

sql:table:CREDENTIAL
  read by (5):
    JpaUserCredentialStore.getStoredCredentialById
    JpaUserCredentialStore.removeCredentialEntity
    JpaUserCredentialStore.updateCredential
    CredentialModelTest.testCredentialUpdateWithDuplicateLabel
    PasswordHashingTest.testPasswordRehashedOnAlgorithmChangedWithMigratedSalt
  written by (1):
    JpaUserCredentialStore.createCredentialEntity
  deleted by (1):
    JpaUserCredentialStore.removeCredentialEntity

The listed write is em.persist(entity) on a CredentialEntity, and the table name appears only once in the code, in @Table(name="CREDENTIAL") on the entity class. Niro joins the two.

This list is not complete, and here is what it leaves out. The answer key for this same question (A/B task p-04) has four methods that write the table, and step 2 shows one insert and one delete:

Both kinds of gap are known problems in this release: see FAQ: wrong or missing answers. Use step 3 to find them.

3. Who sets the field?

The graph records which methods touch a table, not which fields they change. So search for the setter, and ask for the methods that hold it:

niro ask code_grep pattern="setPriority(" path_pattern=model/jpa/ answer=names

18 matching lines in 9 files
JpaUserCredentialStore.createCredentialEntity(RealmModel, UserModel, CredentialModel)
JpaUserCredentialStore.removeCredentialEntity(RealmModel, UserModel, String)
JpaUserCredentialStore.moveCredentialTo(RealmModel, UserModel, String, String)
RealmAdapter.entityToModel(AuthenticationExecutionEntity)
...
[shown 17 names from the first 5 hits a file; raise max_matches_per_file (up to 50) for more hits a file]

Three methods of JpaUserCredentialStore set a credential's priority. moveCredentialTo is not in step 2's list, and updateCredential is listed only as a reader. Both change loaded entities, and the database update happens when the transaction ends. That kind of write has no call Niro can see.

4. What reaches the suspect method?

niro ask get_impact_analysis method_fqn=org.keycloak.models.jpa.JpaUserCredentialStore.moveCredentialTo depth=5 answer=names

Impact analysis for JpaUserCredentialStore.moveCredentialTo — 5 affected functions, risk: medium (+2 in tests, not counted in risk) (upstream 7)
upstream:
  JpaUserProvider.moveCredentialTo (depth 1)
  UserCredentialManager.moveStoredCredentialTo (depth 2)
  SubjectCredentialManagerCacheAdapter.moveStoredCredentialTo (depth 3)
  UserResource.moveCredentialAfter (depth 4)
  UserResource.moveCredentialToFirst (depth 5)
  CredentialModelTest.testCredentialCRUD [test] (depth 4)
  UserStorageTest.testCredentialCRUD [test] (depth 4)

So the admin REST methods UserResource.moveCredentialAfter and moveCredentialToFirst reorder credentials, and two existing tests already reach the code. The path goes through SubjectCredentialManagerCacheAdapter, a class that implements an interface: the call site names only the interface.

5. When the value arrives as a message

If the wrong value comes from another service, ask who sends and who receives it. From the synthetic java-mono corpus (68 small Java services and a main that calls them):

niro ask get_event_producers_and_handlers name=price-changes

redis-pubsub:price-changes   [jedis]
  published by (1):
      BrokerClients.priceChanged
  handled by (1):
      PriceWatch.listen

Then get_blast_radius event_fqn=price-changes answer=names lists what the handler goes on to call. For events in general, see Playbook: data stores and events.

Why the answer is complete, and where it is not

What grep would do instead

Cost

What these steps cost depends on your code and your question. How Niro counts the size of its answers, and how to measure the cost on your own tasks, is in Tokens, speed and accuracy.

Playbook: debug an error message or a stack trace, Playbook: data stores and events, Get shorter answers.