Fix project Relay workspace resolution#1344
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughChangesWorkspace-key resolution
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CLI SDK client
participant Cloud workspace resolver
participant Project workspace key
participant Global workspace store
CLI SDK client->>Cloud workspace resolver: provide explicit key and environment
Cloud workspace resolver->>Project workspace key: read project-local key when needed
Project workspace key-->>Cloud workspace resolver: return project key or undefined
Cloud workspace resolver->>Global workspace store: resolve fallback key
Global workspace store-->>Cloud workspace resolver: return global key or undefined
Cloud workspace resolver-->>CLI SDK client: return resolved key and source
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Code Review
This pull request centralizes project-aware workspace key resolution logic into the @agent-relay/cloud package under a new ./workspace-key subpath, migrating the CLI to use this unified implementation. Feedback is provided to append a random suffix to the temporary file path in packages/cloud/src/project-workspace-key.ts to prevent potential race conditions and file collisions in multi-threaded Node.js environments where threads share the same process ID.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
CHANGELOG.md (1)
8-12: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider "Unreleased - Minor" instead of "Patch."
This entry documents a new public export (
@agent-relay/cloud/workspace-keysubpath) alongside a precedence behavior change. Adding new public API surface is typically a Minor-level change under SemVer, not a Patch. Per coding guidelines, the unreleased level should reflect the most significant change bundled into it.📝 Proposed heading change
-## [Unreleased - Patch] +## [Unreleased - Minor]🤖 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 `@CHANGELOG.md` around lines 8 - 12, Change the changelog heading from “Unreleased - Patch” to “Unreleased - Minor” to reflect the new public workspace-key export documented in the entry, while leaving the release notes unchanged.Source: Coding guidelines
🤖 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.
Nitpick comments:
In `@CHANGELOG.md`:
- Around line 8-12: Change the changelog heading from “Unreleased - Patch” to
“Unreleased - Minor” to reflect the new public workspace-key export documented
in the entry, while leaving the release notes unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 0caa06c8-0982-4dca-8804-02569d3fead9
📒 Files selected for processing (10)
.agentworkforce/trajectories/factory-recovery/completed/2026-07/traj_t8kdxk32okbu/summary.md.agentworkforce/trajectories/factory-recovery/completed/2026-07/traj_t8kdxk32okbu/trajectory.jsonCHANGELOG.mdpackages/cli/src/cli/lib/project-workspace-key.tspackages/cli/src/cli/lib/sdk-client.tspackages/cloud/package.jsonpackages/cloud/src/index.tspackages/cloud/src/project-workspace-key.test.tspackages/cloud/src/project-workspace-key.tspackages/cloud/src/workspace-key.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/cloud/src/project-workspace-key.ts (1)
51-61: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winDo not delete a colliding temporary file.
If
openSyncreturnsEEXIST,rmSync(tmp)can delete another writer’s temporary file before retrying with the same path. Generate a fresh nonce and retry, or propagate the collision; otherwise the collision-safe atomic-write guarantee is undermined.Proposed fix
- const tmp = `${file}.tmp.${process.pid}.${randomUUID()}`; + let tmp = `${file}.tmp.${process.pid}.${randomUUID()}`; const data = `${JSON.stringify({ workspaceKey: key } satisfies ProjectWorkspaceKeyFile, null, 2)}\n`; let fd: number; try { fd = fs.openSync(tmp, 'wx', 0o600); } catch (error) { if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error; - fs.rmSync(tmp, { force: true }); + tmp = `${file}.tmp.${process.pid}.${randomUUID()}`; fd = fs.openSync(tmp, 'wx', 0o600); }🤖 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 `@packages/cloud/src/project-workspace-key.ts` around lines 51 - 61, Update the temporary-file creation logic around the write function’s fs.openSync call so an EEXIST collision never removes the existing temporary file. On collision, generate a fresh randomUUID-based temporary path and retry exclusive creation, or propagate the error; preserve the atomic-write behavior and avoid retrying with the same path.
🤖 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.
Outside diff comments:
In `@packages/cloud/src/project-workspace-key.ts`:
- Around line 51-61: Update the temporary-file creation logic around the write
function’s fs.openSync call so an EEXIST collision never removes the existing
temporary file. On collision, generate a fresh randomUUID-based temporary path
and retry exclusive creation, or propagate the error; preserve the atomic-write
behavior and avoid retrying with the same path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 467737a1-4eee-42d9-ab6c-f551b05f1e37
📒 Files selected for processing (1)
packages/cloud/src/project-workspace-key.ts
|
Addressed the follow-up review in a45df6c: EEXIST now retries with a fresh nonce and never deletes another writer’s temp file. I also moved the changelog entry to Unreleased - Minor for the new public subpath. Focused resolver/CLI tests (15/15), cloud build, formatting, and diff checks pass. |
Summary
@agent-relay/cloud/workspace-keySDK entry pointWhy
A Factory process could connect to the broker running in its checkout but publish through the machine-global Relay workspace. Restored babysitters then existed locally while delivery returned
agent_not_found.Verification
npm run typechecknpm run format:checknpm run build:corenpm test(97 files passed, 2 skipped; 1300 tests passed, 20 skipped)@agent-relay/cloudtarball install and public subpath import smoke