Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: honor explicit per-task model pins; default worktree tasks to open a PR

Adam Eivy760fb5ed0690
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 9d051fe620..c6b651fdf3 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -2,6 +2,9 @@
## CoS Agents
+- **An explicit per-task model pin is now always honored — no more silent, expensive downgrades.** When you set a specific model on a CoS task, PortOS validated it against the provider's `models` list and, on any mismatch, *silently fell back to the provider's default (heaviest) model*. Because `claude-code-tui` lists the dated id `claude-haiku-4-5-20251001` while `claude-code` lists the undated `claude-haiku-4-5`, picking "haiku" on the TUI provider quietly ran **Opus** instead. Explicit user-specified models are now passed through to the CLI even when they're not in the convenience list (the CLIs accept any valid id; a genuine typo surfaces as a provider error rather than a costly silent substitution). Auto-selected models still fall back to the tier default as before.
+- **Worktree tasks now default to opening a PR instead of auto-merging to your default branch.** A CoS task run in an isolated worktree with "Open PR" off merges its commits straight back to the main development branch on completion — fine for trusted agents, dangerous for unreviewed local-model work. Creating a worktree task now defaults "Open PR" on (in the UI, enabling Worktree checks it; via the API, a worktree user-task without an explicit `openPR` defaults to `true`). You can still turn it off per-task for a quick auto-merge, and internal automation (autopilot, self-improvement) keeps its existing auto-merge behavior so nothing starts silently waiting on a human to merge a PR.
+
- **Local-model Claude agents now launch in a lean, isolated mode.** CoS agents on the Ollama-backed Claude providers (`claude-ollama`, `claude-ollama-tui`) previously inherited your full personal Claude Code environment — hooks, plugins, MCP servers, global CLAUDE.md — which reliably derailed small local models (a live eval showed qwen3.6:35b answering a session-start hook instead of its task). These sessions now spawn with `--bare --strict-mcp-config` (no hooks, no plugins, no MCP tool schemas, no CLAUDE.md auto-discovery), authenticating through the provider's existing `ANTHROPIC_BASE_URL` + `ANTHROPIC_AUTH_TOKEN` (pointed at your local Ollama), and get the same plain-`git`/`gh` completion workflow OpenCode agents use instead of slashdo commands bare mode can't load. In the same eval, once isolated this way qwen3.6:35b wrote a correct, test-passing helper (verified 46/46) end to end — the failures were the environment, not the model.
- **Every Claude Code agent now separates its task from the PortOS operating contract.** For all Claude providers (TUI and headless CLI, local and hosted), the PortOS coordination boilerplate — worktree branch, completion-sentinel protocol, git/PR workflow — now rides in a real system prompt via `--append-system-prompt-file` (saved beside the agent's `prompt.txt` as `system-prompt.md`), while the pasted/stdin prompt carries only the task. The model weights the contract as standing instructions rather than conversation, and hosted providers get better prompt-cache reuse on the stable system block. The prompt content is byte-identical to before — only its placement changed. Codex, Antigravity, and OpenCode agents (no equivalent flag) keep the combined prompt unchanged.
diff --git a/client/src/components/cos/TaskAddForm.jsx b/client/src/components/cos/TaskAddForm.jsx
index 97632ed0d4..0f33b3077d 100644
--- a/client/src/components/cos/TaskAddForm.jsx
+++ b/client/src/components/cos/TaskAddForm.jsx
@@ -259,7 +259,7 @@ export default function TaskAddForm({ providers, apps, onTaskAdded, compact = fa
app: newTask.app || undefined,
createJiraTicket,
useWorktree,
- openPR,
+ openPR: useWorktree && openPR,
simplify,
reviewLoop,
reviewers: reviewLoop ? reviewers : undefined,
@@ -449,8 +449,12 @@ export default function TaskAddForm({ providers, apps, onTaskAdded, compact = fa
type="checkbox"
checked={useWorktree}
onChange={(e) => {
+ // Enabling a worktree defaults "Open PR" on (safer than an
+ // unreviewed auto-merge to the default branch); the user can
+ // still uncheck it. Disabling forces it off (openPR is
+ // meaningless without a worktree).
setUseWorktree(e.target.checked);
- if (!e.target.checked) setOpenPR(false);
+ setOpenPR(e.target.checked);
}}
className="w-4 h-4 rounded border-port-border bg-port-bg text-port-accent focus:ring-port-accent focus:ring-offset-0"
/>
diff --git a/server/services/agentProviderResolution.js b/server/services/agentProviderResolution.js
index 7a8212b778..6351c523bb 100644
--- a/server/services/agentProviderResolution.js
+++ b/server/services/agentProviderResolution.js
@@ -115,10 +115,28 @@ export async function resolveAgentProviderAndModel(task) {
// check below still guards it against the fallback provider's model list.
if (fallbackModelPin) selectedModel = fallbackModelPin;
- // Validate model is compatible with provider
+ // Validate model is compatible with provider. An EXPLICIT user-specified
+ // model (task.metadata.model → tier 'user-specified') is honored even when
+ // it isn't in the provider's `models` list: that list is a convenience
+ // enumeration, but the pass-through CLIs (claude/codex/opencode) accept any
+ // valid id — and the claude providers even disagree on alias form
+ // (`claude-code` lists `claude-haiku-4-5`, `claude-code-tui` lists the dated
+ // `claude-haiku-4-5-20251001`). Silently downgrading an explicit pin to the
+ // tier fallback — which for the default tier is the HEAVY model — both
+ // violates the user's intent and maximizes cost, so we trust the pin and let
+ // the provider reject a genuine typo at runtime. Auto-selected models (and a
+ // fallback-model pin, which the comment above deliberately guards) still fall
+ // back to the provider's tier default.
+ const isUserPinnedModel = modelSelection.tier === 'user-specified' && !fallbackModelPin;
if (selectedModel && provider.models && provider.models.length > 0) {
const modelIsValid = provider.models.includes(selectedModel);
- if (!modelIsValid) {
+ if (!modelIsValid && isUserPinnedModel) {
+ emitLog('info', `Honoring user-specified model "${selectedModel}" not in provider "${provider.id}" list (CLI pass-through)`, {
+ taskId: task.id,
+ requestedModel: selectedModel,
+ providerId: provider.id
+ });
+ } else if (!modelIsValid) {
emitLog('warn', `Model "${selectedModel}" not valid for provider "${provider.id}", falling back to provider default`, {
taskId: task.id,
requestedModel: selectedModel,
diff --git a/server/services/agentProviderResolution.test.js b/server/services/agentProviderResolution.test.js
index 6c9d14d005..2e8e51678d 100644
--- a/server/services/agentProviderResolution.test.js
+++ b/server/services/agentProviderResolution.test.js
@@ -99,6 +99,29 @@ describe('resolveAgentProviderAndModel', () => {
expect(r.selectedModel).toBe('m-default');
});
+ it('honors an explicit user-specified model even when it is not in the provider list (no silent downgrade)', async () => {
+ // Regression: claude-code-tui lists the DATED haiku id, so an undated
+ // `claude-haiku-4-5` pin failed the includes() check and silently
+ // downgraded to the provider default (opus, the heaviest model).
+ const provider = { id: 'claude-code-tui', type: 'tui', models: ['claude-haiku-4-5-20251001', 'claude-opus-4-8'], defaultModel: 'claude-opus-4-8', heavyModel: 'claude-opus-4-8' };
+ getActiveProvider.mockResolvedValue(provider);
+ selectModelForTask.mockResolvedValue({ model: 'claude-haiku-4-5', tier: 'user-specified', reason: 'user-preference' });
+
+ const r = await resolveAgentProviderAndModel({ id: 't', metadata: { model: 'claude-haiku-4-5' } });
+ expect(r.ok).toBe(true);
+ expect(r.selectedModel).toBe('claude-haiku-4-5'); // honored, NOT downgraded to opus
+ });
+
+ it('still downgrades an AUTO-selected model that is not in the provider list to the tier default', async () => {
+ const provider = { id: 'p1', type: 'cli', models: ['m-default'], defaultModel: 'm-default', heavyModel: 'm-heavy' };
+ getActiveProvider.mockResolvedValue(provider);
+ selectModelForTask.mockResolvedValue({ model: 'bogus-auto', tier: 'heavy', reason: 'complex-task' });
+
+ const r = await resolveAgentProviderAndModel(TASK);
+ expect(r.ok).toBe(true);
+ expect(r.selectedModel).toBe('m-heavy'); // auto-selected invalid model → tier fallback
+ });
+
it('honors a pinned provider before the active-provider availability gate', async () => {
// The active provider is down, but the task pins a different, healthy
// provider. The pin must win without the active provider's unavailability
diff --git a/server/services/cosTaskStore.js b/server/services/cosTaskStore.js
index 372e2ca8e3..68f8e099d9 100644
--- a/server/services/cosTaskStore.js
+++ b/server/services/cosTaskStore.js
@@ -237,6 +237,15 @@ export async function addTask(taskData, taskType = 'user', { raw = false, ignore
else if (taskData.useWorktree === false) metadata.useWorktree = false;
if (taskData.openPR === true) metadata.openPR = true;
else if (taskData.openPR === false) metadata.openPR = false;
+ // Default a worktree-isolated USER task to opening a PR rather than
+ // auto-merging straight to the default branch — an unreviewed agent commit
+ // landing on main is the more dangerous default (see the local-model eval
+ // that auto-merged). Fires only when openPR wasn't explicitly set AND a
+ // worktree was explicitly requested; an explicit `openPR: false` above
+ // always wins, and internal/system tasks (autopilot, self-improvement) keep
+ // their existing auto-merge behavior so automation isn't silently gated on a
+ // human merging a PR.
+ else if (taskData.useWorktree === true && taskType === 'user') metadata.openPR = true;
if (taskData.simplify === true) metadata.simplify = true;
else if (taskData.simplify === false) metadata.simplify = false;
if (taskData.reviewLoop === true) metadata.reviewLoop = true;
diff --git a/server/services/cosTaskStore.test.js b/server/services/cosTaskStore.test.js
index e9f0fd453f..2cbac698bf 100644
--- a/server/services/cosTaskStore.test.js
+++ b/server/services/cosTaskStore.test.js
@@ -198,6 +198,28 @@ describe('cosTaskStore.addTask', () => {
expect(task.metadata.openPR).toBe(true);
});
+ it('defaults a worktree USER task to openPR:true when openPR is unspecified', async () => {
+ const task = await addTask({ description: 'wt default pr', useWorktree: true }, 'user');
+ expect(task.metadata.useWorktree).toBe(true);
+ expect(task.metadata.openPR).toBe(true);
+ });
+
+ it('does NOT default openPR for a worktree INTERNAL task (automation keeps auto-merge)', async () => {
+ const task = await addTask({ description: 'wt internal', useWorktree: true }, 'internal');
+ expect(task.metadata.useWorktree).toBe(true);
+ expect(task.metadata.openPR).toBeUndefined();
+ });
+
+ it('respects an explicit openPR:false on a worktree task (no default override)', async () => {
+ const task = await addTask({ description: 'wt no pr', useWorktree: true, openPR: false }, 'user');
+ expect(task.metadata.openPR).toBe(false);
+ });
+
+ it('does not set openPR for a non-worktree task', async () => {
+ const task = await addTask({ description: 'no wt', useWorktree: false }, 'user');
+ expect(task.metadata.openPR).toBeUndefined();
+ });
+
it('raw=true stores the pre-built object verbatim', async () => {
const raw = { id: 'sys-raw', description: 'raw\nmultiline', status: 'pending', metadata: { context: 'ctx' } };
const task = await addTask(raw, 'internal', { raw: true });