fix: remove avoidable model runtime limits
Preserve long histories and parsed attachments, expose paged process and Subagent output, isolate MCP discovery failures, and expand browser snapshots and knowledge result selection. Remove fixed Harness output and updated remote Runtime duration limits. Keep released Agent profile and v1 bridge compatibility while enabling larger framed exchanges and optional limits for updated peers. Document remote coverage requirements and real-model boundary validation. Release note: Long model tasks can retain more context and continue reading complete tool output; remote execution preserves compatibility with released Agents. Updated remote limits require an updated Agent and Runtime bundle.
This commit is contained in:
@@ -1166,7 +1166,7 @@ function assertRuntimeManifest(
|
||||
sourcePackage.integrity !== lockedTarget.integrity ||
|
||||
!sha256Pattern.test(String(entrypoint.sha256)) ||
|
||||
!Number.isSafeInteger(limits.maximumPromptRuntimeMilliseconds) ||
|
||||
Number(limits.maximumPromptRuntimeMilliseconds) < 1 ||
|
||||
Number(limits.maximumPromptRuntimeMilliseconds) < 0 ||
|
||||
!Number.isSafeInteger(limits.maximumPromptInputBytes) ||
|
||||
Number(limits.maximumPromptInputBytes) < 1 ||
|
||||
!Number.isSafeInteger(limits.maximumPromptOutputBytes) ||
|
||||
|
||||
@@ -172,12 +172,13 @@ async function sentMessage(
|
||||
channel: FakeBlobChannel,
|
||||
offset = 0
|
||||
) {
|
||||
await vi.waitFor(() =>
|
||||
await vi.waitFor(() => {
|
||||
expect(channel.sent.length).toBeGreaterThan(offset)
|
||||
)
|
||||
expect(() => JSON.parse(Buffer.concat(channel.sent.slice(offset)).toString())).not.toThrow()
|
||||
})
|
||||
return {
|
||||
message: await decodeModelBridgeMessage(channel.sent[offset]!),
|
||||
nextOffset: offset + 1
|
||||
message: await decodeModelBridgeMessage(Buffer.concat(channel.sent.slice(offset))),
|
||||
nextOffset: channel.sent.length
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,7 +316,7 @@ describe('MainModelBridgeSession', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('delivers a maximum-sized response in one bounded message', async () => {
|
||||
it('delivers a maximum-sized response across bounded transport frames', async () => {
|
||||
const channel = new FakeBlobChannel()
|
||||
const largeResponse = {
|
||||
...response,
|
||||
@@ -331,11 +332,11 @@ describe('MainModelBridgeSession', () => {
|
||||
})
|
||||
const requestMessage = await pushRequest(channel, 0)
|
||||
const outgoing = await sentMessage(channel)
|
||||
expect(outgoing.nextOffset).toBe(1)
|
||||
expect(channel.sent).toHaveLength(1)
|
||||
expect(channel.sent[0]!.byteLength).toBeLessThanOrEqual(
|
||||
AGENT_PROTOCOL_LIMITS.maximumBlobFrameBytes
|
||||
)
|
||||
expect(outgoing.nextOffset).toBe(channel.sent.length)
|
||||
expect(channel.sent.length).toBeGreaterThan(1)
|
||||
for (const frame of channel.sent) {
|
||||
expect(frame.byteLength).toBeLessThanOrEqual(AGENT_PROTOCOL_LIMITS.maximumBlobFrameBytes)
|
||||
}
|
||||
expect(outgoing.message).toMatchObject({
|
||||
kind: 'response',
|
||||
response: largeResponse
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { isDeepStrictEqual } from 'node:util'
|
||||
import { AGENT_PROTOCOL_LIMITS } from '../../shared/agent-protocol/contracts'
|
||||
import {
|
||||
MODEL_BRIDGE_LIMITS,
|
||||
MODEL_BRIDGE_PROTOCOL,
|
||||
ModelBridgeMessageBuffer,
|
||||
decodeModelBridgeMessage,
|
||||
encodeModelBridgeMessage,
|
||||
modelBridgeErrorMessageSchema,
|
||||
@@ -22,7 +24,6 @@ import {
|
||||
type MainModelBridgePoison
|
||||
} from './main-model-bridge-dispatcher'
|
||||
|
||||
const DEFAULT_REQUEST_TIMEOUT_MS = 180_000
|
||||
const DEFAULT_CLOSE_TIMEOUT_MS = 2_000
|
||||
|
||||
export type MainModelBridgeSessionIdentity = {
|
||||
@@ -73,7 +74,7 @@ export class MainModelBridgeSession {
|
||||
readonly #onDelivered: MainModelBridgeDelivered
|
||||
readonly #finalizePrompt: MainModelBridgeFinalizePrompt
|
||||
readonly #poisonCallback: MainModelBridgePoison
|
||||
readonly #requestTimeoutMs: number
|
||||
readonly #requestTimeoutMs: number | undefined
|
||||
readonly #closeTimeoutMs: number
|
||||
readonly #lifetime = new AbortController()
|
||||
readonly #closedResolve: (
|
||||
@@ -100,10 +101,9 @@ export class MainModelBridgeSession {
|
||||
this.#onDelivered = options.onDelivered
|
||||
this.#finalizePrompt = options.finalizePrompt
|
||||
this.#poisonCallback = options.poison
|
||||
this.#requestTimeoutMs = boundedTimeout(
|
||||
options.requestTimeoutMs,
|
||||
DEFAULT_REQUEST_TIMEOUT_MS
|
||||
)
|
||||
this.#requestTimeoutMs = options.requestTimeoutMs === undefined
|
||||
? undefined
|
||||
: boundedTimeout(options.requestTimeoutMs, options.requestTimeoutMs)
|
||||
this.#closeTimeoutMs = boundedTimeout(
|
||||
options.closeTimeoutMs,
|
||||
DEFAULT_CLOSE_TIMEOUT_MS
|
||||
@@ -173,7 +173,7 @@ export class MainModelBridgeSession {
|
||||
|
||||
this.#active = { request, phase: 'dispatching' }
|
||||
const controller = new AbortController()
|
||||
const timeout = setTimeout(() => {
|
||||
const timeout = this.#requestTimeoutMs === undefined ? undefined : setTimeout(() => {
|
||||
controller.abort(
|
||||
new DOMException(
|
||||
'Remote model bridge request timed out',
|
||||
@@ -181,7 +181,7 @@ export class MainModelBridgeSession {
|
||||
)
|
||||
)
|
||||
}, this.#requestTimeoutMs)
|
||||
timeout.unref?.()
|
||||
timeout?.unref?.()
|
||||
const abort = (): void => controller.abort(this.#lifetime.signal.reason)
|
||||
this.#lifetime.signal.addEventListener('abort', abort, {
|
||||
once: true
|
||||
@@ -302,25 +302,33 @@ export class MainModelBridgeSession {
|
||||
expectedIdentity?: ModelBridgeIdentity,
|
||||
expectedRequestDigest?: string
|
||||
) {
|
||||
const frame = await this.#channel.receive(this.#lifetime.signal)
|
||||
if (expectedIdentity === undefined) {
|
||||
this.#receivingRequest = true
|
||||
}
|
||||
try {
|
||||
this.#assertCurrent()
|
||||
const message = await decodeModelBridgeMessage(frame.payload, {
|
||||
expectedIdentity,
|
||||
expectedRequestDigest,
|
||||
maximumMessageBytes: MODEL_BRIDGE_LIMITS.maximumMessageBytes
|
||||
})
|
||||
await frame.consume()
|
||||
const buffer = new ModelBridgeMessageBuffer()
|
||||
while (true) {
|
||||
const frame = await this.#channel.receive(this.#lifetime.signal)
|
||||
if (expectedIdentity === undefined) {
|
||||
this.#receivingRequest = false
|
||||
this.#receivingRequest = true
|
||||
}
|
||||
try {
|
||||
this.#assertCurrent()
|
||||
const payload = buffer.push(frame.payload)
|
||||
if (payload === undefined) {
|
||||
await frame.consume()
|
||||
continue
|
||||
}
|
||||
const message = await decodeModelBridgeMessage(payload, {
|
||||
expectedIdentity,
|
||||
expectedRequestDigest,
|
||||
maximumMessageBytes: MODEL_BRIDGE_LIMITS.maximumMessageBytes
|
||||
})
|
||||
await frame.consume()
|
||||
if (expectedIdentity === undefined) {
|
||||
this.#receivingRequest = false
|
||||
}
|
||||
return message
|
||||
} catch (error) {
|
||||
await frame.consume().catch(() => undefined)
|
||||
throw error
|
||||
}
|
||||
return message
|
||||
} catch (error) {
|
||||
await frame.consume().catch(() => undefined)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,7 +377,13 @@ export class MainModelBridgeSession {
|
||||
): Promise<void> {
|
||||
const payload = await encodeModelBridgeMessage(message)
|
||||
this.#assertCurrent()
|
||||
await this.#channel.send(payload, signal)
|
||||
for (let offset = 0; offset < payload.byteLength; offset += AGENT_PROTOCOL_LIMITS.maximumBlobFrameBytes) {
|
||||
this.#assertCurrent()
|
||||
await this.#channel.send(
|
||||
payload.subarray(offset, offset + AGENT_PROTOCOL_LIMITS.maximumBlobFrameBytes),
|
||||
signal
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#assertCurrent(): void {
|
||||
@@ -529,7 +543,7 @@ function boundedTimeout(
|
||||
if (
|
||||
!Number.isSafeInteger(timeout) ||
|
||||
timeout < 1 ||
|
||||
timeout > 300_000
|
||||
timeout > 0x7fff_ffff
|
||||
) {
|
||||
throw new RangeError('Model bridge timeout is invalid')
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { z } from 'zod'
|
||||
import { MODEL_BRIDGE_OPTIONAL_LIMITS_CAPABILITY } from '../../shared/model-bridge-contracts'
|
||||
import type { ResolvedModelProfile } from '../runtime-settings-store'
|
||||
import {
|
||||
createManagedModelBridge,
|
||||
modelProfileForAgent,
|
||||
createResolvedModelProfileDigest
|
||||
} from './managed-model-bridge'
|
||||
|
||||
@@ -24,6 +27,41 @@ const profile: ResolvedModelProfile = {
|
||||
}
|
||||
|
||||
describe('managed Agent prompt model setup', () => {
|
||||
it('supplies the required released 0.11.22 limits only to Agents without optional-limit support', () => {
|
||||
// agent-v0.11.22:src/shared/model-bridge-contracts.ts
|
||||
const releasedLimits = z.object({
|
||||
maximumOutputTokens: z.number().int().min(1).max(1_000_000),
|
||||
requestTimeoutMilliseconds: z.number().int().min(1).max(300_000)
|
||||
}).strict()
|
||||
const setup = createManagedModelBridge({ profile: { ...profile, maximumOutputTokens: undefined } })
|
||||
expect(releasedLimits.safeParse(setup.profile.limits).success).toBe(false)
|
||||
const released = modelProfileForAgent(setup.profile, [])
|
||||
expect(releasedLimits.parse(released.limits)).toEqual({
|
||||
maximumOutputTokens: 32_000,
|
||||
requestTimeoutMilliseconds: 60_000
|
||||
})
|
||||
expect(modelProfileForAgent(setup.profile, [{
|
||||
name: MODEL_BRIDGE_OPTIONAL_LIMITS_CAPABILITY, version: 1
|
||||
}]).limits).toEqual({})
|
||||
expect(setup.profile.limits).toEqual({})
|
||||
const large = { ...setup.profile, limits: { maximumOutputTokens: 2_000_000, requestTimeoutMilliseconds: 600_000 } }
|
||||
expect(releasedLimits.parse(modelProfileForAgent(large, []).limits)).toEqual({
|
||||
maximumOutputTokens: 1_000_000, requestTimeoutMilliseconds: 300_000
|
||||
})
|
||||
expect(modelProfileForAgent(large, [{
|
||||
name: MODEL_BRIDGE_OPTIONAL_LIMITS_CAPABILITY, version: 1
|
||||
}]).limits).toEqual(large.limits)
|
||||
})
|
||||
|
||||
it('leaves unspecified provider limits unset and preserves configured tokens', () => {
|
||||
expect(createManagedModelBridge({
|
||||
profile: { ...profile, maximumOutputTokens: undefined }
|
||||
}).profile.limits).toEqual({})
|
||||
expect(createManagedModelBridge({
|
||||
profile: { ...profile, maximumOutputTokens: 2_000_000 }
|
||||
}).profile.limits).toEqual({ maximumOutputTokens: 2_000_000 })
|
||||
})
|
||||
|
||||
it('validates and clones an Agent prompt profile without prompt-wide quotas', () => {
|
||||
const setup = createManagedModelBridge({ profile })
|
||||
|
||||
@@ -46,8 +84,7 @@ describe('managed Agent prompt model setup', () => {
|
||||
},
|
||||
capabilities: { imageInput: true },
|
||||
limits: {
|
||||
maximumOutputTokens: 8_192,
|
||||
requestTimeoutMilliseconds: 60_000
|
||||
maximumOutputTokens: 8_192
|
||||
}
|
||||
})
|
||||
expect(setup.policy).toEqual({
|
||||
|
||||
@@ -2,14 +2,29 @@ import { createHash } from 'node:crypto'
|
||||
import { canonicalJson } from '../../shared/agent-protocol/canonical'
|
||||
import {
|
||||
agentPromptModelProfileSchema,
|
||||
MODEL_BRIDGE_OPTIONAL_LIMITS_CAPABILITY,
|
||||
modelBridgePolicySchema,
|
||||
type AgentPromptModelProfile,
|
||||
type ModelBridgePolicy
|
||||
} from '../../shared/model-bridge-contracts'
|
||||
import type { ResolvedModelProfile } from '../runtime-settings-store'
|
||||
|
||||
const DEFAULT_MAXIMUM_OUTPUT_TOKENS = 32_000
|
||||
const MODEL_REQUEST_TIMEOUT_MILLISECONDS = 60_000
|
||||
export function modelProfileForAgent(
|
||||
profile: AgentPromptModelProfile,
|
||||
capabilities: ReadonlyArray<{ name: string; version: number }>
|
||||
): AgentPromptModelProfile {
|
||||
if (capabilities.some(capability =>
|
||||
capability.name === MODEL_BRIDGE_OPTIONAL_LIMITS_CAPABILITY && capability.version === 1
|
||||
)) return structuredClone(profile)
|
||||
// Released Agent 0.11.22 requires both fields and enforces these bounds.
|
||||
return {
|
||||
...structuredClone(profile),
|
||||
limits: {
|
||||
maximumOutputTokens: Math.min(profile.limits.maximumOutputTokens ?? 32_000, 1_000_000),
|
||||
requestTimeoutMilliseconds: Math.min(profile.limits.requestTimeoutMilliseconds ?? 60_000, 300_000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt-scoped model material passed directly to the Agent. The policy is
|
||||
@@ -58,14 +73,6 @@ export function createManagedModelBridge(options: {
|
||||
'Managed remote OpenCode requires a usable text model profile'
|
||||
)
|
||||
}
|
||||
const maximumOutputTokens = Math.min(
|
||||
1_000_000,
|
||||
Math.max(
|
||||
1,
|
||||
selected.maximumOutputTokens ??
|
||||
DEFAULT_MAXIMUM_OUTPUT_TOKENS
|
||||
)
|
||||
)
|
||||
const modelProfileDigest =
|
||||
createResolvedModelProfileDigest(selected)
|
||||
const profile = agentPromptModelProfileSchema.parse({
|
||||
@@ -94,9 +101,9 @@ export function createManagedModelBridge(options: {
|
||||
imageInput: selected.supportsImageInput === true
|
||||
},
|
||||
limits: {
|
||||
maximumOutputTokens,
|
||||
requestTimeoutMilliseconds:
|
||||
MODEL_REQUEST_TIMEOUT_MILLISECONDS
|
||||
...(selected.maximumOutputTokens === undefined
|
||||
? {}
|
||||
: { maximumOutputTokens: selected.maximumOutputTokens })
|
||||
}
|
||||
})
|
||||
const policy = modelBridgePolicySchema.parse({
|
||||
|
||||
@@ -3,6 +3,7 @@ import { describe, expect, it, vi } from 'vitest'
|
||||
const remoteHarness = vi.hoisted(() => ({
|
||||
instances: [] as Array<{
|
||||
options: {
|
||||
modelProfile?: import('../../shared/model-bridge-contracts').AgentPromptModelProfile
|
||||
identity: {
|
||||
controllerGeneration: number
|
||||
daemonBootIdAtOpen: string
|
||||
@@ -31,6 +32,7 @@ vi.mock('../agent/acp-remote-runtime', () => ({
|
||||
|
||||
constructor(
|
||||
readonly options: {
|
||||
modelProfile?: import('../../shared/model-bridge-contracts').AgentPromptModelProfile
|
||||
identity: {
|
||||
controllerGeneration: number
|
||||
daemonBootIdAtOpen: string
|
||||
@@ -243,6 +245,19 @@ function harness(
|
||||
}
|
||||
|
||||
describe('createManagedRemoteAcpRuntime', () => {
|
||||
it.each([false, true])('selects prompt limits from the connected Agent capability (optional=%s)', async (optional) => {
|
||||
const fixture = harness()
|
||||
fixture.options.modelBridge.profile.limits = {}
|
||||
if (optional) fixture.connection.capabilities.capabilities.push({
|
||||
name: 'runtime/model-bridge-optional-limits', version: 1, critical: false
|
||||
})
|
||||
const runtime = await createManagedRemoteAcpRuntime(fixture.options)
|
||||
expect(remoteHarness.instances[0]!.options.modelProfile?.limits).toEqual(optional ? {} : {
|
||||
maximumOutputTokens: 32_000, requestTimeoutMilliseconds: 60_000
|
||||
})
|
||||
await runtime.dispose()
|
||||
})
|
||||
|
||||
it('accepts the current OpenCode model profile independently of persisted validation', async () => {
|
||||
const fixture = harness({
|
||||
selection: {
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
} from '../../shared/remote-agent-contracts'
|
||||
import { createProtocolRemoteRuntimeChannel } from './protocol-remote-runtime-channel'
|
||||
import type { RemoteAgentServices } from './remote-agent-services'
|
||||
import type { ManagedModelBridge } from './managed-model-bridge'
|
||||
import { modelProfileForAgent, type ManagedModelBridge } from './managed-model-bridge'
|
||||
import type { AgentInstallationIdentity } from './agent-installation-manager'
|
||||
import type {
|
||||
RemoteRuntimeInstallationIdentity,
|
||||
@@ -157,7 +157,10 @@ export async function createManagedRemoteAcpRuntime(
|
||||
resources.openChannel(transport, bindingId),
|
||||
bindingStore: options.bindingStore,
|
||||
modelBridgePolicy: options.modelBridge.policy,
|
||||
modelProfile: options.modelBridge.profile,
|
||||
modelProfile: modelProfileForAgent(
|
||||
options.modelBridge.profile,
|
||||
activeConnection.capabilities.capabilities
|
||||
),
|
||||
assertHostCurrent: (identity) => {
|
||||
if (
|
||||
identity.controllerId !== controllerId ||
|
||||
|
||||
Reference in New Issue
Block a user