Skip to content

Conversation

@adityachoudhari26
Copy link
Contributor

@adityachoudhari26 adityachoudhari26 commented Oct 24, 2025

Summary by CodeRabbit

  • New Features

    • Workspace data is now automatically saved periodically in the background to ensure continuous data preservation.
  • Refactor

    • Enhanced event system to support configurable event types and intervals for improved backend flexibility.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 24, 2025

Walkthrough

The ticker system is refactored to support configurable event types and intervals. The main.go file introduces a new workspace-save ticker running in parallel with the default ticker. The ticker.go file adds flexibility by extracting event type configuration into a field, providing a backward-compatible NewDefault() constructor while enabling custom event types and intervals via a new New() constructor.

Changes

Cohort / File(s) Summary
Ticker API Refactoring
apps/workspace-engine/pkg/ticker/ticker.go
Added eventType field to Ticker struct. Replaced New(producer) constructor with NewDefault(producer) for backward compatibility and a new flexible New(producer, interval, eventType) constructor. Updated emitTickForWorkspace to use t.eventType instead of hardcoded WorkspaceTickEventType.
Ticker Application & Integration
apps/workspace-engine/main.go
Changed default ticker initialization to ticker.NewDefault(producer). Added new workspaceSaveTicker using the flexible New() constructor with 1-hour interval and WorkspaceSave event type. Introduced new goroutine to run workspace-save ticker periodically with dedicated logging and error handling. Added import for workspace-engine/pkg/events/handler.
Test Updates
apps/workspace-engine/pkg/ticker/ticker_test.go
Updated Ticker struct literals in multiple tests to initialize the new eventType: WorkspaceTickEventType field.

Sequence Diagram

sequenceDiagram
    participant Main as main.go
    participant DefaultTicker as Default Ticker<br/>(WorkspaceTick)
    participant SaveTicker as Workspace-Save Ticker<br/>(WorkspaceSave)
    participant Producer as Kafka Producer

    par Default Ticker Flow
        loop Every interval
            DefaultTicker->>Producer: ProduceEvent(eventType: "workspace_tick")
        end
    and Workspace-Save Ticker Flow
        loop Every 1 hour
            SaveTicker->>Producer: ProduceEvent(eventType: "workspace_save")
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

The changes involve API refactoring with new public constructors, introduction of configurable event types, and parallel execution of multiple tickers. While the individual changes are straightforward, understanding the interaction between the two tickers and verifying backward compatibility requires careful analysis across multiple files.

Poem

🐰✨ Two tickers hop in time,

One saves the workspace sublime,

With events now configurable and free,

The ticker dances gracefully! 🎭⏱️

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% 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 PR title "chore: workspace save ticker" directly refers to the primary functional change in the changeset: the introduction of a new workspace save ticker that runs periodically. The title accurately captures the main objective without being vague or generic. While it doesn't enumerate every detail (such as the 1-hour interval or the ticker package refactoring), it provides sufficient clarity for someone reviewing commit history to understand the core purpose of the change. The title is concise, specific, and free of unnecessary noise.
✨ 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 workspace-save-tick

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.

@github-actions
Copy link

📊 DB Package Test Coverage

pkg/db coverage: 55.6%

View detailed coverage report in artifacts

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: 1

🧹 Nitpick comments (2)
apps/workspace-engine/pkg/ticker/ticker_test.go (1)

32-98: Consider adding test coverage for the new New constructor.

While the existing tests are updated correctly, consider adding tests to verify:

  1. The New constructor with a custom eventType emits events with that type (not WorkspaceTickEventType)
  2. The New constructor respects the custom interval parameter
  3. Both NewDefault and New constructors produce functionally correct tickers

Example test to add:

func TestEmitTickForWorkspace_CustomEventType(t *testing.T) {
	mockProducer := new(MockEventProducer)
	customEventType := "custom.event.type"
	ticker := New(mockProducer, time.Minute, customEventType)
	
	workspaceID := "test-workspace"
	
	// Verify custom event type is used, not WorkspaceTickEventType
	mockProducer.On("ProduceEvent", customEventType, workspaceID, nil).Return(nil)
	
	err := ticker.emitTickForWorkspace(context.Background(), workspaceID)
	assert.NoError(t, err)
	
	mockProducer.AssertExpectations(t)
}
apps/workspace-engine/main.go (1)

157-163: Improve error log messages to distinguish between tickers.

Both ticker goroutines log the generic message "Ticker error", making it difficult to determine which ticker encountered an issue during troubleshooting. Consider adding context to differentiate them.

Apply this diff to improve error logging:

 	workspaceSaveTicker := ticker.New(producer, 1*time.Hour, string(handler.WorkspaceSave))
 	go func() {
 		log.Info("Workspace save ticker started")
 		if err := workspaceSaveTicker.Run(ctx); err != nil {
-			log.Error("Ticker error", "error", err)
+			log.Error("Workspace save ticker error", "error", err)
 		}
 	}()

Similarly, update line 153 for consistency:

-			log.Error("Ticker error", "error", err)
+			log.Error("Workspace ticker error", "error", err)
📜 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 c56826f and fa67b12.

📒 Files selected for processing (3)
  • apps/workspace-engine/main.go (2 hunks)
  • apps/workspace-engine/pkg/ticker/ticker.go (2 hunks)
  • apps/workspace-engine/pkg/ticker/ticker_test.go (4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
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/ticker/ticker_test.go
  • apps/workspace-engine/main.go
  • apps/workspace-engine/pkg/ticker/ticker.go
apps/workspace-engine/**/*_test.go

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

Follow the existing test structure used in *_test.go files

Files:

  • apps/workspace-engine/pkg/ticker/ticker_test.go
🧬 Code graph analysis (3)
apps/workspace-engine/pkg/ticker/ticker_test.go (1)
apps/workspace-engine/pkg/ticker/ticker.go (1)
  • WorkspaceTickEventType (23-23)
apps/workspace-engine/main.go (2)
apps/workspace-engine/pkg/ticker/ticker.go (2)
  • NewDefault (36-45)
  • New (48-54)
apps/workspace-engine/pkg/events/handler/handler.go (1)
  • WorkspaceSave (79-79)
apps/workspace-engine/pkg/ticker/ticker.go (1)
apps/workspace-engine/pkg/kafka/producer.go (1)
  • EventProducer (12-16)
🔇 Additional comments (3)
apps/workspace-engine/pkg/ticker/ticker.go (1)

35-45: LGTM!

The NewDefault constructor correctly maintains backward compatibility by using the default event type and reading the interval from the environment with proper validation.

apps/workspace-engine/main.go (2)

12-12: LGTM!

The import is necessary to access the WorkspaceSave event type constant used in the new ticker configuration.


149-149: LGTM!

The change to NewDefault correctly maintains backward compatibility with the previous behavior while adapting to the refactored ticker API.

Comment on lines +47 to 54
// New creates a new ticker with the configured interval and event type
func New(producer kafka.EventProducer, interval time.Duration, eventType string) *Ticker {
return &Ticker{
producer: producer,
interval: interval,
eventType: eventType,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add input validation to prevent runtime issues.

The constructor should validate that interval is positive and eventType is non-empty to prevent runtime panics (from time.NewTicker) and invalid event production.

Apply this diff to add validation:

 // New creates a new ticker with the configured interval and event type
 func New(producer kafka.EventProducer, interval time.Duration, eventType string) *Ticker {
+	if interval <= 0 {
+		log.Warn("Invalid interval provided, using default", "interval", interval)
+		interval = DefaultTickInterval
+	}
+	if eventType == "" {
+		log.Warn("Empty event type provided, using default")
+		eventType = WorkspaceTickEventType
+	}
+
 	return &Ticker{
 		producer:  producer,
 		interval:  interval,
 		eventType: eventType,
 	}
 }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In apps/workspace-engine/pkg/ticker/ticker.go around lines 47 to 54, validate
inputs in New: ensure interval > 0 and eventType is not empty; if invalid,
return an error (change signature to New(producer kafka.EventProducer, interval
time.Duration, eventType string) (*Ticker, error)), add appropriate fmt.Errorf
messages for each check (or a combined validation error), and only
construct/return the Ticker when validations pass; remember to add the fmt
import and update all call sites to handle the (Ticker, error) return.

@adityachoudhari26 adityachoudhari26 merged commit 57a031d into main Oct 24, 2025
4 of 8 checks passed
@adityachoudhari26 adityachoudhari26 deleted the workspace-save-tick branch October 24, 2025 04:41
@coderabbitai coderabbitai bot mentioned this pull request Oct 24, 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.

2 participants