refactor(daemon): bind session authority to one lifetime

Merged
TH
4d ago
+1791-766

Summary

Implements ADR 0040 step 1. App open, record, and snapshot bind the admitted lease when they create a lifetime, removing in-place lease attachment. Script revisions commit under the lifetime lock, removing the late address reread. Their receipt carries forward to #4970. Replay checks attempt authority at lock acquisition, recording start, capture, snapshot publication, and cleanup.

Before / after

  • Leased open could adopt a live unleased session. It now returns LEASE_SESSION_MISMATCH before launch. Conflicting lease labels also refuse before launch.
  • A queued canceled replay could pin the session opened ahead of it. Cleanup now uses only the lifetime the active attempt acquired or published.
  • A timed-out replay could skip video finalization. It now keeps the original recording through the tail and returns its export when replay settles in that window.

Value

Raw sessionStore reads outside owners fell from 197 to 195. CI rejects increases. Direct store publishers fell from 3 to 1. The 459 net runtime and tooling lines cover three creation paths, replay locking and cancellation, and the CI ratchet.

Validation

At 5eb2f4c719, all 22 hosted checks passed or skipped by design. Targeted Vitest, eager closure, and the full local affected gate passed.

On Android 16, the branch CLI ran test recording-timeout.ad --record-video --json with timeout=15000 and wait 30000. Two runs stopped and exported before return. The initial stop returned UNKNOWN and cleanup exported a playable MP4 that the suite omitted. Suite JSON excerpt with relative artifact paths and the file check follows.

{
  "sha": "5eb2f4c719910b0e86ea30e0483acbae0f9066de",
  "cliExitCode": 1,
  "data": {
    "failed": 1,
    "tests": [
      {
        "status": "failed",
        "attempts": 1,
        "error": {
          "code": "COMMAND_FAILED",
          "message": "TIMEOUT after 15000ms",
          "details": {
            "reason": "timeout",
            "timeoutMs": 15000,
            "timeoutMode": "cooperative",
            "artifactPaths": [
              "attempt-1/replay-timing.ndjson",
              "attempt-1/recording.mp4",
              "attempt-1/recording.gesture-telemetry.json"
            ]
          }
        }
      }
    ]
  },
  "fileCheck": {
    "path": "attempt-1/recording.mp4",
    "bytes": 712717,
    "existedAtReturn": true
  }
}

Closes #4965


See it in action
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.