fix(bash): memory leak - release parsed syntax trees (#24861)
Co-authored-by: jiwenshang <jiwenshang@xiaohongshu.com>
This commit is contained in:
parent
ae8904c4ff
commit
d4bf70be06
1 changed files with 12 additions and 5 deletions
|
|
@ -252,7 +252,7 @@ function tail(text: string, maxLines: number, maxBytes: number) {
|
||||||
const parse = Effect.fn("BashTool.parse")(function* (command: string, ps: boolean) {
|
const parse = Effect.fn("BashTool.parse")(function* (command: string, ps: boolean) {
|
||||||
const tree = yield* Effect.promise(() => parser().then((p) => (ps ? p.ps : p.bash).parse(command)))
|
const tree = yield* Effect.promise(() => parser().then((p) => (ps ? p.ps : p.bash).parse(command)))
|
||||||
if (!tree) throw new Error("Failed to parse command")
|
if (!tree) throw new Error("Failed to parse command")
|
||||||
return tree.rootNode
|
return tree
|
||||||
})
|
})
|
||||||
|
|
||||||
const ask = Effect.fn("BashTool.ask")(function* (ctx: Tool.Context, scan: Scan) {
|
const ask = Effect.fn("BashTool.ask")(function* (ctx: Tool.Context, scan: Scan) {
|
||||||
|
|
@ -596,10 +596,17 @@ export const BashTool = Tool.define(
|
||||||
}
|
}
|
||||||
const timeout = params.timeout ?? DEFAULT_TIMEOUT
|
const timeout = params.timeout ?? DEFAULT_TIMEOUT
|
||||||
const ps = Shell.ps(shell)
|
const ps = Shell.ps(shell)
|
||||||
const root = yield* parse(params.command, ps)
|
yield* Effect.scoped(
|
||||||
const scan = yield* collect(root, cwd, ps, shell)
|
Effect.gen(function* () {
|
||||||
if (!Instance.containsPath(cwd)) scan.dirs.add(cwd)
|
const tree = yield* Effect.acquireRelease(
|
||||||
yield* ask(ctx, scan)
|
parse(params.command, ps),
|
||||||
|
(tree) => Effect.sync(() => tree.delete()),
|
||||||
|
)
|
||||||
|
const scan = yield* collect(tree.rootNode, cwd, ps, shell)
|
||||||
|
if (!Instance.containsPath(cwd)) scan.dirs.add(cwd)
|
||||||
|
yield* ask(ctx, scan)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
return yield* run(
|
return yield* run(
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue