Skip to content

Align ACP session model config - #1625

Open
BlueHotDog wants to merge 5 commits into
mainfrom
fix/acp-session-config-model-state
Open

BlueHotDog wants to merge 5 commits into
mainfrom
fix/acp-session-config-model-state

Conversation

@BlueHotDog

@BlueHotDog BlueHotDog commented Sep 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Keep the draft model preference separate from the persisted session model. Persist picker changes through session/set_config_option and restore session state on task activation.
  • Include ACP currentValue in config options. Send the global model catalog separately, in a map-shaped WebSocket payload, so catalog refreshes cannot overwrite session selection.
  • Support standard ACP session/new without a model preference. Create an unselected session without choosing a default, then reject prompts until a valid model is selected.
  • Preserve legacy explicit prompt model overrides as per-message snapshots without changing the session model. Reject invalid or unavailable selections before recording a message.
  • Preserve live assistant text across cached session replay. Store long custom-model references in a text column.
  • Merge current main, retaining its connection lifecycle, billing allowances, activation tracking, preview behavior, and current model catalog.

Fixes #1289

Validation

Passed locally on the updated branch:

  • make rescript-build
  • make -C libs/client test — 496 tests
  • make -C libs/frontman-client test — 108 tests
  • make -C libs/frontman-protocol test — 33 tests
  • make -C libs/client test-screenshots — 70 Chromium tests
  • make -C libs/frontman-protocol check-schemas
  • make reanalyze and all nine library checks in the pre-push hook — zero issues
  • cd apps/frontman_server && DB_NAME=frontman_pr1625_validation_v2 make precommit — compile with warnings as errors, format, Credo, and 1,099 tests
  • Git pre-commit checks and git diff --check

make e2e could not run locally because test/e2e/.env is absent. The fresh GitHub E2E run must verify the complete authenticated AI workflow.

Regression coverage

  • Encode model-catalog notifications with the real Phoenix WebSocket serializer.
  • Create a model-less session, reject a prompt, select a model through ACP, and accept the next prompt.
  • Persist a 256-character custom model ID without truncation.
  • Reactivate cached sessions with idle replay, same-message streaming continuation, and a new live turn during loading.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-04T13:10:26.505595Z 4d76b41 PR opened
ℹ️ 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

| SetSelectedModelValue({value}) =>
syncSelectedModelValueToStorage(Some(value))
{...state, selectedModelValue: Some(value)}->StateReducer.update

P2 Badge Persist model selections through the session RPC

When the user changes the model dropdown, this action updates only reducer state and local storage; there is no caller for the newly added session/set_config_option handler anywhere in the client. Consequently, tasks.current_model remains unchanged until a prompt is submitted, so switching tasks or reloading before sending a prompt causes session/load to restore the old model and discard the selection. Dispatch an effect that invokes the active session's config-option RPC and reconciles its response.

AGENTS.md reference: AGENTS.md:L197-L233

ℹ️ 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".

ACP.build_config_option_update_notification(socket.assigns.task_id, config_options)
)

{:noreply, socket}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Synchronize the session model after provider changes

When credentials or a custom provider backing current_model are removed, current_config_options/2 advertises a fallback model, but this handler returns the socket unchanged and leaves the stale model in the task row. A generic ACP client that subsequently omits _meta.model—the flow this commit adds support for—therefore executes with the removed model via current_model/1, even after reconnecting because the stale row is loaded again. Update both the socket assign and persisted task to the advertised fallback, or clear them when no models remain.

Useful? React with 👍 / 👎.

Comment on lines +181 to +183
case current_config_value(values, current_value) do
nil ->
[]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Deliver an explicit empty config list to the client

When a user has no configured models, this now returns [], which put_config_options/2 converts into an omitted configOptions field in both session/new and session/load. The client dispatches ConfigOptionsReceived only for Some(configOptions), so it never clears a model restored from local storage and leaves configOptions as None; in turn, providerSetupRequired remains false and the stale model can keep the prompt UI enabled for a session that has no usable provider. Include configOptions: [] in session results or otherwise explicitly clear the client state for this case.

Useful? React with 👍 / 👎.

Comment on lines +1048 to +1052
defp selected_model(socket, %{"model" => model_ref}) do
case parse_client_model(model_ref) do
{:ok, model} -> {:ok, model}
:error -> current_model(socket)
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject invalid explicit model values

When a prompt explicitly contains a malformed model value, this branch silently falls back to the persisted session model and accepts the prompt. That makes a typo or malformed structured value run against a different model than the client requested, whereas only an absent model should use the agent-owned default; return :error when the key is present but cannot be parsed so the request receives an invalid-params response.

AGENTS.md reference: AGENTS.md:L106-L115

Useful? React with 👍 / 👎.

Comment on lines 752 to 755
with {:ok, agent_id} <-
Agents.resolve_agent_id(scope, meta["agent"] || Agents.default_agent_id(scope)),
{:ok, _task} <- Tasks.set_current_model(scope, task_id, model),
{:ok, _row} <-

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Update the model only after accepting the prompt

The task's current model is persisted before submit_user_message/2 validates the selected skill, content blocks, and message ID. If any of those validations fail—for example, a duplicate message ID paired with a different model—the request returns an error but the database still records the new model, while the socket retains the old one because its assign occurs only on success. Move the update after successful submission or make both writes atomic so rejected prompts cannot mutate session configuration.

Useful? React with 👍 / 👎.


def change do
alter table(:tasks) do
add(:current_model, :string)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Store current model references in an unbounded text column

PostgreSQL maps this migration's :string to a 255-character varchar, but custom providers permit 256-character model IDs and serialize them as custom:<36-character UUID>:<model ID>, producing references up to roughly 300 characters. Selecting or prompting with any otherwise-valid custom model ID longer than about 211 characters will therefore fail when set_current_model/3 writes this column. Use :text or constrain the complete serialized reference to the database limit.

Useful? React with 👍 / 👎.

"id" => "model",
"name" => "Model",
"category" => "model",
"currentValue" => selected_value,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve session selection during global config refreshes

On a provider configuration change, both TasksChannel and TaskChannel receive the same PubSub event. The global tasks channel calls build_model_config_options/1 without a session value, so this field identifies the first available model as current, while the task channel independently sends the task's actual persisted value; because those pushes originate from separate channel processes, their delivery order is not guaranteed. If the global update arrives last, ConfigOptionsReceived silently switches the UI and next prompt to the first model rather than the session's model. Global catalog refreshes must not overwrite active session state, or the client must preserve/reconcile the session-specific value.

Useful? React with 👍 / 👎.

@BlueHotDog
BlueHotDog force-pushed the fix/acp-session-config-model-state branch from 4d76b41 to 02c0a6b Compare September 4, 2026 13:11

This branch has not been deployed

No deployments
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.

Align session configuration and lifecycle with ACP v1

1 participant