Skip to content

feat(j5): people can switch a persona worker's model - #934

Merged
Jacksondr5 merged 5 commits into
feat/persona-reviewer-independencefrom
feat/persona-model-switch
Nov 8, 2026
Merged

Jacksondr5 merged 5 commits into
feat/persona-reviewer-independencefrom
feat/persona-model-switch

Conversation

@bryantderosier

@bryantderosier bryantderosier commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Once a persona worker started on a model, I couldn't change it. The server refused any model or provider change on a persona thread, and the web composer hid the picker. So a worker stuck on a provider that hit its usage limit had to be started over. Now a person can switch it from the composer, and the server runs the launch checks again on each switch. Closes #783.

  • Who can switch. Only a person, through a client's command path. CommandAdmission marks a dispatch from a session that names a person with a J5 Context.Reference (AgentPersonaModelSwitch), the same way DispatchModeLimit reaches the orchestrator. Anyone admission already lets send a model change on that thread can switch. Everything without the mark is refused with "Agents can't change a persona worker's model. Replace the worker instead…". That covers t3_thread_configure, an agent's message carrying a model, MCP and scheduled paths, and service sessions with no person.
  • What's checked. A signed-in provider has to offer the model and its options, and that provider has to enforce the persona's access. Any offered model passes, even one outside the persona's list; Models for custom members doesn't apply. A reviewer can be switched onto its author's model. A refusal names the reason, for example "Claude can't enforce Workspace-write access, which this persona runs with. Pick a model on Codex. The worker stays on its current model."
  • The record follows the thread. I didn't update the assignment only in thread.model-selection.set, because the composers don't send that. They send the model on message.dispatch, and upstream applies a message's model in four places: steer, restart, a new run, and later in a separate write when a queued run starts. Sending model-selection.set first would release the live session and kill a running turn. Instead, upstream's two event constructors pass each event through personaGuards.followModelSelection. Any thread.model-selection-updated or thread.provider-switched event on a persona thread then carries the switched assignment. That means resolvedModelSelection, resolvedDriver, resolvedRoute: "override", resolvedEntryIndex when the model matches a list entry, and the new modelSwitchedBy: "person". The snapshot, digest, instructions, pickSource and reviewIndependence don't change. The per-turn runtime check reads the switched driver, so a later turn on a provider that can't enforce the access is still refused.
  • Web and desktop. On a persona thread, the composer shows upstream's model and reasoning pickers next to the persona chip. Access and plan mode stay hidden, because the persona's access sets them. The composer follows the thread's current model until you explicitly pick another (upstream's modelSelectionExplicit). A persona launch also drops the draft's model picks. Without those two rules, a draft's sticky model would show in the picker and could quietly switch a brand-new worker. The chip's tooltip names the current model and says when a person changed its model or reasoning. If the provider is unavailable, the persona and handoff chips stay next to "Open provider settings".
  • Mobile. On a started thread, tapping the persona or its model opens upstream's thread settings, where the model picker is. A refused send comes back with the server's reason, as any refused send does. The mobile thread settings sheet still shows upstream's Runtime row on persona threads; it has no effect there.
client ─ CommandAdmission (person? provide AgentPersonaModelSwitch{providers})
       └─ Orchestrator
          ├─ :3006  personaGuards.modelChange      (model-selection.set / provider.switch)
          ├─ :5130  personaGuards.modelMismatch    (message.dispatch with a new model)
          │           no mark → agent refusal; mark → offered? enforces access?
          └─ makeEvent / makeSystemEvent → followModelSelection
                      selection events on a persona thread carry the switched assignment

No model-facing text changed, so no evals ran.

UI changes

The composer controls row on a persona thread, cropped from 1280x800. Base is feat/persona-reviewer-independence (6890d43) and head is a85bc9f, on the same test home after one "Say hi in your thread" turn as the Haiku helper persona:

Before After
Persona thread composer Persona thread composer, before Persona thread composer, after
Persona thread model picker open new Persona thread model picker open, after

Live testing

Partial, at a85bc9f, using setup-agent-live-test.ts --base origin/feat/persona-reviewer-independence. I ran one real Haiku turn on each server, just to get a persona thread for the captures above.

  • Live: the persona thread's composer shows the model and reasoning pickers on head, and the picker opens with the provider's models.
  • Not live: actually switching and sending. A successful switch runs another turn, and I didn't take one. I couldn't show a refusal either. The test personas run on Claude and Codex, and both enforce those access levels, so any pick would have been allowed. The switch and refusal paths are covered by the integration tests under Evidence.

Evidence

  • New tests in agentPersonaLaunch.integration.test.ts, against the real orchestrator:
    • "lets a person switch a persona worker's model, and checks the switch again":
      • a switch off the list on the same provider gives an override route with no entry index;
      • a cross-provider switch through a person's message lands on Claude with entry index 1 and modelSwitchedBy: "person", the run carries the new model, and the runtime keeps the launch snapshot's instructions;
      • a model that isn't advertised, and a provider that isn't signed in, are refused with their reasons;
      • an agent's model-selection.set and an mcp message carrying a model are refused with the replace-the-worker text, and the assignment stays put.
    • "refuses a switch to a provider that can't enforce the persona's access": a Workspace-write persona can't move to Claude, and its assignment is unchanged.
    • "lets a person switch a reviewer onto its author's model, and queues a switch":
      • a queued message with a new model leaves the assignment alone until it starts;
      • the reviewer can be moved onto its author's model, and reviewIndependence stays as recorded.
    • "follows a queued switch onto the assignment when its run starts": a queued message carrying Opus, then Stop and resume. The queued run starts on Opus, and the assignment follows it in the system write that starts it. The test fails if I take out the makeSystemEvent hook.
  • CommandAdmission.test.ts, "marks only a person's commands as theirs": an owner's command carries the mark and an mcp-client service session's doesn't.
  • personaComposerSelection.test.ts, against the real draft store:
    • "keeps a started persona on its model over a remembered pick, until a person picks";
    • "starts a launched persona's composer from its model, not the draft's sticky one": a sticky gpt-5 on the persona's own provider shows until the launch, then the composer shows gpt-6-luna, and an effort-only change stays on it. It fails without the fix.
  • agentPersonas.test.ts: the chip presents the current model and the switch note.
  • The switch, runtime-policy and subagent suites, the upstream orchestrator suites that exercise model selection, and the sharing suites: 18 + 172 passed.
    vp test run src/j5/agents/agentPersonaLaunch.integration.test.ts src/j5/agents/agentPersonaRuntimePolicy.test.ts src/j5/agents/agentSubagent.integration.test.ts (from apps/server)
    vp test run src/orchestration-v2/{OpenCode2OrchestratorV2.integration,Orchestrator.control-reads,ProjectionStore,ProviderRuntimeRecoveryService,RestartBackgroundNote,SteeringCompletion.integration,SelectionRestart.integration,ThreadLaunchService,runtimeLayer}.test.ts src/j5/sharing/ (from apps/server)
  • vp run check:changed: format, lint, knip, typecheck (32 packages) and tests (25 files, 435 tests) all pass.

Not verified:

  • No live switch. "The next turn runs on it" is proven by tests, not by a real turn (see Live testing).
  • Mobile wasn't run on a device. It typechecks, and the mobile seam test passes.
  • During server startup, before commands are ready, upstream queues a client command to a worker fiber. A person's switch sent in that window loses the mark, so it's refused as an agent's. It fails closed, and sending again works.

Merge Danger

Door: two-way. modelSwitchedBy is optional, so a revert still decodes switched assignments. Threads switched before a revert keep their new model, and the old lock applies from then on.

Blast Radius: model changes on persona threads, plus the persona composer row on web and mobile. If the checks are wrong, a worker could land on a provider that can't enforce its access. The per-turn runtime check still refuses that turn. Ordinary threads go through the same hook, but only selection events on a thread with an assignment are touched.

After merge: #784 (agents replace a worker to change its model) builds on the agent refusal.

Upstream impact

  • apps/server/src/orchestration-v2/Orchestrator.ts: routeLocked becomes modelChange, and makeEvent and makeSystemEvent each pass the event through followModelSelection (3 changed lines). This is the "Role library" row in FORK.md.
  • apps/web/src/components/chat/ChatComposer.tsx, ChatView.tsx: the follow-the-route hook, the persona control in the controls bar, and modelOnly. FORK.md has the persona composer row and its provider-candidate note.
  • apps/web/src/components/chat/ComposerControlsBar.tsx: one modelOnly prop with one early return. Covered in the same FORK.md row.
  • apps/web/src/components/chat/useComposerSend.ts: a J5 comment only.
  • apps/mobile/src/features/threads/ThreadComposer.tsx: onPressModel={openSettings}. Covered in the persona composer row.
  • The register's D18 (docs/j5/product/upstream.md) is rewritten: persona threads now keep the model and reasoning pickers and hide only access and plan mode. Bryant approved switching in Personas: people can switch a persona worker's model #783's plan.

Checklist

  • One concern: the description has no "also"
  • Tests cover the changed behavior (backend changes ship with focused tests)
  • UI changes: before/after screenshots above, and a video for motion or interaction (web only; no motion)
  • Live testing: the section above says what ran live and what did not
  • Upstream-owned files: each one is recorded in FORK.md (case text and file-table row) in this PR
  • Upstream product: any change to what upstream's product does has a human decision linked above and a register entry in docs/j5/product/upstream.md
  • Surfaces: entry points, clients, providers, contracts, reverse states, connection modes (see AGENTS.md)
  • Docs: definitions under docs/j5/product/ and user docs rewritten where this changes them

Surfaces walked:

  • Entry points: the composer picker on web and desktop (its keybinding opens the same picker), and the mobile persona controls. Agent paths (t3_thread_configure, message selections, MCP) are refused.
  • Clients: web, desktop and mobile.
  • Providers: the check reads the enforcement table, so Codex and Claude pass where they enforce the access, and Cursor and the rest only for Full-access.
  • Contracts: one optional field.
  • Reverse states: switching back is just another switch.
  • Connection modes: the check is server-side, and the mark comes from the same admission every connection uses.

Made with Claude Opus 5.5 in Claude Code (J5 Code).

🤖 Generated with Claude Code

@bryantderosier bryantderosier added the enhancement New feature or request label Nov 6, 2026
@bryantderosier bryantderosier self-assigned this Nov 6, 2026
@vercel

vercel Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
j5-code Ready Ready Preview Nov 7, 2026 11:19pm UTC

Request Review

@bryantderosier
bryantderosier added this pull request to stack #933 November 6, 2026 15:34
@github-actions github-actions Bot added the vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. label Nov 6, 2026
@github-actions github-actions Bot added the size:L 100-499 effective changed lines (test files excluded in mixed PRs). label Nov 6, 2026
bryantderosier added a commit that referenced this pull request Nov 6, 2026
@bryantderosier
bryantderosier marked this pull request as ready for review November 6, 2026 16:18
@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 28 billable files and costs up to $7.00.

Or wait 49 seconds for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between c0d28ce and 67d58e8.

Files selected for processing: 28

  • FORK.md
  • apps/mobile/src/features/threads/ThreadComposer.tsx
  • apps/mobile/src/j5/agents/AgentIdentityChip.tsx
  • apps/mobile/src/j5/agents/AgentPersonaAssignmentControls.tsx
  • apps/server/src/j5/agents/agentPersonaLaunch.integration.test.ts
  • apps/server/src/j5/agents/agentPersonaLaunch.ts
  • apps/server/src/j5/agents/agentPersonaOrchestration.ts
  • apps/server/src/j5/sharing/CommandAdmission.integration.test.ts
  • apps/server/src/j5/sharing/CommandAdmission.test.ts
  • apps/server/src/j5/sharing/CommandAdmission.ts
  • apps/server/src/j5/sharing/test-support/conversationHarness.ts
  • apps/server/src/j5/test-support/threadLaunchHarness.ts
  • apps/server/src/orchestration-v2/Orchestrator.ts
  • apps/web/src/components/ChatView.tsx
  • apps/web/src/components/chat/ChatComposer.tsx
  • apps/web/src/components/chat/ComposerControlsBar.tsx
  • apps/web/src/components/chat/useComposerSend.ts
  • apps/web/src/j5/agents/AgentIdentityChip.tsx
  • apps/web/src/j5/agents/AgentPersonaAssignmentControl.tsx
  • apps/web/src/j5/agents/agentDraftState.ts
  • apps/web/src/j5/agents/personaComposerSelection.test.ts
  • apps/web/src/j5/agents/personaComposerSelection.ts
  • docs/j5/product/agent-personas/index.md
  • docs/j5/product/upstream.md
  • docs/j5/user/personas.md
  • packages/client-runtime/src/j5/agentPersonas.test.ts
  • packages/client-runtime/src/j5/agentPersonas.ts
  • packages/contracts/src/j5/agentPersona.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@tyler-barton-horizon tyler-barton-horizon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Automated review of this layer of stack pingdotgg#933 (diff against its base branch). Findings were not individually verified against the source, so please treat them as likely issues and push back on any that are wrong.

apps/server/src/j5/a2a/DeliveryTransport.ts:752 (not in this diff): A2A steer/restart deliveries pin modelSelection to the active run's selection. After a person switches the model mid-run, that no longer equals the assignment, so checkSwitch treats the peer's steer as an agent model change and refuses it. The error is caught and logged, the message falls back to queueing, and steering silently stops working on switched persona threads.

🤖 Generated with Claude Code

export const personaRouteToFollow = (
assignment: OrchestrationV2AgentPersonaAssignment | undefined,
draft: { readonly modelSelectionExplicit?: boolean } | null,
) => (draft?.modelSelectionExplicit === true ? undefined : assignment);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

After the server refuses a switch, the composer keeps the explicit pick, so it keeps sending the refused model and every later message fails.

A person picks Claude on a Builder (workspace-write) thread and sends. The server refuses because Claude can't enforce workspace-write and says the worker stays on its model. But modelSelectionExplicit stays true and the draft-clearing subscription only clears picks that match thread.modelSelection, so selectedModelSelection stays on Claude and each follow-up is refused until the person re-picks the original model.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

True, and I left it on purpose. It's what upstream does on any thread when a picked model's send fails: the picker keeps your pick and every send tells you why. Resetting it automatically would mean clearing the pick in upstream's send path on any failure, network blips included. The refusal text says the worker stays on its model, so you pick again.

const person = reachPersonId(reach);
// Only a person may switch a persona worker's model; the orchestrator checks the switch.
const asPerson = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
person === null

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A person's right to switch rides on an ambient Context.Reference, which is lost when the dispatch runs on another fiber.

During startup, ws.ts routes dispatches through startup.enqueueCommand into a queue drained by a forked commandWorker whose context lacks AgentPersonaModelSwitch. A person's thread.model-selection.set is then refused with "Agents can't change a persona worker's model". Carrying provenance on the command would be sturdier than fiber-local state.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Right, that's the startup window. A switch sent before commands are ready gets refused as an agent's, and resending works once the server's up. It's in Not verified. Putting provenance on the command would mean adding an actor field to upstream's command, and I'd rather not. Since the gap fails closed, I'm keeping the mark where DispatchModeLimit already lives.

// Only a person may switch a persona worker's model; the orchestrator checks the switch.
const asPerson = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
person === null
? effect

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sessions with reach: 'unknown' get no person marker, so their switches are refused with a message that calls them an agent.

A paired client whose session has no j5_a2a_person_session row resolves to { kind: 'unknown' }, reachPersonId returns null, and every model switch fails with AGENT_MODEL_SWITCH_REFUSAL, which is misleading for a human client.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't think this one can happen. An unknown session isn't wide, so admission's requireLevel refuses it before upstream sees the command (CommandAdmission.ts:221: 'This is not shared with you on this server.'). It never gets as far as the model check.

return event;
const driver = yield* deps.getDriver(thread.modelSelection.instanceId);
const definition = yield* library
.readSnapshot(assignment)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

followModelSelection reads and hashes the persona snapshot from disk inside every selection event, only to compute the optional resolvedEntryIndex, and a read failure aborts the event.

If the snapshot file is missing or the legacy built-in version is gone, a switch that already passed checkSwitch fails when the event is written. A queued switch fails in makeSystemEvent (Orchestrator.ts:1213) and leaves the queued run unstarted. Every switch also pays a file read plus a sha256 while holding the thread lock.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That's intended. A thread whose snapshot is missing can't run a turn anyway, since the runtime reads the same snapshot every turn and fails, so failing the switch event says it sooner. It's one read per switch, not per event. The read is there for resolvedEntryIndex, so the assignment records when you switched onto one of the persona's own entries.

const assignment = thread.agentPersonaAssignment;
const selection = command.modelSelection;
if (
assignment === undefined ||

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

switchedAgentPersonaAssignment keeps reviewIndependence unchanged, but the reviewer note is built from the switched model, so the stored outcome can contradict the model the reviewer actually runs on.

A reviewer created with outcome different-model and authors [claude-opus-5] is switched onto claude-opus-5 before its first turn. The note reads 'you run on claude-opus-5; the authors ran on claude-opus-5' with no same-model warning, and the record still claims a different-model review.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The note's only built once, when the brief's composed at creation (spawn, crew launch, delegation), so it always matches the stored outcome. reviewIndependence records what was decided at creation, and that's deliberate. A person moving a reviewer onto the author's model is their call (#782/#783), and modelSwitchedBy on the same assignment shows it happened.

@bryantderosier

Copy link
Copy Markdown
Collaborator Author

Re the review note on DeliveryTransport.ts:752 (#934 (review)): good catch, but I think the queue fallback is what we want here. If that peer steer went through with the run's old model, upstream's steer path would write the old model back onto the thread and undo the person's switch. Pinning the new model would restart the run instead. So during the rest of a run the person switched mid-turn, a peer's steer waits and lands right after the run. The message still gets there, and it's logged at info. Leaving it.

@bryantderosier

Copy link
Copy Markdown
Collaborator Author

Restacked onto #932's head (2f2c9cf); no changes beyond fitting #931/#932's review fixes.

@bryantderosier

Copy link
Copy Markdown
Collaborator Author

Restacked onto #932's head (82025de) for #931's code-block mention fix; no other changes.

bryantderosier and others added 3 commits November 7, 2026 17:56
A persona worker was locked to its launch model: the server refused any
model or provider change, and the web composer hid the picker. A worker
stuck on a provider at its usage limit had to be started over.

A person can now switch it from the composer on web, desktop and mobile.
The server checks the switch again: a signed-in provider must offer the
model and its options, and that provider must enforce the persona's
access. A refusal names why, and the worker stays put. Only a person's
client command counts (CommandAdmission marks it); agents, MCP tools and
service sessions are refused and told to replace the worker.

The assignment's model fields follow the thread's selection in the same
event, at upstream's two event constructors, so the chip, the composer
and the per-turn runtime check all read the model the thread runs on,
however upstream applied it (selection command, a message's model on
steer, restart or a new run, or a queued run starting).

Done with Claude Opus 5.5 in Claude Code (J5 Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A queued message carrying a new model applies it later, in the system
write that starts the queued run. Nothing drove that path, so the hook
that keeps the assignment on the thread's model there was untested. Stop
and resume start the queued run without a provider; the test fails
without the makeSystemEvent hook.

Done with Claude Opus 5.5 in Claude Code (J5 Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A new-task draft carries the person's sticky model, and launching it as a
persona never cleared that pick. On the started thread the picker could
show the sticky model while sending the worker's, and an effort change
made it an explicit pick, switching the worker onto a model nobody chose.
The draft's model picks are now dropped once the persona launches, and
choosing a persona no longer resets the draft, so clearing it keeps the
person's pick.

Done with Claude Opus 5.5 in Claude Code (J5 Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bryantderosier and others added 2 commits November 7, 2026 17:56
A change to effort alone counts as a person's switch, since reasoning is
part of the model selection and takes the same checks, but the note only
said the model changed. It now reads "A person changed its model or
reasoning since launch."

Done with Claude Opus 5.5 in Claude Code (J5 Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lable

The model-only composer row was skipped when the provider was
unavailable, so upstream's "Open provider settings" button rendered alone
and the persona and handoff chips disappeared. They now stay beside it.

Done with Claude Opus 5.5 in Claude Code (J5 Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Jacksondr5 Jacksondr5 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Approved as part of the persona stack (#931 → #938), reviewed and live-tested as one unit. Details on #938.

@Jacksondr5
Jacksondr5 merged commit a385e56 into j5/main Nov 8, 2026
56 of 68 checks passed
@Jacksondr5
Jacksondr5 deleted the feat/persona-model-switch branch November 8, 2026 02:15

This branch was successfully deployed

1 active deployment
Preview — 67d58e80 Deployed Nov 7, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L 100-499 effective changed lines (test files excluded in mixed PRs). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Personas: people can switch a persona worker's model

3 participants