Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-6971 fix(issues): stop rejecting description edits against a stale baseline (#7926)
Bohan Jiang835c5437a9ca
diff --git a/packages/views/issues/components/issue-detail.test.tsx b/packages/views/issues/components/issue-detail.test.tsxindex d93fd40d37..892b679196 100644--- a/packages/views/issues/components/issue-detail.test.tsx+++ b/packages/views/issues/components/issue-detail.test.tsx@@ -1919,7 +1919,12 @@ describe("IssueDetail (shared)", () => {});});- it("keeps a description draft visible when its captured content conflicts", async () => {+ // Descriptions are last-write-wins (MUL-6971). The baseline still ships as+ // channel-media merge metadata, but a rejected save no longer opens a compare+ // panel — that panel fired on the editor's own autosave and wedged the+ // session, and the title/comment editors keep the compare flow they can+ // actually satisfy.+ it("keeps editing after a failed description save without a compare panel", async () => {mockApiObj.updateIssue.mockRejectedValueOnce({body: { code: "revision_conflict" },});@@ -1938,40 +1943,24 @@ describe("IssueDetail (shared)", () => {}),),);+ // The compare panel's own actions — still rendered for a title conflict,+ // so their absence is about the description, not a missing translation.expect(- await screen.findByText("The description was changed concurrently. Compare both versions."),- ).toBeVisible();- expect(screen.getAllByText("My local description").length).toBeGreaterThan(0);- expect(screen.getByDisplayValue("My local description")).toBeVisible();- });-- it("restores the server description when the user takes the latest version", async () => {- mockApiObj.updateIssue.mockRejectedValueOnce({- body: { code: "revision_conflict" },- });- renderIssueDetail();-- const editor = await screen.findByDisplayValue("Add JWT auth to the backend");- fireEvent.focus(editor);- fireEvent.change(editor, { target: { value: "My local description" } });-+ screen.queryByRole("button", { name: "Keep my version" }),+ ).not.toBeInTheDocument();expect(- await screen.findByText("The description was changed concurrently. Compare both versions."),- ).toBeVisible();- const callsBeforeDiscard = mockApiObj.updateIssue.mock.calls.length;-- fireEvent.click(screen.getByRole("button", { name: "Use the latest version" }));+ screen.queryByRole("button", { name: "Use the latest version" }),+ ).not.toBeInTheDocument();+ expect(screen.getByDisplayValue("My local description")).toBeVisible();+ // The save gate reopened: the next edit still reaches the server.+ fireEvent.change(editor, { target: { value: "My next description" } });await waitFor(() =>- expect(- screen.queryByText("The description was changed concurrently. Compare both versions."),- ).not.toBeInTheDocument(),+ expect(mockApiObj.updateIssue).toHaveBeenLastCalledWith(+ "issue-1",+ expect.objectContaining({ description: "My next description" }),+ ),);- // A dirty editor ignores prop-driven content, so seeing the server text- // back in the editor proves the imperative adopt path ran.- expect(screen.getByDisplayValue("Add JWT auth to the backend")).toBeVisible();- // Taking the server version is local-only: the server already holds it.- expect(mockApiObj.updateIssue).toHaveBeenCalledTimes(callsBeforeDiscard);});it("serializes description saves and rebases the queued draft on submitted content", async () => {@@ -2011,32 +2000,6 @@ describe("IssueDetail (shared)", () => {);});- it("keeps the newest queued description when the in-flight save conflicts", async () => {- let rejectFirst!: (error: unknown) => void;- const firstSave = new Promise<Issue>((_resolve, reject) => {- rejectFirst = reject;- });- mockApiObj.updateIssue.mockReturnValueOnce(firstSave);- renderIssueDetail();-- const editor = await screen.findByDisplayValue("Add JWT auth to the backend");- fireEvent.focus(editor);- fireEvent.change(editor, { target: { value: "First local description" } });- await waitFor(() => expect(mockApiObj.updateIssue).toHaveBeenCalledTimes(1));- fireEvent.change(editor, { target: { value: "Newest local description" } });-- await act(async () => {- rejectFirst({ body: { code: "revision_conflict" } });- await firstSave.catch(() => undefined);- });-- expect(mockApiObj.updateIssue).toHaveBeenCalledTimes(1);- expect(- await screen.findByText("The description was changed concurrently. Compare both versions."),- ).toBeVisible();- expect(screen.getByDisplayValue("Newest local description")).toBeVisible();- });-it("ignores a late description callback after switching issues", async () => {const queryClient = createTestQueryClient();const issue2: Issue = {diff --git a/packages/views/issues/components/issue-detail.tsx b/packages/views/issues/components/issue-detail.tsxindex 772cfd097e..5b82e94bc8 100644--- a/packages/views/issues/components/issue-detail.tsx+++ b/packages/views/issues/components/issue-detail.tsx@@ -1992,8 +1992,6 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = trconst descEditorRef = useRef<ContentEditorRef>(null);const descriptionEditingRef = useRef(false);- const [descriptionConflictDraft, setDescriptionConflictDraft] = useState<string | null>(null);- const descriptionAttachmentIdsRef = useRef<string[]>([]);const descriptionSaveInFlightRef = useRef(false);const descriptionSaveIssueIdRef = useRef(id);const pendingDescriptionSaveRef = useRef<{@@ -2015,9 +2013,7 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = trconst [titleResetToken, setTitleResetToken] = useState(0);useEffect(() => {setTitleConflictDraft(null);- setDescriptionConflictDraft(null);titleBaseRef.current = undefined;- descriptionAttachmentIdsRef.current = [];descriptionSaveInFlightRef.current = false;descriptionSaveIssueIdRef.current = id;pendingDescriptionSaveRef.current = null;@@ -2270,7 +2266,6 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr{onSuccess: (serverIssue) => {if (descriptionSaveIssueIdRef.current !== id) return;- setDescriptionConflictDraft(null);descriptionSaveInFlightRef.current = false;const pending = pendingDescriptionSaveRef.current;pendingDescriptionSaveRef.current = null;@@ -2285,16 +2280,10 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = trpersistDescriptionSave({ ...pending, baseMarkdown: nextBase });}},- onError: (error) => {+ onError: () => {if (descriptionSaveIssueIdRef.current !== id) return;descriptionSaveInFlightRef.current = false;- const pending = pendingDescriptionSaveRef.current;pendingDescriptionSaveRef.current = null;- if (errorCode(error) === "revision_conflict") {- const latest = pending ?? draft;- descriptionAttachmentIdsRef.current = latest.attachmentIds;- setDescriptionConflictDraft(latest.markdown);- }},},);@@ -2303,7 +2292,6 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = trconst queueDescriptionSave = (draft: { markdown: string; baseMarkdown: string; attachmentIds: string[] },) => {- descriptionAttachmentIdsRef.current = draft.attachmentIds;if (descriptionSaveInFlightRef.current) {pendingDescriptionSaveRef.current = draft;return;@@ -3057,7 +3045,7 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr<ContentEditorref={descEditorRef}key={id}- value={descriptionConflictDraft ?? issue.description ?? ""}+ value={issue.description ?? ""}placeholder={t(($) => $.detail.desc_placeholder)}onUpdate={(md, baseMarkdown) => {// Bind any pending uploads still referenced in the markdown@@ -3096,64 +3084,6 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = trattachments={descEditorAttachments}/>- {descriptionConflictDraft !== null ? (- <RevisionConflictCompare- className="mt-3"- title={t(($) => $.revision.compare_description)}- serverLabel={t(($) => $.revision.server_version)}- localLabel={t(($) => $.revision.local_version)}- serverValue={issue.description || ""}- localValue={descriptionConflictDraft}- serverAction={(- <Button- type="button"- size="sm"- variant="outline"- onClick={() => {- // The editor is dirty — that is why this conflict- // exists — so the `value` prop cannot land: ContentEditor- // deliberately refuses to clobber unsaved bytes.- // adoptContent is the explicit "take this content"- // channel and applies without emitting an update, so- // discarding never writes.- descEditorRef.current?.adoptContent(issue.description || "");- descriptionAttachmentIdsRef.current = [];- pendingDescriptionSaveRef.current = null;- setDescriptionConflictDraft(null);- }}- >- {t(($) => $.revision.use_server)}- </Button>- )}- localAction={(- <Button- type="button"- size="sm"- variant="outline"- onClick={() => {- handleUpdateField(- {- description: descriptionConflictDraft,- description_base: issue.description || "",- attachment_ids:- descriptionAttachmentIdsRef.current.length > 0- ? descriptionAttachmentIdsRef.current- : undefined,- },- {- onSuccess: () => {- setDescriptionConflictDraft(null);- },- },- );- }}- >- {t(($) => $.revision.keep_local)}- </Button>- )}- />- ) : null}-<div className="flex items-center gap-1 mt-3"><ReactionBarreactions={issueReactions}diff --git a/packages/views/locales/en/issues.json b/packages/views/locales/en/issues.jsonindex d3d6958814..9c69b1f8ef 100644--- a/packages/views/locales/en/issues.json+++ b/packages/views/locales/en/issues.json@@ -69,7 +69,6 @@"revision": {"conflict": "The issue or comment changed. The latest version was refreshed; compare it before saving again.","compare_title": "The title was changed concurrently. Compare both versions.",- "compare_description": "The description was changed concurrently. Compare both versions.","compare_comment": "The comment was changed concurrently. Compare both versions.","server_version": "Latest server version","local_version": "Your local version",diff --git a/packages/views/locales/ja/issues.json b/packages/views/locales/ja/issues.jsonindex 13e50f2b35..c546ba4867 100644--- a/packages/views/locales/ja/issues.json+++ b/packages/views/locales/ja/issues.json@@ -68,7 +68,6 @@"revision": {"conflict": "タスクまたはコメントが変更されました。最新版に更新したので、比較してからもう一度保存してください。","compare_title": "タイトルが同時に変更されました。両方の内容を比較してください。",- "compare_description": "説明が同時に変更されました。両方の内容を比較してください。","compare_comment": "コメントが同時に変更されました。両方の内容を比較してください。","server_version": "サーバー上の最新版","local_version": "ローカル版",diff --git a/packages/views/locales/ko/issues.json b/packages/views/locales/ko/issues.jsonindex 3bd5e17bf7..af2d5998b0 100644--- a/packages/views/locales/ko/issues.json+++ b/packages/views/locales/ko/issues.json@@ -68,7 +68,6 @@"revision": {"conflict": "태스크 또는 댓글이 변경되었습니다. 최신 버전으로 새로 고쳤으니 비교한 후 다시 저장하세요.","compare_title": "제목이 동시에 변경되었습니다. 두 버전을 비교하세요.",- "compare_description": "설명이 동시에 변경되었습니다. 두 버전을 비교하세요.","compare_comment": "댓글이 동시에 변경되었습니다. 두 버전을 비교하세요.","server_version": "서버의 최신 버전","local_version": "내 로컬 버전",diff --git a/packages/views/locales/zh-Hans/issues.json b/packages/views/locales/zh-Hans/issues.jsonindex c31c008657..18fd36d5c1 100644--- a/packages/views/locales/zh-Hans/issues.json+++ b/packages/views/locales/zh-Hans/issues.json@@ -68,7 +68,6 @@"revision": {"conflict": "任务或评论已发生变化。已刷新到最新版本,请比较后重新保存。","compare_title": "标题存在并发修改,请比较两个版本。",- "compare_description": "描述存在并发修改,请比较两个版本。","compare_comment": "评论存在并发修改,请比较两个版本。","server_version": "服务端最新版本","local_version": "你的本地版本",diff --git a/server/internal/handler/issue.go b/server/internal/handler/issue.goindex e6850bea82..216386d9c6 100644--- a/server/internal/handler/issue.go+++ b/server/internal/handler/issue.go@@ -3282,12 +3282,21 @@ func (h *Handler) updateIssueAtomically(ctx context.Context, workspaceID pgtype.currentDescription = current.Description.String}incomingDescription := params.Description.String- if descriptionBase != nil && currentDescription != *descriptionBase && currentDescription != incomingDescription {- baseWithLateMedia := mergeIssueChannelMediaDescription(currentDescription, *descriptionBase, descriptionBase, attachments)- if currentDescription != baseWithLateMedia {- return db.Issue{}, current, false, errIssueFieldConflict- }- }+ // No baseline REJECTION here, deliberately: the description editor+ // autosaves on a debounce, and its base could not be kept in step with+ // what the server had already accepted — a save whose own echo landed+ // while the editor was dirty, or any stored description that was not+ // byte-identical to its own trimmed form, reported a conflict with no+ // second writer present and then wedged the editor for the session+ // (MUL-6971). The guard also never covered the writers most likely to+ // race a human here — mobile and the CLI/agent path send no base at+ // all — so it mostly rejected the user's own autosave.+ //+ // `descriptionBase` stays in the request: it is ALSO the merge metadata+ // below, which is what lets a user delete channel media the editor had+ // adopted instead of having it restored on every save. Description+ // writes are last-write-wins; concurrent edits are recorded by the+ // `description_updated` activity.params.Description = pgtype.Text{String: mergeIssueChannelMediaDescription(currentDescription, incomingDescription, descriptionBase, attachments),Valid: true,diff --git a/server/internal/handler/issue_revision_test.go b/server/internal/handler/issue_revision_test.goindex 2edb55dba1..fa96a820d0 100644--- a/server/internal/handler/issue_revision_test.go+++ b/server/internal/handler/issue_revision_test.go@@ -14,6 +14,7 @@ import ("github.com/jackc/pgx/v5""github.com/jackc/pgx/v5/pgtype""github.com/multica-ai/multica/server/internal/events"+ "github.com/multica-ai/multica/server/internal/testutil""github.com/multica-ai/multica/server/internal/util"db "github.com/multica-ai/multica/server/pkg/db/generated""github.com/multica-ai/multica/server/pkg/protocol"@@ -272,13 +273,31 @@ func TestTextBaselinesIgnoreUnrelatedAggregateRevisionChanges(t *testing.T) {if text.Code != http.StatusOK {t.Fatalf("text update after unrelated revision = %d: %s", text.Code, text.Body.String())}+ staleTitle := httptest.NewRecorder()+ testHandler.UpdateIssue(staleTitle, withURLParam(newRequest(http.MethodPut, "/api/issues/"+issueID, map[string]any{+ "title": "stale title overwrite",+ "title_base": "baseline title",+ }), "id", issueID))+ if staleTitle.Code != http.StatusConflict {+ t.Fatalf("true issue title conflict = %d, want 409: %s", staleTitle.Code, staleTitle.Body.String())+ }++ // Descriptions are last-write-wins (MUL-6971): the baseline is merge+ // metadata only, so a stale base overwrites instead of returning 409.staleDescription := httptest.NewRecorder()testHandler.UpdateIssue(staleDescription, withURLParam(newRequest(http.MethodPut, "/api/issues/"+issueID, map[string]any{"description": "stale description overwrite","description_base": "baseline description",}), "id", issueID))- if staleDescription.Code != http.StatusConflict {- t.Fatalf("true issue description conflict = %d, want 409: %s", staleDescription.Code, staleDescription.Body.String())+ if staleDescription.Code != http.StatusOK {+ t.Fatalf("stale issue description overwrite = %d, want 200: %s", staleDescription.Code, staleDescription.Body.String())+ }+ var storedDescription string+ if err := testPool.QueryRow(ctx, `SELECT description FROM issue WHERE id = $1`, issueID).Scan(&storedDescription); err != nil {+ t.Fatalf("reload description after stale overwrite: %v", err)+ }+ if storedDescription != "stale description overwrite" {+ t.Fatalf("description after stale overwrite = %q, want the overwrite", storedDescription)}// A reaction/resolve-style aggregate bump on the comment must likewise not@@ -305,6 +324,36 @@ func TestTextBaselinesIgnoreUnrelatedAggregateRevisionChanges(t *testing.T) {}}+// A description stored with surrounding whitespace — every CLI/integration+// write that keeps a trailing newline — used to reject EVERY edit from the web+// editor, which sends its base trimmed. No second writer was involved, and the+// rejection repeated for the life of the session (MUL-6971).+func TestDescriptionEditAcceptsATrimmedBaseOfUntrimmedStoredMarkdown(t *testing.T) {+ if testHandler == nil || testPool == nil {+ t.Skip("database not available")+ }+ // Stored with a trailing newline — what every CLI/integration write that+ // keeps one leaves behind.+ issueID := dbfx.Issue(t, "untrimmed baseline", testutil.Cols{+ "description": "roadmap body\n",+ })++ testutil.Call(t, testHandler.UpdateIssue, testutil.WithURLParams(+ newRequest(http.MethodPut, "/api/issues/"+issueID, map[string]any{+ "description": "roadmap body edited",+ // What the editor actually sends: the stored Markdown, trimmed.+ "description_base": "roadmap body",+ }),+ "id", issueID,+ )).Want(http.StatusOK)++ var stored string+ dbfx.QueryRow(t, `SELECT description FROM issue WHERE id = $1`, issueID).Scan(&stored)+ if stored != "roadmap body edited" {+ t.Fatalf("stored description = %q, want the edit", stored)+ }+}+func TestConcurrentRevisionWritesHaveExactlyOneWinner(t *testing.T) {if testHandler == nil {t.Skip("database not available")