You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(hosted): a hosted agent with heartbeat on runs a turn on its schedule, hourly at most and 6 a day per owner (D244) - #3417
D244 dogfood finding 3. A hosted install acked every heartbeat with no run, so a self-serve user couldn't have a scheduled agent. Our Triage pilot needed an admin to switch it to native to get one.
Why it skipped
HOSTED_NATIVE_EVENT_TYPES came from #2224 (TASK-261, 10-15). That PR moved hosted agents onto the native runtime and kept the Durable Object's two event types, chat.mention and first_contact, as parity: "Other events are acked with no run and no model call." No Sam direction or ledger row chose it. D244 lists it as a bug.
What changes
heartbeat joins the hosted event types (hostedEngine.ts). A hosted install with heartbeat on (Settings → wake, per pod) now runs a real turn on its schedule.
Floor: one heartbeat run per install an hour. This holds whatever config.heartbeat.everyMinutes says; the scheduler allows 1. The check looks back 55 minutes, so dispatch jitter on an hourly schedule doesn't skip every other tick.
Cap: HOSTED_HEARTBEAT_RUNS_PER_DAY, default 6. That's 6 heartbeat runs per owner per UTC day, across all their hosted installs: a 4-hourly agent, or an hourly one for a morning. Setting 0 switches hosted heartbeats off.
Both counts fail closed. They come from AgentRun, and a failed count returns heartbeat_cap_check_failed, like the per-user ceiling. A held heartbeat is acked with no AgentRun, like any other hosted decline.
Unchanged. Heartbeats still count against the plan line (30 turns a day free, 200 pro) and the per-user ceiling. They run on the server-built hosted config: the deployment's native model (claude-haiku-5-5), the hosted tool set, and the same grant and refusal rules. Mentions never touch the heartbeat counts. The owner cap counts every heartbeat run stamped with the owner, so heartbeats from a non-hosted native install the owner has also count toward the 6. That makes it conservative.
Cost at the cap
The baseline is CTO's measure of native runs over 30 days (11-04): 1,467 runs, 18.8M tokens in and 1.17M out, and at most 31.9K per call.
Per run: about 12.8K in and 0.8K out. At Haiku 5.5's $0.10/$0.50 per MTok that's about $0.0017.
One owner at the cap: 6 a day × 30 days = 180 runs, about $0.30 a month. That's 12% of the baseline's run count.
The whole baseline is about $2.50 a month at list price. CTO's estimate was $3–6.
Route budget: the Haiku route's LiteLLM budget is $50 a month. After the baseline, it covers about 150 owners at the full heartbeat cap.
Worst case per run is the 200K-token run budget. That's at most $0.10 even if every token were output. Heartbeats can't raise an owner's ceiling, though, because they spend the same plan-line turns a mention does. The most an owner can run in a day doesn't change; heartbeats only let turns fire without a person.
Tests
nativeRuntimeService.hostedEngine.test.js adds seven tests. Six failed before this change; the other two guard against regressions.
A heartbeat runs a real turn, recorded as heartbeat for the owner.
A second heartbeat within the hour is held, and the floor query is per install over a 55-minute window.
The owner's cap: 5 today runs, 6 doesn't.
The env var sets the cap, and 0 is off.
A failed count fails closed.
A heartbeat still counts against the plan line.
A mention isn't touched by the heartbeat counts.
Every hosted, native, scheduler and heartbeat unit suite passes, 56 suites and 890 tests. tsc --noEmit is clean, and eslint reports no errors in the changed files.
Follow-up, not in this PR
Settings → wake still offers 15 and 30 minutes, and its "turns used" preview counts 1440 ÷ minutes. For a hosted agent the server now floors those to hourly and caps them at 6 a day, so the select and the preview overstate what will run. A small frontend change could start the hosted options at 60 and preview against the cap.
…edule (D244)
A hosted install acked every heartbeat with no run, kept from the Durable
Object's two event types (#2224), so a self-serve user couldn't have a
scheduled agent. It now runs, with two spend bounds of its own, both
counted from AgentRun and failing closed: one heartbeat run per install
an hour, and HOSTED_HEARTBEAT_RUNS_PER_DAY (default 6, 0 = off) across an
owner's hosted installs a day. Heartbeats still count against the plan
line and the per-user ceiling, and run on the hosted config (the
deployment's native model, Haiku), so grants and refusals are unchanged.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MDs9DRRdfD6THbfDgHSPZ5
This is the one review, run on a stronger model because the change touches wake and money.
Spend bounds hold. The run row is stamped trigger: 'heartbeat' and userId (nativeRuntimeService.ts:1746-1748, 2163-2170), so both counts in hostedHeartbeatHold see it. A decline returns before AgentRun.create, so no row is written. Count-then-run has no lock, but a duplicate can't get through. The in-process lane serialises runs of one install (agentEventService.ts:1819-1840). The scheduler runs under a cluster lease and skips an install with a pending heartbeat (schedulerService.ts:1509-1517).
No new grants. The hosted config sets no model, so the run uses NATIVE_RUNTIME_MODEL (Haiku). triggerTextIsHumanWritten excludes heartbeat, so the heartbeat cue and the digest frame can't unlock a fetch. wasDirectlyAddressed is false for a heartbeat. The tool set and outsider-grant narrowing don't depend on the trigger.
Wake path.dispatchAgentHeartbeats enqueues for hosted installs with heartbeat.enabled, and the settings PATCH writes it for hosted installs. runsInProcess includes hostedRunsNative with no type filter.
Tests. The new tests fail with the change reverted.
Not blocking. The owner cap also counts heartbeats from the owner's non-hosted native installs. That's conservative, and the PR body says so.
Locally, 56 suites and 890 tests pass, and tsc is clean. CI must be green at this head before merge.
Hosted heartbeat events can now start real runs. The runtime applies per-installation hourly and per-owner daily limits before execution. Tests cover successful runs, limit handling, count errors, plan limits, and mention events.
The hosted event set now includes heartbeat. The module defines a 60-minute minimum interval, five-minute floor slack, and a daily cap that defaults to six and accepts valid nonnegative integer overrides.
Heartbeat run checks backend/services/nativeRuntimeService.ts, backend/__tests__/unit/services/nativeRuntimeService.hostedEngine.test.js
Before selecting the run configuration, the runtime holds heartbeat runs that exceed installation or owner limits. Count-check errors fail with heartbeat_cap_check_failed. Tests cover execution, limits, configuration, and unaffected mention events.
sequenceDiagram
participant HostedHeartbeat
participant runAgent
participant hostedHeartbeatHold
participant AgentRunCounts
participant AgentRun
HostedHeartbeat->>runAgent: trigger heartbeat
runAgent->>hostedHeartbeatHold: check heartbeat limits
hostedHeartbeatHold->>AgentRunCounts: count installation and owner runs
AgentRunCounts-->>hostedHeartbeatHold: return counts or error
hostedHeartbeatHold-->>runAgent: return hold, failure, or null
runAgent->>AgentRun: create run for an eligible heartbeat
Loading
Possibly related issues
The hosted-heartbeat silence issue: this change allows eligible hosted heartbeats to create runs. Other observability requirements remain outside the change.
Merge Risk: Low · up to f9a1b
Hosted heartbeats now run real turns with hourly and daily limits. In rare concurrent cases, one owner's installations can slightly exceed the daily heartbeat cap. This is a bounded cost overshoot and does not block merge.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: hosted agents with heartbeat on now run scheduled turns, limited to hourly per install and 6 per owner per day. It matches the changeset (adds heartbeat to HOSTED_NATI…
Description check
The description explains the bug, which is that hosted installs acknowledged heartbeats with no run. It lists the change to HOSTED_NATIVE_EVENT_TYPES, the hourly per-install floor, the daily per-owner…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: hosted agents with heartbeat on now run scheduled turns, limited to hourly per install and 6 per owner per day. It matches the changeset (adds heartbeat to HOSTED_NATIVE_EVENT_TYPES, adds hourly floor and daily cap). The title is long, at 119 characters, but it is specific and accurate.
Full details: Description check
Explanation
The description explains the bug, which is that hosted installs acknowledged heartbeats with no run. It lists the change to HOSTED_NATIVE_EVENT_TYPES, the hourly per-install floor, the daily per-owner cap with HOSTED_HEARTBEAT_RUNS_PER_DAY, fail-closed counting, cost estimates, the tests added, and a follow-up item. It is directly related to the changeset.
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.
1922-1927: Major · Stability & Availability · Heavy lift
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Retry a heartbeat after a count failure instead of retiring its event.
If either count throws, this result makes agentEventService mark the heartbeat event failed. That state is terminal, so recovery of the count service cannot deliver the held heartbeat. Keep model execution blocked while the count is unavailable, but preserve a retryable wake. As per path instructions, a failed guard lookup must not lead to “a message or event nobody sees.” (raw.githubusercontent.com)
… previews its daily cap (Team-Commonly#3489)
* fix(settings): a hosted agent's heartbeat select starts at hourly and previews its daily cap
The hosted engine runs a heartbeat at most hourly per install and caps an
owner's hosted heartbeats a day (D244, Team-Commonly#3417), but Settings → Wake still
offered 15 and 30 minutes and previewed 1440 ÷ minutes. manage-settings now
returns hostedHeartbeat { minMinutes, runsPerDay } for a hosted install; the
panel offers intervals from the floor up, counts a stored shorter interval as
hourly, caps the preview at the daily cap, and says so in one line (en, zh-CN).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MDs9DRRdfD6THbfDgHSPZ5
* fix(settings): only an install the native engine runs is told it heartbeats
From the PR's review: the route treated every runtimeType 'hosted' row as
heartbeating, but the engine floors and caps (and runs) a hosted heartbeat
only when hostedRunsNative holds. A Durable Object install, a deprovisioned
native row or an unfinished migration runs none, and is now told runsPerDay 0,
so the panel previews 0 and says heartbeats aren't available. The English line
names "your" agents, matching zh-CN's 你.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MDs9DRRdfD6THbfDgHSPZ5
* fix(settings): hosted heartbeat bounds are per installation
From CodeRabbit on Team-Commonly#3489: runtimeType is a per-row field, so one identity's
installations need not agree. Each manage-settings row now carries its own
hostedHeartbeat, and the wake panel applies the hourly floor and the daily cap
to hosted rows only; a row that isn't hosted keeps every interval and counts
as it is set. The agent-level field stays for the explanatory line.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MDs9DRRdfD6THbfDgHSPZ5
---------
Co-authored-by: Claude Opus 5.5 <[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
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.
D244 dogfood finding 3. A hosted install acked every heartbeat with no run, so a self-serve user couldn't have a scheduled agent. Our Triage pilot needed an admin to switch it to native to get one.
Why it skipped
HOSTED_NATIVE_EVENT_TYPEScame from #2224 (TASK-261, 10-15). That PR moved hosted agents onto the native runtime and kept the Durable Object's two event types,chat.mentionandfirst_contact, as parity: "Other events are acked with no run and no model call." No Sam direction or ledger row chose it. D244 lists it as a bug.What changes
heartbeatjoins the hosted event types (hostedEngine.ts). A hosted install with heartbeat on (Settings → wake, per pod) now runs a real turn on its schedule.config.heartbeat.everyMinutessays; the scheduler allows 1. The check looks back 55 minutes, so dispatch jitter on an hourly schedule doesn't skip every other tick.HOSTED_HEARTBEAT_RUNS_PER_DAY, default 6. That's 6 heartbeat runs per owner per UTC day, across all their hosted installs: a 4-hourly agent, or an hourly one for a morning. Setting 0 switches hosted heartbeats off.heartbeat_cap_check_failed, like the per-user ceiling. A held heartbeat is acked with no AgentRun, like any other hosted decline.claude-haiku-5-5), the hosted tool set, and the same grant and refusal rules. Mentions never touch the heartbeat counts. The owner cap counts every heartbeat run stamped with the owner, so heartbeats from a non-hosted native install the owner has also count toward the 6. That makes it conservative.Cost at the cap
The baseline is CTO's measure of native runs over 30 days (11-04): 1,467 runs, 18.8M tokens in and 1.17M out, and at most 31.9K per call.
Tests
nativeRuntimeService.hostedEngine.test.jsadds seven tests. Six failed before this change; the other two guard against regressions.heartbeatfor the owner.Every hosted, native, scheduler and heartbeat unit suite passes, 56 suites and 890 tests.
tsc --noEmitis clean, and eslint reports no errors in the changed files.Follow-up, not in this PR
Settings → wake still offers 15 and 30 minutes, and its "turns used" preview counts 1440 ÷ minutes. For a hosted agent the server now floors those to hourly and caps them at 6 a day, so the select and the preview overstate what will run. A small frontend change could start the hosted options at 60 and preview against the cap.
🤖 Generated with Claude Code
https://claude.ai/code/session_01MDs9DRRdfD6THbfDgHSPZ5