fix(background-agent): inherit parent session directory for background tasks
Background tasks were defaulting to $HOME instead of the parent session's working directory. This caused background agents to scan the entire home directory instead of the project directory, leading to: - High CPU/memory load from scanning unrelated files - Permission errors on system directories - Task failures and timeouts The fix retrieves the parent session's directory before creating a new background session and passes it via the query.directory parameter. Files modified: - manager.ts: Look up parent session directory in launch() - call-omo-agent/tools.ts: Same fix for sync mode - look-at/tools.ts: Same fix for look_at tool - sisyphus-task/tools.ts: Same fix + interface update for directory prop - index.ts: Pass directory to sisyphusTask factory
This commit is contained in:
@@ -75,11 +75,23 @@ export class BackgroundManager {
|
||||
|
||||
await this.concurrencyManager.acquire(concurrencyKey)
|
||||
|
||||
const parentSession = await this.client.session.get({
|
||||
path: { id: input.parentSessionID },
|
||||
}).catch((err) => {
|
||||
log(`[background-agent] Failed to get parent session: ${err}`)
|
||||
return null
|
||||
})
|
||||
const parentDirectory = parentSession?.data?.directory ?? this.directory
|
||||
log(`[background-agent] Parent dir: ${parentSession?.data?.directory}, using: ${parentDirectory}`)
|
||||
|
||||
const createResult = await this.client.session.create({
|
||||
body: {
|
||||
parentID: input.parentSessionID,
|
||||
title: `Background: ${input.description}`,
|
||||
},
|
||||
query: {
|
||||
directory: parentDirectory,
|
||||
},
|
||||
}).catch((error) => {
|
||||
this.concurrencyManager.release(concurrencyKey)
|
||||
throw error
|
||||
|
||||
@@ -238,6 +238,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
|
||||
const sisyphusTask = createSisyphusTask({
|
||||
manager: backgroundManager,
|
||||
client: ctx.client,
|
||||
directory: ctx.directory,
|
||||
userCategories: pluginConfig.categories,
|
||||
gitMasterConfig: pluginConfig.git_master,
|
||||
});
|
||||
|
||||
@@ -145,11 +145,23 @@ async function executeSync(
|
||||
sessionID = args.session_id
|
||||
} else {
|
||||
log(`[call_omo_agent] Creating new session with parent: ${toolContext.sessionID}`)
|
||||
const parentSession = await ctx.client.session.get({
|
||||
path: { id: toolContext.sessionID },
|
||||
}).catch((err) => {
|
||||
log(`[call_omo_agent] Failed to get parent session:`, err)
|
||||
return null
|
||||
})
|
||||
log(`[call_omo_agent] Parent session dir: ${parentSession?.data?.directory}, fallback: ${ctx.directory}`)
|
||||
const parentDirectory = parentSession?.data?.directory ?? ctx.directory
|
||||
|
||||
const createResult = await ctx.client.session.create({
|
||||
body: {
|
||||
parentID: toolContext.sessionID,
|
||||
title: `${args.description} (@${args.subagent_type} subagent)`,
|
||||
},
|
||||
query: {
|
||||
directory: parentDirectory,
|
||||
},
|
||||
})
|
||||
|
||||
if (createResult.error) {
|
||||
|
||||
@@ -65,11 +65,19 @@ Be thorough on what was requested, concise on everything else.
|
||||
If the requested information is not found, clearly state what is missing.`
|
||||
|
||||
log(`[look_at] Creating session with parent: ${toolContext.sessionID}`)
|
||||
const parentSession = await ctx.client.session.get({
|
||||
path: { id: toolContext.sessionID },
|
||||
}).catch(() => null)
|
||||
const parentDirectory = parentSession?.data?.directory ?? ctx.directory
|
||||
|
||||
const createResult = await ctx.client.session.create({
|
||||
body: {
|
||||
parentID: toolContext.sessionID,
|
||||
title: `look_at: ${args.goal.substring(0, 50)}`,
|
||||
},
|
||||
query: {
|
||||
directory: parentDirectory,
|
||||
},
|
||||
})
|
||||
|
||||
if (createResult.error) {
|
||||
|
||||
@@ -89,6 +89,7 @@ function resolveCategoryConfig(
|
||||
export interface SisyphusTaskToolOptions {
|
||||
manager: BackgroundManager
|
||||
client: OpencodeClient
|
||||
directory: string
|
||||
userCategories?: CategoriesConfig
|
||||
gitMasterConfig?: GitMasterConfig
|
||||
}
|
||||
@@ -113,7 +114,7 @@ export function buildSystemContent(input: BuildSystemContentInput): string | und
|
||||
}
|
||||
|
||||
export function createSisyphusTask(options: SisyphusTaskToolOptions): ToolDefinition {
|
||||
const { manager, client, userCategories, gitMasterConfig } = options
|
||||
const { manager, client, directory, userCategories, gitMasterConfig } = options
|
||||
|
||||
return tool({
|
||||
description: SISYPHUS_TASK_DESCRIPTION,
|
||||
@@ -400,11 +401,19 @@ System notifies on completion. Use \`background_output\` with task_id="${task.id
|
||||
let syncSessionID: string | undefined
|
||||
|
||||
try {
|
||||
const parentSession = await client.session.get({
|
||||
path: { id: ctx.sessionID },
|
||||
}).catch(() => null)
|
||||
const parentDirectory = parentSession?.data?.directory ?? directory
|
||||
|
||||
const createResult = await client.session.create({
|
||||
body: {
|
||||
parentID: ctx.sessionID,
|
||||
title: `Task: ${args.description}`,
|
||||
},
|
||||
query: {
|
||||
directory: parentDirectory,
|
||||
},
|
||||
})
|
||||
|
||||
if (createResult.error) {
|
||||
|
||||
Reference in New Issue
Block a user