fix(background-agent): redact archived prompts and cap fallback archive
Store only sanitized completed-task snapshots in archive to avoid retaining sensitive prompts after cleanup. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -6014,7 +6014,41 @@ describe("BackgroundManager regression fixes - resume and aborted notification",
|
||||
|
||||
//#then
|
||||
expect(getTaskMap(manager).has(task.id)).toBe(false)
|
||||
expect(manager.getTask(task.id)?.sessionId).toBe(task.sessionId)
|
||||
const archivedTask = manager.getTask(task.id)
|
||||
expect(archivedTask?.sessionId).toBe(task.sessionId)
|
||||
expect(archivedTask?.prompt).toBe("[redacted]")
|
||||
|
||||
manager.shutdown()
|
||||
})
|
||||
|
||||
test("should cap completed task archive size at 100 entries", () => {
|
||||
//#given
|
||||
const manager = createBackgroundManager()
|
||||
|
||||
//#when
|
||||
for (let index = 0; index < 120; index += 1) {
|
||||
const task: BackgroundTask = {
|
||||
id: `task-archive-${index}`,
|
||||
sessionId: `session-archive-${index}`,
|
||||
parentSessionId: "parent-session",
|
||||
parentMessageId: "msg-1",
|
||||
description: "archive cap regression",
|
||||
prompt: `sensitive-${index}`,
|
||||
agent: "explore",
|
||||
status: "completed",
|
||||
startedAt: new Date(),
|
||||
completedAt: new Date(),
|
||||
}
|
||||
;(cast<{ removeTask: (task: BackgroundTask) => void }>(manager)).removeTask(task)
|
||||
}
|
||||
|
||||
//#then
|
||||
const archive = cast<Map<string, unknown>>(Reflect.get(manager, "completedTaskArchive"))
|
||||
expect(archive.size).toBe(100)
|
||||
expect(archive.has("task-archive-0")).toBe(false)
|
||||
expect(archive.has("task-archive-19")).toBe(false)
|
||||
expect(archive.has("task-archive-20")).toBe(true)
|
||||
expect(archive.has("task-archive-119")).toBe(true)
|
||||
|
||||
manager.shutdown()
|
||||
})
|
||||
|
||||
@@ -188,7 +188,7 @@ export interface SubagentSessionCreatedEvent {
|
||||
export type OnSubagentSessionCreated = (event: SubagentSessionCreatedEvent) => Promise<void>
|
||||
|
||||
const MAX_TASK_REMOVAL_RESCHEDULES = 6
|
||||
const MAX_COMPLETED_TASK_ARCHIVE_SIZE = 500
|
||||
const MAX_COMPLETED_TASK_ARCHIVE_SIZE = 100
|
||||
|
||||
export interface BackgroundManagerConfig {
|
||||
pluginContext: PluginInput
|
||||
@@ -374,7 +374,22 @@ export class BackgroundManager {
|
||||
return
|
||||
}
|
||||
|
||||
this.completedTaskArchive.set(task.id, task)
|
||||
const archivedTask: BackgroundTask = {
|
||||
id: task.id,
|
||||
parentSessionId: task.parentSessionId,
|
||||
parentMessageId: task.parentMessageId,
|
||||
description: task.description,
|
||||
prompt: "[redacted]",
|
||||
agent: task.agent,
|
||||
sessionId: task.sessionId,
|
||||
status: task.status,
|
||||
completedAt: task.completedAt,
|
||||
model: task.model,
|
||||
error: task.error,
|
||||
category: task.category,
|
||||
}
|
||||
|
||||
this.completedTaskArchive.set(task.id, archivedTask)
|
||||
if (this.completedTaskArchive.size <= MAX_COMPLETED_TASK_ARCHIVE_SIZE) {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user