Skip to content

feat(site): send expect_id with saved workflow saves and deletes - #400

Merged
ibetitsmike merged 16 commits into
mainfrom
mike/issue-392-site-expect-id
Nov 21, 2026
Merged

ibetitsmike merged 16 commits into
mainfrom
mike/issue-392-site-expect-id

Conversation

@ibetitsmike

Copy link
Copy Markdown
Owner

Coder Agents opened this PR on behalf of @ibetitsmike.

Closes #392.

What changed

The saved workflows pages now use the conditional-write guard the server gained in #394.

  • The editor save sends expect_id with the id of the revision the editor loaded (loadedFrom). The server rejects the save with 409 when the stored workflow under that name has another id, so a stale editor cannot overwrite a replacement.
  • On a 409, the editor shows an info toast, keeps the user's draft open, and refetches the list and detail, which turns on the existing changed-workflow handling. Nothing is overwritten.
  • The delete no longer does a GET-then-compare before deleting. It sends expect_id with the id the user picked and maps both 404 (gone) and 409 (replaced) to the existing SavedWorkflowChangedError, whose handling already shows the info toast and refetches. The conditional write on the server makes the client-side check redundant, and it closes the window where the workflow changed between the check and the delete.
  • An explicit but empty expect_id now throws on the client instead of being silently dropped by the search-param builder, which would have turned a guarded write into an unconditional one.
  • The fork section of coderd/x/chatd/ARCHITECTURE.md replaces its expect_id TODO with final prose describing the shipped behavior.

Why the delete fast path went away

The GET-then-compare was the only guard the server offered before #394. Keeping it would add a request and still race; the conditional delete now does the same check atomically on the server. The 404 case (workflow already gone) keeps the same user-visible outcome.

How it was tested

  • pnpm exec tsc --noEmit clean; biome lint clean on the touched files.
  • vitest run on src/api/queries/forkSavedWorkflows.test.ts (15 tests), src/pages/AISettingsPage/ForkWorkflowsPage/ForkWorkflowsPage.test.tsx (19 tests), and src/api/forkSavedWorkflows.test.ts (1 test): all pass. New coverage asserts expect_id on the save and the delete, the unconditional-write negative control, the 409 delete refusing with an info toast and no list change, the 409 save keeping the draft and refetching, and the empty-expect_id rejection.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T23:50:05.237867Z cf313b9 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7e60df3f83

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread site/src/api/forkSavedWorkflows.test.ts Resolved
Comment thread site/src/api/forkSavedWorkflows.test.ts Resolved
Comment thread coderd/x/chatd/ARCHITECTURE.md Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 7e60df3f83

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- only an absent id writes unconditionally; an empty string reaches the
  throwing search-param builder instead of being dropped
- the 409 editor test asserts the conflict refetch of the list
- the axios test exposes hoisted spies and asserts the encoded URLs
- the architecture prose limits the write-only-scope claim to the member
  PATCH and organization DELETE routes
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6127bdd402

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread site/src/api/forkSavedWorkflows.ts Resolved
- Treat a params object without expect_id, not only an absent params
  argument, as an unconditional write; only an explicit empty expect_id
  still fails closed (Codex round 3, finding 1).
- Drop the explicit refetchForEdit from the 409 save handler: the
  mutation's own non-exact invalidation already refetches the list and
  detail queries. Proved with a TEMP-disabled refetch: the list spy
  still advances without it (finding 2).
- Strengthen the 409 page test: after the conflict, edit the retained
  draft and save again, asserting the retry still targets the workflow
  the editor loaded with the same expect_id (finding 3).
- Report the stale-write toast for a 404 as well as a 409, so a
  workflow deleted after the editor loaded it explains why the save was
  rejected and that the draft was kept (finding 4).
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2d524052ae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

The stale-write toast now covers 404 as well as 409, but only the 409
arm had a page test. Add the 404 case: a workflow deleted after the
editor loaded it keeps the draft in the open editor, fires the
explanatory toast, and the mutation invalidation refetches the list.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 74ba6f36d3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/ARCHITECTURE.md Resolved
Comment thread site/src/api/forkSavedWorkflows.test.ts Resolved
- ARCHITECTURE.md now says the 409 only covers a stored workflow whose
  id differs, and that a workflow deleted before the write, or one the
  caller may not see or touch, answers the plain not-found 404, which
  okAfterConditionalWrite does (Codex round 5, finding 1).
- The URL boundary suite runs over both route families, personal and
  organization, so a dropped params forward or a wrong organization URL
  fails a test (finding 2).
- The 404 page test drops its dialog-presence claim and proves the
  retained editor through a second conditional save, like the 409 test
  (finding 3).
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e6260f510e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- UpdateSavedWorkflowArgs.id now states the guard in its true
  direction: the write goes through only when the stored workflow still
  has that id, and the server rejects it with 409 otherwise (Codex
  round 6, finding 1).
- Add the StaleSaveError story to the editor dialog, capturing the
  retained draft with the stale-save message a 404 or 409 leaves
  (finding 2).
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4502a2bf56

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread site/src/api/forkSavedWorkflows.test.ts Resolved
Codex round 7 found the conflict mocks kept returning the original
workflow after the save was rejected, so the asserted retry could not
distinguish the stale guard from a plain success, and the boundary test
file missed its trailing newline.

The mocks now flip to the server state the first rejected save implies:
the 409 test refetches a replacement under the same name and asserts
the replacement lands in the cache before a second submit, which the
stale guard then blocks with no second request and the explanatory
banner; the 404 test refetches a list without the row and asserts the
same. The boundary test file ends with a newline.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 11918b3c05

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/ARCHITECTURE.md Resolved
Align the ARCHITECTURE.md 403 prose with okAfterConditionalWrite: the
probe that forwards a denial answers 403 for a readable but unwritable
row, and 404 only when the row is hidden. Document that the query layer
rejects an empty expect_id locally. Drop the banner text assertions from
the 409 and 404 page tests; the stale guard there is non visual and the
StaleSaveError story covers the banner.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 874db4adc1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…e toast

The 409 branch reports a replacement under the same name and the 404
branch reports deletion or a hidden row, so the comment now says that.
A scope change or a replaced editor can discard the draft while the
request is pending, so the toast asks the user to copy unsaved changes
from the editor if it is still open instead of promising the draft.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: b1b627cb86

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b1b627cb86

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

A mismatch answers 409 only when a workflow the caller may write holds
the name, and 404 when the name holds nothing or a row the caller may
not see, so the type doc says that instead of calling every failed
match a conflict.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 677f054bc9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

A mismatch answers 409 only when a workflow the caller may write holds
the name, and 404 when the name holds nothing or a row the caller may
not see, matching the revision guard docs on the query layer.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: de9fe8273b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 90dc174fd6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Valid finding, fixed in 1a0206f: the 404 branch of the stale-delete handler now says the name no longer resolves to the picked workflow because it was deleted, or because the server hides the stored row or its hidden replacement from the caller and answers not-found for that.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1a0206f3b1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: cf313b9a65

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike
ibetitsmike merged commit f874782 into main Nov 21, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/issue-392-site-expect-id branch November 21, 2026 00:04
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged at head cf313b9a6508229be10fb61ff5128b79d10d30c9 as f874782, on main e9e9b1331a44be37b5b524031f828b0e5b7f41b9, with the server running that main.

Gates on this exact head:

  1. The head matched the SHA I verified (--match-head-commit).
  2. Every check run passed. fork-ci run 44839214714 passed on this head.
  3. Codex receipt for this head: feat(site): send expect_id with saved workflow saves and deletes #400 (comment) ("Didn't find any major issues").
  4. No unresolved review thread.
  5. 0 commits behind main.
  6. I ran the tests below on this exact head.

Tests I ran on cf313b9a65:

  • pnpm exec vitest run --project unit on api/forkSavedWorkflows.test.ts, api/queries/forkSavedWorkflows.test.ts, AISettingsPage/ForkWorkflowsPage and AgentSettingsPage/ForkSavedWorkflowsPage: 5 files, 57 tests passed.
  • Negative control: with the API client dropping expect_id from the query, 2 tests fail. The source was restored after it.
  • The workstream ran tsc --noEmit, biome and oxlint on the touched files.

Review notes:

Not exercised: the race in a dev build. Coverage uses mocked API calls.

ibetitsmike added a commit that referenced this pull request Nov 21, 2026
ibetitsmike added a commit that referenced this pull request Nov 21, 2026
…ork-workflows) (#404)

* feat: members share personal saved workflows with the organization (fork-workflows)

Adds POST .../members/{user}/workflows/{workflow}/share, which moves a
personal workflow to the organization tier in one statement. The owner
keeps read, update and delete through user_acl, and the Everyone group
gets read. The member Workflows page gains a Share action and lets the
owner edit and delete the organization workflows they shared.

Closes #395
Closes #327

* fix: only the owner shares a saved workflow, clearer share errors (fork-workflows)

* refactor(site): extract the share dialog, behavior-only share tests (fork-workflows)

* fix(site): keep a shared workflow listed in the organization cache (fork-workflows)

* chore(site): document the share dialog, trim the share tests (fork-workflows)

* fix(site): share uses the conditional write params from #400 (fork-workflows)

* fix(site): drop a stale shared row before its dialog closes (fork-workflows)

* chore(site): name share test fixtures Mock*, narrow the share state contract (fork-workflows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

saved workflows: id-conditional PATCH and DELETE

1 participant