-
Notifications
You must be signed in to change notification settings - Fork 0
Fleet placement requester: spawn an agent on any available node (#411) #414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3d2e8b0
feat(placement): wire the fleet placement requester side (#411)
khaliqgant f6c140b
test(placement): rung-1 cross-node gate + extract electron-free helpe…
khaliqgant 2fdecaa
feat(placement): spawn-dialog node picker + chat-first remote surface…
khaliqgant b968310
test(placement): rung-2 mini enrollment + from-Mac placement (#411)
khaliqgant 6baf646
test(placement): rung-2 cleanup verifies broker-side release + best-e…
khaliqgant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { describe, it, expect } from 'vitest' | ||
| import { RelayPlacementError, type RelayNode } from '@agent-relay/sdk' | ||
| import { | ||
| buildPlacementMessage, | ||
| placementRequesterName, | ||
| toBrokerNodeSummary | ||
| } from './placement' | ||
|
|
||
| function placementError(code: RelayPlacementError['code'], ctx: { capability?: string; node?: string; repo?: string } = {}): RelayPlacementError { | ||
| return new RelayPlacementError(code, `raw ${code}`, { | ||
| capability: ctx.capability ?? 'spawn:claude', | ||
| node: ctx.node, | ||
| repo: ctx.repo, | ||
| attempts: 1 | ||
| }) | ||
| } | ||
|
|
||
| describe('buildPlacementMessage', () => { | ||
| it('names the offending node and cli for capability_mismatch', () => { | ||
| const message = buildPlacementMessage(placementError('capability_mismatch', { node: 'gpu-box-1' })) | ||
| expect(message).toBe('Node "gpu-box-1" can\'t run claude.') | ||
| }) | ||
|
|
||
| it('falls back to a generic capability message when no node is named', () => { | ||
| const message = buildPlacementMessage(placementError('capability_mismatch')) | ||
| expect(message).toBe('No node can run claude.') | ||
| }) | ||
|
|
||
| it('reports queue saturation for placement_queue_full', () => { | ||
| expect(buildPlacementMessage(placementError('placement_queue_full'))).toMatch(/try again/i) | ||
| }) | ||
|
|
||
| it('reports no eligible node for placement_ttl_expired (never a hang)', () => { | ||
| expect(buildPlacementMessage(placementError('placement_ttl_expired'))).toBe( | ||
| 'No node advertises claude right now.' | ||
| ) | ||
| }) | ||
|
|
||
| it('names the repo for unmapped_repo', () => { | ||
| expect(buildPlacementMessage(placementError('unmapped_repo', { repo: 'pear' }))).toBe( | ||
| 'No node has repo "pear" checked out.' | ||
| ) | ||
| }) | ||
|
|
||
| it('strips the spawn: prefix from the capability in messages', () => { | ||
| const message = buildPlacementMessage(placementError('placement_ttl_expired', { capability: 'spawn:codex' })) | ||
| expect(message).toContain('codex') | ||
| expect(message).not.toContain('spawn:') | ||
| }) | ||
| }) | ||
|
|
||
| describe('placementRequesterName', () => { | ||
| it('derives a sanitized, workspace-safe requester identity per project', () => { | ||
| expect(placementRequesterName('project-1')).toBe('pear-requester-project-1') | ||
| }) | ||
|
|
||
| it('replaces path/space characters that a workspace name cannot carry', () => { | ||
| expect(placementRequesterName('a/b c:d')).toBe('pear-requester-a-b-c-d') | ||
| }) | ||
|
|
||
| it('never returns an empty name', () => { | ||
| expect(placementRequesterName('')).toBe('pear-requester') | ||
| }) | ||
| }) | ||
|
|
||
| describe('toBrokerNodeSummary', () => { | ||
| const baseNode: RelayNode = { | ||
| name: 'other-node', | ||
| status: 'online', | ||
| live: true, | ||
| load: 2, | ||
| activeAgents: 1, | ||
| maxAgents: 4, | ||
| capabilities: [{ name: 'spawn:claude' }, { name: 'spawn:codex' }], | ||
| repoKeys: ['pear'], | ||
| tags: ['pear', 'local'] | ||
| } as RelayNode | ||
|
|
||
| it('flattens capabilities and preserves liveness/load for the picker', () => { | ||
| const summary = toBrokerNodeSummary(baseNode, 'my-self-node') | ||
| expect(summary.capabilities).toEqual(['spawn:claude', 'spawn:codex']) | ||
| expect(summary.live).toBe(true) | ||
| expect(summary.load).toBe(2) | ||
| expect(summary.activeAgents).toBe(1) | ||
| expect(summary.isSelf).toBe(false) | ||
| }) | ||
|
|
||
| it('flags this machine when the node name matches the local fleet node', () => { | ||
| const summary = toBrokerNodeSummary({ ...baseNode, name: 'my-self-node' }, 'my-self-node') | ||
| expect(summary.isSelf).toBe(true) | ||
| }) | ||
|
|
||
| it('treats an absent live flag as offline', () => { | ||
| const summary = toBrokerNodeSummary({ ...baseNode, live: undefined }, 'my-self-node') | ||
| expect(summary.live).toBe(false) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If two
listNodes/placeAgentcalls arrive before the first cache fill—such as the doubled roster effect under the existing React StrictMode or calls from multiple windows—both pass this check and invokeregisterOrRotatefor the same identity. The second rotation invalidates the first token, so one caller can immediately issue its roster or placement request with a revoked token and fail intermittently. Cache a keyed in-flight promise and clear it safely with the session, as required by the repository's duplicate-event lifecycle guidance.Useful? React with 👍 / 👎.