Skip to content

Commit 748c611

Browse files
committed
fix(core): resolve V2 session runner test failures after upstream sync
- gate get_tool_schema meta-tool on deferred tool presence in registry - fix missing yield* in llm.ts publish settlement fiber - add spawn_agent to location-layer builtin test expectations - fix compaction select head duplication when splitPrefix is present - adjust session-runner compaction test thresholds for L4/L5 levels - remove leftover debug appendFileSync calls
1 parent 5713694 commit 748c611

5 files changed

Lines changed: 29 additions & 21 deletions

File tree

packages/core/src/session/compaction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ const select = (
180180
split = index
181181
}
182182
return {
183-
head: [...conversation.slice(0, split), splitPrefix].filter(Boolean).join("\n\n"),
183+
head: [...conversation.slice(0, splitPrefix ? split - 1 : split), splitPrefix].filter(Boolean).join("\n\n"),
184184
recent: [splitSuffix, ...conversation.slice(split)].filter(Boolean).join("\n\n"),
185185
}
186186
}
@@ -281,6 +281,7 @@ export const make = (dependencies: Dependencies) => {
281281
const usedTokens = estimate({ system: input.request.system, messages: input.request.messages, tools: input.request.tools })
282282
const usageRatio = usedTokens / context
283283
const level = ContextLevels.computeLevel(usageRatio, config.levels)
284+
284285
if (level <= 1) return { compacted: false, request: input.request }
285286
// L2 — Snip Compact: drop oldest messages (in-memory only, no durable event)
286287
if (level === 2) {

packages/core/src/session/runner/llm.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ const layer = Layer.effect(
296296
toolChoice: isLastStep ? "none" : undefined,
297297
generation: maxTokensOverride === undefined ? undefined : { maxTokens: maxTokensOverride },
298298
})
299+
299300
const degradation = yield* compaction.degrade({ sessionID: session.id, entries, model, request })
300301
const activeRequest = degradation.request
301302
if (degradation.compacted)
@@ -358,7 +359,7 @@ const layer = Layer.effect(
358359
Effect.gen(function* () {
359360
const preResult = yield* hooks.runPreToolUse({ name: event.name, input: event.input })
360361
if (preResult.action === "deny") {
361-
return publish(
362+
return yield* publish(
362363
LLMEvent.toolResult({
363364
id: event.id,
364365
name: event.name,
@@ -367,7 +368,7 @@ const layer = Layer.effect(
367368
)
368369
}
369370
if (preResult.action === "skip") {
370-
return publish(
371+
return yield* publish(
371372
LLMEvent.toolResult({
372373
id: event.id,
373374
name: event.name,
@@ -401,7 +402,7 @@ const layer = Layer.effect(
401402
postResult.action === "continue" && "additionalContext" in postResult && postResult.additionalContext
402403
? appendContextNote(settlement.result, postResult.additionalContext)
403404
: settlement.result
404-
return publish(
405+
return yield* publish(
405406
LLMEvent.toolResult({
406407
id: event.id,
407408
name: event.name,

packages/core/src/tool/registry.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ const registryLayer = Layer.effect(
170170
const activated = yield* Ref.get(activatedToolsRef)
171171
const touched = yield* Ref.get(touchedPathsRef)
172172
const defs: Array<ToolDefinition> = []
173+
let hasDeferred = false
173174
for (const [name, registration] of registrations) {
174175
const tool = registration.tool
175176
const deferred = isDeferred(tool)
@@ -185,6 +186,7 @@ const registryLayer = Layer.effect(
185186
if (!shouldActivate) continue
186187
}
187188
if (deferred && !activated.has(name)) {
189+
hasDeferred = true
188190
const fullDef = definition(name, tool)
189191
defs.push(
190192
new ToolDefinition({
@@ -197,20 +199,22 @@ const registryLayer = Layer.effect(
197199
}
198200
defs.push(definition(name, tool))
199201
}
200-
defs.push(
201-
new ToolDefinition({
202-
name: GET_TOOL_SCHEMA,
203-
description:
204-
'Get the full schema (including input/output parameters) for a deferred tool. Input: { "tool_name": "<name>" }',
205-
inputSchema: {
206-
type: "object",
207-
properties: {
208-
tool_name: { type: "string", description: "Name of the tool to get the full schema for" },
202+
if (hasDeferred) {
203+
defs.push(
204+
new ToolDefinition({
205+
name: GET_TOOL_SCHEMA,
206+
description:
207+
'Get the full schema (including input/output parameters) for a deferred tool. Input: { "tool_name": "<name>" }',
208+
inputSchema: {
209+
type: "object",
210+
properties: {
211+
tool_name: { type: "string", description: "Name of the tool to get the full schema for" },
212+
},
213+
required: ["tool_name"],
209214
},
210-
required: ["tool_name"],
211-
},
212-
}),
213-
)
215+
}),
216+
)
217+
}
214218
return {
215219
definitions: defs,
216220
settle: (input) => {

packages/core/test/location-layer.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ describe("LocationServiceMap", () => {
114114
"question",
115115
"read",
116116
"skill",
117+
"spawn_agent",
117118
"todowrite",
118119
"webfetch",
119120
"websearch",
@@ -132,6 +133,7 @@ describe("LocationServiceMap", () => {
132133
"question",
133134
"read",
134135
"skill",
136+
"spawn_agent",
135137
"todowrite",
136138
"webfetch",
137139
"websearch",

packages/core/test/session-runner.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const replacementModel = Model.make({ id: "replacement", provider: "fake", route
101101
const compactModel = Model.make({
102102
id: "compact",
103103
provider: "fake",
104-
route: OpenAIChat.route.with({ limits: { context: 4_000, output: 50 } }),
104+
route: OpenAIChat.route.with({ limits: { context: 2_300, output: 50 } }),
105105
})
106106
const recoveryModel = Model.make({
107107
id: "recovery",
@@ -1090,7 +1090,7 @@ describe("SessionRunnerLLM", () => {
10901090
response = fragmentFixture("text", "text-first", ["Earlier answer"]).completeEvents
10911091
yield* session.prompt({
10921092
sessionID,
1093-
prompt: Prompt.make({ text: "Earlier question ".repeat(180) }),
1093+
prompt: Prompt.make({ text: "Earlier question ".repeat(188) }),
10941094
resume: false,
10951095
})
10961096
yield* session.resume(sessionID)
@@ -1103,7 +1103,7 @@ describe("SessionRunnerLLM", () => {
11031103
]
11041104
yield* session.prompt({
11051105
sessionID,
1106-
prompt: Prompt.make({ text: "Recent exact request ".repeat(180) }),
1106+
prompt: Prompt.make({ text: "Recent exact request ".repeat(188) }),
11071107
resume: false,
11081108
})
11091109
yield* session.resume(sessionID)
@@ -1129,7 +1129,7 @@ describe("SessionRunnerLLM", () => {
11291129
]
11301130
yield* session.prompt({
11311131
sessionID,
1132-
prompt: Prompt.make({ text: "Newest exact request ".repeat(180) }),
1132+
prompt: Prompt.make({ text: "Newest exact request ".repeat(188) }),
11331133
resume: false,
11341134
})
11351135
yield* session.resume(sessionID)

0 commit comments

Comments
 (0)