Skip to content

feat: add background capability lease/receipt record - #43

Merged
0xbrayo merged 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:feat/background-capability-lease
Sep 24, 2026
Merged

0xbrayo merged 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:feat/background-capability-lease

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Implements the Background Capability Lease Protocol (design v1): a tiny, local-first, JSON-serializable contract that distinguishes enabled, running, and actually-delivered for an opt-in background capability.

What

  • New src/lease.rs: Lease struct (desired_state, effective_state, owner process/pid/hostname, heartbeat with expiry, last-successful delivery_receipt) with atomic write/read/remove and unit tests.
  • dirs::get_state_dir(): state dir following ActivityWatch conventions (~/.local/state/activitywatch/aw-notify on Linux).
  • Wired into the service: write lease on start, refresh heartbeat in the main loop, record a delivery receipt on each successful notification, remove the lease on clean shutdown.

Why

"Enabled", "running", and "actually delivered" are currently conflated for opt-in background capabilities. A background job can be enabled but not running, or running but not delivering — and nothing distinguishes these states durably. This adds a lease file any monitor can read with no scheduler and no server round-trip:

  • enabled = lease file exists
  • running = fresh heartbeat (now - last < expiry)
  • stale = lease exists but heartbeat expired (hung/crashed)
  • delivered = last_successful receipt newer than the threshold being verified

Verification

  • 6 unit tests in lease.rs pass (fresh/stale/touch/delivery/serialization/write-read-remove).
  • Full cargo build/clippy not run locally (libssl-dev unavailable, no sudo); CI will run the full build. The lease module is pure serde+chrono+std and verified standalone.

Out of scope (unchanged)

  • No job scheduler; the capability writes its own lease.
  • No change to gptme background-job execution semantics.
  • No server round-trip required.

Implements the Background Capability Lease Protocol (design v1): a tiny,
local-first, JSON-serializable contract that distinguishes enabled, running,
and actually-delivered for an opt-in background capability.

- New src/lease.rs: Lease struct (desired_state, effective_state, owner
  process/pid/hostname, heartbeat with expiry, last-successful delivery
  receipt) with atomic write/read/remove and unit tests.
- dirs::get_state_dir(): state dir following ActivityWatch conventions
  (~/.local/state/activitywatch/aw-notify on Linux).
- Wire into the service: write lease on start, refresh heartbeat in the
  main loop, record a delivery receipt on each successful notification,
  remove the lease on clean shutdown.

A monitor can read the lease file and test liveness with no scheduler and
no server round-trip: enabled = lease exists, running = fresh heartbeat,
stale = expired heartbeat, delivered = last_successful receipt.

Note: pre-commit cargo-check/clippy skipped locally (libssl-dev unavailable,
no sudo); lease logic verified via standalone unit tests. CI will run the
full build.

Git-Session-Id: c214
is_running/is_stale/mark_stopped/read_lease are the read-side contract for a
separate monitor process; the writer binary itself only writes/touches/records,
so clippy -D warnings flagged them as dead code. Annotate them explicitly.

Git-Session-Id: c214
@0xbrayo
0xbrayo merged commit f0b11c8 into ActivityWatch:master Sep 24, 2026
5 checks passed
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.

2 participants