feat(environment): add --detach to 'environment new' for background duplication#937
Open
0xnmn wants to merge 1 commit into
Open
feat(environment): add --detach to 'environment new' for background duplication#9370xnmn wants to merge 1 commit into
0xnmn wants to merge 1 commit into
Conversation
…uplication `railway environment new --duplicate <src>` is non-atomic today: the CLI creates an empty env, then client-side fetches the source config and applies it, all under a hardcoded 30s HTTP timeout. The server-side environmentCreate blocks the response until the service + volume copy finishes (p95 ~118s), so duplicates of non-trivial envs routinely exceed 30s, abort, and leave an orphaned empty environment behind. Add an opt-in `--detach` flag that uses the backend's atomic path (sourceEnvironmentId) with applyChangesInBackground:true, so the copy runs in a background workflow and the call returns immediately. Default behavior is unchanged. `--detach` errors if combined with --service-config/-variable, since the server-side copy can't apply CLI-side per-service overrides. Closes #923
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 environment new <name> --duplicate <src>is non-atomic. The CLI:EnvironmentCreatewithsourceId: null),EnvironmentPatchCommit,…all sharing one hardcoded 30s HTTP timeout (
src/client.rs). The server-sideenvironmentCreateblocks the HTTP response by long-polling its Temporal workflow until the service + volume copy completes (measured p50 ~13s, p95 ~118s). When the copy exceeds 30s the CLI aborts withoperation timed out— but the empty env from step 1 already exists, so a broken orphan ("husk") is left behind, and retries collide on the name. The reporter sees this fail the majority of the time.Fix
The backend already exposes the right primitives on
EnvironmentCreate—sourceEnvironmentId(atomic server-side duplicate) andapplyChangesInBackground(defer the heavy copy to a background child workflow) — the CLI just never used them.This adds an opt-in
--detachflag toenvironment newthat mirrors therailway up --detach"trigger + return, user polls" idiom:--detach⇒ a singleEnvironmentCreate { sourceId: <dup>, applyChangesInBackground: true }, then returns immediately. The copy runs server-side in the background.--detach+--service-config/--service-variable⇒ errors with a clear message, since the server-side copy can't apply CLI-side per-service overrides.-dis already taken by--duplicate), matching--jsonin this command.Default behavior is unchanged — without
--detach, the existing create→fetch→apply→wait flow runs exactly as before. No breaking change.Usage
Test plan
cargo buildclean;cargo fmtrailway environment new --helpshows--detach--detach --duplicate <src>returns immediately; services/volumes populate shortly after (verify on staging)--detach --service-config …errors clearly, creates nothing--detach) unchanged--detachcreate worksFollow-ups (out of scope)
applyChangesInBackgroundinto the MCPcreate_environmenttool (src/commands/mcp/tools/project.rs).StartWorkflowExecutionrather than long-pollingGetWorkflowExecutionHistory, so even the synchronous prelude doesn't block the request under worker contention.Closes #923
🤖 Generated with Claude Code