Skip to content

Commit d053f67

Browse files
committed
refactor(core): take location_idle_timeout in milliseconds
1 parent e7cbd33 commit d053f67

9 files changed

Lines changed: 22 additions & 17 deletions

File tree

‎packages/client/src/promise/generated/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2331,7 +2331,7 @@ export type ConfigEntry =
23312331
portable_shell_scanner?: boolean
23322332
todo?: boolean
23332333
subagent_depth?: number
2334-
location_idle_timeout?: string | false
2334+
location_idle_timeout?: number | false
23352335
policies?: Array<{
23362336
action: "provider.use" | "tool.use" | "integration.use"
23372337
resource: string

‎packages/core/src/location-activity.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ export function layer(options: { readonly timeToLive?: Duration.Input; readonly
4444
(entry): entry is Document =>
4545
entry.type === "document" && entry.info.experimental?.location_idle_timeout !== undefined,
4646
)
47-
return configured?.info.experimental?.location_idle_timeout ?? timeToLive
47+
const timeout = configured?.info.experimental?.location_idle_timeout
48+
if (timeout === undefined) return timeToLive
49+
return timeout === false ? false : Duration.millis(timeout)
4850
}).pipe(
4951
Effect.scoped,
5052
Effect.orElseSucceed(() => timeToLive),

‎packages/core/test/config/normalization.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ describe("ConfigNormalize", () => {
526526
portable_shell_scanner: true,
527527
todo: true,
528528
subagent_depth: 0,
529-
location_idle_timeout: "2 hours",
529+
location_idle_timeout: 7_200_000,
530530
policies: [{ action: "provider.use", resource: "custom", effect: "allow" }],
531531
},
532532
}).encoded,
@@ -535,7 +535,7 @@ describe("ConfigNormalize", () => {
535535
portable_shell_scanner: true,
536536
todo: true,
537537
subagent_depth: 0,
538-
location_idle_timeout: "7200000 millis",
538+
location_idle_timeout: 7_200_000,
539539
},
540540
policies: [
541541
{ action: "provider.use", resource: "*", effect: "deny" },

‎packages/core/test/location-activity.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { ConfigExperimental } from "@opencode/schema/config/experimental"
2828
import { testEffect } from "./lib/effect"
2929

3030
// Per-workspace experimental.location_idle_timeout, read by each location's Config.
31-
const idleTimeouts = new Map<string, Duration.Duration | false>()
31+
const idleTimeouts = new Map<string, number | false>()
3232

3333
// Keep real execution ownership, location caching, forms, and eviction. The fixture
3434
// runner waits on a form instead of making a model request before asking a question.
@@ -262,14 +262,14 @@ describe("LocationActivity eviction", () => {
262262
)
263263

264264
for (const [timeout, after, evicted] of [
265-
["10 minutes", "11 minutes", true],
265+
[600_000, "11 minutes", true],
266266
[false, "3 hours", false],
267267
] as const)
268268
it.effect(`honors experimental.location_idle_timeout = ${JSON.stringify(timeout)}`, () =>
269269
Effect.gen(function* () {
270270
const map = yield* LocationServiceMap.Service
271-
const workspaceID = Workspace.ID.make(`wrk_timeout_${String(timeout).replace(" ", "_")}`)
272-
idleTimeouts.set(workspaceID, timeout === false ? false : Duration.fromInputUnsafe(timeout))
271+
const workspaceID = Workspace.ID.make(`wrk_timeout_${timeout}`)
272+
idleTimeouts.set(workspaceID, timeout)
273273
yield* Effect.addFinalizer(() => Effect.sync(() => idleTimeouts.delete(workspaceID)))
274274
const configured = Location.Ref.make({ directory: AbsolutePath.make("/project"), workspaceID })
275275
const fallback = Location.Ref.make({ directory: AbsolutePath.make("/project") })

‎packages/protocol/openapi.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14327,7 +14327,8 @@
1432714327
"location_idle_timeout": {
1432814328
"anyOf": [
1432914329
{
14330-
"type": "string"
14330+
"type": "integer",
14331+
"exclusiveMinimum": 0
1433114332
},
1433214333
{
1433314334
"type": "boolean",

‎packages/schema/src/config/experimental.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export * as ConfigExperimental from "./experimental.js"
22

33
import { Schema } from "effect"
4-
import { NonNegativeInt, optional } from "../schema.js"
4+
import { NonNegativeInt, PositiveInt, optional } from "../schema.js"
55
import { ConfigPolicy } from "./policy.js"
66

77
export class Info extends Schema.Class<Info>("ConfigExperimental.Info")({
@@ -14,11 +14,11 @@ export class Info extends Schema.Class<Info>("ConfigExperimental.Info")({
1414
subagent_depth: NonNegativeInt.pipe(optional).annotate({
1515
description: "Maximum subagent nesting depth. Defaults to 1.",
1616
}),
17-
location_idle_timeout: Schema.Union([Schema.DurationFromString, Schema.Literal(false)])
17+
location_idle_timeout: Schema.Union([PositiveInt, Schema.Literal(false)])
1818
.pipe(optional)
1919
.annotate({
2020
description:
21-
'How long a location can go without session activity before its services are unloaded. Running sessions and background jobs keep a location loaded. Set to false to never unload (default: "60 minutes")',
21+
"Milliseconds a location can go without session activity before its services are unloaded. Running sessions and background jobs keep a location loaded. Set to false to never unload. Defaults to 3600000 (60 minutes).",
2222
}),
2323
policies: ConfigPolicy.Info.pipe(Schema.Array, optional).annotate({
2424
description: "Deprecated: use top-level policies. Ordered policies controlling access to configured resources",

‎services/www/openapi.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14327,7 +14327,8 @@
1432714327
"location_idle_timeout": {
1432814328
"anyOf": [
1432914329
{
14330-
"type": "string"
14330+
"type": "integer",
14331+
"exclusiveMinimum": 0
1433114332
},
1433214333
{
1433314334
"type": "boolean",

‎services/www/public/openapi.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14327,7 +14327,8 @@
1432714327
"location_idle_timeout": {
1432814328
"anyOf": [
1432914329
{
14330-
"type": "string"
14330+
"type": "integer",
14331+
"exclusiveMinimum": 0
1433114332
},
1433214333
{
1433314334
"type": "boolean",

‎services/www/src/docs/content/config.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ All experimental settings live under the `experimental` key:
626626
"todo": true,
627627
"subagent_depth": 2,
628628
"portable_shell_scanner": true,
629-
"location_idle_timeout": "4 hours",
629+
"location_idle_timeout": 14400000,
630630
},
631631
}
632632
```
@@ -648,8 +648,8 @@ Defaults to `false`. See [Permissions](/permissions#scanner) for how it behaves.
648648
### Location idle timeout
649649

650650
`location_idle_timeout` controls how long a project location can go without session activity before OpenCode unloads
651-
its services. It takes a duration such as `"2 hours"` and defaults to `"60 minutes"`. Running sessions and background
652-
jobs keep a location loaded. Set it to `false` to never unload idle locations. Project config can override the global
651+
its services. The value is in milliseconds and defaults to `3600000` (60 minutes). Running sessions and background jobs
652+
keep a location loaded. Set it to `false` to never unload idle locations. Project config can override the global
653653
value.
654654

655655
### Deprecated policies

0 commit comments

Comments
 (0)