Skip to content

Conversation

nicktrn
Copy link
Collaborator

@nicktrn nicktrn commented Sep 3, 2025

No description provided.

Copy link

changeset-bot bot commented Sep 3, 2025

⚠️ No Changeset found

Latest commit: 31b97b7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Sep 3, 2025

Walkthrough

  • Added WorkerQueueResolver class with override parsing (via zod) and logging.
  • New exports: WorkerQueueResolver, WorkerQueueResolverOptions, WorkerQueueOverrides.
  • Resolver reads overrides from provided config or RUN_ENGINE_WORKER_QUEUE_OVERRIDES, validates, and logs outcomes.
  • Override precedence: environmentId > projectId > orgId > workerQueue.
  • getWorkerQueueFromMessage supports V2 (uses workerQueue or override) and V1 (uses environmentId for development, masterQueues[0] otherwise).
  • RunQueue now composes and delegates worker queue determination to WorkerQueueResolver.
  • Added comprehensive unit tests covering precedence, V1/V2 behavior, env var fallback, parsing errors, and logging.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/worker-queue-overrides

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (11)
internal-packages/run-engine/src/run-queue/index.ts (3)

173-173: Make resolver reference immutable

Declare the resolver as readonly to prevent accidental reassignment.

-  private workerQueueResolver: WorkerQueueResolver;
+  private readonly workerQueueResolver: WorkerQueueResolver;

191-193: Optional: allow injectable overrides for tests/ops

Consider accepting an optional overrides JSON via RunQueueOptions and pass it here, so production can avoid relying solely on process.env and tests can inject without mutating env.

If you want, I can draft a minimal RunQueueOptions addition (e.g. workerQueueOverridesJson?: string) and plumb it through.


1852-1854: Wrapper method name clarity (optional)

Method is now a thin pass-through. Consider renaming to resolveWorkerQueue for clarity, or inline calls at use-sites. Totally optional.

internal-packages/run-engine/src/run-queue/workerQueueResolver.ts (5)

5-13: Disambiguate schema vs type and validate non-empty values

Rename the Zod schema to avoid name shadowing with the exported type, and ensure override values aren’t empty strings (which could route to a blank queue).

-const WorkerQueueOverrides = z.object({
-  environmentId: z.record(z.string(), z.string()).optional(),
-  projectId: z.record(z.string(), z.string()).optional(),
-  orgId: z.record(z.string(), z.string()).optional(),
-  workerQueue: z.record(z.string(), z.string()).optional(),
-});
+const WorkerQueueOverridesSchema = z.object({
+  environmentId: z.record(z.string(), z.string().min(1)).optional(),
+  projectId: z.record(z.string(), z.string().min(1)).optional(),
+  orgId: z.record(z.string(), z.string().min(1)).optional(),
+  workerQueue: z.record(z.string(), z.string().min(1)).optional(),
+});

-export type WorkerQueueOverrides = z.infer<typeof WorkerQueueOverrides>;
+export type WorkerQueueOverrides = z.infer<typeof WorkerQueueOverridesSchema>;
-      const result = WorkerQueueOverrides.safeParse(parsed);
+      const result = WorkerQueueOverridesSchema.safeParse(parsed);

Also applies to: 35-41


66-74: Fix comment: version reference typo

This branch handles v1 messages, not v2. Update the comment to avoid confusion.

-    // In v2, if the environment is development, the worker queue is the environment id.
+    // In v1, if the environment is development, the worker queue is the environment id.

71-74: Guard against empty masterQueues in v1

If masterQueues is empty/malformed, we’ll return undefined. Add a safe fallback and log once for visibility.

-    return message.masterQueues[0];
+    const first = message.masterQueues[0];
+    if (!first) {
+      this.logger.error("v1 message missing masterQueues[0], falling back to environmentId", {
+        orgId: message.orgId,
+        projectId: message.projectId,
+        environmentId: message.environmentId,
+      });
+      return message.environmentId;
+    }
+    return first;

23-26: Hot-reload overrides (optional)

If you anticipate changing overrides at runtime, expose a small API to reload without recreating RunQueue.

   constructor(opts: WorkerQueueResolverOptions) {
     this.logger = opts.logger;
     this.overrides = this.parseOverrides(opts.overrideConfig);
   }
+
+  public reloadOverrides(overrideConfig?: string) {
+    this.overrides = this.parseOverrides(overrideConfig);
+  }

81-99: Optional observability: log which override matched

Adding a debug log when an override is applied helps explain unexpected routing during incidents.

-    if (this.overrides.environmentId?.[message.environmentId]) {
-      return this.overrides.environmentId[message.environmentId];
-    }
+    if (this.overrides.environmentId?.[message.environmentId]) {
+      const q = this.overrides.environmentId[message.environmentId];
+      this.logger.debug("Applying workerQueue override", {
+        scope: "environmentId",
+        key: message.environmentId,
+        workerQueue: q,
+      });
+      return q;
+    }
 
-    if (this.overrides.projectId?.[message.projectId]) {
-      return this.overrides.projectId[message.projectId];
-    }
+    if (this.overrides.projectId?.[message.projectId]) {
+      const q = this.overrides.projectId[message.projectId];
+      this.logger.debug("Applying workerQueue override", {
+        scope: "projectId",
+        key: message.projectId,
+        workerQueue: q,
+      });
+      return q;
+    }
 
-    if (this.overrides.orgId?.[message.orgId]) {
-      return this.overrides.orgId[message.orgId];
-    }
+    if (this.overrides.orgId?.[message.orgId]) {
+      const q = this.overrides.orgId[message.orgId];
+      this.logger.debug("Applying workerQueue override", {
+        scope: "orgId",
+        key: message.orgId,
+        workerQueue: q,
+      });
+      return q;
+    }
 
-    if (this.overrides.workerQueue?.[message.workerQueue]) {
-      return this.overrides.workerQueue[message.workerQueue];
-    }
+    if (this.overrides.workerQueue?.[message.workerQueue]) {
+      const q = this.overrides.workerQueue[message.workerQueue];
+      this.logger.debug("Applying workerQueue override", {
+        scope: "workerQueue",
+        key: message.workerQueue,
+        workerQueue: q,
+      });
+      return q;
+    }
internal-packages/run-engine/src/run-queue/tests/workerQueueResolver.test.ts (3)

9-9: Align suite name with class

Minor: rename describe title to match the class name.

-describe("WorkerQueueOverrideResolver", () => {
+describe("WorkerQueueResolver", () => {

431-437: Restore all mocks after each test

Prevents cross-test leakage from spies.

   afterEach(() => {
     if (originalEnv === undefined) {
       delete process.env.RUN_ENGINE_WORKER_QUEUE_OVERRIDES;
     } else {
       process.env.RUN_ENGINE_WORKER_QUEUE_OVERRIDES = originalEnv;
     }
   });
+
+  afterEach(() => {
+    vi.restoreAllMocks();
+  });

400-421: Add edge-case: v1 with empty masterQueues

Ensure fallback path is exercised and stable.

   describe("V1 message handling", () => {
+    it("should fall back when v1 masterQueues is empty", () => {
+      const logger = new Logger("test", "error");
+      const resolver = new WorkerQueueResolver({ logger });
+
+      const v1Msg: OutputPayloadV1 = {
+        version: "1",
+        runId: "run_123",
+        taskIdentifier: "task_123",
+        orgId: "org_123",
+        projectId: "proj_123",
+        environmentId: "env_prod",
+        environmentType: RuntimeEnvironmentType.PRODUCTION,
+        queue: "test-queue",
+        timestamp: Date.now(),
+        attempt: 0,
+        masterQueues: [],
+      };
+
+      const result = resolver.getWorkerQueueFromMessage(v1Msg);
+      expect(result).toBe("env_prod");
+    });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ed23615 and 31b97b7.

📒 Files selected for processing (3)
  • internal-packages/run-engine/src/run-queue/index.ts (4 hunks)
  • internal-packages/run-engine/src/run-queue/tests/workerQueueResolver.test.ts (1 hunks)
  • internal-packages/run-engine/src/run-queue/workerQueueResolver.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Always prefer using isomorphic code like fetch, ReadableStream, etc. instead of Node.js specific code
For TypeScript, we usually use types over interfaces
Avoid enums
No default exports, use function declarations

Files:

  • internal-packages/run-engine/src/run-queue/index.ts
  • internal-packages/run-engine/src/run-queue/workerQueueResolver.ts
  • internal-packages/run-engine/src/run-queue/tests/workerQueueResolver.test.ts
**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Our tests are all vitest

Files:

  • internal-packages/run-engine/src/run-queue/tests/workerQueueResolver.test.ts
**/*.{test,spec}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{test,spec}.{ts,tsx,js,jsx}: Unit tests must use Vitest
Tests should avoid mocks or stubs and use helpers from @internal/testcontainers when Redis or Postgres are needed
Test files live beside the files under test and should use descriptive describe and it blocks

Files:

  • internal-packages/run-engine/src/run-queue/tests/workerQueueResolver.test.ts
🧬 Code graph analysis (3)
internal-packages/run-engine/src/run-queue/index.ts (2)
internal-packages/run-engine/src/run-queue/workerQueueResolver.ts (2)
  • WorkerQueueResolver (19-100)
  • message (76-99)
internal-packages/run-engine/src/run-queue/types.ts (2)
  • OutputPayload (31-31)
  • OutputPayload (33-33)
internal-packages/run-engine/src/run-queue/workerQueueResolver.ts (1)
internal-packages/run-engine/src/run-queue/index.ts (5)
  • message (1399-1447)
  • message (1696-1751)
  • message (1753-1801)
  • message (1803-1831)
  • message (1852-1854)
internal-packages/run-engine/src/run-queue/tests/workerQueueResolver.test.ts (1)
internal-packages/run-engine/src/run-queue/workerQueueResolver.ts (3)
  • WorkerQueueResolver (19-100)
  • message (76-99)
  • WorkerQueueOverrides (12-12)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (23)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 8)
  • GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
internal-packages/run-engine/src/run-queue/index.ts (1)

45-45: Good delegation: use the centralized resolver

Importing and delegating to WorkerQueueResolver reduces duplication and keeps resolution logic isolated. LGTM.

internal-packages/run-engine/src/run-queue/tests/workerQueueResolver.test.ts (1)

1-8: Vitest usage and structure look good

Uses vitest, colocated with implementation, and covers V1/V2 paths and precedence thoroughly. Nice work.

@nicktrn nicktrn merged commit 59c17e0 into main Sep 4, 2025
31 checks passed
@nicktrn nicktrn deleted the feat/worker-queue-overrides branch September 4, 2025 08:27
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