Skip to content

lakebox: resolve names → IDs from local cache#5371

Merged
akshaysingla-db merged 2 commits into
databricks:demo-lakeboxfrom
akshaysingla-db:akshay/lakebox-name-resolver
May 29, 2026
Merged

lakebox: resolve names → IDs from local cache#5371
akshaysingla-db merged 2 commits into
databricks:demo-lakeboxfrom
akshaysingla-db:akshay/lakebox-name-resolver

Conversation

@akshaysingla-db
Copy link
Copy Markdown
Collaborator

databricks lakebox ssh my-project and the same shape on status / stop / start / delete / config / default now accept a --name value in place of a sandbox ID, resolved purely from local state — no extra API call on the slow path.

How it works:

  • The state file (~/.databricks/lakebox.json) grows a per-profile sandboxes list of (id, name) pairs.
  • resolveLocalID maps the user-typed arg to an ID:
    1. Exact ID match → return as-is (fast path; preserves the existing "I know the ID" workflow).
    2. Exact name match in cache → return the corresponding ID. Ambiguous names (server allows duplicate --name values) error out with the candidate IDs.
    3. No match → pass arg through unchanged. Either it's an ID the cache hasn't seen yet (fresh sandbox, user hasn't listed) or a typo; either way the next API call surfaces a clean 404.

The cache is populated incrementally by the commands that already observe sandbox state:

  • create upserts the new sandbox.
  • list replaces the cache in full.
  • status / stop / start / config / default upsert the one entry they touch.
  • delete removes it.

A stale cache can only fail to find a name; it can never cause the CLI to operate on the wrong sandbox. Resolution is ID-first so a sandbox whose --name happens to collide with another sandbox's ID never gets mistakenly matched by name.

Co-authored-by: Isaac

Changes

Why

Tests

@github-actions
Copy link
Copy Markdown
Contributor

Waiting for approval

Based on git history, these people are best suited to review:

  • @pietern -- recent work in cmd/lakebox/

Eligible reviewers: @andrewnester, @anton-107, @denik, @renaudhartert-db, @shreyas-goenka, @simonfaltum

Suggestions based on git history. See OWNERS for ownership rules.

`databricks lakebox ssh my-project` and the same shape on status /
stop / start / delete / config / default now accept a `--name` value
in place of a sandbox ID, resolved purely from local state — no
extra API call on the slow path.

How it works:

- The state file (~/.databricks/lakebox.json) grows a per-profile
  `sandboxes` list of (id, name) pairs.
- `resolveLocalID` maps the user-typed arg to an ID:
    1. Exact ID match → return as-is (fast path; preserves the
       existing "I know the ID" workflow).
    2. Exact name match in cache → return the corresponding ID.
       Ambiguous names (server allows duplicate --name values)
       error out with the candidate IDs.
    3. No match → pass arg through unchanged. Either it's an ID the
       cache hasn't seen yet (fresh sandbox, user hasn't `list`ed)
       or a typo; either way the next API call surfaces a clean 404.

The cache is populated incrementally by the commands that already
observe sandbox state:
  - `create` upserts the new sandbox.
  - `list` replaces the cache in full.
  - `status` / `stop` / `start` / `config` / `default` upsert the
    one entry they touch.
  - `delete` removes it.

A stale cache can only fail to find a name; it can never cause the
CLI to operate on the wrong sandbox. Resolution is ID-first so a
sandbox whose `--name` happens to collide with another sandbox's ID
never gets mistakenly matched by name.

Co-authored-by: Isaac
Now that the resolver populates `~/.databricks/lakebox.json` with an
(id, name) cache per profile, the completion path no longer needs to
hit the API on every `<TAB>`. Reads the cache directly via
`getSandboxes`, falling back to no suggestions when the cache is empty.

Benefits:
  - Instant tab feedback. No round-trip blocks the shell.
  - Tab works offline / on a flaky network.
  - Auth token issues no longer make completion fail silently.

Trade-off: a sandbox created from another machine doesn't show up
until you run `lakebox list` locally. That's the same refresh model
as the resolver itself, so the two stay consistent: if `lakebox ssh
my-project` can resolve it, `lakebox ssh <TAB>` can suggest it.

Also offers display names as suggestions when they differ from the
ID, so users who set `--name foo` can tab to either `foo` or the
underlying pet-name.

`ssh-key delete <hash>` still calls the API — key hashes aren't
cached locally (per-user cap is ~100 and listing is cheap).

Co-authored-by: Isaac
@akshaysingla-db akshaysingla-db force-pushed the akshay/lakebox-name-resolver branch from 31f0d93 to 8e5e950 Compare May 29, 2026 06:58
@akshaysingla-db akshaysingla-db merged commit 60997ef into databricks:demo-lakebox May 29, 2026
12 of 19 checks passed
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