Skip to content

fix(s3): guard switch_applications against missing wmctrl window match - #221

Open
starm2010 wants to merge 1 commit into
simular-ai:mainfrom
starm2010:fix/switch-apps-window-id-guard
Open

starm2010 wants to merge 1 commit into
simular-ai:mainfrom
starm2010:fix/switch-apps-window-id-guard

Conversation

@starm2010

Copy link
Copy Markdown

Problem

The UBUNTU_APP_SETUP template used by agent.switch_applications() references window_id without initializing it. When difflib.get_close_matches finds no match (target app not open, or no window with a similar title), exec() raises:

NameError: name 'window_id' is not defined

Because cli_app.run_agent() executes the generated code with no error handling, a single missing-window switch kills the entire agent process mid-task.

Solution

Initialize window_id = None before the match loop and guard the two wmctrl calls with if window_id:. When no window matches, the action becomes a no-op instead of a crash — the agent sees an unchanged screen on the next step and can adapt (open the app another way, or honestly report it is not open).

Testing

  • RED: executed the real template from grounding.py with an app name matching no window → NameError kills the process (reproducible).
  • GREEN: same scenario with the guard → template completes cleanly.
  • E2E: task "switch to Calculator" with Calculator not open — before: process dead at step 1 (42s). After: agent continues, reports the app is not open, and completes the task with an honest failure report.

The UBUNTU_APP_SETUP template used by agent.switch_applications()
references window_id without initializing it. When
difflib.get_close_matches finds no match (app not open, no window
with a similar title), exec() raises NameError: name 'window_id'
is not defined — which kills the whole agent process mid-task
because cli_app's exec has no try/except.

This makes the failure non-fatal: initialize window_id=None and
only run the wmctrl activate/maximize calls when a match was found.
The agent sees an unchanged screen and can adapt (e.g. open the app
another way or report it is missing).

Reproduced E2E: task 'switch to Calculator' with Calculator not
open → NameError at step 1, process dead (logs: NameError traceback).
With the guard → agent continues, reports the app is not open, and
completes the task with an honest failure report.
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