Skip to content

Return clone-safe persona spawn payloads#136

Merged
kjgbot merged 2 commits into
mainfrom
fix/persona-spawn-clone-payload
Jun 7, 2026
Merged

Return clone-safe persona spawn payloads#136
kjgbot merged 2 commits into
mainfrom
fix/persona-spawn-clone-payload

Conversation

@kjgbot
Copy link
Copy Markdown
Contributor

@kjgbot kjgbot commented Jun 6, 2026

Summary

  • Normalize broker spawn results to the IPC contract fields only: name, runtime, and optional cli
  • Strip non-cloneable SDK/client fields before returning from spawnAgent or spawnPersona
  • Add a workforce persona regression with a non-cloneable spawnPty result

Tests

  • npx vitest run src/main/broker.test.ts
  • npm run build

@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@codeant-ai
Copy link
Copy Markdown

codeant-ai Bot commented Jun 6, 2026

Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 6, 2026

Review Change Stack

Warning

Review limit reached

@kjgbot, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 10 minutes and 49 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b8c040c5-d8ee-4535-afe4-153ed34d784a

📥 Commits

Reviewing files that changed from the base of the PR and between 8224de3 and a0eb70e.

📒 Files selected for processing (2)
  • src/main/broker.test.ts
  • src/main/broker.ts
📝 Walkthrough

Walkthrough

The PR introduces a shared BrokerSpawnResult type and normalizeSpawnPtyResult() helper function to standardize spawn response handling across broker APIs. Both spawnAgent()/spawnAgentOnce() and spawnPersona()/spawnPersonaWithMode() are updated to use the normalization helper and return the unified contract, with a new test verifying clone-safety.

Changes

Unified broker spawn result normalization

Layer / File(s) Summary
Spawn result type and normalization helper
src/main/broker.ts
BrokerSpawnResult type and normalizeSpawnPtyResult() helper extract or derive name and runtime from spawn results with fallbacks, and optionally resolve cli from an explicit parameter or record field.
Agent spawning API updates
src/main/broker.ts
spawnAgent() and spawnAgentOnce() return Promise<BrokerSpawnResult> and use normalizeSpawnPtyResult() to standardize agent spawn responses for consistent session bookkeeping and return shapes.
Persona spawning API updates
src/main/broker.ts
spawnPersona() and spawnPersonaWithMode() return Promise<BrokerSpawnResult> and use normalizeSpawnPtyResult() with harness-derived cli to standardize persona spawn responses.
Spawn result clone-safety test
src/main/broker.test.ts
Verifies spawnPersona() returns a structured-clone-safe payload with only name, runtime, and cli fields and succeeds with structuredClone().

🎯 2 (Simple) | ⏱️ ~12 minutes

🐰 A broker once spawned replies with inconsistent care,
'Til normalize came to the rescue there!
Now agents and personas clone without fear—
Safe, sound, and structured, the result's crystal clear! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. 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 'Return clone-safe persona spawn payloads' directly and clearly describes the main change: normalizing spawn results to return only cloneable fields.
Description check ✅ Passed The description clearly explains the changes: normalizing broker spawn results, stripping non-cloneable fields, and adding a regression test for non-cloneable results.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/persona-spawn-clone-payload

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

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

@agent-relay-code
Copy link
Copy Markdown
Contributor

Reviewed PR #136 against .workforce/pr.diff, changed files, and current callers.

I found no validated breakage to fix. The sanitized spawn result matches the shared IPC contract, and current callers only depend on name, runtime, and persona cli.

Verification run:

  • npm install
  • npm run build
  • npm test
  • npx vitest run src/main/broker.test.ts

Copy link
Copy Markdown

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

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

@agent-relay-code
Copy link
Copy Markdown
Contributor

ℹ️ pr-reviewer: review only — no file changes were applied to the PR (nothing to commit after review). The notes below are advisory and were not pushed.

Reviewed PR #136 against .workforce/pr.diff, changed files, and current callers.

I found no validated breakage to fix. The sanitized spawn result matches the shared IPC contract, and current callers only depend on name, runtime, and persona cli.

Verification run:

  • npm install
  • npm run build
  • npm test
  • npx vitest run src/main/broker.test.ts

@kjgbot kjgbot force-pushed the fix/persona-spawn-clone-payload branch from 25dd845 to 8224de3 Compare June 6, 2026 20:31
@codeant-ai
Copy link
Copy Markdown

codeant-ai Bot commented Jun 6, 2026

Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI.

@agent-relay-code
Copy link
Copy Markdown
Contributor

ℹ️ pr-reviewer: review only — no file changes were applied to the PR (nothing to commit after review). The notes below are advisory and were not pushed.

Reviewed PR #136 against the diff, changed files, current callers, IPC types, tests, and bot comments.

No validated breakage found, so I made no file edits. The spawn result normalization matches the IPC contract and renderer usage.

Local validation passed:

  • npm ci
  • npm run verify:mcp-resources-drift
  • npx vitest run src/main/broker.test.ts
  • npm test
  • npm run build

GitHub state observed:

  • PR is mergeable.
  • GitHub Actions jobs completed successfully.
  • CodeRabbit commit status is still pending, so I’m not printing READY.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/main/broker.test.ts (1)

587-614: 💤 Low value

Consider using afterEach for temp directory cleanup.

The test uses a finally block for cleanup, which is acceptable, but other test suites in this file use a suite-level tempDir variable with afterEach cleanup (see lines 227-252, 1079-1082) for more robust handling of test timeouts and cancellations.

♻️ More robust cleanup pattern

Declare tempDir at the suite level and clean up in afterEach:

 describe('BrokerManager local + cloud coexistence', () => {
+  let personaTempDir: string | null = null
+
   beforeEach(() => {
     mock.state.spawnedClients.length = 0
     ...
   })

+  afterEach(async () => {
+    if (personaTempDir) await rm(personaTempDir, { recursive: true, force: true })
+    personaTempDir = null
+  })

   it('returns a clone-safe payload when spawning a workforce persona', async () => {
-    const tempDir = await mkdtemp(join(tmpdir(), 'pear-persona-spawn-'))
+    personaTempDir = await mkdtemp(join(tmpdir(), 'pear-persona-spawn-'))
+    const tempDir = personaTempDir
     ...
-    try {
       ...
-    } finally {
-      await rm(tempDir, { recursive: true, force: true })
-    }
   })
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/broker.test.ts` around lines 587 - 614, The test currently creates
tempDir locally and cleans it in a finally block; change it to declare tempDir
at the suite level and move the cleanup into an afterEach hook to ensure
deletion even if tests time out or get cancelled—declare the tempDir variable
alongside other suite-scoped fixtures, assign it before each test that uses it
(the code that calls manager.start(PROJECT_ID, tempDir, ...)), and replace the
try/finally rm(tempDir...) with a single afterEach that calls rm(tempDir, {
recursive: true, force: true }); keep the rest of the test logic (instantiating
BrokerManager, calling manager.start and manager.spawnPersona) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/broker.test.ts`:
- Around line 568-615: Add a duplicate/replay concurrency test for persona
spawns similar to the existing spawnAgent duplicate test: create a new it(...)
case that uses BrokerManager and the same temp agentworkforce binary setup, then
call manager.spawnPersona(PROJECT_ID, 'autonomous-actor') twice (concurrently or
nearly concurrently) and assert both calls resolve to the same persona result
and that only one underlying spawn was performed (inspect lastSpawned() or
local.spawnPty call count); ensure the test also checks clone-safety
(structuredClone) and cleans up via manager.shutdown() and rm(tempDir).
- Around line 570-585: The test writes a Unix-style JS with shebang into both
agentworkforce and agentworkforce.cmd causing Windows to treat the .cmd as a
batch file and fail; modify the test to create two files: keep the current
shebang JS content in agentworkforce (executable for POSIX) and write a real
Windows wrapper for agentworkforce.cmd that invokes node pointing at a separate
JS file (the same logic as the shebang JS but saved as e.g., agentworkforce.js);
ensure resolveAgentWorkforceCommand()/canExecute() will pick up the .cmd and
execFileSync(command.cli, ...) will run node with the JS file so
runAgentWorkforceJson()/findWorkforcePersona()/spawnPersona() work on Windows.

---

Nitpick comments:
In `@src/main/broker.test.ts`:
- Around line 587-614: The test currently creates tempDir locally and cleans it
in a finally block; change it to declare tempDir at the suite level and move the
cleanup into an afterEach hook to ensure deletion even if tests time out or get
cancelled—declare the tempDir variable alongside other suite-scoped fixtures,
assign it before each test that uses it (the code that calls
manager.start(PROJECT_ID, tempDir, ...)), and replace the try/finally
rm(tempDir...) with a single afterEach that calls rm(tempDir, { recursive: true,
force: true }); keep the rest of the test logic (instantiating BrokerManager,
calling manager.start and manager.spawnPersona) unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2e739536-8a69-4637-8565-0bc7a339b5c7

📥 Commits

Reviewing files that changed from the base of the PR and between 89eec3a and 8224de3.

📒 Files selected for processing (2)
  • src/main/broker.test.ts
  • src/main/broker.ts

Comment thread src/main/broker.test.ts
Comment thread src/main/broker.test.ts Outdated
@codeant-ai
Copy link
Copy Markdown

codeant-ai Bot commented Jun 7, 2026

Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI.

@kjgbot kjgbot merged commit 6e66172 into main Jun 7, 2026
4 checks passed
@kjgbot kjgbot deleted the fix/persona-spawn-clone-payload branch June 7, 2026 06:57
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.

1 participant