fix: [AI-11331] name the workspace and signed-in account when a link hits a hidden workspace

Merged
HK
1d ago
+593-139

Issue for this PR

Closes #

Jira: AI-11331. There is no GitHub issue; the bug was reported in Slack.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Problem. altimate-code link failed with:

This project is already linked to a workspace you can't see, most likely a teammate's private one. …

At the same time, the workspace menu said "this project is not linked". I traced the reported case through the service's database and request logs:

  • The repo's remote was linked by the user's own account to one of their private workspaces.
  • The CLI was later signed in to the same instance with a different account (a support login).
  • That account cannot see the private workspace. So the link lookup returned 404 ("not linked"), and the bind returned 409 with the workspace id and no name.

The service behaved as designed. The client message was the gap: it named neither the workspace nor the signed-in account, so a second sign-in could not be diagnosed.

Fix.

  • hiddenBindingMessage(detail, account?) names:

    • the workspace id the 409 already returns (only when it is a positive integer),
    • the email and instance of the account the failing request ran as.

    It says the workspace may be a teammate's, or the user's own under another sign-in.

  • Each of the 7 hidden-binding paths captures one credential before its bind or create-and-bind, and uses it for both the request and the message:

    • CLI: browser handoff, create, pick/headless.
    • TUI: browser handoff, quick create, picker, inline bind/re-link.

    So a sign-in switch while the request is in flight cannot attribute the conflict to the wrong account. The browser handoff binds as exactly the credential its tenant check validated.

  • WorkspaceApi.signedInAccount(actAs?) reads /users/me with that credential and a 3 s budget, and never throws. If the lookup fails or returns no email, the message still names the workspace id.

  • Server-sourced text (email, instance) is put on one line, stripped of control and bidi characters, and clipped (inertMessageValue in workspace-name.ts).

  • For a project already linked elsewhere, the unbound create and the rebind that follows also run as the captured credential.

  • The local link record is pinned to the same account as the write. If the account changes mid-request, nothing is recorded under the new account, and the TUI warns that the link stands but nothing was synced (the picker also closes, so it cannot link twice).

  • The picker closes before the account lookup, so a slow lookup cannot close a dialog the user opened in the meantime.

  • stripControlChars moved to workspace-name.ts, which the CLI and TUI share. link.ts re-exports it for existing importers.

Follow-ups (pre-existing, not changed here):

  • The create flow reads the credential three times (accountDigest, accountFingerprint, and the request).
  • A stale "(lines 377 and 496)" comment in link.ts.
  • The picker closes only after its bind/rebind request returns, so a slow request can still close a dialog opened meanwhile. This predates the PR; the PR only removed the extra wait it added (the account lookup).

How did you verify your code works?

  • Reproduced end to end. I ran altimate-code link --workspace <name> --yes against a mock service returning the production 409 body and /users/me. main prints the original error verbatim; this branch names workspace 38 and the signed-in account (recording below).
  • Regression tests, each confirmed to fail with its fix reverted:
    • account switch during the bind (listed and ambient credential, TUI);
    • CLI create-and-bind with an account switch;
    • a TUI quick create whose account is switched records nothing under the new account and warns;
    • /users/me failing, or answering without an email;
    • picker closes before the lookup;
    • bad ids, long values, and control/bidi/line-separator injection.
  • Local checks:
    • bun run typecheck is clean.
    • bun test test/altimate/workspace test/altimate/plugin/workspace.test.ts test/cli/cmd test/skill/release-v0.12.4-adversarial.test.ts test/skill/release-v0.11.2-adversarial.test.ts: 1714 pass, 0 fail.
    • oxlint reports 0 errors. script/check-tracker-leaks.ts passes. script/upstream/analyze.ts --markers --strict with the upstream remote passes.

Cost side effects

None. The only new call is one GET /users/me, made only after a link has already failed with a hidden-binding 409. It is bounded to 3 s, and its cost does not grow with user data.

Screenshots / recordings

Terminal recording of altimate-code link before (main) and after (this PR) against the mock service: attached below.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR
  • I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"

🤖 Generated with Claude Code