Skip to content

--locked-app / locked_app_package only launches the app once; nothing keeps the agent in it #240

Open

Description

@mmcgov

What is declared

The CLI option says the agent is restricted to one package:

locked_app_package: Annotated[
str | None,
typer.Option(
"--locked-app",
"-a",
help="Optional Android package name to restrict the agent to.",
),
] = None,

--locked-app, -a: "Optional Android package name to restrict the agent to."

The MCP tool description says the same, more strongly:

locked_app_package: Optional package name to lock execution to; the
agent auto-launches it and restricts actions to that app.

"Optional package name to lock execution to; the agent auto-launches it and restricts actions to that app."

and the SDK docstring: ".with_locked_app_package() to restrict execution to a specific app"

- .with_locked_app_package() to restrict execution to a specific app

What the code does instead

The only use of the value is _prepare_app_lock, which launches the package once before the run and stores the result. If the launch fails, it logs a warning and the run continues:

async def _prepare_app_lock(self, task: Task, context: ArtemisContext):
"""Prepare app lock by launching the locked app if specified."""
if not task.request.locked_app_package:
return
task_name = task.get_name()
logger.info(f"[{task_name}] Preparing app lock for: {task.request.locked_app_package}")
app_lock_status = await _handle_initial_app_launch(
ctx=context, locked_app_package=task.request.locked_app_package
)
if context.execution_setup is None:
context.execution_setup = ExecutionSetup(app_lock_status=app_lock_status)
else:
context.execution_setup.app_lock_status = app_lock_status
if app_lock_status.locked_app_initial_launch_success is False:
error = app_lock_status.locked_app_initial_launch_error
logger.warning(f"[{task_name}] Failed to launch locked app: {error}")

The stored status has an accessor, ExecutionSetup.get_locked_app_package(), but nothing calls it:

app_lock_status: AppLaunchResult | None = None
def get_locked_app_package(self) -> str | None:
"""Get the locked app package name if app locking is enabled.
Returns:
The locked app package name, or None if app locking is not enabled.
"""
if self.app_lock_status:
return self.app_lock_status.locked_app_package

I could not find a per-step foreground check, a tool filter, or prompt text in either the Flash runner or the Pro graph that refers to the locked package. After the first launch the agent can open or act in any other app, and nothing detects it.

(The builder's own docstring is accurate - "ensures the specified app is launched and in the foreground before the agentic loop starts" - so the gap is between that behaviour and what the CLI help, MCP description and SDK docstring promise.)

def with_locked_app_package(self, package_name: str) -> Self:
"""Set the app package to lock execution to.
This ensures the specified app is launched and in the foreground before
the agentic loop starts.
Args:
package_name: Package name (Android, e.g., 'com.whatsapp')
"""
self._locked_app_package = package_name
return self

What a user would expect

Passing --locked-app com.example.app (or locked_app_package over MCP) keeps the agent's actions inside that app for the whole run, or stops the run if it leaves or if the app cannot be launched.

Suggested fix

Either of:

  1. Enforce it: after each action (or in the pre-action check), compare the foreground package with ctx.execution_setup.get_locked_app_package(); on a mismatch relaunch the locked app or end the run with a clear status, and fail the run when the initial launch fails instead of warning.
  2. If launch-only is the intended behaviour, reword the CLI help, the MCP tool description and the sdk/agent.py docstring to say the app is launched at the start and the agent is not confined to it.

This is a reading of the code, not a run.

Disclosure: this finding came from an automated review of the repository's code with a tool I am developing, and was re-checked by a second, slower pass of the same kind; nothing was run.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions