Skip to content

Show dynamic and disabled function states in the Debug tab and fix flaky agent tests - #104

Open
borisr-code-ibm wants to merge 4 commits into
android:mainfrom
borisr-code-ibm:feature/function-state-and-tests
Open

borisr-code-ibm wants to merge 4 commits into
android:mainfrom
borisr-code-ibm:feature/function-state-and-tests

Conversation

@borisr-code-ibm

@borisr-code-ibm borisr-code-ibm commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What I have done and why

Related to #38.

Problem

The Debug tab is where developers check their app functions, but it doesn't show how their state
changes at runtime:

  • It reads function states only when an app is selected. A function that the app disables or
    enables at runtime keeps its old state until the app is selected again. The same goes for a
    dynamic function that an activity registers or unregisters, and for functions added by a
    reinstall.
  • Dynamic functions (@AppFunctionSignature(scope = AppFunctionMetadata.SCOPE_ACTIVITY), registered
    with registerAppFunction/handleAppFunction, as discussed in Feat/dynamic function and runtime gating #94 and drafted in Feat/ChatApp-Work-Adjustments #98) look like
    static ones. Their Run button is enabled, but it always fails with FUNCTION_NOT_FOUND: the agent
    doesn't set ExecuteAppFunctionRequest.activityId.
  • A disabled function is greyed out with a small "Disabled" chip, with no reason, and it can't be
    expanded to see its parameters.

Solution

  1. Each function gets a runtime status in the UI state (AppFunctionStatus): whether it is enabled
    and, for an activity-scoped function, how many activities register it right now
    (AppFunctionState.activityIds, API 37+).
  2. The selected app updates live. GetAppFunctionsUseCase already emits again when
    observeAppFunctions() reports a metadata or state change. DebuggingViewModel now applies each
    emission to the selected app and keeps typed inputs, expanded functions and an open result.
    Results of a run go to the latest state, so a refresh during the run isn't reverted.
  3. Rows explain the state:
    • Disabled: the label plus "Turned off by the app, or not registered". Run is disabled with
      "Disabled functions can't run."
    • Dynamic: the label plus "Registered by N activities", or "Not registered: open the
      activity that provides it". Run is disabled with "The Debug tab can't run activity-scoped
      functions yet."
    • Any function can be expanded and collapsed, including one that becomes disabled while it is
      expanded.
  4. The "Unable to determine enabled state" text moved to strings.xml.
main this PR
App disables/enables a function while it is shown stale until the app is selected again updates in place, inputs kept
Dynamic function registered/unregistered stale; looks like a static function; Run fails "Dynamic" + registration count, updates in place; Run disabled with the reason
Disabled function grey, no reason, can't be expanded label + reason, can be expanded, Run disabled with the reason

Running dynamic functions in their activity is left for #105. The Debug tab needs a way to pick one
of activityIds, and the agent needs the foreground activity
(VoiceInteractionSession.getAppFunctionActivityId) for the overlay use case in #94.

LLM payload

Unchanged. Agent Demo and Live still request isEnabled = true tools for every turn, and
GetAppFunctionsUseCase and ExecuteAppFunctionUseCase aren't changed.

Flaky tests

  • Unit: AndroidLiveAudioSessionTest > stopAudio flushes active AudioTrack and discards queued chunks failed in CI on 2026-11-17 (main) and 2026-11-23 (Hide specialized Gemini models in the model picker and fix the default #103) with "One matching call found, but
    needs at least 2 calls". flushActiveTrack() calls pause → flush → play on the playback thread,
    and the test checked for the second play() as soon as flush() ran. With a 200 ms pause after
    flush(), the old assertion fails every time. It now waits for the call
    (verify(timeout = …)). Another test in the class waited 30 ms for a second thread to start
    release(); it now waits until that thread blocks on the state lock.
  • Instrumented: the GMD step failed in 4 of the last 9 runs (main on 11-20, 11-23 and 11-25, Hide specialized Gemini models in the model picker and fix the default #103 on
    11-24). CI doesn't keep the report, so the failing test isn't known. All three tests that run
    without an API key need the freshly installed app's functions to be indexed. They waited 10 s for
    a shell command and then called other APIs, never reset fakeFunction's state, and never dropped
    the shell identity. A shared FakeAppFunctionRule now waits up to 60 s, through the APIs the tests
    call, until fakeFunction shows in searchAppFunctions and getAppFunctionStates. It prints
    diagnostics on timeout and restores the state and identity after each test. CI now uploads the
    instrumentation results when that step fails, so a recurrence names the test. Locally (48 cores,
    or pinned to 4 like a hosted runner) the step didn't fail on main in 16 runs, so I couldn't
    confirm the cause.

Testing

  • Unit tests (written with Robolectric/MockK like their neighbours):
    • AppFunctionStatusTest (new): status mapping and canRun.
    • DebuggingViewModelTest: a runtime disable updates the selected app; functions added or removed
      at runtime show up and inputs and expanded functions are kept; an update without the app keeps
      the list; a run's result isn't reverted by a refresh; dynamic functions; error paths.
    • GetAppFunctionsUseCaseTest: a states change event re-reads states for the isEnabled filter
      in both directions; a metadata change searches again.
  • Screenshot tests: the function list with an enabled, a disabled, a registered dynamic and an
    unregistered dynamic function; an expanded disabled function; an expanded dynamic function. The
    existing references are unchanged.
  • Instrumented tests (GMD pixel7Api37, the CI task): fakeFunction is disabled and enabled at
    runtime and checked through GetAppFunctionStatesUseCase, GetAppFunctionsUseCase (isEnabled
    filter and a new emission after the change) and DebuggingViewModel with the real use cases.
    observeAppFunctions() registers its observer only when collected, after the use case's first
    result, so a change right after that result could be missed. The tests therefore repeat the change
    every 5 s until it shows (setEnabledAndAwait).
  • ./gradlew --continue spotlessCheck test validateScreenshotTest -PGEMINI_API_KEY=dummy_key:
    315/315 unit tests and 31/31 screenshot tests per flavor. The unit suites passed 5 more times in a
    row.
  • GMD (:app:pixel7Api37StandardDebugAndroidTest, swiftshader, as in CI): 12/12 runs green on this
    branch, 8 pinned to 4 CPUs and 4 unpinned. Each run had 8 tests, and the 13 Gemini tests were
    skipped because they need a key. main was also green in 16/16 runs.
  • On a Pixel 9 emulator (API 37), against ChatApp with a temporary activity-scoped function (Feat/ChatApp-Work-Adjustments #98's
    appendDraftMessage):
    • cmd app_function set-enabled … makeCall --state disable → the row updates in place; the typed
      endpointValue stays, and Run is disabled. Back to default → enabled again.
    • Two ChatApp activities → "Registered by 2 activities", which matches
      cmd app_function get-app-function-states. Force-stopping ChatApp while the Debug tab is on
      screen → "Not registered".

Evidence

Pixel 9 emulator (API 37), with ChatApp plus a temporary activity-scoped appendDraftMessage. That
patch isn't part of this PR.

main this PR
ChatApp disables makeCall at runtime
still shown as enabled

updates in place, input kept
Two ChatApp activities register appendDraftMessage
still "Disabled"

"Registered by 2 activities"
Run on the dynamic function
FUNCTION_NOT_FOUND

Run disabled, with the reason
ChatApp is force-stopped while the Debug tab is on screen —
"Not registered", in place

Recording of the whole flow on this branch:
09-e2e-flow.mp4

Targets tested: agent standard debug (unit tests and screenshots for standard and retail).

The Debug tab read function states only when an app was selected, so a function that an app
enabled or disabled at runtime, or a dynamic function that an activity registered or
unregistered, kept its old state until the app was selected again. Activity-scoped (dynamic)
functions looked like static ones, and their Run button always failed with FUNCTION_NOT_FOUND
because the agent can't target an activity yet.

- Model each function's runtime status (enabled, activity-scoped, number of registering
  activities) in the UI state instead of a Boolean.
- Refresh the selected app's functions and statuses on every update from GetAppFunctionsUseCase,
  keeping inputs, expanded functions and an open result. Results of a run are applied to the
  latest state, so a refresh during the run isn't reverted.
- Label disabled and dynamic functions with a reason, keep the header clickable so any function
  can be expanded or collapsed, and enable Run only for functions this screen can run.
- Add unit tests for the status mapping, the live refresh and the use case's re-emission on state
  changes, and screenshot tests for the new rows.
- AndroidLiveAudioSessionTest: "stopAudio flushes active AudioTrack and discards queued chunks"
  failed in CI (2026-11-17, 2026-11-23) because it checked for the play() that follows flush()
  before the playback thread made it. Wait for that call. Another test in the class relied on a
  30 ms sleep for a second thread to start release(); wait until that thread blocks on the state
  lock instead.
- Instrumented tests: a shared FakeAppFunctionRule waits until the freshly installed app's
  functions are visible through the APIs the tests call (searchAppFunctions and
  getAppFunctionStates, up to 60 s, with diagnostics on timeout) instead of polling a shell command
  for 10 s. It also restores fakeFunction's state and drops the shell identity after each test.
- New instrumented tests disable and re-enable fakeFunction at runtime and check
  GetAppFunctionStatesUseCase, GetAppFunctionsUseCase (isEnabled filter and re-emission) and the
  Debug tab's ViewModel.
- CI uploads the instrumentation test results when that step fails, so the failing test is known.
A flow built on observeAppFunctions() registers its platform observer only when collected, after GetAppFunctionsUseCase has emitted its first result, so a change made right after that result could go unnoticed and time the test out. FakeAppFunctionRule.setEnabledAndAwait sets the state and, until the change shows, switches the function to the other state and back every 5 s, always ending in the requested state.
With the Disabled and Dynamic labels next to it, a medium-length name such as appendDraftMessage was shortened to "appendD…Message" on a Pixel 9. The labels now go on a line below the name. Rows of enabled global functions don't change.
@google-cla

google-cla Bot commented Nov 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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