fix(projects): truthful cloud presence + project header state/actions (#912)

* fix(projects): tell the truth about cloud presence and separate header state

Box-runner heartbeats as cloud but could register bridge presence as local,
so /terminal said Cloud offline while the journal shipped work. Infer cloud
from box-* versions, force the channel in box-runner, and scope the terminal
honesty chip. Project header now shows listing/live as status, not peer links;
catalogue invite waits until kickoff/build is idle.

Co-authored-by: Cursor <cursoragent@cursor.com>

* chore(desktop): bump Fleet Runner to 0.8.33 for presence-channel fix

desktop/bridge-subscriber changed so box-* runners register as cloud; the
release-drift gate requires a version bump and changelog entry before merge.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
CatoandCursor authored and GitHub committed 2026-09-25 05:29:46 -07:00
1 parent 14cd5ae93c
commit f2f6206bcf
15 files changed
+204 -58

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "fleet-runner",
"version": "0.8.32",
"version": "0.8.33",
"description": "Fleet Runner — the Loki desktop agent runtime: owns the agent terminals on this computer for projects set to run here.",
"main": "./out/main/index.js",
"author": {
+23 -4
View File
@@ -78,6 +78,23 @@ function resolveBridgeUrl(): string {
return override.length > 0 ? override : BRIDGE_URL
}
/**
* Which presence channel this runner registers on the bridge.
*
* SSOT with the runtime-state heartbeat: a `box-*` version is the cloud
* builder; everything else is this computer. An explicit env overrides both
* so a mis-labelled unit can still be corrected without a code change.
*/
export function resolveRunnerPresenceChannel(): 'cloud' | 'local' {
const env = (process.env.LOKI_RUNNER_PRESENCE_CHANNEL ?? '').trim()
if (env === 'cloud' || env === 'local') return env
const version = (process.env.LOKI_RUNNER_VERSION ?? '').trim()
if (version === 'box' || version.startsWith('box-') || version.startsWith('box/')) {
return 'cloud'
}
return 'local'
}
// The bridge emits a `: ping` heartbeat every 25s (bridge/src/server.ts). If no
// bytes at all (data OR ping) arrive within this window, the socket is half-dead
// — laptop sleep, Wi-Fi flap, or a proxy idle-drop where no FIN/RST reaches us.
@@ -136,10 +153,12 @@ export function startBridgeSubscriber(
// open the same bridge without this flag and must NOT flip the badge.
// See docs/architecture/connection-presence.md.
sseUrl.searchParams.set('client', 'runner')
const presenceChannel = (process.env.LOKI_RUNNER_PRESENCE_CHANNEL ?? 'local').trim()
if (presenceChannel === 'cloud' || presenceChannel === 'local') {
sseUrl.searchParams.set('channel', presenceChannel)
}
// Channel must match the heartbeat's channel (runtime-state keys off
// LOKI_RUNNER_VERSION's box- prefix). Defaulting to "local" while the
// box-runner heartbeats as "cloud" made applyHeartbeatExpiry clear BOTH
// sides — /terminal then said "Cloud builder offline" while the journal
// still said connected and was shipping work. Env wins; otherwise infer.
sseUrl.searchParams.set('channel', resolveRunnerPresenceChannel())
// One connection attempt schedules at most one reconnect. Destroying a
// half-dead socket can fire both 'timeout' and 'error'/'end'; without this
+14
View File
@@ -1,3 +1,9 @@
---
created_date: 2026-06-15
last_modified_date: 2026-09-25
last_modified_summary: Document channel mismatch — box-runner must register bridge presence as cloud (same as box-* heartbeats), or /terminal reports Cloud offline while the box ships work.
---
# Connection-based runner presence
**Status:** rolling out (additive → cutover)
@@ -31,6 +37,14 @@ web /control reads runner_presence.connected (no timer)
- **Online = an open runner→bridge connection.** Not a heartbeat age.
- The browser also connects to the bridge, so the runner tags itself
`?client=runner`; only runner connections move presence.
- **Channel must match the heartbeat.** The runtime-state pusher keys the
snapshot row by `isCloudRunnerVersion(LOKI_RUNNER_VERSION)` (`box-*` →
`cloud`). The bridge SSE must use the same channel (`?channel=cloud|local`).
`resolveRunnerPresenceChannel()` infers cloud from a `box-*` version when
`LOKI_RUNNER_PRESENCE_CHANNEL` is unset; `scripts/box-runner.ts` also forces
cloud. If connection says `local` and heartbeats say `cloud`,
`applyHeartbeatExpiry` clears both — `/terminal` then shows "Cloud builder
offline" while the journal still says connected and is shipping work.
- Reconnect-safe via a connection **count** (multiple machines / brief overlaps).
- **Bridge boot resets all counts to 0** — a fresh bridge holds no connections,
so any stale `connected=true` from a crash is cleared on the next deploy.
+7
View File
@@ -51,6 +51,13 @@ const VERSION = boxRunnerVersion();
// The pusher reports whatever this env holds (lazily) — publish the derived
// version so the heartbeat and Settings agree with the log line below.
process.env.LOKI_RUNNER_VERSION = VERSION;
// Bridge presence must register as cloud. The systemd unit sets this too, but
// deploy syncs code without rewriting the unit — if the env is missing, a
// default of "local" in bridge-subscriber made /terminal say the cloud builder
// was offline while this process was the one shipping the work.
if (!process.env.LOKI_RUNNER_PRESENCE_CHANNEL?.trim()) {
process.env.LOKI_RUNNER_PRESENCE_CHANNEL = "cloud";
}
const WEB = (process.env.LOKI_WEB_URL || "").trim() || APP_URL;
function log(msg: string): void {
+9
View File
@@ -71,5 +71,14 @@ ok(
"a project with no live URL is still asked — 'being built' belongs in the catalogue",
);
ok(
!shouldInviteToPublicCatalogue({ ...eligible, buildBusy: true }),
"kickoff or an active build: catalogue ask waits until the work path is idle",
);
ok(
shouldInviteToPublicCatalogue({ ...eligible, buildBusy: false }),
"buildBusy false is the same as omitted — still asked",
);
console.log(`${pass} passed, ${fail} failed`);
process.exit(fail === 0 ? 0 : 1);
+48
View File
@@ -0,0 +1,48 @@
/**
* Bridge presence channel must match the runtime-state heartbeat channel.
* A box-* version that registered as "local" made /terminal say Cloud offline
* while the box-runner was shipping.
*
* Run: npx tsx scripts/test/runner-presence-channel.ts
*/
import assert from "node:assert/strict";
import { resolveRunnerPresenceChannel } from "../../desktop/src/main/bridge-subscriber";
const savedPresence = process.env.LOKI_RUNNER_PRESENCE_CHANNEL;
const savedVersion = process.env.LOKI_RUNNER_VERSION;
function withEnv(env: { presence?: string; version?: string }, fn: () => void): void {
if (env.presence === undefined) delete process.env.LOKI_RUNNER_PRESENCE_CHANNEL;
else process.env.LOKI_RUNNER_PRESENCE_CHANNEL = env.presence;
if (env.version === undefined) delete process.env.LOKI_RUNNER_VERSION;
else process.env.LOKI_RUNNER_VERSION = env.version;
try {
fn();
} finally {
if (savedPresence === undefined) delete process.env.LOKI_RUNNER_PRESENCE_CHANNEL;
else process.env.LOKI_RUNNER_PRESENCE_CHANNEL = savedPresence;
if (savedVersion === undefined) delete process.env.LOKI_RUNNER_VERSION;
else process.env.LOKI_RUNNER_VERSION = savedVersion;
}
}
withEnv({ version: "box-0.8.31" }, () => {
assert.equal(resolveRunnerPresenceChannel(), "cloud", "box-* version → cloud");
});
withEnv({ version: "box" }, () => {
assert.equal(resolveRunnerPresenceChannel(), "cloud", "bare box → cloud");
});
withEnv({ version: "0.8.31" }, () => {
assert.equal(resolveRunnerPresenceChannel(), "local", "desktop semver → local");
});
withEnv({ version: "dev" }, () => {
assert.equal(resolveRunnerPresenceChannel(), "local", "dev desktop → local");
});
withEnv({ presence: "cloud", version: "0.8.31" }, () => {
assert.equal(resolveRunnerPresenceChannel(), "cloud", "explicit env wins over version");
});
withEnv({ presence: "local", version: "box-0.8.31" }, () => {
assert.equal(resolveRunnerPresenceChannel(), "local", "explicit local wins over box-");
});
console.log("✓ runner-presence-channel");
@@ -83,7 +83,7 @@ export function ProjectBuildStatus({
}
case "queued": {
headline = "Starting up";
detail = `Sent ${timeAgo(status.sinceMs)}. An agent picks it up within a few minutes.`;
detail = `Sent ${timeAgo(status.sinceMs)}. Waiting for a builder to claim it — watch Terminal or Control.`;
action = (
<Link
href={fleetSurfaceHref("control", workspaceKey)}
@@ -12,7 +12,9 @@
// rule that matters: featuring never overrides consent. The showcase query is
// consent AND featured (db/queries/public-visibility.ts), and the API refuses
// to feature a project whose owner has not listed it — so this only renders
// once consent exists, and says why when it does not.
// once consent exists. Until then this control is absent — listing state lives
// in the project header status line, not as a second ghost "Not listed" peer
// of "List publicly".
//
// Only the site operator sees it at all; the API enforces the same thing, so
// hiding it is an affordance rather than the control.
@@ -40,17 +42,11 @@ export function ProjectFeatureToggle({
const [error, setError] = useState<string | null>(null);
// Nothing to curate until the owner has opted in. Saying so beats a control
// that looks available and answers 404.
// that looks available and answers 404 — but it is STATE, not an action, so
// it must not sit in the action row next to "List publicly" as a second
// ghost control that looks clickable. The listing toggle already says that.
if (!listedPublicly) {
return (
<span
className="ui-btn-ghost min-h-11 gap-1.5 opacity-60"
title="The owner has not listed this project publicly, so it cannot be featured. Consent comes first."
>
<Star className="h-4 w-4" aria-hidden="true" />
Not listed
</span>
);
return null;
}
async function toggle() {
@@ -60,8 +60,10 @@ export function ProjectPublicListingToggle({
onClick={toggle}
disabled={saving}
className="ui-btn-ghost min-h-11 gap-1.5"
// Says what is true now and what a click will do — the button is both the
// state and the decision, and a reader must not have to guess which.
// Action label is always the verb for what a click does. The current
// listing STATE lives in the header status line (ProjectWorkspaceView),
// not in this button — "Not listed" / "Listed publicly" dressed as
// peers of "Repository" and "Share" made state look like another link.
title={
error
? `Could not save: ${error}`
@@ -76,7 +78,7 @@ export function ProjectPublicListingToggle({
) : (
<Globe className={listed ? "h-4 w-4 text-accent-text" : "h-4 w-4"} aria-hidden="true" />
)}
{listed ? "Listed publicly" : "List publicly"}
{listed ? "Unlist from catalogue" : "List publicly"}
</button>
);
}
@@ -87,15 +87,6 @@ export function ProjectWorkspaceView({
commits: dossier.commits,
nowMs: dossier.builtAtMs,
});
// Ask once, per project, and only when there is something worth showing.
// The rule is in lib/ so it is testable without a browser or a database.
const inviteToCatalogue = shouldInviteToPublicCatalogue({
listedPublicly: userProject?.listedPublicly ?? false,
dismissedAt: userProject?.listingPromptDismissedAt ?? null,
isActive: userProject?.isActive ?? false,
gitUrl: userProject?.gitUrl ?? project.gitUrl ?? null,
readonly: dossier.readonly,
});
const showKickoff =
!dossier.readonly &&
@@ -107,6 +98,18 @@ export function ProjectWorkspaceView({
agentRunning: isBuildActive(buildStatus),
});
// Ask once, per project, and only when there is something worth showing.
// The rule is in lib/ so it is testable without a browser or a database.
// Kickoff / active build owns the page — catalogue consent waits.
const inviteToCatalogue = shouldInviteToPublicCatalogue({
listedPublicly: userProject?.listedPublicly ?? false,
dismissedAt: userProject?.listingPromptDismissedAt ?? null,
isActive: userProject?.isActive ?? false,
gitUrl: userProject?.gitUrl ?? project.gitUrl ?? null,
readonly: dossier.readonly,
buildBusy: showKickoff || isBuildActive(buildStatus),
});
/**
* WHAT IS WRONG, ABOVE WHAT IS HAPPENING.
*
@@ -212,16 +215,22 @@ export function ProjectWorkspaceView({
health={health}
readonly={dossier.readonly}
/>
{/* One visual tier only: the header offers destinations, not actions,
so everything here is a quiet ghost link. The page's real CTA
(Make it happen, in the build strip or the kickoff hero) lives in
the content flow below — five
identical secondary buttons up here made it invisible.
That was the stated rule but not the rendered one: LiveUrlField
drew a bordered secondary button and OrangeCatPublishButton an
unlabelled icon, so on a phone — where the row wraps to two lines
— it read as four unrelated controls rather than one set. Both
are ghost links with labels now. */}
{/* Status facts first, then destinations/actions. Listing used to
wear the same ghost-button clothes as Repository and Share, so
"Not listed" looked like a sixth link sitting next to its own
opposite. Deploy progress also lived inside Register site. */}
{!dossier.readonly && (
<p className="flex flex-wrap items-center gap-2 text-sm text-text-secondary">
<span className="ui-tag ui-tag-neutral">
{userProject?.listedPublicly ? "Listed in catalogue" : "Not in catalogue"}
</span>
{links.prodUrl ? (
<span className="ui-tag ui-tag-positive">Live site set</span>
) : userProject?.gitUrl || project.gitUrl ? (
<span className="ui-tag ui-tag-neutral">No live URL yet</span>
) : null}
</p>
)}
<div className="flex flex-wrap items-center gap-1.5">
<LiveUrlField
userProjectId={userProject?.id ?? null}
+12 -4
View File
@@ -48,7 +48,7 @@ export function RegisterSiteButton({
}
return (
<div className="inline-flex max-w-full flex-col gap-1">
<>
<button
type="button"
className="ui-btn-ghost min-h-11 gap-1.5"
@@ -63,8 +63,16 @@ export function RegisterSiteButton({
)}
{busy ? "Registering…" : "Register site"}
</button>
<SiteDeploymentStatus deployment={deployment} />
{error && <span className="ui-error text-xs">{error}</span>}
</div>
{/* Full-width status under the action row (basis-full in a flex-wrap
parent). Nesting the sentence + "Check deployment" inside the same
ghost control made Registering… read as a third peer of Repository
and Share. */}
{(deployment || error) && (
<div className="basis-full w-full max-w-xl space-y-1">
<SiteDeploymentStatus deployment={deployment} />
{error && <span className="ui-error text-xs">{error}</span>}
</div>
)}
</>
);
}
+23 -13
View File
@@ -366,19 +366,29 @@ export function TerminalSurface({
const [liveState, setLiveState] = useState<TerminalLiveState>("connecting");
const [geometry, setGeometry] = useState<PtyGeometry | null>(null);
const honesty = deriveExecutorHonestyLabel(
source === "machine"
? {
runnerConnected: presence.builderPresence?.local ?? presence.runnerConnected,
runtimeAvailable: false,
scope: "machine",
}
: {
runnerConnected: presence.runnerConnected,
runtimeAvailable: local || presence.runtimeAvailable,
scope: "cloud",
},
);
// Scope the chip to THIS source. Using any-builder `runnerConnected` on the
// cloud tab labelled a laptop-only online state as "Cloud builder online",
// and the inverse (null while presence loads) as "Cloud builder offline"
// while the box was shipping. Live tabs are the tie-break when channels
// disagree with presence — same rule as useTerminalTabs.offline.
const channelOnline =
source === "machine" ? presence.builderPresence?.local : presence.builderPresence?.cloud;
const honesty =
presence.builderPresence == null && tabs.length === 0
? null
: deriveExecutorHonestyLabel(
source === "machine"
? {
runnerConnected: channelOnline ?? (tabs.length > 0 ? true : false),
runtimeAvailable: false,
scope: "machine",
}
: {
runnerConnected: channelOnline ?? (tabs.length > 0 ? true : false),
runtimeAvailable: local || presence.runtimeAvailable,
scope: "cloud",
},
);
// Agent roster derived from context (already fetched above for tab resolution)
const agents = useMemo(
+8 -2
View File
@@ -33,14 +33,20 @@ export function useTerminalTabs(channel: BuilderChannel): TerminalTabsState {
unavailable?: { code: string; message: string };
}>(`/api/control/open-tabs?channel=${channel}`, 5000);
const presence = useBuilderPresence();
const tabs = data?.tabs ?? [];
const connected =
channel === "cloud" ? presence.builderPresence?.cloud : presence.builderPresence?.local;
// Presence unknown (still loading) is not offline — claiming "Cloud builder
// offline" while the first poll is in flight made the mode bar look stuck.
// Live tabs also win: a mis-tagged presence channel must not hide sessions
// that open-tabs already returned for this builder.
const offline = connected === false && tabs.length === 0;
return {
tabs: data?.tabs ?? [],
tabs,
loading,
gatedMessage: data?.unavailable?.message ?? null,
offline: connected === false,
offline,
presence,
};
}
+11
View File
@@ -28,6 +28,17 @@ export interface ReleaseEntry {
/** Newest first. */
export const FLEET_RUNNER_RELEASES: ReleaseEntry[] = [
{
version: "0.8.33",
tag: "fleet-runner-v0.8.33",
date: "2026-09-25T00:00:00Z",
highlights: [
"The cloud builder no longer reports offline while the box runner is connected and shipping work. Bridge presence now uses the same cloud/local channel as the heartbeat, so /terminal and the journal agree.",
],
breaking: [],
notes:
"A box-* runner that registered bridge presence as local made applyHeartbeatExpiry clear both channels. Presence channel is inferred from the runner version (or LOKI_RUNNER_PRESENCE_CHANNEL) so it matches the runtime-state heartbeat.",
},
{
version: "0.8.32",
tag: "fleet-runner-v0.8.32",
+7
View File
@@ -27,6 +27,12 @@ export type ListingInvitationInput = {
gitUrl: string | null;
/** Viewing someone else's project (org peer): never their decision to take. */
readonly: boolean;
/**
* Kickoff or an active build is on screen. Asking about the catalogue on top
* of "Make it happen" / "Building now" stacks a shop-window question on the
* work itself — ask after the build path is idle.
*/
buildBusy?: boolean;
};
/**
@@ -42,5 +48,6 @@ export function shouldInviteToPublicCatalogue(p: ListingInvitationInput): boolea
if (p.listedPublicly) return false;
if (p.dismissedAt) return false;
if (!p.isActive) return false;
if (p.buildBusy) return false;
return Boolean(p.gitUrl?.trim());
}