Skip to content

fix(shortcuts): route accepts agent name OR id (was: id only) - #280

Merged
jaylfc merged 2 commits into
masterfrom
fix/shortcuts-name-lookup
May 1, 2026
Merged

fix(shortcuts): route accepts agent name OR id (was: id only)#280
jaylfc merged 2 commits into
masterfrom
fix/shortcuts-name-lookup

Conversation

@jaylfc

@jaylfc jaylfc commented Apr 30, 2026

Copy link
Copy Markdown
Owner

Summary

`AgentsApp` passes `agent.name` ("john") to `/api/agents/{ref}/shortcuts`, but the route's `_get_agent_by_id` helper only matched `agent.id` (a hex hash). Result: 404 → `shortcuts=[]` → `AgentShortcutRow` rendered null → no shortcut buttons in AgentsApp.

This was the actual reason agent shortcuts weren't showing in the iOS PWA — not a cache problem.

The fix renames the helper to `_get_agent_by_name_or_id` and tries the name first (matching the convention used by `/api/agents/{name}/logs` and similar existing routes), falling through to id. Both callers (`list_shortcuts`, `launch_shortcut`) updated.

`shortcut_proxy.py` was checked — its `_resolve_container_ip` and `_get_shortcuts_for_agent` already matched by both `id` and `name`, so no change needed there.

Test plan

  • New tests verify both name and id paths return 200
  • Existing list/launch/proxy tests still pass (52 total)
  • Manual: open AgentsApp on iPhone — agents with shortcuts (john, tom, don) should show a second row of buttons

Summary by CodeRabbit

  • New Features

    • Shortcut-list endpoint now accepts agent identifiers by name as well as by ID, making agent lookup more flexible and user-friendly.
  • Tests

    • Added route tests to verify agent lookup by name and by ID, ensuring the endpoint returns successful JSON responses and maintains backward compatibility.

AgentsApp passes agent.name to /api/agents/{ref}/shortcuts but the
route only matched against agent.id. Result: 404 -> empty list ->
AgentShortcutRow rendered null -> user saw no shortcut buttons.

The convention elsewhere in taOS (logs, agents/{name}/...) is name-
based, so accept both name and id at this route too. Renames the
helper from _get_agent_by_id to _get_agent_by_name_or_id and tries
name first, then id.
@coderabbitai

coderabbitai Bot commented Apr 30, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Agent resolution in shortcut routes now matches by either name or id (helper _get_agent_by_name_or_id); both list_shortcuts and launch_shortcut use it. Two tests added to assert the shortcut-list endpoint accepts agent.name and agent.id and returns HTTP 200 with a JSON array.

Changes

Cohort / File(s) Summary
Tests
tests/routes/test_shortcuts_list.py
Added two route-coverage tests: test_get_shortcuts_by_name and test_get_shortcuts_by_id, validating the shortcut-list endpoint accepts agent.name and agent.id, asserting HTTP 200 and JSON array responses.
Route Logic
tinyagentos/routes/shortcuts.py
Replaced _get_agent_by_id with _get_agent_by_name_or_id; agent resolution now attempts name match first, then id if no name match; both list_shortcuts and launch_shortcut use the new helper and still return 404 when not found.

Sequence Diagram(s)

sequenceDiagram
  participant Client as Client
  participant Route as Server Route
  participant Registry as Agent Registry
  participant Shortcuts as Shortcuts Service

  Client->>Route: GET /shortcuts?agent.name=alice (or agent.id=...)
  Route->>Registry: _get_agent_by_name_or_id(query)
  Registry-->>Route: matches agent (by name or id) / not found
  Route->>Shortcuts: list_shortcuts(agent)
  Shortcuts-->>Route: JSON array of shortcuts
  Route-->>Client: HTTP 200 + JSON
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 By name or by id I hop with glee,
I sniff the registry for who you want me to be.
Two tests applaud each path that I try,
Shortcuts respond — a cheer and a sigh! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: the shortcuts route now accepts both agent name OR id, whereas previously it only accepted id.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/shortcuts-name-lookup

Review rate limit: 8/10 reviews remaining, refill in 7 minutes and 14 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@kilo-code-bot

kilo-code-bot Bot commented Apr 30, 2026

Copy link
Copy Markdown

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 0
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
tinyagentos/routes/shortcuts.py 104 mint_ticket call uses agent_id parameter instead of agent["id"] - when agent is looked up by name, this passes the name instead of the actual ID, potentially causing incorrect ticket minting
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
tinyagentos/routes/shortcuts.py 20-22 Previous WARNING (potential ambiguity in agent lookup) has been resolved by updating the lookup logic to prioritize name matches first, then fall back to ID matches.
Files Reviewed (2 files)
  • tinyagentos/routes/shortcuts.py - 1 issue
  • tests/routes/test_shortcuts_list.py - 0 issues

Fix these issues in Kilo Cloud


Reviewed by grok-code-fast-1:optimized:free · 155,115 tokens

Comment thread tinyagentos/routes/shortcuts.py Outdated
agents = request.app.state.config.agents
for agent in agents:
if agent.get("id") == agent_id:
if agent.get("name") == agent_ref or agent.get("id") == agent_ref:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Potential ambiguity in agent lookup

If multiple agents have the same name, this function returns the first match. This could lead to inconsistent behavior if names are not guaranteed to be unique. Consider ensuring name uniqueness or prioritizing ID matches.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/routes/test_shortcuts_list.py (1)

88-105: ⚡ Quick win

Add a collision-case regression test for identifier precedence.

These tests cover both accepted identifiers, but they don’t lock the critical edge case: when one agent’s id equals another agent’s name. Add one test asserting /api/agents/{ref}/shortcuts resolves by name first to prevent future regressions.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/routes/test_shortcuts_list.py` around lines 88 - 105, Add a regression
test that verifies name takes precedence when an agent id collides with another
agent's name: create two fixtures/agents (use existing test helpers like
agent_with_shortcuts or new ones) where agent_a["name"] == agent_b["id"], then
call test_client.get(f"/api/agents/{agent_a['name']}/shortcuts",
headers=admin_auth_headers) and assert the response returns agent_a's shortcuts
(status 200 and expected list contents), ensuring the lookup resolves by name
first; name the test e.g. test_get_shortcuts_name_precedence_collision and reuse
admin_auth_headers/test_client to mirror the existing tests
test_get_shortcuts_by_name and test_get_shortcuts_by_id.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tinyagentos/routes/shortcuts.py`:
- Around line 16-21: The function _get_agent_by_name_or_id currently uses a
single-pass "name OR id" match which can return an id-match before a name-match;
change the logic to perform a deterministic name-first lookup by first iterating
over request.app.state.config.agents and returning the agent where
agent.get("name") == agent_ref, and only if no name match is found do a second
pass returning the agent where agent.get("id") == agent_ref; keep the same 404
behavior if neither pass finds a match.

---

Nitpick comments:
In `@tests/routes/test_shortcuts_list.py`:
- Around line 88-105: Add a regression test that verifies name takes precedence
when an agent id collides with another agent's name: create two fixtures/agents
(use existing test helpers like agent_with_shortcuts or new ones) where
agent_a["name"] == agent_b["id"], then call
test_client.get(f"/api/agents/{agent_a['name']}/shortcuts",
headers=admin_auth_headers) and assert the response returns agent_a's shortcuts
(status 200 and expected list contents), ensuring the lookup resolves by name
first; name the test e.g. test_get_shortcuts_name_precedence_collision and reuse
admin_auth_headers/test_client to mirror the existing tests
test_get_shortcuts_by_name and test_get_shortcuts_by_id.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 70341d30-8cf2-49bf-a38d-064b37fbd9f8

📥 Commits

Reviewing files that changed from the base of the PR and between 16b02b1 and 9ed6831.

📒 Files selected for processing (2)
  • tests/routes/test_shortcuts_list.py
  • tinyagentos/routes/shortcuts.py

Comment thread tinyagentos/routes/shortcuts.py
…allback)

Single-pass 'name or id' matching is order-dependent — if an agent has
id='tom' and another has name='tom', list order decides which wins. Use
two passes: try name across all agents first, fall back to id only when
no name matches.

Addresses CodeRabbit review on PR #280.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tinyagentos/routes/shortcuts.py (1)

84-109: ⚠️ Potential issue | 🟠 Major

Use the resolved agent's canonical id when minting the ticket.

launch_shortcut correctly resolves the agent using a two-pass lookup (name first, then id), but line 104 passes the raw path parameter agent_id to mint_ticket instead of the resolved agent's canonical id. This creates fragility downstream: the ticket and session store the raw value (which may be a name), and the proxy routes later use single-pass id-or-name resolution to look up the agent. If the agent list is reordered or a new agent is added, the single-pass resolver could match a different agent, bypassing the two-pass constraint that was enforced at launch time.

Extract the canonical id from the resolved agent before minting:

Proposed fix
 async def launch_shortcut(
@@
-    _ticket, token = mint_ticket(
-        agent_id=agent_id,
+    canonical_agent_id = agent.get("id", agent_id)
+    _ticket, token = mint_ticket(
+        agent_id=canonical_agent_id,
         shortcut_idx=idx,
         scope=scope,
         signing_key=signing_key,
         worker_url=worker_url,
         ttl=30,
     )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tinyagentos/routes/shortcuts.py` around lines 84 - 109, The launch_shortcut
flow currently resolves the agent with _get_agent_by_name_or_id(request,
agent_id) but then passes the original path parameter agent_id into mint_ticket;
change mint_ticket to receive the resolved agent's canonical id (e.g.,
agent["id"] or agent.get("id")) instead of the raw agent_id so the
ticket/session record uses the resolved canonical id; update the call site where
mint_ticket(...) is invoked (and any local variable you add, e.g., canonical_id)
to pass that resolved id.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@tinyagentos/routes/shortcuts.py`:
- Around line 84-109: The launch_shortcut flow currently resolves the agent with
_get_agent_by_name_or_id(request, agent_id) but then passes the original path
parameter agent_id into mint_ticket; change mint_ticket to receive the resolved
agent's canonical id (e.g., agent["id"] or agent.get("id")) instead of the raw
agent_id so the ticket/session record uses the resolved canonical id; update the
call site where mint_ticket(...) is invoked (and any local variable you add,
e.g., canonical_id) to pass that resolved id.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5326c855-067c-45fd-9c3a-a4ecab824e5e

📥 Commits

Reviewing files that changed from the base of the PR and between 9ed6831 and 2748050.

📒 Files selected for processing (1)
  • tinyagentos/routes/shortcuts.py

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