Skip to content

feat: refresh dynamic parameters on secret changes#24786

Merged
dylanhuff-at-coder merged 3 commits into
mainfrom
split/plat-100-secret-live-refresh
May 6, 2026
Merged

feat: refresh dynamic parameters on secret changes#24786
dylanhuff-at-coder merged 3 commits into
mainfrom
split/plat-100-secret-live-refresh

Conversation

@dylanhuff-at-coder

@dylanhuff-at-coder dylanhuff-at-coder commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Publishes user secret create, update, and delete events and subscribes dynamic parameter websockets to authorized owner secret changes.

Secret changes trigger fresh renders with monotonic response IDs, with backend tests covering subscription authorization and websocket refresh behavior.

dylanhuff-at-coder commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

@dylanhuff-at-coder
dylanhuff-at-coder force-pushed the split/plat-100-secret-live-refresh branch from d1c033e to bc9d432 Compare April 28, 2026 15:08
@dylanhuff-at-coder
dylanhuff-at-coder force-pushed the split/plat-100-secret-requirements-contract branch from c2353f8 to 07e4175 Compare April 28, 2026 15:08
@dylanhuff-at-coder
dylanhuff-at-coder force-pushed the split/plat-100-secret-live-refresh branch from bc9d432 to a107410 Compare April 28, 2026 15:41
@dylanhuff-at-coder
dylanhuff-at-coder force-pushed the split/plat-100-secret-requirements-contract branch from 07e4175 to 054e408 Compare April 28, 2026 15:41
@dylanhuff-at-coder
dylanhuff-at-coder force-pushed the split/plat-100-secret-live-refresh branch 3 times, most recently from e3033de to e55e194 Compare April 29, 2026 16:42
@dylanhuff-at-coder
dylanhuff-at-coder force-pushed the split/plat-100-secret-requirements-contract branch from b61307b to d2f81bc Compare April 29, 2026 17:24
@dylanhuff-at-coder
dylanhuff-at-coder force-pushed the split/plat-100-secret-live-refresh branch from e55e194 to e760f0b Compare April 29, 2026 17:24
Comment thread coderd/parameters.go Outdated
Comment thread coderd/parameters.go Outdated
@dylanhuff-at-coder

Copy link
Copy Markdown
Contributor Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The pubsub approach is the right mechanism for this feature, and the implementation details are mostly solid: event coalescing via a size-1 buffered channel, RBAC gating before subscribing, monotonic response IDs, and a clean integration test covering the full secret lifecycle (create/delete/re-create/update). The sendRender extraction and nextDynamicParametersResponseID helper are well-structured.

Two P2s, six P3s. The P2s are a documentation/contract mismatch in response IDs and a test coverage gap for the owner-switch subscription lifecycle. The P3s are a subscribe-after-render race window (also raised by @zedkipp), a dedup guard bug, and several smaller gaps.

Severity counts: 2× P2, 6× P3.

"I pulled every thread in the closure and they all held." (Hisoka)


codersdk/parameters.go:166

P2 [DEREM-1] Response IDs no longer match request IDs, violating this documented contract.

This comment says: "The response contains the same ID so that the client can match it to the request." The new nextDynamicParametersResponseID breaks this: when a secret event fires, lastResponseID advances, and the next client request gets a bumped response ID that differs from the request ID.

Sequence: client sends ID=0, gets ID=0. Secret event fires, server sends unsolicited ID=1. Client sends ID=1 (its local counter), server returns nextDynamicParametersResponseID(1, 1) = 2. Client sent ID=1, got ID=2.

The current frontend (CreateWorkspacePage.tsx:148) uses latestResponse.id >= response.id for staleness ordering, not ID matching, so no bug manifests today. But any future consumer following the documented contract would silently discard or misattribute responses. The comment should describe the actual behavior: response IDs are monotonically increasing and may exceed the request ID. (Mafuuu)

🤖

coderd/parameters.go:160

P3 [DEREM-7] This initial render block duplicates the sendRender closure defined six lines later. Replacing with if !sendRender(-1, initial.OwnerID, initial.Inputs) { return } removes 10 lines and unifies the response-building and error-handling paths. (Netero)

🤖

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/parameters.go Outdated
Comment thread coderd/parameters.go Outdated
Comment thread coderd/parameters.go Outdated
Comment thread coderd/parameters.go Outdated
Comment thread coderd/parameters.go Outdated
Comment thread coderd/parameters_internal_test.go
Base automatically changed from split/plat-100-secret-requirements-contract to main April 29, 2026 23:38
@dylanhuff-at-coder
dylanhuff-at-coder force-pushed the split/plat-100-secret-live-refresh branch from e760f0b to 9f4db1e Compare April 30, 2026 17:03
@dylanhuff-at-coder
dylanhuff-at-coder force-pushed the split/plat-100-secret-live-refresh branch from 9f4db1e to 6605621 Compare May 4, 2026 15:40
@dylanhuff-at-coder dylanhuff-at-coder changed the title feat(coderd): refresh dynamic parameters on secret changes feat: refresh dynamic parameters on secret changes May 4, 2026
@dylanhuff-at-coder
dylanhuff-at-coder marked this pull request as ready for review May 4, 2026 17:56
Comment thread coderd/parameters.go Outdated
@zedkipp
zedkipp requested a review from Emyrk May 4, 2026 22:03
Comment thread coderd/parameters.go
@Emyrk

Emyrk commented May 5, 2026

Copy link
Copy Markdown
Member

Is the idea that a secret change should immediately update on the Create Workspace page?

Comment thread coderd/parameters.go Outdated
@dylanhuff-at-coder

Copy link
Copy Markdown
Contributor Author

Is the idea that a secret change should immediately update on the Create Workspace page?

Yup! The following PR in the stack adds the UI

Comment thread coderd/parameters.go Outdated
Comment thread coderd/parameters.go

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Had brief DMs with @Emyrk on using the pubsub for this. Steven asked

Are people really updating secrets when the Create Workspace form is open?

There's an intent to have a modal for a user to enter missing secrets when the form is open. It's also possible a user fixes the secret requirement in another tab or via the CLI. I don't think there's a firm requirement to live refresh user secrets, but doing so seems to fall in line with how other things are handled (e.g. template active version changes, notification inbox).

We could instead reload the page on modal close (or similar), but I don't think there's much impact if there are no subscribers listening because Postgres will just drop the messages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah that matches my thinking. The follow-up PR adds the modal flow, and refreshing also covers another tab or CLI fixing the missing secret while the form is open

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't mind the pubsub as long as it's cost is low.

PostgreSQL LISTEN and NOTIFY is a native, lightweight pub/sub system where messages sent via NOTIFY are dropped immediately if no active clients are currently LISTENing to that channel.

It should be cheap most of the time 👍

@Emyrk Emyrk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 👍

I did not look closely at the tests.

@dylanhuff-at-coder
dylanhuff-at-coder merged commit 6a200a4 into main May 6, 2026
51 of 53 checks passed
@dylanhuff-at-coder
dylanhuff-at-coder deleted the split/plat-100-secret-live-refresh branch May 6, 2026 16:27
zedkipp added a commit that referenced this pull request May 19, 2026
zedkipp added a commit that referenced this pull request May 19, 2026
Two minor lint failures surfaced by 'make lint' after the revert series:

  - coderd/dynamicparameters/resolver_test.go: replaces two pre-existing
    emdashes (in comments restored by the revert of #24785) with commas,
    matching the form on origin/main. Required by 'make lint/emdash'.
  - coderd/usersecrets.go: trims two trailing blank lines left over from
    the conflict resolution in the revert of #24786. Required by
    goimports / trailing-whitespace lint.

Co-authored-by: Coder Agents <agents@coder.com>
zedkipp added a commit that referenced this pull request May 19, 2026
Two minor lint failures surfaced by 'make lint' after the revert series:

  - coderd/dynamicparameters/resolver_test.go: replaces two pre-existing
    emdashes (in comments restored by the revert of #24785) with commas,
    matching the form on origin/main. Required by 'make lint/emdash'.
  - coderd/usersecrets.go: trims two trailing blank lines left over from
    the conflict resolution in the revert of #24786. Required by
    goimports / trailing-whitespace lint.

Co-authored-by: Coder Agents <agents@coder.com>
zedkipp added a commit that referenced this pull request May 19, 2026
Two minor lint failures surfaced by 'make lint' after the revert series:

  - coderd/dynamicparameters/resolver_test.go: replaces two pre-existing
    emdashes (in comments restored by the revert of #24785) with commas,
    matching the form on origin/main. Required by 'make lint/emdash'.
  - coderd/usersecrets.go: trims two trailing blank lines left over from
    the conflict resolution in the revert of #24786. Required by
    goimports / trailing-whitespace lint.

Co-authored-by: Coder Agents <agents@coder.com>
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.

3 participants