# R17: Settlement without eligible sessions

Before [e9236274a3](https://git.cafe/pingdotgg/t3code/commit/e9236274a3a6e0c731a7df4092db1e686f039068); after [63e44670dd](https://git.cafe/pingdotgg/t3code/commit/63e44670dd1d222cf63619d5e02415f2a9fd3bc2).

Before run: `/tmp/lead-24640-r1/capture/2026-10-27T14-25-51.321Z-before-R17`. After run: `/tmp/lead-24640-r1/capture/2026-10-27T14-25-51.331Z-after-R17`.

Environment: fs-31 Linux x86_64, Node v26.12.1; no viewport/theme/DPR/font scaling. Fresh per-run app databases. Same RPC fixture on each side. Native sidecars compiled with isolated Rust 1.99.1 where used.

Empty and exited-only settlement both await a completed ThreadSettlementServiceV2.cleanUpSettledThread trace span. Neither cleanup issues a table query or closure for ineligible sessions.

Wrapper timings exclude Python startup and stream drain. Acquisition timings use the real terminal.posixProcessTableSnapshot trace span. An idle gap is END→next START, never start-to-start. Before delay=min(1000×2^failureCount,60000)ms; after delay=min(max(1000×2^failureCount,4×measured fallback acquisition),60000)ms. Native-failed production ticks increment failureCount even when fallback succeeds; successful absent-supplier harness ticks reset it. Native requests and terminal processing can add overhead.

| Event | Before ([e9236274a3](https://git.cafe/pingdotgg/t3code/commit/e9236274a3a6e0c731a7df4092db1e686f039068)) | After ([63e44670dd](https://git.cafe/pingdotgg/t3code/commit/63e44670dd1d222cf63619d5e02415f2a9fd3bc2)) | Δ |
|---|---|---|---|
| Background completion→next-query gaps | No subsequent background pair | No subsequent background pair | Same no-query cleanup |
| Terminal event 1 | 2026-10-27T14:26:03.628Z `fixture-thread-a/term-0` exited, seq=3 | 2026-10-27T14:26:04.107Z `fixture-thread-a/term-0` exited, seq=3 | Compare identity/sequence; subscriptions deduplicated |
| Terminal event 2 | 2026-10-27T14:26:08.070Z `fixture-thread-a/term-0` closed, seq=4 | 2026-10-27T14:26:08.593Z `fixture-thread-a/term-0` closed, seq=4 | Compare identity/sequence; subscriptions deduplicated |
| Peak all fallback queries | 0 | 0 | Independent closeIdle may overlap one background query |
| Peak background fallback queries | 0 | 0 | Independent closeIdle may overlap one background query |

## Before scripted milestones and final observation states
```json
[
  {
    "kind": "control",
    "utc": "2026-10-27T14:25:51.550Z",
    "mono_ns": "921740673361630",
    "ms": 226.505636,
    "phase": "R17",
    "mode": "valid",
    "delay": 0
  },
  {
    "kind": "server-ready",
    "utc": "2026-10-27T14:26:00.724Z",
    "mono_ns": "921749847518128",
    "ms": 9400.668865
  },
  {
    "kind": "rpc-connected",
    "utc": "2026-10-27T14:26:00.892Z",
    "mono_ns": "921750015035537",
    "ms": 9568.182888
  },
  {
    "kind": "settle-empty",
    "utc": "2026-10-27T14:26:01.002Z",
    "mono_ns": "921750125130215",
    "ms": 9678.272407
  },
  {
    "kind": "settlement-cleanup-completed",
    "utc": "2026-10-27T14:26:01.974Z",
    "mono_ns": "921751097018739",
    "ms": 10650.162974,
    "threadId": "fixture-thread-a",
    "span": {
      "type": "effect-span",
      "name": "ThreadSettlementServiceV2.cleanUpSettledThread",
      "traceId": "04142abbabcd7e77161833156f602805",
      "spanId": "c263517884b47616",
      "parentSpanId": "c657a46796aab6a3",
      "sampled": true,
      "kind": "internal",
      "startTimeUnixNano": "1793111161039611547",
      "endTimeUnixNano": "1793111161042265056",
      "durationMs": 2.653509,
      "attributes": {},
      "events": [],
      "links": [],
      "exit": {
        "_tag": "Success"
      }
    }
  },
  {
    "kind": "control",
    "utc": "2026-10-27T14:26:05.147Z",
    "mono_ns": "921754270738257",
    "ms": 13823.881841,
    "phase": "R17-exited",
    "mode": "valid",
    "delay": 0
  },
  {
    "kind": "settlement-cleanup-completed",
    "utc": "2026-10-27T14:26:05.962Z",
    "mono_ns": "921755085774959",
    "ms": 14638.919445,
    "threadId": "fixture-thread-a",
    "span": {
      "type": "effect-span",
      "name": "ThreadSettlementServiceV2.cleanUpSettledThread",
      "traceId": "04142abbabcd7e77161833156f602805",
      "spanId": "c11867664ccb6140",
      "parentSpanId": "c657a46796aab6a3",
      "sampled": true,
      "kind": "internal",
      "startTimeUnixNano": "1793111165166409753",
      "endTimeUnixNano": "1793111165168578732",
      "durationMs": 2.168979,
      "attributes": {},
      "events": [],
      "links": [],
      "exit": {
        "_tag": "Success"
      }
    }
  },
  {
    "kind": "negative-window",
    "utc": "2026-10-27T14:26:07.964Z",
    "mono_ns": "921757087290338",
    "ms": 16640.434313,
    "queryCount": 0
  },
  {
    "kind": "scenario-complete",
    "utc": "2026-10-27T14:26:08.065Z",
    "mono_ns": "921757187924559",
    "ms": 16741.06644
  },
  {
    "kind": "cleanup-start",
    "utc": "2026-10-27T14:26:08.191Z",
    "mono_ns": "921757314330517",
    "ms": 16867.475724,
    "pids": [
      3400242,
      3400250
    ],
    "ptyPids": [
      3402224
    ]
  },
  {
    "kind": "cleanup-end",
    "utc": "2026-10-27T14:26:10.275Z",
    "mono_ns": "921759398628750",
    "ms": 18951.77557,
    "survivorsBeforeFinalKill": [],
    "remaining": []
  }
]
```
Metadata snapshots taken before and after driver cleanup:
```json
[
  {
    "kind": "state",
    "utc": "2026-10-27T14:26:03.577Z",
    "mono_ns": "921752700149030",
    "ms": 12253.293015,
    "terminals": []
  },
  {
    "kind": "state",
    "utc": "2026-10-27T14:26:08.064Z",
    "mono_ns": "921757187820835",
    "ms": 16740.96488,
    "terminals": [
      {
        "threadId": "fixture-thread-a",
        "terminalId": "term-0",
        "cwd": "/tmp/lead-24640-r1/capture/2026-10-27T14-25-51.321Z-before-R17",
        "worktreePath": null,
        "status": "exited",
        "pid": null,
        "exitCode": 0,
        "exitSignal": 0,
        "hasRunningSubprocess": false,
        "label": "Terminal 0",
        "updatedAt": "2026-10-27T14:26:03.623Z"
      }
    ]
  },
  {
    "kind": "state",
    "utc": "2026-10-27T14:26:08.172Z",
    "mono_ns": "921757294996708",
    "ms": 16848.140663,
    "terminals": []
  }
]
```

## After scripted milestones and final observation states
```json
[
  {
    "kind": "control",
    "utc": "2026-10-27T14:25:51.532Z",
    "mono_ns": "921740655604189",
    "ms": 198.920949,
    "phase": "R17",
    "mode": "valid",
    "delay": 0
  },
  {
    "kind": "server-ready",
    "utc": "2026-10-27T14:26:01.232Z",
    "mono_ns": "921750354907919",
    "ms": 9898.233405
  },
  {
    "kind": "rpc-connected",
    "utc": "2026-10-27T14:26:01.346Z",
    "mono_ns": "921750469153534",
    "ms": 10012.475845
  },
  {
    "kind": "settle-empty",
    "utc": "2026-10-27T14:26:01.444Z",
    "mono_ns": "921750567246659",
    "ms": 10110.561826
  },
  {
    "kind": "settlement-cleanup-completed",
    "utc": "2026-10-27T14:26:02.463Z",
    "mono_ns": "921751586256178",
    "ms": 11129.572587,
    "threadId": "fixture-thread-a",
    "span": {
      "type": "effect-span",
      "name": "ThreadSettlementServiceV2.cleanUpSettledThread",
      "traceId": "4499c2a26cecbc1b89a5d9c23b0a2be5",
      "spanId": "9f002285b8ef2928",
      "parentSpanId": "0bf2d4e731be4bf4",
      "sampled": true,
      "kind": "internal",
      "startTimeUnixNano": "1793111161472368124",
      "endTimeUnixNano": "1793111161474648993",
      "durationMs": 2.280869,
      "attributes": {},
      "events": [],
      "links": [],
      "exit": {
        "_tag": "Success"
      }
    }
  },
  {
    "kind": "control",
    "utc": "2026-10-27T14:26:05.628Z",
    "mono_ns": "921754750939956",
    "ms": 14294.256665,
    "phase": "R17-exited",
    "mode": "valid",
    "delay": 0
  },
  {
    "kind": "settlement-cleanup-completed",
    "utc": "2026-10-27T14:26:06.486Z",
    "mono_ns": "921755609758399",
    "ms": 15153.076531,
    "threadId": "fixture-thread-a",
    "span": {
      "type": "effect-span",
      "name": "ThreadSettlementServiceV2.cleanUpSettledThread",
      "traceId": "4499c2a26cecbc1b89a5d9c23b0a2be5",
      "spanId": "02adbe5a0dceba08",
      "parentSpanId": "0bf2d4e731be4bf4",
      "sampled": true,
      "kind": "internal",
      "startTimeUnixNano": "1793111165659355650",
      "endTimeUnixNano": "1793111165661609097",
      "durationMs": 2.253447,
      "attributes": {},
      "events": [],
      "links": [],
      "exit": {
        "_tag": "Success"
      }
    }
  },
  {
    "kind": "negative-window",
    "utc": "2026-10-27T14:26:08.487Z",
    "mono_ns": "921757610788027",
    "ms": 17154.103815,
    "queryCount": 0
  },
  {
    "kind": "scenario-complete",
    "utc": "2026-10-27T14:26:08.588Z",
    "mono_ns": "921757711476711",
    "ms": 17254.791457
  },
  {
    "kind": "cleanup-start",
    "utc": "2026-10-27T14:26:08.712Z",
    "mono_ns": "921757834964423",
    "ms": 17378.282506,
    "pids": [
      3400241,
      3400244
    ],
    "ptyPids": [
      3402226
    ]
  },
  {
    "kind": "cleanup-end",
    "utc": "2026-10-27T14:26:10.791Z",
    "mono_ns": "921759914196943",
    "ms": 19457.518753,
    "survivorsBeforeFinalKill": [],
    "remaining": []
  }
]
```
Metadata snapshots taken before and after driver cleanup:
```json
[
  {
    "kind": "state",
    "utc": "2026-10-27T14:26:04.066Z",
    "mono_ns": "921753188984004",
    "ms": 12732.299943,
    "terminals": []
  },
  {
    "kind": "state",
    "utc": "2026-10-27T14:26:08.588Z",
    "mono_ns": "921757711385830",
    "ms": 17254.701748,
    "terminals": [
      {
        "threadId": "fixture-thread-a",
        "terminalId": "term-0",
        "cwd": "/tmp/lead-24640-r1/capture/2026-10-27T14-25-51.331Z-after-R17",
        "worktreePath": null,
        "status": "exited",
        "pid": null,
        "exitCode": 0,
        "exitSignal": 0,
        "hasRunningSubprocess": false,
        "label": "Terminal 0",
        "updatedAt": "2026-10-27T14:26:04.104Z"
      }
    ]
  },
  {
    "kind": "state",
    "utc": "2026-10-27T14:26:08.694Z",
    "mono_ns": "921757817403461",
    "ms": 17360.718907,
    "terminals": []
  }
]
```

## Behaviour difference
Same no-query cleanup
Raw UTC/monotonic RPC, query, signal, metadata, warnings, and cleanup records are in the paired transcripts. PID, randomly generated script terminal suffix, database path, UTC, sequence batching, and scheduler jitter naturally vary between fresh runs. No visual comparison is applicable.