Skip to content

feat: library / embedded mode#4355

Open
mnafees wants to merge 69 commits into
mainfrom
nafees/library-mode
Open

feat: library / embedded mode#4355
mnafees wants to merge 69 commits into
mainfrom
nafees/library-mode

Conversation

@mnafees

@mnafees mnafees commented Jul 5, 2026

Copy link
Copy Markdown
Member

Description

Adds the ability to spawn an embedded Hatchet engine from a Go SDK client simply by providing a URL to a PostgreSQL DB.

import (
    hatchet "github.com/hatchet-dev/hatchet/sdks/go"

    _ "github.com/hatchet-dev/hatchet/embed"
)

client, err := hatchet.NewClient(hatchet.WithEmbeddedPostgres(databaseURL))
if err != nil {
    return err
}
defer func() { _ = client.Close(context.Background()) }()

This runs a full Hatchet engine (no UI) in-process with the Go binary it is embedded in.

Partially resolves #3680

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

Changes have been:

  • Tested (unit, integration, or manually with steps specified)
  • Linted and formatted

🤖 AI Disclosure
  • I acknowledge that an LLM was used in the creation of this Pull Request, in accordance with Hatchet's AI_POLICY.md.
  • Details: [e.g. generating tests, writing docs]

@mnafees mnafees self-assigned this Jul 5, 2026
@vercel

vercel Bot commented Jul 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hatchet-docs Ready Ready Preview, Comment Jul 17, 2026 4:08pm

Request Review

@github-actions github-actions Bot added github_actions Pull requests that update GitHub Actions code sdk-go Related to the Go SDK labels Jul 5, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Optional test failure: The load-deadlock job failed on this PR (optimistic-scheduling=false). This check is non-mandatory and does not block merging, but may be worth investigating. View logs

Copilot AI left a comment

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.

Pull request overview

Adds a new in-process “embedded engine” mode via github.com/hatchet-dev/hatchet/embed, enabling Go applications to start a Hatchet engine (API + engine, no UI) inside the host process and obtain a configured Go SDK client. This advances the “library-only mode” effort from #3680 by providing a runnable embed package plus example binaries/scripts.

Changes:

  • Introduces the new embed package (startup, config options, keyset persistence, version resolution, fleet sizing) and an embed/example module with engine/worker/trigger/basic examples.
  • Refactors advisory-lock hashing into pkg/repository/sqlchelpers.AdvisoryLockKey and reuses it from pkg/repository/task.go.
  • Adds a local dev runner script for embedded mode and minor workflow/task tweaks.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
Taskfile.yaml Makes version bump tasks fail-fast via set -e.
pkg/repository/task.go Switches advisory-lock key hashing to shared helper.
pkg/repository/sqlchelpers/advisory.go Adds shared advisory-lock key hashing helper.
hack/dev/embed/run.sh Adds a local script to spin up multiple embedded engines/workers and trigger runs.
embed/version.go Resolves Hatchet module version from build info for embedded startup.
embed/options.go Adds embed configuration options and validation.
embed/keyset.go Persists/loads local encryption keysets with an advisory lock.
embed/fleet.go Checks active fleet size from DB to report “joining a fleet” status.
embed/example/worker/main.go Example worker process for embedded engines.
embed/example/trigger/main.go Example trigger tool to run workflows and summarize distribution.
embed/example/go.sum Dependency lockfile for the standalone example module.
embed/example/go.mod Standalone example module (with replace to local repo).
embed/example/engine/main.go Example embedded engine launcher that writes connection info to a file.
embed/example/basic/main.go Minimal single-process embedded engine + worker example.
embed/embed.go Core embedded instance lifecycle (migrations, seeding, token minting, goroutine startup, SDK client).
cmd/hatchet-engine/main.go Removes an outdated FIXME comment on Version.
.github/workflows/build.yml Normalizes quoting for python-version values.

Comment thread embed/embed.go Outdated
Comment thread embed/embed.go
Comment on lines +82 to +90
if err := os.Setenv("DATABASE_URL", cfg.postgresURL); err != nil {
return nil, fmt.Errorf("could not set DATABASE_URL: %w", err)
}
if cfg.adminEmail != "" {
_ = os.Setenv("ADMIN_EMAIL", cfg.adminEmail)
}
if cfg.adminPassword != "" {
_ = os.Setenv("ADMIN_PASSWORD", cfg.adminPassword)
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't like this since I think it makes sense to simply override these env vars from within the embed engine since we have config level options. Open to what you think @abelanger5

Comment thread embed/embed.go
Comment on lines +221 to +226
fleetStatus := "starting a new fleet"
if fleetSize > 0 {
fleetStatus = fmt.Sprintf("joining a fleet of %d engine(s)", fleetSize)
}
fmt.Fprintf(os.Stderr, "embed engine ready: api=%s grpc=%s | %s\n", apiURL, grpcBroadcast, fleetStatus)

Comment thread embed/options.go Outdated
Comment thread embed/options.go
Comment thread embed/options.go
Comment thread pkg/repository/sqlchelpers/advisory.go Outdated
Comment thread embed/embed.go Outdated
Comment on lines +225 to +226
fmt.Fprintf(os.Stderr, "embed engine ready: api=%s grpc=%s | %s\n", apiURL, grpcBroadcast, fleetStatus)

Comment thread embed/keyset.go

@mnafees mnafees Jul 13, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The idea here is to have a shared hatchet_embed.keyset DB table which keeps the autogenerated keyset information for such embedded instances and the user does not need to generate a keyset themselves.

When WithKeysets is provided we always use that instead of this path.

Can convert to required sqlc constructs once this approach is approved.

Comment thread embed/version.go

const hatchetModulePath = "github.com/hatchet-dev/hatchet"

func resolveVersion() (string, error) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Just resolving the library tagged version from the respective go.mod file

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Optional test failure: The load-deadlock job failed on this PR (optimistic-scheduling=true). This check is non-mandatory and does not block merging, but may be worth investigating. View logs

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Optional test failure: The load-deadlock job failed on this PR (optimistic-scheduling=true). This check is non-mandatory and does not block merging, but may be worth investigating. View logs

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Optional test failure: The load-deadlock job failed on this PR (optimistic-scheduling=false). This check is non-mandatory and does not block merging, but may be worth investigating. View logs

Comment thread cmd/hatchet-engine/main.go Outdated
Comment thread embed/example/trigger/main.go Outdated
Comment thread pkg/repository/task.go Outdated
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Optional test failure: The load-deadlock job failed on this PR (optimistic-scheduling=false). This check is non-mandatory and does not block merging, but may be worth investigating. View logs

Comment thread embed/example/trigger/main.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine Related to the core Hatchet engine github_actions Pull requests that update GitHub Actions code sdk-go Related to the Go SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Library-only mode and optional authentication

3 participants