fix(ca): fall back to the default project when a directory link is stale - #1096
Merged
Conversation
`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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
railway code --railway(and every otherrailway code/railway calaunch) failed withwhen run in a directory whose link points at a project that has since been deleted. Two things made this baffling in practice:
~/projectslinked to a long-deleted sandbox project poisons every launch under it).choose_targetis meant to deliver, but the link was trusted without validation.resolve_targetreturned the dead IDs, the pane launch re-entered the pipeline viaLaunchArgs::for_target(flags), andget_projectfinally hit the API and died with the generic error above.Fix
Probe the link in
resolve_targetbefore it outranks the configured default. A definite server-side "gone" demotes it:deletedAtsetwith a warning naming what went stale (
This directory is linked to a project that no longer exists — ignoring the link (railway linkto fix it).) plus which default the launch is using instead. The launch then lands where a linkless run would have: the configured default, orrailway ca setupwhen 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
stale_link_reasonhelper with unit tests covering all verdicts (not found / deleted project / missing env / deleted env / healthy / inconclusive).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