[pull] main from czlonkowski:main - #61
Merged
Merged
Conversation
…save (#769) * fix(workflow-diff): roll back to prior state when n8n PUT fails post-save When n8n_update_partial_workflow's underlying PUT fails (e.g. n8n persisted the workflow body but the activation step within the same PUT then tripped on an unsupported typeVersion), the workflow was being left in a broken state. The handler already snapshots the prior workflow into workflowBefore for telemetry, so we piggyback on it: on PUT failure, attempt a rollback PUT to restore the prior state. Three return paths on failure: - Pre-mutation (no snapshot, e.g. validateOnly) — preserve current behaviour - Rollback succeeded — error suffixed with "(workflow restored to prior state)" + details.rollbackPerformed = true - Rollback failed — composite error pointing to n8n_workflow_versions for manual recovery + details.rollbackPerformed = false + rollbackError Success path is byte-identical to before. Tests: - New "should roll back to prior state when n8n PUT fails after persisting body" test asserts the rollback PUT fires with the prior snapshot - New "should report rollback failure when both PUTs fail" test asserts the composite error is surfaced - Existing "should not attempt rollback in validateOnly mode" remains intact Known limitations (documented in PR description): - Concurrent writers can race the rollback. Same race window as today's plain PUT. A future iteration could use versionId for optimistic concurrency. - Rollback fires even when n8n rejected pre-save (body never persisted). Rollback is a no-op in that case — one extra HTTP request on the failure path. Chose this over guessing n8n's error semantics. * fix(workflow-diff): skip rollback on pre-save rejection + actionable recovery Building on the rollback-on-error fix, distinguish two failure modes via a post-failure GET that compares versionId / versionCounter / updatedAt against the snapshot: - Persist-then-fail (n8n saved the body before activation died): roll back by re-PUTting the prior snapshot. Error gets the existing "(workflow restored to prior state)" suffix. - Pre-save rejection (body never persisted): skip the rollback PUT — it would be wasted and the suffix would mislead the caller. details.rollbackPerformed: false; no suffix. When rollback fails, surface workflowBefore.versionId as details.priorVersionId so callers can recover via n8n_workflow_versions. The version comparison is tri-state (same / changed / unknown). On "unknown" — older n8n versions that omit all three fields, or a failing post-failure GET — fall back to attempting rollback. The silent-corruption class from #770 is far worse than a redundant PUT. Tests cover persist-then-fail rollback, pre-save no-rollback, GET-failure best-effort rollback, versionCounter-only fallback, no-version-fields safety net, and double-PUT-failure with priorVersionId. 45/45 in handlers-workflow-diff.test.ts; 611/611 across tests/unit/mcp. Bumped to v2.50.3.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )