Skip to content

fix(local-surface): expose prepared persona execution ownership - #339

Merged
khaliqgant merged 2 commits into
mainfrom
codex/persona-execution-lifecycle
Sep 13, 2026
Merged

fix(local-surface): expose prepared persona execution ownership#339
khaliqgant merged 2 commits into
mainfrom
codex/persona-execution-lifecycle

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Sep 13, 2026

Copy link
Copy Markdown
Member

A host serving spawn:persona cannot retain the executor's actual handle before delegation or dispose a successful persona mount through the factory's public API. Add an optional, awaited onExecutionPrepared(name, execution) callback exposing that handle and its scratch directory before a worker can start.

The callback runs once for coalesced requests. Rejection prevents delegation and triggers factory cleanup. Following a successful spawn, the documented host contract is to release and verify the specific worker first, then dispose the retained handle and remove its scratch directory. Failure cleanup now attempts scratch removal even if disposal throws. Export the receipt type as WorkforcePersonaExecution.

Validation under native Node v22.22.1:

  • pnpm --filter @agentworkforce/local-surface... run build passed.
  • pnpm --filter @agentworkforce/local-surface test passed: 19 tests, including async ownership ordering, coalescing, callback/delegation/disposal failures, and real executor mount cleanup after success.
  • The normal product build resolves a real OpenCode persona JSON. Product tsconfig already targets ES2022; no build configuration change is included.

Scope is limited to the local-surface callback, exported type, lifecycle documentation, and tests. This draft has no live fleet/provider acceptance claim.

Review in cubic


Note

Medium Risk
Changes persona spawn lifecycle and resource ownership for hosts that opt into the callback; optional API preserves default behavior but incorrect host cleanup could leak mounts or dispose too early.

Overview
Adds an optional onExecutionPrepared(name, execution) hook on defineWorkforcePersonaSpawnNode and workforcePersonaSpawnCapability so hosts can keep the real executor ExecutionHandle and factory scratchDir before the broker spawns a worker. The factory awaits this callback once per prepared launch (including coalesced duplicate requests); rejection skips delegation and triggers cleanup.

Exports WorkforcePersonaExecution for typing the receipt. Error paths now remove the scratch directory in a finally block even when handle.dispose() throws. README documents the host contract after success: release the worker first, then dispose the retained handle and delete scratchDir. Omitting the callback leaves prior successful-execution lifetime unchanged.

Tests cover delegation ordering vs. ownership, coalescing, failure cleanup (ownership, delegation, dispose), and real mount teardown after success.

Reviewed by Cursor Bugbot for commit a248dc1. Bugbot is set up for automated code reviews on this repo. Configure here.

Session-Id: 01a09aa7-26ec-7411-ae96-559372458f12
@coderabbitai

coderabbitai Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 06dea385-6e94-4f4c-9430-18d57d1ea1ad

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 28180124-6838-48ba-9c4a-2d6524123909

📥 Commits

Reviewing files that changed from the base of the PR and between 896dfec and 3e675f4.

📒 Files selected for processing (4)
  • packages/local-surface/README.md
  • packages/local-surface/src/index.ts
  • packages/local-surface/src/persona-spawn.test.ts
  • packages/local-surface/src/persona-spawn.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The local surface now exposes prepared persona execution resources and an optional ownership callback. The callback runs before broker delegation. Failure paths dispose resources and remove scratch directories. Tests and documentation cover ownership, cleanup, coalescing, and mounted project contents.

Changes

Prepared execution ownership

Layer / File(s) Summary
Execution contract and callback flow
packages/local-surface/src/persona-spawn.ts, packages/local-surface/src/index.ts
Adds WorkforcePersonaExecution, adds onExecutionPrepared, forwards the callback, and awaits it before broker delegation. Re-exports the new type.
Failure cleanup guarantees
packages/local-surface/src/persona-spawn.ts, packages/local-surface/src/persona-spawn.test.ts
Ensures scratch-directory removal runs even when execution disposal fails. Tests cover ownership, delegation, and disposal failures.
Success lifecycle validation and documentation
packages/local-surface/src/persona-spawn.test.ts, packages/local-surface/README.md
Tests coalesced launches, retained handles, mounted project contents, and host cleanup. Documentation describes the ownership lifecycle and failure behavior.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Host
  participant launchResolvedPersona
  participant PersonaExecutor
  participant Broker
  Host->>launchResolvedPersona: provide onExecutionPrepared
  launchResolvedPersona->>PersonaExecutor: prepare execution
  launchResolvedPersona->>Host: await callback with handle and scratchDir
  Host-->>launchResolvedPersona: retain execution ownership
  launchResolvedPersona->>Broker: delegate persona spawn
  Broker-->>Host: launched worker
  Host->>Broker: release launched worker
  Host->>PersonaExecutor: dispose handle
  Host->>PersonaExecutor: remove scratchDir
Loading

Merge Risk: ⚪ Minimal · up to 3e675

The new prepared-execution callback and cleanup lifecycle are documented and covered without an identified current-head regression, so the change is ready to merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: exposing ownership for prepared persona execution in local-surface.
Description check ✅ Passed The description directly explains the callback, execution ownership, cleanup behavior, exported type, tests, and scope of the changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/persona-execution-lifecycle

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit guards the handle bright,
The callback waits before the flight,
Scratch paths clear when failures start,
Tests protect each mounted part,
Coalesced launches hop as one,
Cleanup waits when work is done.

Comment @coderabbitai help to get the list of available commands.

@khaliqgant
khaliqgant marked this pull request as ready for review September 13, 2026 13:38
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-13T13:43:17.589331Z 3e675f4 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files

You’re at about 96% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/local-surface/README.md
Session-Id: 01a09aa7-26ec-7411-ae96-559372458f12
@khaliqgant
khaliqgant merged commit c5a30b6 into main Sep 13, 2026
5 checks passed
@khaliqgant
khaliqgant deleted the codex/persona-execution-lifecycle branch September 13, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants