Skip to content

fix(registry): surface timed-out compliance heartbeats to agent owners - #8319

Merged
bokelley merged 1 commit into
mainfrom
fix/8268-heartbeat-timeout-visibility
Oct 19, 2026
Merged

bokelley merged 1 commit into
mainfrom
fix/8268-heartbeat-timeout-visibility

Conversation

@bokelley

@bokelley bokelley commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #8268

Problem

A hosted heartbeat that runs out of time is recorded non-authoritative, so run-publication.ts correctly keeps it out of the published grade. On its own that makes a consistently slow agent invisible rather than visibly degraded: the card keeps rendering the last good run and nothing tells the owner their latest heartbeats are being dropped. Production saw 201 such runs across 13 agents in Sep 13–30, and still sees a few a day.

What changes

Publication semantics are untouched — isAuthoritativeComplianceRun and run-publication.ts are not in this diff. What changes is visibility.

  • heartbeat_timeout on the compliance card. While the newest scheduled heartbeat is a timeout, owners and operators get the timestamp, the wall-clock spent, the budget it was given, the storyboard coverage reached, the current streak, the published run it failed to refresh, and a ready-to-render sentence. Null for every other viewer; clears itself once a heartbeat completes.
  • The dashboard agent card renders that sentence — folded into the existing "Latest attempt" block when both describe the same run, standalone otherwise (the credential-free case latest_attempt cannot see).
  • The heartbeat job DMs the agent's owners when an agent starts timing out, with the same sentence. Edge-triggered rather than notificationDb.exists-deduped, so a later regression notifies again. Nothing goes to the shared channel: an audit-only timeout is not a public verdict change.

Both shapes of timeout count, because the owner-visible consequence is identical — a runner-reported completeness = 'timed_out', and a run the worker's hard deadline had to abort (recorded not_completed under a Timed out: headline). That second path previously surfaced nowhere at all, which is the same silent-stale-card failure the issue describes, at the point where the agent is worst behaved. It now also records the wall-clock it burned and the budget it was given, so its card entry can say "ran 912s against a 600s budget" instead of a bare timestamp.

Why not latest_attempt

It is scoped by triggered_org_id, which a heartbeat only sets when the agent has saved owner credentials — so credential-free agents, the ones most likely to go silent, saw nothing. getRecentHeartbeatAttempts reads the heartbeat stream instead, admitting unattributed runs to any owner of the URL while leaving runs charged to another organization's credentials with that organization (their coverage and duration would otherwise tell a co-claiming org that someone else holds working credentials). The projection carries only runner- and platform-generated scalars, so no agent response text reaches the card or the notification title.

Timeout policy — evaluated, deliberately unchanged

The issue asks whether heartbeats should use HOSTED_EXTENDED_COMPLIANCE_TIMEOUT_MS or per-storyboard budgets.

  • The escalation already exists and is unchanged: a slow agent gets the extended budget on its next heartbeat.
  • Lock/OOM risk is not the constraint. perAgentBudgetMs and the job's executionTimeoutMs (2h) are both already sized from HOSTED_EXTENDED_COMPLIANCE_TIMEOUT_MS, so neither the existing escalation nor an extended-by-default policy would need more lock headroom. The real cost of extended-by-default is cadence: a batch where every agent times out takes ~113 min at the extended budget against ~48 min at the full one, with job.executing blocking re-entry throughout. Escalating only on evidence reaches the same agents one heartbeat later for a fraction of the throughput.
  • Escalation stays keyed on a runner-reported timed_out, never on a hard-deadline abort. An agent that self-limits is slow; one that overshoots its own budget by HOSTED_COMPLIANCE_OVERRUN_MS is hung, and handing a hang 30 minutes treats it as the wrong problem.
  • Per-storyboard budgets are not implementable here — comply() only accepts a whole-run timeout_ms (ComplyOptions in @adcp/sdk). They need an SDK change in adcp-client first.

Expert review

code-reviewer, security-reviewer, and debugger (for the compliance-heartbeat/claim-logic owner perspective, per #8188's claim recovery). No ship-blockers; four real defects found and fixed before this PR opened:

Finding Fix
The DM's edge-trigger was cross-org suppressible. It read the newest run of any trigger and any org, so a co-claiming org could keep a timed-out owner_test newest and permanently silence the owner's only push signal — or fire a completed one to spam it. Decided from the heartbeat-only stream, which also gives the DM the card's streak count.
Duplicate card blocks on credentialed agents, where the same run populates both latest_attempt and heartbeat_timeout. Folded into one block; the standalone block renders only when they describe different runs.
Two copies of the wording — the card re-derived in JS what the server ships as summary. The card renders the server's sentence verbatim.
Cross-org inference leak from coverage/duration on credentialed heartbeats. Query admits unattributed runs to any owner, keeps org-charged runs with that org.

Also from review: consecutive silently saturated at the lookback window (now reports "at least N" when capped); the worker now stops waiting on DM delivery after 15s, because slackPostRequest has no fetch timeout and sleeps a minute per rate-limited retry while the agent still holds its execution fence and heartbeat claim (worst case measured at ~150 min, against a 300s shared pad); a NaN guard on the new query's LIMIT; .datetime() on the two timestamp fields.

Two findings answered rather than fixed, both noted for follow-up:

Separately flagged, outside this diff: notifyComplianceChange interpolates the raw DB headline into a Slack DM title, and that headline is Unreachable: ${errorMessage} with untruncated agent text — a pre-existing violation of the repo's "only sanitized strings in DM titles" rule. The new notifier does not do this.

Testing

  • server/tests/unit/compliance-heartbeat-timeout.test.ts — projection, streak counting, window capping, both timeout shapes, NaN/unparseable-input handling.
  • server/tests/unit/dashboard-heartbeat-timeout.test.ts — renders the server sentence, escapes it, folds into the attempt block without losing the diagnostics link.
  • server/tests/unit/compliance-heartbeat.test.ts — DM content, escalated-budget reporting, hard-deadline abort path, streak suppression, non-heartbeat runs ignored, fail-soft on notification and lookup failure, bounded wait on a hanging delivery.
  • server/tests/integration/registry-api-compliance-verdict-source.test.ts — owner sees the credential-free timeout while the public verdict stays passing, hard-deadline aborts surface, other incomplete runs don't, streak counts and clears, anonymous/cross-org see null with the key present, another org's credentialed heartbeat stays hidden.

Each behaviour was mutation-checked: reverting the fix fails the corresponding test.

Local: tsc --noEmit clean; npm run test:openapi clean; full pre-commit suite green (4601 server unit tests + typecheck). No hooks skipped — the storyboard matrix auto-skipped because no training-agent or compliance source changed.

🤖 Generated with Claude Code


Open workspace in Conductor

A hosted heartbeat that runs out of time is recorded non-authoritative, so
`run-publication.ts` correctly keeps it out of the published grade. On its
own that makes a consistently slow agent invisible rather than visibly
degraded: the card keeps rendering the last good run and nothing tells the
owner their latest heartbeats are being dropped. Production saw 201 such
runs across 13 agents in Sep 13-30 and still sees a few a day.

Publication is unchanged. What changes is visibility:

- `heartbeat_timeout` on the compliance card: while the newest scheduled
  heartbeat is a timeout, owners and operators get the timestamp, the
  wall-clock spent, the budget it was given, the storyboard coverage
  reached, the current streak, the published run it failed to refresh, and
  a ready-to-render sentence. Null for every other viewer, and it clears
  itself once a heartbeat completes.
- The dashboard agent card renders that sentence — folded into the
  "Latest attempt" block when both describe the same run, standalone
  otherwise, which is the credential-free case `latest_attempt` can't see.
- The heartbeat job DMs the agent's owners when an agent starts timing
  out, with the same sentence. Edge-triggered rather than
  `notificationDb.exists`-deduped so a later regression notifies again;
  nothing goes to the shared channel, since an audit-only timeout is not a
  public verdict change.

Both shapes of timeout count, because the owner-visible consequence is
identical: a runner-reported `completeness = 'timed_out'`, and a run the
worker's hard deadline had to abort (recorded `not_completed` under a
`Timed out:` headline). The aborted path now also records the wall-clock it
burned and the budget it was given, so its card entry can say "ran 912s
against a 600s budget" instead of a bare timestamp.

`latest_attempt` could not carry any of this: it is scoped by
`triggered_org_id`, which a heartbeat only sets when the agent has saved
owner credentials, so credential-free agents — the ones most likely to go
silent — saw nothing. `getRecentHeartbeatAttempts` reads the heartbeat
stream, admitting unattributed runs to any owner of the URL while leaving
runs charged to another organization's credentials with that organization;
their coverage and duration would otherwise tell a co-claiming org that
someone else holds working credentials. The projection carries only
runner- and platform-generated scalars, so no agent response text reaches
the card or the notification title.

The DM is decided from that same heartbeat-only stream. Reading the newest
run of any trigger would let a single `owner_test` — which a co-claiming
org can fire at will — either re-arm the edge for a duplicate DM or, if it
timed out itself, suppress the real first alert entirely. The worker also
stops waiting on delivery after 15s: `slackPostRequest` has no fetch
timeout and sleeps a minute per rate-limited retry, and this runs while the
agent still holds its execution fence and heartbeat claim.

Timeout policy, evaluated per the issue and left as is. `perAgentBudgetMs`
and the job's `executionTimeoutMs` are both already sized from
HOSTED_EXTENDED_COMPLIANCE_TIMEOUT_MS, so neither the existing escalation
nor an extended-by-default policy would need more lock headroom — the cost
of extended-by-default is cadence, not locking: a batch where every agent
times out takes ~113 minutes at the extended budget against ~48 at the full
one, with `job.executing` blocking re-entry throughout. Escalating only on
evidence reaches the same agents one heartbeat later for a fraction of the
throughput. Escalation stays keyed on a runner-reported `timed_out` and
never on a hard-deadline abort: an agent that self-limits is slow, one that
overshoots its own budget by the overrun allowance is hung, and handing a
hang 30 minutes treats it as the wrong problem. Per-storyboard budgets are
not available here — `comply()` only accepts a whole-run `timeout_ms` — and
need an SDK change first.

Closes #8268

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@aao-secretariat aao-secretariat Bot 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.

Ladon verdict: Approve

Approve — surfaces timed-out compliance heartbeats (adcp#8268) that were previously invisible.

No blocking, high, or medium findings. Key checks:

  • Platform/app change only — no static/schemas/source/** touched, so no changeset required; static/openapi/registry.yaml and schemas/registry.ts are field-for-field consistent (no spec drift).
  • heartbeat-timeout.ts (+208): pure module. describeHeartbeatTimeout uses parsed ints only — no agent text reaches the Slack-DM title; projectHeartbeatTimeout null-guards timestamps/durations/budgets against NaN (tested).
  • Operational readiness: owner DM bounded at 15s via Promise.race while the fence is held; delivery promise carries its own .catch; notifyHeartbeatTimeout never throws; streak-lookup failure is caught (batch continuity tested).
  • Multi-tenant boundary: getRecentHeartbeatAttempts filter (triggered_org_id IS NULL OR = $3) tested for anonymous, cross-org, and other-org-credentialed callers (all return null).
  • Edge-trigger suppression reads the heartbeat stream, not newest-of-any-trigger — co-claiming owner_test can't re-arm the edge.

high_risk is true only via (modified) entries on server/src/addie/** and server/src/routes/**, but the reviewer found no medium-or-higher concerns on those files, so the modifications are presumed safe (row 5 does not fire). gated_paths is false; no no-auto-approve team match; first review. No rows 1–8 fire → row 9 approve.

@bokelley
bokelley merged commit ea881e7 into main Oct 19, 2026
35 checks passed
@bokelley
bokelley deleted the fix/8268-heartbeat-timeout-visibility branch October 19, 2026 08:53
bokelley added a commit that referenced this pull request Oct 19, 2026
…ity key (#8325)

* fix(registry): resolve notification owners through the registry identity key

`resolveAgentOwnerUserIds` matched owners by the raw `agent_url` while the
registry identity key folds a non-root trailing slash (#7830): `/mcp` and
`/mcp/` are one agent. An owner profile holding the other spelling matched
nothing, so compliance regression/recovery, verification badge changes, the
heartbeat-timeout notice from #8319, and extended-outage alerts all failed
closed and silently — no DM, no error.

The notifiers now resolve recipients through every spelling that folds to the
agent's identity key. SQL may not canonicalize agent URLs, so the stored side
cannot be folded in the query; the new `registryAgentUrlKeySpellings` returns
the key, the key's path carrying the slash the fold removed, and the caller's
own spelling, each verified to key back to the same identity so a lookup can
never reach a second agent. Org scoping is unchanged, and `declared_url` is
not consulted — that is the spec-exact authorization spelling (#7829) and must
never decide identity.

`isAgentPublic` folds the same way: it gates the shared-channel post, and
leaving it raw would suppress the post for exactly the agents this reaches.
The owner lookup also gains `DISTINCT` (two orgs can co-claim one agent) and
an `ORDER BY`, so the `LIMIT 5` cap no longer truncates planner-dependently,
and its swallowed-error log moves from debug to warn — the callers read an
empty result as "nobody owns this", so a silent query failure is
indistinguishable from a correct silence.

Unit tests pin which spellings are asked for; an integration test runs the
real SQL against Postgres, including the negative case for a different agent
sharing the URL prefix. Both fail if the fold is removed.

Readers in `services/agent-ownership.ts`, `badge-issuance.ts`,
`verification-profile-db.ts` and `compliance-db.ts` have the same shape, as
does the admin `PUT /api/admin/member-profiles/:id` writer that still stores
`agents[].url` unkeyed. Those are authorization predicates and a writer, not
notification delivery, and are tracked in #8322 rather than widened here.

Closes #8321

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* test(notifications): match the owner-lookup spellings exactly, not by substring

CodeQL's `js/incomplete-url-substring-sanitization` fired on
`requestedAgentUrls(params).includes(URL)` in the #8321 unit test. The receiver
is a `string[]`, so `includes` was already an exact element match and the alert
is a false positive — but `some((url) => url === …)` says that unambiguously
and costs nothing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

Hosted heartbeats that exceed the 600 s budget are silently not published

1 participant