← Back to Pull requests

fix(effectors): recover failed deliveries in the API, not by heartbeat resync #637

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Dec 04, 2026 23:11 UTC
Author

Stacked on #632. First of three follow-up PRs from the 2026-12-04 owner decisions on effector delivery recovery (items D1–D4). They change the wire contract, so they land before rc1.

Owner decisions behind this PR: the heartbeat held-digest resync is dropped, because under a delivery backlog it makes every agent re-fetch everything every minute. The agent pulls effects only at startup (GET /api/agent/effects stays). Recovery belongs to the API: its retries, its 24h give-up, failed deliveries shown to users, and users re-sending them.

Changes (one commit per item)

  • D1, drop the heartbeat resync (e666770)

  • - Service.Heartbeat now records the heartbeat time, re-checks rule actions, enqueues verification while pending, and answers the delivery keys.
    - DesiredHeldDigest, HeldDigest, the stored held_digest and the NUL check on it are gone.
    - The response is {"effector": {"delivery_keys": [...]}}, with no resync.
  • D2, remove the admin resync (80ad9f1)

  • - POST /api/admin/agents/{id}/effector/resync is gone, with EffectorAdminHandler.Resync, Service.RequestResync, AgentEffector.ResyncRequested and the view's resync-requested.
    - The route used the admin:manage admin guard, so there was no authz manifest entry to drop.
  • D3, record the agent's permanent answers (06dd90c)

  • - Answers of 400, 413, 422 and 431 are recorded like the 24h give-up, in UndeliveredGeneration, UndeliveredAt and UndeliveredReason. The reason quotes the status, the agent's error code and its message, e.g. the agent refused the delivery (422, not retried): unknown-event: ….
    - These answers are not retried.
    - Users see them where they see the give-up: delivery-failed on the effect view and on a rule's effects list.
  • D4, re-send an undelivered generation in any state (f6ba189)

  • - POST /api/effects/{id}/redeliver on an effect whose latest generation is undelivered (UndeliveredGeneration == Generation) delivers that same generation again, in any state, without bumping it. This is how a lost cleared reaches the agent.
    - A successful delivery clears the undelivered record. All other cases keep today's semantics.
    - Both cases are documented on the route and on Machine.Redeliver.
    - Deliveries are River jobs unique by args, and River keeps the generation's completed job, which would swallow a re-send. DeliverArgs and its outbox payload therefore get resend, the re-send's time in Unix ns, omitted otherwise. Other deliveries keep their args and their uniqueness.
    - RedeliverAction, the redelivery after a params change, still always bumps.

    Mixed versions


  • An agent built from agent#180 still sends held_digest and reads resync. The heartbeat ignores held_digest like any unknown field (a NUL in it is no longer a 400), and a missing resync reads as false. A test sends that old body raw.

  • No migration: AgentEffector and AgentEffectorInstance are unreleased, so resync_requested and held_digest are simply dropped from the models. AutoMigrate leaves any column a dev database already has, which does no harm.
  • Companion change


  • After #640 (stacked on #639), agent#180 (at 33a652c) doesn't build against this SDK. #640 deletes the deprecated EffectorHeartbeat.HeldDigest and EffectorHeartbeatResponse.Resync (decision 1 below).

  • Even with them kept, agent#180's TestRuntime_RegisterFetchHeartbeat (which waits for a resync) and TestAgent_EffectorPluginEndToEnd (which asserts held_digest) fail against this PR.

  • The agent follow-up is a PR on top of agent#180. It removes the resync path and adds the recipient check from #638: refuse a body whose agent-id isn't the agent's own with 421 wrong-recipient, also on effector.verify.

  • Agent PR: _to be added once it exists_.
  • UI follow-up (D2 and D1): files that use what this removes


    UI stack #420–#437, at effectors/18-routes-navigation:
  • src/composables/effectors/useAgentEffector.ts (ui#422): resync() POSTs /api/admin/agents/{id}/effector/resync, plus isResyncing.

  • src/components/effectors/AgentEffectorTab.vue (ui#424): the Resync button and doResync.

  • src/components/effectors/__tests__/AgentEffectorTab.spec.ts (ui#424): the resync mock and the "resyncs" test.

  • src/types/effectors.ts (ui#420): resyncRequested: boolean on the agent effector view, and heldDigest?: string on the instance view (D1 drops held-digest).

  • Also, for D4: src/composables/effectors/useEffects.ts (ui#422) documents redeliver as "New generation with transition redelivered". That is no longer always true.
  • Decisions to confirm


    1. The SDK keeps two deprecated, wire-less fields. _Superseded by #640: both fields are deleted, and the agent follow-up above is the companion change._
    - The spec says to drop held_digest/resync from sdk/types, and also that an sdk/ change must stay buildable by the agent.
    - agent#180 references EffectorHeartbeat.HeldDigest and EffectorHeartbeatResponse.Resync. I kept both as // Deprecated: fields: HeldDigest is json:"-", and Resync is never marshalled or read and is hidden from swagger. Neither is on the wire, and the agent still builds.
    - They can be deleted once the agent's follow-up stops using them. If you'd rather delete them now, the agent's follow-up must land in the same step.
    2. A permanent refusal (D3) doesn't turn the agent's effector failing; the 24h give-up does. _#640 also records 401, 421, 410 and every other non-delivered answer, and turns the agent failing on 401 and 421._ The agent answered and takes other deliveries; the problem is that one delivery.

    Docs


    docs/effectors/*.md (wire-interface, operations, plugin-runtime and others) still describe the resync. Per the spec's grouping, that cleanup is D7, in the third PR of this follow-up. docs/ swagger is regenerated here.

    Verification (at f6ba189)


  • make swag: no diff.

  • make lint (golangci-lint v2.15.0): the 6 issues it reports are all pre-existing and identical on 80a604b (3× govet inline in workflows/, 3× SA1019 in worker risk tests). None are in touched code.

  • make test: passes.

  • go vet -tags integration ./...: passes.

  • Integration tests (Docker, postgres:17.5):

  • - ./internal/service/effector/ (all), ./internal/service/effects/ (all) and ./sdk/....
    - ./internal/api/handler/ -run 'TestEffect|TestHeartbeatApi|TestRules'.
    - ./internal/api/handler/oscal/ -run TestComponentChanges.
    - ./internal/service/worker/ -run 'TestEffectors|TestDomainEvents'.
  • Tests that fail before their fix:

  • - D1: TestEffectorHeartbeatHasNoResync (sdk/types).
    - D2: TestEffectorAdminHasNoResync.
    - D3: TestDelivererIntegration/TestPermanentRefusalsAreRecorded.
    - D4: TestEffectsApi/TestRedeliverUndelivered.

    Open questions for reviewers


    None.

    🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: gusfcarvalho Review duration: 683m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.52) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #637"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.7% · Safe to merge
    29.7%