Repository navigation
fix(registry): surface timed-out compliance heartbeats to agent owners - #8319
Merged
Merged
Conversation
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]>
Contributor
There was a problem hiding this comment.
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.yamlandschemas/registry.tsare field-for-field consistent (no spec drift). heartbeat-timeout.ts(+208): pure module.describeHeartbeatTimeoutuses parsed ints only — no agent text reaches the Slack-DM title;projectHeartbeatTimeoutnull-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;notifyHeartbeatTimeoutnever throws; streak-lookup failure is caught (batch continuity tested). - Multi-tenant boundary:
getRecentHeartbeatAttemptsfilter (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.
This was referenced Oct 19, 2026
Closed
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #8268
Problem
A hosted heartbeat that runs out of time is recorded non-authoritative, so
run-publication.tscorrectly 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 —
isAuthoritativeComplianceRunandrun-publication.tsare not in this diff. What changes is visibility.heartbeat_timeouton 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.latest_attemptcannot see).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 (recordednot_completedunder aTimed 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_attemptIt 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.getRecentHeartbeatAttemptsreads 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_MSor per-storyboard budgets.perAgentBudgetMsand the job'sexecutionTimeoutMs(2h) are both already sized fromHOSTED_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, withjob.executingblocking re-entry throughout. Escalating only on evidence reaches the same agents one heartbeat later for a fraction of the throughput.timed_out, never on a hard-deadline abort. An agent that self-limits is slow; one that overshoots its own budget byHOSTED_COMPLIANCE_OVERRUN_MSis hung, and handing a hang 30 minutes treats it as the wrong problem.comply()only accepts a whole-runtimeout_ms(ComplyOptionsin@adcp/sdk). They need an SDK change inadcp-clientfirst.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:
owner_testnewest and permanently silence the owner's only push signal — or fire a completed one to spam it.latest_attemptandheartbeat_timeout.summary.Also from review:
consecutivesilently saturated at the lookback window (now reports "at least N" when capped); the worker now stops waiting on DM delivery after 15s, becauseslackPostRequesthas 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); aNaNguard on the new query'sLIMIT;.datetime()on the two timestamp fields.Two findings answered rather than fixed, both noted for follow-up:
resolveAgentOwnerUserIdsmatches the rawagent_urlwhile every helper inservices/agent-ownership.tscanonicalizes first, so DMs can miss owners whose profile stores the other spelling (relevant after fix(registry): match agent_url spec-exactly on the directory inverse-lookup #8314/fix(registry): surface declared agent_url spellings so the agents page can ask the directory #8316). Pre-existing and shared bynotifyComplianceChangeandnotifyVerificationChange— it fails closed (fewer recipients, never more) and changing recipient resolution for three notification types deserves its own PR.(agent_url, tested_at DESC) WHERE triggered_by = 'heartbeat'was suggested. The window is ≤20 rows behind the existingidx_compliance_runs_agent_time, andEXPLAINconfirms theLIMITsits under the window function, so the extra index isn't earning its write cost yet.Separately flagged, outside this diff:
notifyComplianceChangeinterpolates the raw DBheadlineinto a Slack DM title, and that headline isUnreachable: ${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 stayspassing, hard-deadline aborts surface, other incomplete runs don't, streak counts and clears, anonymous/cross-org seenullwith the key present, another org's credentialed heartbeat stays hidden.Each behaviour was mutation-checked: reverting the fix fails the corresponding test.
Local:
tsc --noEmitclean;npm run test:openapiclean; 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