Skip to content

fix(ca): fall back to the default project when a directory link is stale - #1096

Merged
codyde merged 1 commit into
masterfrom
cody/ca-stale-link-fallback
Aug 13, 2026
Merged

fix(ca): fall back to the default project when a directory link is stale#1096
codyde merged 1 commit into
masterfrom
cody/ca-stale-link-fallback

Conversation

@codyde

@codyde codyde commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Problem

railway code --railway (and every other railway code / railway ca launch) failed with

Project not found. Run railway link to connect to a project.

when run in a directory whose link points at a project that has since been deleted. Two things made this baffling in practice:

  • The link lookup walks ancestor directories, so the stale link is often in a parent the user doesn't remember linking (e.g. ~/projects linked to a long-deleted sandbox project poisons every launch under it).
  • The user's expectation — "no usable link → use my default cloud agents project" — is exactly what the precedence in choose_target is meant to deliver, but the link was trusted without validation. resolve_target returned the dead IDs, the pane launch re-entered the pipeline via LaunchArgs::for_target (flags), and get_project finally hit the API and died with the generic error above.

Fix

Probe the link in resolve_target before it outranks the configured default. A definite server-side "gone" demotes it:

  • project not found
  • project readable but deletedAt set
  • linked environment missing or deleted

with a warning naming what went stale (This directory is linked to a project that no longer exists — ignoring the link (railway link to fix it).) plus which default the launch is using instead. The launch then lands where a linkless run would have: the configured default, or railway ca setup when there is none.

Anything short of definite (auth/network errors) keeps the link and lets the launch's own calls decide — a transient failure must not be able to reroute a launch to a different project.

Flags (-p/-e) are unaffected: an explicitly passed dead ID still errors, as it should. The probe only runs when a link would actually be consulted (no flags), so flag-driven and TUI launches pay nothing.

Notes

  • The staleness verdict lives in a pure stale_link_reason helper with unit tests covering all verdicts (not found / deleted project / missing env / deleted env / healthy / inconclusive).
  • Known follow-up, deliberately out of scope: railway ca ssh <name>'s first-agent auto-create consults the link directly (lifecycle.rs) and would still target a stale environment; and a configured default that is itself dead still fails with the generic error (setup re-validates it).

🤖 Generated with Claude Code

`railway code` let a directory link outrank the configured default
project without ever checking the link still names something real.
Links are never cleaned up, so a link to a since-deleted project — or a
parent directory's link, since the lookup walks ancestors — sent the
launch into `get_project` with a dead ID, which surfaced as a bare
"Project not found. Run `railway link` to connect to a project." in a
directory nobody remembers linking.

Probe the link before it wins: a definite server-side "gone" (project
not found, project deleted, or the linked environment missing/deleted)
demotes the link with a warning naming what went stale, and the launch
lands where a linkless run would have — the configured default, or
setup when there is none. Anything short of definite (auth or network
failures) keeps the link, so a blip cannot reroute a launch to a
different project.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codyde codyde added the release/patch Author patch release label Aug 13, 2026
@codyde
codyde merged commit 4c1a9d4 into master Aug 13, 2026
7 of 8 checks passed
@codyde
codyde deleted the cody/ca-stale-link-fallback branch August 13, 2026 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release/patch Author patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant