Skip to content

feat(background): auto-sync subscribed toolsets on deployment complete#2850

Open
simplesagar wants to merge 1 commit into
sagar/age-1377-auto-sync-sources-apifrom
sagar/age-1377-auto-sync-activity
Open

feat(background): auto-sync subscribed toolsets on deployment complete#2850
simplesagar wants to merge 1 commit into
sagar/age-1377-auto-sync-sources-apifrom
sagar/age-1377-auto-sync-activity

Conversation

@simplesagar
Copy link
Copy Markdown
Member

Summary

The engine for AGE-1377. When a deployment finishes processing, the new AutoSyncToolsets Temporal activity finds every toolset whose auto_sync_sources subscription overlaps the deployment's function sources, and appends any new tool URNs as a new toolset_versions row.

Stacks on the RPC PR (#2848); rebases to main once #2834 and #2848 land. Design: #2833.

What's in here

  • AutoSyncToolsets activity (server/internal/background/activities/auto_sync_toolsets.go):
    • Lists new function tool URNs for the deployment, buckets by urn.Source (the function slug).
    • Looks up subscribed toolsets via ListToolsetsByAutoSyncSource (introduced in feat(toolsets): expose auto_sync_sources on UpdateToolset RPC #2848).
    • For each subscriber: opens its own transaction, locks the toolset row `FOR UPDATE`, diffs URNs, inserts a new `toolset_versions` row when there are additions, emits an audit event. Never deletes.
    • Per-toolset failures don't block other extensions.
    • Idempotent on replay (a second run finds no new URNs).
  • Workflow wiring (server/internal/background/deployments.go): activity runs after `DeployFunctionRunners` succeeds, best-effort — a failure logs but does not fail the deployment.
  • Worker registration + `Activities` struct wiring.
  • SQL:
    • `toolsets.LockToolsetForAutoSync` row-lock query.
    • `functions.ListFunctionToolURNsByDeployment` join over `function_tool_definitions` + `deployments_functions`.
  • Audit logging: `ActionToolsetToolsAutoAdded` + `LogToolsetToolsAutoAdded`. Actor is the existing `user:system` sentinel (mirrors `background/triggers/app.go`). Metadata carries `deployment_id`, `sources`, `added_urns`, `toolset_version_after`.

Test plan

  • `go test ./internal/background/activities/ -run TestAutoSyncToolsets` — 5 scenarios pass:
    • empty deployment → no-op
    • subscribed toolset → extension + audit event
    • replay → idempotent
    • no subscribers → clean no-op
    • subscribed to a source not in this deployment → no-op
  • `mise build:server` clean
  • PR 2's `UpdateToolset` integration test still green (no regression)
  • Reviewer: confirm the workflow's "best-effort" semantics are the right call. If we'd rather have auto-sync failures bubble up as `finalStatus = "failed"`, that's a 2-line change.
  • Future PR 6 will add the broader E2E scenarios (multi-toolset, multi-source, cross-deployment increment) using full deployment fixtures.

🤖 Generated with Claude Code

Adds the AutoSyncToolsets Temporal activity that runs after a successful
function-runner deploy. For each toolset whose auto_sync_sources array
overlaps a function source touched by the deployment, the activity
appends any new tool URNs as a new toolset_versions row and emits a
toolset:tools_auto_added audit event. Never deletes URNs.

Each toolset extension runs in its own transaction with SELECT ... FOR
UPDATE on the toolset row so concurrent deployment-completed runs can't
race past the unique (toolset_id, version) constraint. A failure on one
toolset doesn't block extension of the others.

Activity is best-effort relative to the deployment: a failure logs but
does not transition the deployment to "failed" -- subscribers can still
be reconciled on the next push.

Supporting plumbing:
- toolsets.LockToolsetForAutoSync row-lock query.
- functions.ListFunctionToolURNsByDeployment query (joins
  function_tool_definitions with deployments_functions to surface the
  source slug needed for bucketing).
- audit.ActionToolsetToolsAutoAdded action + LogToolsetToolsAutoAdded
  event with deployment_id, sources, and added_urns in metadata.
- Wired into ProcessDeploymentWorkflow after DeployFunctionRunners.
- Registered with the Temporal worker.

Tests cover: empty deployment no-op, subscribed-toolset extension with
audit log, idempotent replay, no-subscribers no-op, subscribed-to-wrong-
source no-op.

Stacks on #2848. Refs AGE-1377.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@simplesagar simplesagar requested a review from a team as a code owner May 15, 2026 00:05
@vercel
Copy link
Copy Markdown

vercel Bot commented May 15, 2026

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

Project Deployment Actions Updated (UTC)
gram-docs-redirect Ready Ready Preview, Comment May 15, 2026 0:05am

Request Review

@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 15, 2026

AGE-1377

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 15, 2026

⚠️ No Changeset found

Latest commit: b22ab48

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

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