Skip to content

chore: move changeset package#677

Merged
adityachoudhari26 merged 2 commits intomainfrom
fix-changeset-package
Oct 13, 2025
Merged

chore: move changeset package#677
adityachoudhari26 merged 2 commits intomainfrom
fix-changeset-package

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented Oct 13, 2025

Summary by CodeRabbit

  • New Features
    • Automatic initial workspace bootstrap populates in-memory state on first load, improving readiness for event handling.
  • Refactor
    • Reworked workspace loading to return a consolidated initial state, simplifying control flow and producing clearer, per-step error messages.
    • Standardized how related entities are aggregated and exposed for consumers, improving consistency across the app.
  • Chores
    • Updated internal package paths to a unified location for change tracking, reducing duplication and easing maintenance.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 13, 2025

Walkthrough

Refactors workspace loading to return a new InitialWorkspaceState aggregate, updating helper signatures and error propagation. Event handler now initializes non-existent workspaces and populates them from DB via a new loader. Multiple files switch imports to the top-level changeset package without logic changes.

Changes

Cohort / File(s) Summary
Workspace initial state refactor
apps/workspace-engine/pkg/db/workspace_load.go, apps/workspace-engine/pkg/events/handler/handler.go, apps/workspace-engine/pkg/events/handler/workspace.go
Introduces InitialWorkspaceState with accessor methods; rewrites LoadWorkspace to return aggregated slices via loadX helpers (now by workspaceID, return slices+error). Event handler path for missing workspaces initializes in-memory workspace and populates via loadWorkspaceWithInitialState; adjusts control flow and error propagation.
Changeset import path migration
apps/workspace-engine/pkg/db/changeset.go, apps/workspace-engine/pkg/workspace/store/deployment_variables.go, .../deployment_versions.go, .../job_agents.go, .../jobs.go, .../policy.go, .../relationships.go, .../releases.go, .../resource_providers.go, .../resource_variables.go, .../resources.go, .../systems.go, .../user_approval_records.go
Updates imports from workspace-engine/pkg/workspace/changeset to workspace-engine/pkg/changeset. No functional changes; existing usage (FromContext, Record, ChangeType*) retained.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant ES as Event Source
  participant H as Event Handler
  participant WS as Workspace Store
  participant DB as DB (LoadWorkspace)

  ES->>H: Event(workspaceID)
  alt Workspace exists
    H->>WS: Get(workspaceID)
    H->>H: Prepare ChangeSet
    H->>WS: Apply event mutations
  else Workspace missing
    H->>WS: New(workspaceID)
    H->>DB: LoadWorkspace(workspaceID)
    DB-->>H: InitialWorkspaceState{systems, resources, ...}
    loop Upsert all entities
      H->>WS: Upsert(entity)
    end
    H->>H: Mark ChangeSet.IsInitialLoad
  end
  H-->>ES: Ack/continue
  note over H,WS: Subsequent reconciliation proceeds with ChangeSet context
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • chore: init workspaces from db #674 — Adjusts workspace initialization/loading and cache interactions, overlapping with the new initial-state load path and workspace store usage.
  • chore: init db changeset #675 — Refactors the changeset package API/placement, matching this PR’s migration to the top-level changeset import across stores and DB.

Poem

I thump my paw: a workspace wakes,
New seeds of state the database makes.
Slices hop in, one by one,
Systems, resources—load is done.
A tidy trail of changes set—
Carrots tall, no code regret. 🥕🐇

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The current title “chore: move changeset package” accurately describes the import path updates for the changeset package but overlooks the more significant refactor of LoadWorkspace to return an InitialWorkspaceState and related handler changes. It is therefore only partially related to the main functional change in this pull request.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-changeset-package

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.

Copy link
Copy Markdown
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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/workspace-engine/pkg/db/workspace_load.go (1)

171-181: Remove redundant GetDB call in LoadWorkspace
In apps/workspace-engine/pkg/db/workspace_load.go (lines 171–181), delete the db, err := GetDB(ctx) / defer db.Release() block—each get* helper opens and releases its own DB handle.

🧹 Nitpick comments (2)
apps/workspace-engine/pkg/db/workspace_load.go (2)

15-25: Add doc for exported type (lint/readability)

Please document InitialWorkspaceState per guidelines for exported types.

As per coding guidelines

+// InitialWorkspaceState aggregates all entities fetched for a workspace during initial load.
+// Fields are unexported; use accessors to read. Callers should treat returned slices as read-only.
 type InitialWorkspaceState struct {

171-171: Add doc for exported function

Briefly document LoadWorkspace’s contract and return value.

As per coding guidelines

- func LoadWorkspace(ctx context.Context, workspaceID string) (initialWorkspaceState *InitialWorkspaceState, err error) {
+ // LoadWorkspace fetches all workspace entities and returns an InitialWorkspaceState snapshot.
+ func LoadWorkspace(ctx context.Context, workspaceID string) (initialWorkspaceState *InitialWorkspaceState, err error) {
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • 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 a620429 and 6ea408f.

📒 Files selected for processing (16)
  • apps/workspace-engine/pkg/db/changeset.go (1 hunks)
  • apps/workspace-engine/pkg/db/workspace_load.go (3 hunks)
  • apps/workspace-engine/pkg/events/handler/handler.go (2 hunks)
  • apps/workspace-engine/pkg/events/handler/workspace.go (1 hunks)
  • apps/workspace-engine/pkg/workspace/store/deployment_variables.go (1 hunks)
  • apps/workspace-engine/pkg/workspace/store/deployment_versions.go (1 hunks)
  • apps/workspace-engine/pkg/workspace/store/job_agents.go (1 hunks)
  • apps/workspace-engine/pkg/workspace/store/jobs.go (1 hunks)
  • apps/workspace-engine/pkg/workspace/store/policy.go (1 hunks)
  • apps/workspace-engine/pkg/workspace/store/relationships.go (1 hunks)
  • apps/workspace-engine/pkg/workspace/store/releases.go (1 hunks)
  • apps/workspace-engine/pkg/workspace/store/resource_providers.go (1 hunks)
  • apps/workspace-engine/pkg/workspace/store/resource_variables.go (1 hunks)
  • apps/workspace-engine/pkg/workspace/store/resources.go (1 hunks)
  • apps/workspace-engine/pkg/workspace/store/systems.go (1 hunks)
  • apps/workspace-engine/pkg/workspace/store/user_approval_records.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/workspace-engine/**/*.go

📄 CodeRabbit inference engine (apps/workspace-engine/CLAUDE.md)

apps/workspace-engine/**/*.go: Do not add extraneous inline comments that state the obvious
Do not add comments that simply restate what the code does
Do not add comments for standard Go patterns (e.g., noting WaitGroup or semaphore usage)
Write comments that explain why, document complex logic/algorithms, provide non-obvious context, include TODO/FIXME, and document exported functions/types/methods

Files:

  • apps/workspace-engine/pkg/workspace/store/relationships.go
  • apps/workspace-engine/pkg/workspace/store/deployment_variables.go
  • apps/workspace-engine/pkg/events/handler/workspace.go
  • apps/workspace-engine/pkg/workspace/store/releases.go
  • apps/workspace-engine/pkg/db/changeset.go
  • apps/workspace-engine/pkg/workspace/store/resource_providers.go
  • apps/workspace-engine/pkg/workspace/store/jobs.go
  • apps/workspace-engine/pkg/workspace/store/resources.go
  • apps/workspace-engine/pkg/workspace/store/resource_variables.go
  • apps/workspace-engine/pkg/workspace/store/deployment_versions.go
  • apps/workspace-engine/pkg/events/handler/handler.go
  • apps/workspace-engine/pkg/workspace/store/systems.go
  • apps/workspace-engine/pkg/workspace/store/policy.go
  • apps/workspace-engine/pkg/db/workspace_load.go
  • apps/workspace-engine/pkg/workspace/store/job_agents.go
  • apps/workspace-engine/pkg/workspace/store/user_approval_records.go
🧬 Code graph analysis (3)
apps/workspace-engine/pkg/events/handler/workspace.go (8)
apps/workspace-engine/pkg/db/workspace_load.go (1)
  • LoadWorkspace (171-221)
apps/workspace-engine/pkg/workspace/store/systems.go (1)
  • Systems (21-27)
apps/workspace-engine/pkg/workspace/store/store.go (1)
  • Store (38-57)
apps/workspace-engine/pkg/workspace/store/resources.go (1)
  • Resources (18-21)
apps/workspace-engine/pkg/workspace/store/deployment_versions.go (1)
  • DeploymentVersions (18-23)
apps/workspace-engine/pkg/workspace/store/deployment_variables.go (1)
  • DeploymentVariables (17-19)
apps/workspace-engine/pkg/workspace/store/policy.go (1)
  • Policies (22-26)
apps/workspace-engine/pkg/workspace/store/job_agents.go (1)
  • JobAgents (16-18)
apps/workspace-engine/pkg/events/handler/handler.go (1)
apps/workspace-engine/pkg/workspace/workspace.go (2)
  • New (13-22)
  • Set (131-133)
apps/workspace-engine/pkg/db/workspace_load.go (7)
apps/workspace-engine/pkg/oapi/oapi.gen.go (1)
  • RelationshipRule (243-256)
apps/workspace-engine/pkg/workspace/store/systems.go (1)
  • Systems (21-27)
apps/workspace-engine/pkg/workspace/store/resources.go (1)
  • Resources (18-21)
apps/workspace-engine/pkg/workspace/store/deployment_versions.go (1)
  • DeploymentVersions (18-23)
apps/workspace-engine/pkg/workspace/store/deployment_variables.go (1)
  • DeploymentVariables (17-19)
apps/workspace-engine/pkg/workspace/store/policy.go (1)
  • Policies (22-26)
apps/workspace-engine/pkg/workspace/store/job_agents.go (1)
  • JobAgents (16-18)
⏰ 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). (1)
  • GitHub Check: Lint
🔇 Additional comments (10)
apps/workspace-engine/pkg/workspace/store/jobs.go (1)

5-5: LGTM! Clean import path refactor.

The changeset package import has been correctly updated to the top-level path.

apps/workspace-engine/pkg/workspace/store/deployment_versions.go (1)

5-5: LGTM! Import path updated correctly.

The changeset package import aligns with the top-level restructuring.

apps/workspace-engine/pkg/workspace/store/deployment_variables.go (1)

5-5: LGTM! Import path updated correctly.

The changeset package import aligns with the top-level restructuring.

apps/workspace-engine/pkg/workspace/store/resource_variables.go (1)

5-5: LGTM! Import path updated correctly.

The changeset package import aligns with the top-level restructuring.

apps/workspace-engine/pkg/workspace/store/policy.go (1)

6-6: LGTM! Import path updated correctly.

The changeset package import aligns with the top-level restructuring.

apps/workspace-engine/pkg/workspace/store/relationships.go (1)

6-6: LGTM! Import path updated correctly.

The changeset package import aligns with the top-level restructuring.

apps/workspace-engine/pkg/workspace/store/releases.go (1)

5-5: LGTM! Import path updated correctly.

The changeset package import aligns with the top-level restructuring.

apps/workspace-engine/pkg/db/changeset.go (1)

6-6: LGTM — all old changeset imports removed
No references to workspace-engine/pkg/workspace/changeset remain; imports now consistently use workspace-engine/pkg/changeset.

apps/workspace-engine/pkg/events/handler/handler.go (2)

7-7: Import path update looks correct

Switch to the top-level changeset package is consistent with the PR intent.


146-154: Initial-load flow is sound

Create new workspace, load state, then register and mark IsInitialLoad. Prevents partially-registered workspaces if load fails. LGTM.

Comment on lines +15 to +41
for _, system := range initialWorkspaceState.Systems() {
ws.Store().Systems.Upsert(ctx, system)
}
for _, resource := range initialWorkspaceState.Resources() {
ws.Store().Resources.Upsert(ctx, resource)
}
for _, deployment := range initialWorkspaceState.Deployments() {
ws.Store().Deployments.Upsert(ctx, deployment)
}
for _, deploymentVersion := range initialWorkspaceState.DeploymentVersions() {
ws.Store().DeploymentVersions.Upsert(ctx, deploymentVersion.Id, deploymentVersion)
}
for _, deploymentVariable := range initialWorkspaceState.DeploymentVariables() {
ws.Store().DeploymentVariables.Upsert(ctx, deploymentVariable.Id, deploymentVariable)
}
for _, environment := range initialWorkspaceState.Environments() {
ws.Store().Environments.Upsert(ctx, environment)
}
for _, policy := range initialWorkspaceState.Policies() {
ws.Store().Policies.Upsert(ctx, policy)
}
for _, jobAgent := range initialWorkspaceState.JobAgents() {
ws.Store().JobAgents.Upsert(ctx, jobAgent)
}
for _, relationship := range initialWorkspaceState.Relationships() {
ws.Store().Relationships.Upsert(ctx, relationship)
}
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.

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Confirm Upsert signatures; handle errors if any are returned

You’re ignoring return values from Upsert. If any Upsert method returns an error, failures will be silently dropped during initial load. Please verify signatures and propagate/log errors per entity, or batch with aggregation.

Run to confirm Upsert signatures:


🏁 Script executed:

#!/bin/bash
# List Upsert method signatures and detect if they return errors
rg -nP --type=go -C1 'func\s*\(\s*\*?\w+\s*\)\s+Upsert\s*\([^)]*\)\s*(\([^)]+\)|\w+)?\s*\{' apps/workspace-engine | sed -n 's/^\(.*\)$/\1/p'
echo "---- Potential error-returning Upserts ----"
rg -nP --type=go 'func\s*\(\s*\*?\w+\s*\)\s+Upsert\s*\([^)]*\)\s*(error|\(.*error.*\))' apps/workspace-engine -n -C1

Length of output: 43


🏁 Script executed:

#!/bin/bash
# Find all Upsert occurrences to inspect method signatures
rg -nP '\bUpsert\(' -n -C3 apps/workspace-engine

Length of output: 64629


Capture and propagate errors from Upsert calls
Upsert methods on Systems, Environments, Resources, Releases, Policies, Deployments and RelationshipRules return an error (or value,error) that’s currently ignored in the initial‐load loop; wrap each call to handle and return/log errors.

@adityachoudhari26 adityachoudhari26 merged commit f36b812 into main Oct 13, 2025
2 of 6 checks passed
@adityachoudhari26 adityachoudhari26 deleted the fix-changeset-package branch October 13, 2025 18:08
This was referenced Oct 22, 2025
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