Skip to content
Closed
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- Server: `/v1/metrics` reports a `tensorfold:open_connections` gauge, the client connections admitted over TCP or the Unix socket and not yet closed, including idle keep-alive ones (#3925). Thanks to @plotarmordev.

- Tools: served checks reject unexercised draft, seed, cache, cancellation and logit comparisons, covered by 11 served and constraint regression tests, and benchmark receipts name vacuous comparisons (#3772, refs #2460). Thanks to @jschmied.

- App: a Solo Kanban ticket can be assigned a saved bot, which builds with that bot's model, instructions and permissions while keeping the ticket's capability limits (#3737, fixes #3336). Thanks to @jamesadcock.

- Living Weights: in a container that refuses file clones with a permission error (LXC), lessons and rollbacks copy the files instead of failing (#4147).

- Build: the Qwen ModelOpt admission host test gets the `living` module, so `test-cuda-host` compiles on Windows again after #3294 (#4146).
Expand Down
1 change: 1 addition & 0 deletions app/electron/agent/types/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export interface Ticket {
projectId: string
roomId?: string | null
executionMode?: TicketExecutionMode
botId?: string | null
title: string
body: string
type: 'epic' | 'task' | 'subticket' | 'bug'
Expand Down
2 changes: 2 additions & 0 deletions app/electron/main/host/room-ticket-patch-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const ROOM_CONFIG_KEYS = new Set<keyof Room>([
const TICKET_USER_KEYS = new Set<keyof Ticket>([
'roomId',
'executionMode',
'botId',
'title',
'body',
'type',
Expand Down Expand Up @@ -236,6 +237,7 @@ export function appendRoomSteeringEvent(

export function pickTicketUserPatch(input: unknown): Partial<Ticket> {
const patch = strictOwnPatch<Ticket>(input, TICKET_USER_KEYS, 'ticket')
if (Object.prototype.hasOwnProperty.call(patch, 'botId')) assertNullableId(patch.botId, 'botId')
if (Object.prototype.hasOwnProperty.call(patch, 'roomId')) assertNullableId(patch.roomId, 'roomId')
if (Object.prototype.hasOwnProperty.call(patch, 'parentId')) assertNullableId(patch.parentId, 'parentId')
if (Object.prototype.hasOwnProperty.call(patch, 'executionMode')) assertEnum(patch.executionMode, TICKET_EXECUTION_MODES, 'executionMode')
Expand Down
5 changes: 4 additions & 1 deletion app/electron/main/host/thread-run-execution.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { restrictTicketToolContext } from '../../agent/ticket-tool-policy'
import { selectedResponseLocale } from '../../agent/response-language'
import { RunRecoveryTracker } from '../../agent/run-recovery/tracker'
import { assertThreadMemoryTransport, canContributeThreadMemory } from '../../../shared/thread-memory-policy'
Expand Down Expand Up @@ -93,7 +94,9 @@ export function createThreadRouteRunner(input: ThreadRouteContext) {
// undefined backend) could reinterpret the remote path as a local lookalike.
if (thread.bot && (activeProvider.id !== thread.bot.providerId || route.providerAccountId !== thread.bot.providerAccountId || runModel !== thread.bot.model)) throw new Error('Bots keep their captured model and account; start a new bot chat to change them.')
const baseToolContext = botVm ? { cwd: '/workspace', signal: controller.signal, currentThread: thread } : fullToolContext({ thread, provider: activeProvider, model: runModel, signal: controller.signal, memoryPolicy })
const toolContext = scopeBotToolContext(thread.bot, botVm ? createBotVmToolContext(vmHost!, thread.bot!.presetId, baseToolContext) : baseToolContext)
let toolContext = scopeBotToolContext(thread.bot, botVm ? createBotVmToolContext(vmHost!, thread.bot!.presetId, baseToolContext) : baseToolContext)
const botTicket = thread.bot ? store.tickets.find((ticket) => ticket.threadId === thread.id && !ticket.archivedAt) : undefined
if (botTicket) toolContext = restrictTicketToolContext(toolContext, botTicket.allowedCapabilities) as typeof toolContext
toolContext.memoryPolicy = memoryPolicy
assertThreadMemoryTransport(thread, activeProvider, memoryPolicy)
if (restrictedBot) toolContext.botToolScopeGuard = () => {
Expand Down
3 changes: 2 additions & 1 deletion app/electron/main/host/thread-run-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export function createThreadRunStarter(deps: ThreadRuntimeDeps, support: ThreadR
assertBotLifecycleIdle(thread.bot.presetId)
if (thread.engine && thread.engine !== 'native') throw new Error('Bot chats require TensorFold permission checks.')
if (thread.providerId !== thread.bot.providerId || (thread.providerAccountId ?? null) !== thread.bot.providerAccountId || thread.model !== thread.bot.model) throw new Error('The model differs from the captured bot configuration; start a new bot chat.')
if (thread.workspace || thread.projectId || (botVm ? thread.cwd !== '/workspace' : !!thread.cwd)) throw new Error('The bot execution location has changed; start a new bot chat.')
const ticketBotThread = !botVm && store.tickets.some((ticket) => ticket.threadId === thread.id && ticket.projectId === thread.projectId && !ticket.archivedAt)
if (thread.workspace || (!ticketBotThread && (thread.projectId || (botVm ? thread.cwd !== '/workspace' : !!thread.cwd)))) throw new Error('The bot execution location has changed; start a new bot chat.')
if (botVm && !vmHost) throw new Error('The bot VM service is unavailable; the run will not use this Mac instead.')
}
// Guard against a second concurrent run for the same thread: it would overwrite the shared
Expand Down
51 changes: 51 additions & 0 deletions app/electron/main/host/ticket-bot.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import assert from 'node:assert/strict'
import { captureTicketBot, sameTicketBot } from './ticket-bot'
import { pickTicketUserPatch } from './room-ticket-patch-policy'
import { mkTicket } from './ticket-helpers'
import { defaultSettings } from '../../store/defaults'
import type { Settings, Ticket } from '../../agent/types'

const settings = {
...defaultSettings(),
providers: [{ id: 'local', kind: 'local', name: 'Local', baseUrl: 'http://127.0.0.1:8080/v1', models: ['small'] }],
agentPresets: [{ id: 'builder', lane: 'development', createdAt: 1, updatedAt: 1, name: 'Builder', role: 'Read documentation', instructions: 'Summarize concisely', providerId: 'local', model: 'small', approvalScope: 'readonly', executionTarget: 'workspace' }],
} as Settings
const ticket = { botId: 'builder', executionMode: 'solo' } as Ticket
const bot = captureTicketBot(ticket, 'build', settings)!
assert.equal(bot.model, 'small')
assert.equal(bot.instructions, 'Summarize concisely')
assert.equal(bot.approvalScope, 'readonly')
assert.equal(captureTicketBot(ticket, 'review', settings), undefined)
assert.equal(captureTicketBot({ ...ticket, executionMode: 'room' }, 'build', settings), undefined)
assert.equal(captureTicketBot({ ...ticket, botId: null }, 'build', settings), undefined)
assert.throws(() => captureTicketBot({ ...ticket, botId: 'missing' }, 'build', settings), /unavailable/)
settings.agentPresets[0].paused = true
assert.throws(() => captureTicketBot(ticket, 'build', settings), /Resume/)
settings.agentPresets[0].paused = false
settings.agentPresets[0].executionTarget = 'vm'
assert.throws(() => captureTicketBot(ticket, 'build', settings), /VM ticket execution/)

assert.equal(sameTicketBot(undefined, undefined), true)
assert.equal(sameTicketBot(undefined, bot), false)
assert.equal(sameTicketBot(bot, undefined), false)
assert.equal(sameTicketBot(bot, { ...bot, capturedAt: bot.capturedAt + 1 }), true)
assert.equal(sameTicketBot(bot, { ...bot, instructions: 'Changed instructions' }), false)
assert.equal(sameTicketBot(bot, { ...bot, presetId: 'another' }), false)

assert.equal(pickTicketUserPatch({ botId: 'builder' }).botId, 'builder')
assert.equal(pickTicketUserPatch({ botId: null }).botId, null)
assert.throws(() => pickTicketUserPatch({ botId: { instructions: 'untrusted' } }), /botId/)
assert.equal(mkTicket('project', { botId: 'builder' }).botId, 'builder')
settings.agentPresets[0].executionTarget = 'workspace'
settings.agentPresets[0].toolScope = { mode: 'selected', names: ['read_file'] }
const scopedBot = captureTicketBot(ticket, 'build', settings)!
assert.deepEqual(scopedBot.toolScope, { mode: 'selected', names: ['read_file'] })
settings.agentPresets[0].instructions = 'New instructions'
assert.equal(scopedBot.instructions, 'Summarize concisely')
settings.agentPresets[0].archivedAt = 1
assert.throws(() => captureTicketBot(ticket, 'build', settings), /Restore/)
settings.agentPresets[0].archivedAt = null
settings.agentPresets[0].model = 'missing'
assert.throws(() => captureTicketBot(ticket, 'build', settings), /model is unavailable/)

console.log('ticket bot assignment checks passed')
35 changes: 35 additions & 0 deletions app/electron/main/host/ticket-bot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { isDeepStrictEqual } from 'node:util'
import { captureBotConfig, botRunApprovalMode } from '../../../shared/bot-policy'
import { isRestrictedBot } from '../../../shared/bot-tool-policy'
import type { BotThreadConfig, Settings, Ticket } from '../../agent/types'
import { assertBotLifecycleIdle } from './bot-run-boundary'
import { engineService } from './engine-runtime'
import { isEngineProvider } from '../../agent/engine/provider'

export function captureTicketBot(ticket: Ticket, phase: 'build' | 'review', settings: Settings): BotThreadConfig | undefined {
if (phase !== 'build' || (ticket.executionMode ?? 'solo') !== 'solo' || !ticket.botId) return undefined
const preset = settings.agentPresets.find((candidate) => candidate.id === ticket.botId)
if (!preset) throw new Error('The assigned bot is unavailable; choose another Bot or Agent on this ticket.')
const bot = captureBotConfig(preset, settings.providers)
if (bot.executionTarget !== 'workspace') throw new Error('Solo tickets require a bot that runs in This Mac workspace; VM ticket execution is unavailable.')
return bot
}

export function assertTicketBotReady(bot: BotThreadConfig, settings: Settings): void {
assertBotLifecycleIdle(bot.presetId)
botRunApprovalMode({ bot }, settings.agentPresets, settings.providers, settings.approvalMode)
if (isRestrictedBot(bot)) {
const engine = engineService()
const provider = settings.providers.find((candidate) => candidate.id === bot.providerId)
if (engine?.hasExternalResearchEnabled() || isEngineProvider(provider) && !engine) {
throw new Error('Turn off Cortheon in AI settings before using a restricted bot.')
}
}
}

export function sameTicketBot(previous: BotThreadConfig | undefined, next: BotThreadConfig | undefined): boolean {
if (!previous || !next) return previous === next
const { capturedAt: previousTime, ...previousConfig } = previous
const { capturedAt: nextTime, ...nextConfig } = next
return isDeepStrictEqual(previousConfig, nextConfig)
}
1 change: 1 addition & 0 deletions app/electron/main/host/ticket-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export function mkTicket(projectId: string, p: Partial<Ticket>): Ticket {
return {
id: randomUUID(), projectId, title: p.title || 'Untitled', body: p.body || '',
roomId: p.roomId ?? null,
botId: p.botId ?? null,
type: p.type || 'task', status: p.status || 'todo', priority: p.priority || 'medium', effort: p.effort || 'medium',
tags: normalizeStringList(p.tags, []), ...execution,
dependsOn: normalizeTicketDependencyIds(p.dependsOn),
Expand Down
4 changes: 4 additions & 0 deletions app/electron/main/host/ticket-worker-publication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { readFileSync } from 'node:fs'
import path from 'node:path'
import { randomUUID } from 'node:crypto'
import ts from 'typescript'
import { botRunApprovalMode } from '../../../shared/bot-policy'
import { scopeBotToolContext } from '../../agent/bot-tool-scope'
import { normalizeTicketCapabilities, startTicketExecution, settleTicketExecution, ticketStateAfterRun, ticketWorkPrompt } from '../../agent/tickets'
import { captureTicketBot, sameTicketBot } from './ticket-bot'

const file = path.join(__dirname, 'ticket-worker-runtime.ts')
const source = ts.createSourceFile(file, readFileSync(file, 'utf8'), ts.ScriptTarget.ES2022, true)
Expand All @@ -27,6 +30,7 @@ async function scenario(roomScoped: boolean, rendererAvailable = true) {
const aborters = new Map<string, AbortController>()
const bindings: Record<string, unknown> = {
selectedResponseLocale: () => 'en', randomUUID, path, store,
botRunApprovalMode, scopeBotToolContext, captureTicketBot, sameTicketBot,
runAgent: () => new Promise<void>((resolve) => { finishRun = resolve }),
assertProviderEndpoint() {}, auditPreview: String, auditEvent: async () => {}, requireSecurityRole() {},
normalizeTicketCapabilities, startTicketExecution, settleTicketExecution, ticketStateAfterRun, ticketWorkPrompt,
Expand Down
29 changes: 22 additions & 7 deletions app/electron/main/host/ticket-worker-runtime.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { botInstructions, botRunApprovalMode } from '../../../shared/bot-policy'
import { scopeBotToolContext } from '../../agent/bot-tool-scope'
import { captureTicketBot, assertTicketBotReady, sameTicketBot } from './ticket-bot'
import { selectedResponseLocale } from '../../agent/response-language'
import { randomUUID } from 'node:crypto'
import path from 'node:path'
Expand Down Expand Up @@ -146,6 +149,8 @@ async function startTicketWork(input: TicketWorkerInput): Promise<Thread> {
? room?.seats.find((seat) => seat.name === input.source?.seat) : undefined
const configuredEffort = input.source?.reasoningEffort === undefined ? roomSeat : input.source
const reasoningEffort = captureAgentReasoningEffort(configuredEffort, store.settings.reasoningEffort)
const bot = input.source?.roomId ? undefined : captureTicketBot(ticket, phase, store.settings)
if (bot) assertTicketBotReady(bot, store.settings)
const configuredWorkspace = room?.workspace ?? project.workspace ?? null
if (configuredWorkspace?.kind === 'ssh') {
throw new Error('Local ticket workers do not support SSH workspaces; run this ticket on its remote Orchestrator.')
Expand All @@ -160,14 +165,18 @@ async function startTicketWork(input: TicketWorkerInput): Promise<Thread> {
let reservedController: AbortController | null = null
let launched = false
try {
const opts = ticketWorkOptionsWithProjectRoute(project, requestedOpts, phase === 'review' ? 'ticket_review' : 'ticket_build')
const routeOptions = bot
? { ...requestedOpts, providerId: bot.providerId, providerAccountId: bot.providerAccountId, model: bot.model }
: requestedOpts
const opts = ticketWorkOptionsWithProjectRoute(project, routeOptions, phase === 'review' ? 'ticket_review' : 'ticket_build')
const roomWorkspace = project && room
? await awaitTicketStartupStep(ensureRoomWorktree(project, room), () => assertActiveTicketWorkOwnership(ticket, project, room, existingThread))
: null
if (room && project?.cwd && roomWorkspace && path.resolve(roomWorkspace) === path.resolve(project.cwd)) {
throw new Error('Room ticket work must run in an isolated room worktree, not the base project folder.')
}
const resolvedRoute = resolveProjectProvider(project, opts?.providerAccountId, opts?.model, opts?.providerId)
if (bot && (resolvedRoute.baseProvider.id !== bot.providerId || resolvedRoute.providerAccountId !== bot.providerAccountId || resolvedRoute.model !== bot.model)) throw new Error('The assigned bot model is unavailable for this project.')
const baseProvider = resolvedRoute.baseProvider
const routeBaseProvider = store.settings.providers.find((p) => p.id === baseProvider.id) ?? baseProvider
const requestedProviderAccountId = resolvedRoute.providerAccountId
Expand All @@ -176,7 +185,7 @@ async function startTicketWork(input: TicketWorkerInput): Promise<Thread> {
provider: routeBaseProvider,
model: resolvedRoute.model,
requestedAccountId: requestedProviderAccountId,
allowFailover: modelRouteAutoFailoverEnabled(routeBaseProvider, requestedProviderAccountId),
allowFailover: !bot && modelRouteAutoFailoverEnabled(routeBaseProvider, requestedProviderAccountId),
localOnly: project?.localOnly === true,
contextLimit: effectiveContextLimit(routeBaseProvider, resolvedRoute.model, requestedProviderAccountId),
reasoningEffort,
Expand All @@ -202,10 +211,12 @@ async function startTicketWork(input: TicketWorkerInput): Promise<Thread> {
let thread = ticket.threadId ? store.threads.find((t) => t.id === ticket.threadId) : null
assertActiveTicketWorkOwnership(ticket, project, room, thread)
if (thread && aborters.has(thread.id)) throw new Error('Ticket work is already running.')
if (!sameTicketBot(thread?.bot, bot)) thread = null
const isNewThread = !thread
if (!thread) {
thread = {
documentSourceIds: [],
...(bot ? { bot } : {}),
id: randomUUID(), title: ticket.title, kind: 'task', projectId: ticket.projectId ?? null,
cwd,
providerId: baseProvider.id, providerAccountId, model,
Expand All @@ -229,7 +240,7 @@ async function startTicketWork(input: TicketWorkerInput): Promise<Thread> {
ticket.status = 'in_progress'
ticket.runState = 'running'
ticket.startedAt = Date.now()
ticket.assignee = input.source?.seat || ticket.assignee || model
ticket.assignee = input.source?.seat || bot?.name || (!existingThread?.bot && ticket.assignee) || model
// Execution tracking (VST-018): branch / engine / run, stamped at start, settled below.
ticket.execution = startTicketExecution({
target: input.source?.roomId ? 'room' : (ticket.executionMode === 'frontier' || ticket.executionMode === 'cli') ? ticket.executionMode : 'solo',
Expand Down Expand Up @@ -325,22 +336,26 @@ async function startTicketWork(input: TicketWorkerInput): Promise<Thread> {
}
let activeRoute = { provider, providerAccountId, model }
const runTicketWithRoute = async (route: { provider: Provider; providerAccountId: string | null; model: string }) => {
if (bot) assertTicketBotReady(bot, store.settings)
const timelineStart = t.timeline.length
const context = fullToolContext({ thread: t, provider: route.provider, model: route.model, signal: controller.signal })
if (bot) context.botToolScopeGuard = () => assertTicketBotReady(bot, store.settings)
const toolContext = restrictTicketToolContext(
fullToolContext({ thread: t, provider: route.provider, model: route.model, signal: controller.signal }),
context,
allowedCapabilities,
)
await executeAgent({
responseLocale: selectedResponseLocale(store.settings.uiPreferences),
thread: t,
provider: route.provider,
model: route.model,
approvalMode: store.settings.approvalMode === 'auto' ? 'suggest' : store.settings.approvalMode,
...(bot ? { personaBlock: botInstructions(bot) } : {}),
approvalMode: botRunApprovalMode(t, store.settings.agentPresets, store.settings.providers, store.settings.approvalMode === 'auto' ? 'suggest' : store.settings.approvalMode),
temperature: store.settings.temperature,
reasoningEffort,
autoCompact: store.settings.autoCompact,
contextLimit: effectiveContextLimit(route.provider, route.model),
toolContext,
toolContext: scopeBotToolContext(bot, toolContext),
drainCues: () => drainThreadCues(t.id),
waitForCue: (timeoutMs, signal) => waitForThreadCue(t.id, timeoutMs, signal),
maxSteps: 40,
Expand All @@ -365,7 +380,7 @@ async function startTicketWork(input: TicketWorkerInput): Promise<Thread> {
accountId: activeRoute.providerAccountId,
model: activeRoute.model,
error: err,
allowFailover: modelRouteAutoFailoverEnabled(latestBaseProvider, activeRoute.providerAccountId) || t.modelRoute?.resetPolicy === 'rotate_on_limit',
allowFailover: !bot && (modelRouteAutoFailoverEnabled(latestBaseProvider, activeRoute.providerAccountId) || t.modelRoute?.resetPolicy === 'rotate_on_limit'),
localOnly: project?.localOnly === true,
contextLimit: effectiveContextLimit(latestBaseProvider, activeRoute.model, activeRoute.providerAccountId),
reasoningEffort,
Expand Down
Loading