# R20: Hung settlement fallback and queued resize

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-27-58.717Z-before-R20`. After run: `/tmp/lead-24640-r1/capture/2026-10-27T14-27-58.710Z-after-R20`.

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.

Real thread settlement owns the hung short query. Same-thread resize is sent while it is in flight; another-thread resize completes before cleanup. Both versions timeout near 1s, retain the terminal, and release the same-thread resize. Completion is awaited via the settlement span.

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)) | Δ |
|---|---|---|---|
| Fallback query 1 | R20-seed, background; shim START 2026-10-27T14:28:08.854Z (mono 921877977041268); END 2026-10-27T14:28:08.867Z (mono 921877989972256); 12.9ms, exit 0; acquisition 2026-10-27T14:28:08.817Z→2026-10-27T14:28:08.875Z, 58.0ms | R20-seed, background; shim START 2026-10-27T14:28:08.593Z (mono 921877715245771); END 2026-10-27T14:28:08.612Z (mono 921877734648980); 19.4ms, exit 0; acquisition 2026-10-27T14:28:08.550Z→2026-10-27T14:28:08.619Z, 68.9ms | Same short timeout and lock release |
| Fallback query 2 | R20-slow, closeIdle; shim START 2026-10-27T14:28:08.976Z (mono 921878098265315); END 2026-10-27T14:28:09.948Z (mono 921879071059256); 972.8ms, signal 15; acquisition 2026-10-27T14:28:08.937Z→2026-10-27T14:28:09.955Z, 1017.9ms | R20-slow, closeIdle; shim START 2026-10-27T14:28:08.712Z (mono 921877835103464); END 2026-10-27T14:28:09.685Z (mono 921878808148026); 973.0ms, signal 15; acquisition 2026-10-27T14:28:08.675Z→2026-10-27T14:28:09.692Z, 1016.7ms | Measured duration/result above |
| Fallback query 3 | R20-slow, background; shim START 2026-10-27T14:28:10.933Z (mono 921880055883025); END 2026-10-27T14:28:11.891Z (mono 921881014131310); 958.2ms, signal 15; acquisition 2026-10-27T14:28:10.878Z→2026-10-27T14:28:11.903Z, 1024.4ms | — | Measured duration/result above |
| Background completion→next-query gaps | R20-seed→R20-slow: shim gap 2.066s, acquisition gap 2.003s | No subsequent background pair | Same short timeout and lock release |
| Terminal event 1 | 2026-10-27T14:28:08.884Z `fixture-thread-a/term-0` activity, seq=5, busy=True, label=`fixture-child` | 2026-10-27T14:28:08.623Z `fixture-thread-a/term-0` activity, seq=5, busy=True, label=`fixture-child` | Compare identity/sequence; subscriptions deduplicated |
| Terminal event 2 | 2026-10-27T14:28:08.886Z `fixture-thread-b/term-10` activity, seq=6, busy=True, label=`fixture-child` | 2026-10-27T14:28:08.625Z `fixture-thread-b/term-10` activity, seq=6, busy=True, label=`fixture-child` | Compare identity/sequence; subscriptions deduplicated |
| Terminal event 3 | 2026-10-27T14:28:12.009Z `fixture-thread-a/term-0` closed, seq=6 | 2026-10-27T14:28:09.899Z `fixture-thread-a/term-0` closed, seq=6 | Compare identity/sequence; subscriptions deduplicated |
| Terminal event 4 | 2026-10-27T14:28:12.013Z `fixture-thread-b/term-10` closed, seq=7 | 2026-10-27T14:28:09.903Z `fixture-thread-b/term-10` closed, seq=7 | Compare identity/sequence; subscriptions deduplicated |
| Peak all fallback queries | 1 | 1 | Independent closeIdle may overlap one background query |
| Peak background fallback queries | 1 | 1 | Independent closeIdle may overlap one background query |

## Before scripted milestones and final observation states
```json
[
  {
    "kind": "control",
    "utc": "2026-10-27T14:27:58.982Z",
    "mono_ns": "921868105215681",
    "ms": 260.047027,
    "phase": "R20",
    "mode": "hang",
    "delay": 0
  },
  {
    "kind": "server-ready",
    "utc": "2026-10-27T14:28:07.532Z",
    "mono_ns": "921876654297549",
    "ms": 8809.13148
  },
  {
    "kind": "rpc-connected",
    "utc": "2026-10-27T14:28:07.831Z",
    "mono_ns": "921876954160508",
    "ms": 9108.996332
  },
  {
    "kind": "control",
    "utc": "2026-10-27T14:28:08.027Z",
    "mono_ns": "921877149753013",
    "ms": 9304.583007,
    "phase": "R20-seed",
    "mode": "valid",
    "delay": 0
  },
  {
    "kind": "child-ready",
    "utc": "2026-10-27T14:28:08.221Z",
    "mono_ns": "921877344207614",
    "ms": 9499.037648,
    "threadId": "fixture-thread-a",
    "terminalId": "term-0",
    "childPid": 3413113,
    "marker": "READY_R20_0"
  },
  {
    "kind": "child-ready",
    "utc": "2026-10-27T14:28:08.339Z",
    "mono_ns": "921877462038726",
    "ms": 9616.86921,
    "threadId": "fixture-thread-b",
    "terminalId": "term-10",
    "childPid": 3413138,
    "marker": "READY_R20_10"
  },
  {
    "kind": "control",
    "utc": "2026-10-27T14:28:08.905Z",
    "mono_ns": "921878027372085",
    "ms": 10182.203562,
    "phase": "R20-slow",
    "mode": "hang",
    "delay": 0
  },
  {
    "kind": "settle-start",
    "utc": "2026-10-27T14:28:08.905Z",
    "mono_ns": "921878028057180",
    "ms": 10182.887855
  },
  {
    "kind": "other-thread-resize-complete",
    "utc": "2026-10-27T14:28:08.988Z",
    "mono_ns": "921878110942596",
    "ms": 10265.771879
  },
  {
    "kind": "settlement-cleanup-completed",
    "utc": "2026-10-27T14:28:10.983Z",
    "mono_ns": "921880105694618",
    "ms": 12260.526565,
    "threadId": "fixture-thread-a",
    "span": {
      "type": "effect-span",
      "name": "ThreadSettlementServiceV2.cleanUpSettledThread",
      "traceId": "6360b5d5a4441eb30e4a9416819cbc48",
      "spanId": "a7f11ac27bbd92aa",
      "parentSpanId": "92706f6dbb424ac0",
      "sampled": true,
      "kind": "internal",
      "startTimeUnixNano": "1793111288928018011",
      "endTimeUnixNano": "1793111289956012965",
      "durationMs": 1027.994954,
      "attributes": {},
      "events": [
        {
          "name": "[\n  \"failed to close idle terminals\",\n  {\n    \"threadId\": \"fixture-thread-a\",\n    \"error\": \"Failed to inspect terminal subprocesses with ps (timed out)\"\n  }\n]",
          "timeUnixNano": "1793111289955995111",
          "attributes": {
            "effect.fiberId": 6818,
            "effect.logLevel": "WARN"
          }
        }
      ],
      "links": [],
      "exit": {
        "_tag": "Success"
      }
    }
  },
  {
    "kind": "same-thread-resize-complete",
    "utc": "2026-10-27T14:28:10.983Z",
    "mono_ns": "921880105806958",
    "ms": 12260.636672
  },
  {
    "kind": "scenario-complete",
    "utc": "2026-10-27T14:28:12.002Z",
    "mono_ns": "921881124938195",
    "ms": 13279.767889
  },
  {
    "kind": "cleanup-start",
    "utc": "2026-10-27T14:28:12.134Z",
    "mono_ns": "921881257028346",
    "ms": 13411.863339,
    "pids": [
      3410879,
      3410882,
      3413111,
      3413113,
      3413131,
      3413138
    ],
    "ptyPids": [
      3413111,
      3413113,
      3413131,
      3413138
    ]
  },
  {
    "kind": "cleanup-end",
    "utc": "2026-10-27T14:28:14.269Z",
    "mono_ns": "921883391570462",
    "ms": 15546.411186,
    "survivorsBeforeFinalKill": [],
    "remaining": []
  }
]
```
Metadata snapshots taken before and after driver cleanup:
```json
[
  {
    "kind": "state",
    "utc": "2026-10-27T14:28:12.002Z",
    "mono_ns": "921881124805697",
    "ms": 13279.638386,
    "terminals": [
      {
        "threadId": "fixture-thread-a",
        "terminalId": "term-0",
        "cwd": "/tmp/lead-24640-r1/capture/2026-10-27T14-27-58.717Z-before-R20",
        "worktreePath": null,
        "status": "running",
        "pid": 3413111,
        "exitCode": null,
        "exitSignal": null,
        "hasRunningSubprocess": true,
        "label": "fixture-child",
        "updatedAt": "2026-10-27T14:28:09.957Z"
      },
      {
        "threadId": "fixture-thread-b",
        "terminalId": "term-10",
        "cwd": "/tmp/lead-24640-r1/capture/2026-10-27T14-27-58.717Z-before-R20",
        "worktreePath": null,
        "status": "running",
        "pid": 3413131,
        "exitCode": null,
        "exitSignal": null,
        "hasRunningSubprocess": true,
        "label": "fixture-child",
        "updatedAt": "2026-10-27T14:28:08.986Z"
      }
    ]
  },
  {
    "kind": "state",
    "utc": "2026-10-27T14:28:12.115Z",
    "mono_ns": "921881238073628",
    "ms": 13392.905616,
    "terminals": []
  }
]
```

## After scripted milestones and final observation states
```json
[
  {
    "kind": "control",
    "utc": "2026-10-27T14:27:58.983Z",
    "mono_ns": "921868106592023",
    "ms": 270.024925,
    "phase": "R20",
    "mode": "hang",
    "delay": 0
  },
  {
    "kind": "server-ready",
    "utc": "2026-10-27T14:28:07.136Z",
    "mono_ns": "921876258938658",
    "ms": 8422.373364
  },
  {
    "kind": "rpc-connected",
    "utc": "2026-10-27T14:28:07.368Z",
    "mono_ns": "921876490821442",
    "ms": 8654.25776
  },
  {
    "kind": "control",
    "utc": "2026-10-27T14:28:07.989Z",
    "mono_ns": "921877111641890",
    "ms": 9275.073029,
    "phase": "R20-seed",
    "mode": "valid",
    "delay": 0
  },
  {
    "kind": "child-ready",
    "utc": "2026-10-27T14:28:08.296Z",
    "mono_ns": "921877419062325",
    "ms": 9582.493815,
    "threadId": "fixture-thread-a",
    "terminalId": "term-0",
    "childPid": 3413130,
    "marker": "READY_R20_0"
  },
  {
    "kind": "child-ready",
    "utc": "2026-10-27T14:28:08.378Z",
    "mono_ns": "921877500521215",
    "ms": 9663.953717,
    "threadId": "fixture-thread-b",
    "terminalId": "term-10",
    "childPid": 3413148,
    "marker": "READY_R20_10"
  },
  {
    "kind": "control",
    "utc": "2026-10-27T14:28:08.641Z",
    "mono_ns": "921877763356343",
    "ms": 9926.789746,
    "phase": "R20-slow",
    "mode": "hang",
    "delay": 0
  },
  {
    "kind": "settle-start",
    "utc": "2026-10-27T14:28:08.641Z",
    "mono_ns": "921877764144341",
    "ms": 9927.576352
  },
  {
    "kind": "other-thread-resize-complete",
    "utc": "2026-10-27T14:28:08.724Z",
    "mono_ns": "921877847093717",
    "ms": 10010.524115
  },
  {
    "kind": "settlement-cleanup-completed",
    "utc": "2026-10-27T14:28:09.791Z",
    "mono_ns": "921878913843042",
    "ms": 11077.275924,
    "threadId": "fixture-thread-a",
    "span": {
      "type": "effect-span",
      "name": "ThreadSettlementServiceV2.cleanUpSettledThread",
      "traceId": "6d610fcbb7c1598d1791f35aa5f16e4b",
      "spanId": "3c4b53e75f67485d",
      "parentSpanId": "0f5716cbfcb9c687",
      "sampled": true,
      "kind": "internal",
      "startTimeUnixNano": "1793111288672170935",
      "endTimeUnixNano": "1793111289692904909",
      "durationMs": 1020.733974,
      "attributes": {},
      "events": [
        {
          "name": "[\n  \"failed to close idle terminals\",\n  {\n    \"threadId\": \"fixture-thread-a\",\n    \"error\": \"Failed to inspect terminal subprocesses with ps (timed out)\"\n  }\n]",
          "timeUnixNano": "1793111289692882997",
          "attributes": {
            "effect.fiberId": 6806,
            "effect.logLevel": "WARN"
          }
        }
      ],
      "links": [],
      "exit": {
        "_tag": "Success"
      }
    }
  },
  {
    "kind": "same-thread-resize-complete",
    "utc": "2026-10-27T14:28:09.791Z",
    "mono_ns": "921878913943911",
    "ms": 11077.374659
  },
  {
    "kind": "scenario-complete",
    "utc": "2026-10-27T14:28:09.893Z",
    "mono_ns": "921879015203776",
    "ms": 11178.634554
  },
  {
    "kind": "cleanup-start",
    "utc": "2026-10-27T14:28:10.022Z",
    "mono_ns": "921879144770052",
    "ms": 11308.204086,
    "pids": [
      3410880,
      3410883,
      3413117,
      3413130,
      3413145,
      3413148
    ],
    "ptyPids": [
      3413117,
      3413130,
      3413145,
      3413148
    ]
  },
  {
    "kind": "cleanup-end",
    "utc": "2026-10-27T14:28:12.168Z",
    "mono_ns": "921881290198139",
    "ms": 13453.637474,
    "survivorsBeforeFinalKill": [],
    "remaining": []
  }
]
```
Metadata snapshots taken before and after driver cleanup:
```json
[
  {
    "kind": "state",
    "utc": "2026-10-27T14:28:09.892Z",
    "mono_ns": "921879015094391",
    "ms": 11178.526962,
    "terminals": [
      {
        "threadId": "fixture-thread-a",
        "terminalId": "term-0",
        "cwd": "/tmp/lead-24640-r1/capture/2026-10-27T14-27-58.710Z-after-R20",
        "worktreePath": null,
        "status": "running",
        "pid": 3413117,
        "exitCode": null,
        "exitSignal": null,
        "hasRunningSubprocess": true,
        "label": "fixture-child",
        "updatedAt": "2026-10-27T14:28:09.694Z"
      },
      {
        "threadId": "fixture-thread-b",
        "terminalId": "term-10",
        "cwd": "/tmp/lead-24640-r1/capture/2026-10-27T14-27-58.710Z-after-R20",
        "worktreePath": null,
        "status": "running",
        "pid": 3413145,
        "exitCode": null,
        "exitSignal": null,
        "hasRunningSubprocess": true,
        "label": "fixture-child",
        "updatedAt": "2026-10-27T14:28:08.723Z"
      }
    ]
  },
  {
    "kind": "state",
    "utc": "2026-10-27T14:28:10.004Z",
    "mono_ns": "921879126300334",
    "ms": 11289.732666,
    "terminals": []
  }
]
```

## Behaviour difference
Same short timeout and lock release
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.