The daemon fallback can't run in an orb. Ghost sweep waits for the Amp PID to die (it never does before the pause), and processQueue returns before any item when no claude/codex/gemini is logged in, even the upload-only ones.
manager.go:620-629, session_finalize.go:2624-2687
4
ox doesn't know it's in an orb. handleEnd always hands off over a 100 ms IPC; session stop in delegated mode defers to the daemon.
Orb lifecycle (Amp docs, verified): an orb pauses at the later of agent idle 5 min and last interaction 20 min. Archiving pauses it at once. executor.keepAlive() holds it awake (billed).
Loading diagram...
Mermaid diagram
PR 1: this issue
A. runtime: new capability HostOutlivesAgent, false for AMP_ORB, CLAUDE_CODE_REMOTE, DEVIN_TASK_ID. It is not added to Reason(), so the daemon stays on (it clones the Ledger). AMP_ORB → LifetimeHours.
B. Session end is synchronous when !DaemonViable || !HostOutlivesAgent. handleEnd runs the same path as ox agent <id> session stop: sync upload, no summary prompt (no agent is left to answer it). session stop never picks delegated there. This also fixes Codex and Claude Code SessionEnd in orbs. An automatic end leaves no explicit-stop marker, so a later prime records again.
C. Amp gets a SessionEnd event:AGENT_ENV=amp ox agent hook SessionEnd resolves to the end phase. agentx maps only Amp's tool events, so resolvePhase will also consult local supplements. The marker is looked up by thread URL, falling back to the recording whose native session id ends in /threads/<id>.
D. ox-bridge, orbs only (gated on AMP_ORB):
after agent.end, schedule the end at max(end+2m, lastPrompt+17m);
cancel it on the thread's next agent.start;
when it fires, take a keepAlive lease (best effort), run ox agent hook SessionEnd in workspaceRoot with a 4 min timeout, then release the lease.
Laptops are unchanged.
Tests
Go, table-driven:
venue and capability probe;
resolvePhase(amp, SessionEnd);
handleEnd routing (sync when the host may not outlive the agent, IPC otherwise);
thread-id marker fallback;
stop-mode choice.
E2E, red-first: an orb-flagged SessionEnd lands the session on a bare remote.
bun test for the bridge timer with a fake PluginAPI: orb gating, deadline, cancel on agent.start, spawn args, keepAlive release on failure.
Decisions
#
Decision
Default
1
A prompt sent after the idle end (more than ~17 min since the last prompt)
Not recorded in PR 1; follow-up issue. Restarting needs the new recording to begin at the sidecar's current offset, or the continued session repeats earlier turns. Orb threads are mostly one-shot background work.
2
keepAlive lease only while the upload runs
Yes. A few seconds of orb billing per session, and the orb can't pause mid-push.
3
Daemon uploads without an LLM runner (the issue's fix #3)
Separate PR. It's a different subsystem (the agentwork queue), it also helps laptops, and orbs don't need it once B lands.
Risks
The bridge must load inside the orb. ~/.config/amp/plugins on a laptop doesn't reach orbs, so the orb setup has to run ox integrate install --amp. I can't run Amp here, so this PR needs a real-orb check before the docs recipe ships.
An archive pauses the orb at once. A session archived before its deadline stays in the paused orb until it wakes.