Skip to content

refactor: preserve dag-run file layout in persistence store - #2214

Merged
yohamta0 merged 14 commits into
mainfrom
refactor-dagrun-persistence-compat
May 27, 2026
Merged

yohamta0 merged 14 commits into
mainfrom
refactor-dagrun-persistence-compat

Conversation

@yohamta0

@yohamta0 yohamta0 commented May 26, 2026 •

Copy link
Copy Markdown
Member

Summary

  • move the DAG-run file store under the file backend without changing its on-disk layout
  • add compatibility coverage for dag-run directories, attempts, sub-runs, status JSONL, outputs, messages, and work dirs
  • extract legacy .proc sidecar file mechanics from the DB-neutral store package into a file backend adapter

Testing

  • make fmt
  • make lint
  • make test

Summary by CodeRabbit

  • Refactor

    • Consolidated on-disk persistence wiring to a unified file-backed store layer for runs, procs, agents, and service stores.
    • Standardized snapshot and workspace base-config factory injection across scheduler, engine, worker, and API.
  • Bug Fixes

    • Improved query-cursor validation and error handling for DAG-run listing.
    • Restored on-disk DAG-run layout compatibility to preserve existing artifacts.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 26, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 92b74d3a-5444-4cdf-8d9c-e08d3d121969

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Unifies file-backed persistence behind internal/persis/file factories, renames filedagrun→dagrun, introduces proc LegacyStore and ProcLegacyStore adapter, injects DAGRunStore and snapshot/base-config factories across engine/scheduler/API/worker, and updates tests/docs.

Changes

Persistence layer unification

Layer / File(s) Summary
Factories and dagrun rename
internal/persis/file/*, internal/persis/file/dagrun/*
Adds file-backed constructors for DAG, DAGRun, proc, service registry, base config, event/audit stores; renames packages to dagrun and adjusts query-cursor errors and compatibility tests.
Proc legacy adapter & proc meta
internal/persis/file/proc/legacy.go, internal/persis/store/proc_legacy_adapter.go, internal/persis/store/proc_meta.go, internal/persis/store/*
Introduces LegacyStore and ProcLegacyStore interface, exposes legacy methods (FilePath, Write, Remove, ListEntries, LatestHeartbeat), adds proc meta validation and deterministic record naming, and updates ProcStore plumbing.
Agent stores & snapshot factory
internal/persis/file/agent_stores.go, internal/agentsnapshot/*
Adds AgentStores aggregate, NewAgentStores, NewSnapshotStores, NewSecretStore, and makes agentsnapshot.BuildFromPaths accept a StoreFactory for snapshot creation.
Runtime wiring (engine/scheduler/worker/API)
internal/engine/*, internal/service/scheduler/*, internal/service/worker/*, internal/service/frontend/*, internal/cmd/*
Threads exec.DAGRunStore and snapshot/base-config factories into engine, scheduler, worker, API; updates NewWorker/NewTaskHandler signatures, scheduler options, agent/session wiring, and replaces many ad-hoc file-store constructions with file.* factories.
Commands, tests, docs migration
internal/test/*, internal/persis/filegithubdispatch/*, internal/persis/file/service_stores_test.go, refactor_persis_layer.html, many internal/* tests
Updates numerous tests to use dagrun.New or file.NewDAGRunStore, makes filegithubdispatch context-aware, adds unit tests for new factories, and updates documentation to reflect the Phase 2 DAG-run compatibility refactor.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

  • dagucloud/dagu#1986 — Introduces agent snapshot payload and hydration; this PR updates build/injection paths for those snapshots.
  • dagucloud/dagu#2202 — ProcStore backend refactor aligned with this PR’s switch to file.NewProcStore and legacy adapter wiring.
  • dagucloud/dagu#2108 — Workspace base-config endpoints; this PR adds base-config store factory plumbing consumed by those flows.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor-dagrun-persistence-compat

@yohamta0

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 48 files

Re-trigger cubic

@yohamta0

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 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.

Inline comments:
In `@internal/persis/file/dagrun_store.go`:
- Around line 41-43: The options loop in dagrun_store.go unconditionally calls
each option callback (for _, opt := range opts { opt(&options) }), which will
panic if an element is nil; update the loop to guard against nil callbacks by
checking each opt for nil before invoking it (i.e., skip nil entries), keeping
the same variables names opts and options so the change is localized to the loop
that applies option callbacks.

In `@internal/service/worker/handler.go`:
- Around line 35-37: NewTaskHandler currently passes a nil DAG-run store into
NewTaskHandlerWithDAGRunStore which later rejects nil, causing workspace-bundle
tasks to fail; fix this by having NewTaskHandler construct or obtain a valid
DAG-run store from the provided cfg and pass that instead of nil into
NewTaskHandlerWithDAGRunStore (if a DAGRunStore factory/constructor exists, call
it here), or if intentional, update NewTaskHandlerWithDAGRunStore to accept and
initialize a nil store internally—ensure the change references NewTaskHandler
and NewTaskHandlerWithDAGRunStore so workspace-bundle task handling no longer
receives a nil DAG-run store.

In `@internal/service/worker/worker.go`:
- Around line 108-110: The loop over opts may call a nil function value and
panic; in the function that iterates opts (the slice named opts, with loop
variable opt that applies to options), add a nil-check before invoking opt
(e.g., if opt == nil { continue }) so nil entries are safely skipped (or
alternatively return an error if you prefer strictness). Update the loop that
currently reads "for _, opt := range opts { opt(&options) }" to guard against
nil opt and apply only non-nil option functions to options.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e5afb34e-5b23-41e9-bcfd-69301e704e37

📥 Commits

Reviewing files that changed from the base of the PR and between 3f2e0fe and c1e55d9.

📒 Files selected for processing (18)
  • internal/cmd/context.go
  • internal/cmd/process/scheduler.go
  • internal/cmd/worker.go
  • internal/core/exec/dagrun.go
  • internal/engine/engine.go
  • internal/engine/types.go
  • internal/engine/worker.go
  • internal/intg/distr/fixtures_test.go
  • internal/intg/queue/fixture_test.go
  • internal/persis/file/dagrun/query_cursor.go
  • internal/persis/file/dagrun_store.go
  • internal/service/frontend/api/v1/dagruns.go
  • internal/service/worker/handler.go
  • internal/service/worker/worker.go
  • internal/test/helper.go
  • internal/test/reschedule_inline_helpers.go
  • internal/test/scheduler.go
  • refactor_persis_layer.html
✅ Files skipped from review due to trivial changes (1)
  • refactor_persis_layer.html
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/persis/file/dagrun/query_cursor.go
  • internal/service/frontend/api/v1/dagruns.go

Comment thread internal/persis/file/dagrun_store.go Resolved
Comment thread internal/service/worker/handler.go Resolved
Comment thread internal/service/worker/worker.go Resolved
@yohamta0

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@yohamta0

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@yohamta0

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
internal/githubdispatch/tracker.go (1)

17-22: 💤 Low value

Consider adding context.Context to Tracker interface methods.

The Tracker interface methods (Upsert, Delete, List) don't accept a context.Context parameter. For file-based implementations this may be fine, but if the tracker is later backed by a database or remote store, context propagation for cancellation and deadlines would be needed. Adding context now avoids a breaking interface change later.

♻️ Suggested interface with context
 // Tracker persists in-flight GitHub dispatch jobs until they are reported.
 type Tracker interface {
-	Upsert(TrackedJob) error
-	Delete(string) error
-	List() ([]TrackedJob, error)
+	Upsert(ctx context.Context, job TrackedJob) error
+	Delete(ctx context.Context, jobID string) error
+	List(ctx context.Context) ([]TrackedJob, error)
 }
🤖 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 `@internal/githubdispatch/tracker.go` around lines 17 - 22, Tracker's methods
(Upsert, Delete, List) lack a context.Context parameter which prevents
cancellation/deadline propagation; update the Tracker interface to accept
context.Context (e.g., Upsert(ctx context.Context, t TrackedJob) error,
Delete(ctx context.Context, id string) error, List(ctx context.Context)
([]TrackedJob, error)), then update all implementations of Tracker and all call
sites to pass through the incoming context; also add the context import where
needed and ensure any file-based or DB-backed implementations respect context
for long-running operations.
🤖 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.

Inline comments:
In `@internal/persis/file/agent_stores.go`:
- Around line 221-231: NewContextStore currently dereferences cfg and will panic
if cfg is nil; add an explicit nil check at the top of NewContextStore (checking
cfg == nil) and return a descriptive error instead of proceeding. Ensure the
guard returns (nil, error) before calling crypto.ResolveKey or
crypto.NewEncryptor, and keep the rest of the flow that calls crypto.ResolveKey,
crypto.NewEncryptor, and clicontext.NewStore unchanged so callers receive an
error rather than a panic when config.Config is nil.

In `@internal/persis/file/service_stores.go`:
- Around line 90-92: NewEventCollector currently builds a fileeventstore
collector unconditionally which will panic on cfg==nil and touch the event-store
even when disabled; update NewEventCollector to mirror NewEventStore's gating:
check cfg != nil and cfg.EventStore.Enabled (or equivalent eventStore.enabled
flag) before calling fileeventstore.NewCollector, and when the gate is off
return the "disabled" result used elsewhere in this package (e.g., the same
nil/zero-value and nil error or the disabled collector helper that NewEventStore
returns) so the caller cannot start a collector when the feature is disabled.

In `@internal/service/frontend/api/v1/api.go`:
- Around line 231-241: The API currently treats baseConfigFactory as optional
but UpdateWorkspaceBaseConfig requires it; update the API constructor (where API
is created) to either (A) install a sane default WorkspaceBaseConfigStoreFactory
when none is provided (so baseConfigFactory and baseConfigStore are always
non-nil), or (B) perform a fail-fast validation in the NewAPI/constructor that
checks a.baseConfigFactory (and/or a.baseConfigStore) and returns an error or
panics so the server cannot start without the factory; ensure you update
WithWorkspaceBaseConfigStoreFactory handling accordingly and adjust
requireBaseConfigManagement to reflect the new invariant.

---

Nitpick comments:
In `@internal/githubdispatch/tracker.go`:
- Around line 17-22: Tracker's methods (Upsert, Delete, List) lack a
context.Context parameter which prevents cancellation/deadline propagation;
update the Tracker interface to accept context.Context (e.g., Upsert(ctx
context.Context, t TrackedJob) error, Delete(ctx context.Context, id string)
error, List(ctx context.Context) ([]TrackedJob, error)), then update all
implementations of Tracker and all call sites to pass through the incoming
context; also add the context import where needed and ensure any file-based or
DB-backed implementations respect context for long-running operations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ca085f19-35d0-44ef-951f-44faf84df0c5

📥 Commits

Reviewing files that changed from the base of the PR and between d482425 and bcff438.

📒 Files selected for processing (36)
  • internal/agentsnapshot/dispatch.go
  • internal/agentsnapshot/dispatch_test.go
  • internal/cmd/agent.go
  • internal/cmd/context.go
  • internal/cmd/license.go
  • internal/cmd/process/agent_stores.go
  • internal/cmd/process/dag_store.go
  • internal/cmd/process/scheduler.go
  • internal/cmd/upgrade.go
  • internal/engine/engine.go
  • internal/engine/run.go
  • internal/githubdispatch/tracker.go
  • internal/persis/file/agent_stores.go
  • internal/persis/file/dag_store.go
  • internal/persis/file/dagrun_store.go
  • internal/persis/file/proc_store.go
  • internal/persis/file/service_registry.go
  • internal/persis/file/service_stores.go
  • internal/persis/filegithubdispatch/store.go
  • internal/service/frontend/api/v1/api.go
  • internal/service/frontend/api/v1/base_config.go
  • internal/service/frontend/api/v1/dagruns.go
  • internal/service/frontend/api/v1/dagruns_edit_retry.go
  • internal/service/frontend/api/v1/dags.go
  • internal/service/frontend/server.go
  • internal/service/scheduler/dag_executor.go
  • internal/service/scheduler/dag_executor_internal_test.go
  • internal/service/scheduler/export_test.go
  • internal/service/scheduler/github_dispatch.go
  • internal/service/scheduler/scheduler.go
  • internal/service/worker/remote_handler.go
  • internal/service/worker/remote_handler_test.go
  • internal/test/helper.go
  • internal/test/proc.go
  • internal/test/scheduler.go
  • refactor_persis_layer.html
✅ Files skipped from review due to trivial changes (1)
  • refactor_persis_layer.html
🚧 Files skipped from review as they are similar to previous changes (12)
  • internal/persis/file/service_registry.go
  • internal/test/scheduler.go
  • internal/persis/file/proc_store.go
  • internal/service/worker/remote_handler_test.go
  • internal/cmd/process/dag_store.go
  • internal/engine/engine.go
  • internal/cmd/process/agent_stores.go
  • internal/persis/file/dag_store.go
  • internal/service/worker/remote_handler.go
  • internal/persis/file/dagrun_store.go
  • internal/cmd/agent.go
  • internal/test/helper.go

Comment thread internal/persis/file/agent_stores.go Resolved
Comment thread internal/persis/file/service_stores.go Resolved
Comment thread internal/service/frontend/api/v1/api.go Resolved
@yohamta0

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cubic-dev-ai

cubic-dev-ai Bot commented May 27, 2026

Copy link
Copy Markdown

You're iterating quickly on this pull request. To help protect your rate limits, cubic has paused automatic reviews on new pushes for now—when you're ready for another review, comment @cubic-dev-ai review.

@yohamta0
yohamta0 merged commit a2e4184 into main May 27, 2026
9 checks passed
@yohamta0
yohamta0 deleted the refactor-dagrun-persistence-compat branch May 27, 2026 10:50
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