Skip to content

Harden scoped cleanup for agent timeout, observer listeners, and composition runners#113

Open
danielbdyer wants to merge 1 commit into
mainfrom
codex/audit-lifecycle-edges-for-agent-sessions
Open

Harden scoped cleanup for agent timeout, observer listeners, and composition runners#113
danielbdyer wants to merge 1 commit into
mainfrom
codex/audit-lifecycle-edges-for-agent-sessions

Conversation

@danielbdyer
Copy link
Copy Markdown
Owner

Motivation

  • Ensure agent LLM calls, Playwright page listeners, and composition-level resources are reliably finalized under interruption/timeouts by using Effect scoped lifecycle primitives.
  • Replace ad-hoc promise cancellation and loose listener registration with structured Effect.acquireRelease / Effect.scoped so fibers and resources are not leaked during timeouts or cancellations.
  • Normalize the agent timeout semantics so timeouts and interpretation cancellation share the same scoped-fiber cancellation model instead of racing raw promises.

Description

  • Reworked agent timeout wiring: withAgentTimeout now invokes withAgentTimeoutEffect inside Effect.scoped, and withAgentTimeoutEffect races a scoped interpretation fiber against a timeout using Effect.forkScoped, Fiber.join, and Effect.raceFirst to return the deterministic fallback on timeout (lib/application/agent-interpreter-provider.ts).
  • Wrapped Playwright screen observation in Effect.scoped and registered the page close listener with Effect.acquireRelease so the listener is always removed on scope exit and observations fail-fast if the page is already closed (lib/infrastructure/observation/playwright-screen-observer.ts).
  • Scoped composition boundaries by running the runtime scenario runner body under Effect.scoped and returning a scoped provide in the local services composition so downstream scoped resources are finalized reliably (lib/composition/local-runtime-scenario-runner.ts, lib/composition/local-services.ts).
  • Minor imports/shape adjustments to support Fiber/scoped forks and to preserve existing fallback behavior on errors or timeouts (lib/application/agent-interpreter-provider.ts).

Testing

  • Ran the focused lifecycle stress tests with Playwright: npm test -- tests/agent-resource-lifecycle.spec.ts and all tests in that file passed (4/4) after the changes.
  • Ran npm run typecheck which reported pre-existing unrelated diagnostics in other modules, so typecheck did not pass end-to-end; the failures are unrelated to the lifecycle changes.
  • Verified the repository diff includes only the intended files: lib/application/agent-interpreter-provider.ts, lib/infrastructure/observation/playwright-screen-observer.ts, lib/composition/local-runtime-scenario-runner.ts, and lib/composition/local-services.ts.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant