Skip to content

AI-140 Standing roles: badged persistent threads with check-ins, polled triggers and per-thread compaction - #27

Merged
Supermaxman merged 3 commits into
t4from
feat/ai-140-roles
Nov 24, 2026
Merged

Supermaxman merged 3 commits into
t4from
feat/ai-140-roles

Conversation

@Supermaxman

@Supermaxman Supermaxman commented Nov 24, 2026 •

Copy link
Copy Markdown

AI-140. Standing roles: persistent, pinned, badged threads per client (like the release manager) that wake on check-ins and on polled triggers, plus a compaction point per thread for roles and release managers.

What changes

  • t4_roles table (migration 5) and t4/T4Roles.ts: list / save / delete / run, check-ins as scheduled tasks bound to the role thread (threadMode: continue), and the t4-roles job (every minute). The job runs each due trigger (bash -c <command> in the project's main checkout, 60 s cap, T4_PROBE_STATE / T4_PROBE_SINCE), dedupes items by id, gathers them for batchMinutes, and delivers one message when the thread is idle, outside quiet hours and under the daily cap. A trigger's first run only records what it sees. Three failures in a row send the thread one note (at most every 6 h).
  • Role threads are never settled, snoozed or archived (T4Ledger.standingRoleOf: settle refusal, t3_thread_organize, auto-archive), and roleOf gives them role role with roleKind / roleTitle in thread facts.
  • t4/threadCompaction.ts: a per-thread compaction point, rebuilt every minute from the roles and the release managers (releaseManager.compactAtTokens in t4-server.json, or a client override). Codex gets model_auto_compact_token_limit in the thread config; Claude gets autoCompactWindow = point + 33,000. usa-rs's release manager sent ~286k tokens with each of 3,172 requests (11-21..23) because Codex compacts only near its 475k window.
  • HTTP: GET/POST /api/t4/roles, /roles/:id/delete, /roles/:id/run, /roles/release-manager; /api/t4/state gains standingRoles.

Verified

  • pnpm run typecheck (effect-tsgo) clean.
  • New T4Roles.test.ts (baseline, dedupe, batching, message format, Pacific quiet hours across midnight, roleOf, compaction table) plus the t4 suites around it: 9 files, 237 tests pass. ClaudeAdapterV2.test.ts: 477 pass.
  • The t4 side (AI-Escape/t4) carries t4-probe, the catalog, the role skills and the dashboard's Roles tab; its probes were run against usa-rs's real Sentry, Linear, GitHub and AI-cost data.

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

…ed triggers and per-thread compaction

A role is a pinned thread per client that never settles, snoozes or archives
(like the release manager). It wakes on check-ins (scheduled tasks bound to
its thread) and on triggers: commands run every N minutes in the project's
main checkout that print new items (t4-probe). New items are deduped,
batched, held in quiet hours and capped per day, then delivered as one
message; nothing is spent while nothing is new.

Roles and release managers get a compaction point per thread (Codex
model_auto_compact_token_limit, Claude autoCompactWindow): usa-rs's release
manager carried ~286k tokens into each of 3,172 requests in two days.

API: GET/POST /api/t4/roles, /roles/:id/delete, /roles/:id/run,
/roles/release-manager; /api/t4/state gains standingRoles.
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XXL labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire — 5.0 KiB — 6.8 KiB ✅
Codex Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅
Codex Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅
Codex Live turn WebSocket decoded — 21.5 KiB — 24.4 KiB ✅
Codex Live turn messages — 1 — 8 ✅
Claude Total thread wire — 5.0 KiB — 6.8 KiB ✅
Claude Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅
Claude Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅
Claude Live turn WebSocket decoded — 21.9 KiB — 24.4 KiB ✅
Claude Live turn messages — 1 — 8 ✅

Other scenarios

No main baseline exists yet for these 64 scenario measurements.

All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded — 10.5 KiB — 12.7 KiB ✅
Codex short turn resume WebSocket messages — 2 — 2 ✅
Codex long turn running, cold open HTTP decoded — 281.7 KiB — 302.7 KiB ✅
Codex long turn running, cold open rows — 75 — 75 ✅
Codex long turn running, history page HTTP decoded — 92.4 KiB — 107.4 KiB ✅
Codex long turn running, history page rows — 75 — 75 ✅
Codex long turn finished, cold open HTTP decoded — 381.5 KiB — 410.2 KiB ✅
Codex long turn finished, cold open rows — 151 — 151 ✅
Codex long turn finished, socket cold open WebSocket decoded — 381.6 KiB — 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages — 2 — 2 ✅
Codex long turn finished, socket cold open rows — 151 — 151 ✅
Codex long turn finished, work page HTTP decoded — 186.2 KiB — 200.2 KiB ✅
Codex long turn finished, work page rows — 150 — 150 ✅
Codex idle thread resume WebSocket decoded — 65 B — 200 B ✅
Codex idle thread resume WebSocket messages — 1 — 1 ✅
Codex fleet shell snapshot HTTP decoded — 42.4 KiB — 53.7 KiB ✅
Codex fleet shell snapshot rows — 27 — 27 ✅
Codex fleet shell subscribe WebSocket decoded — 65 B — 200 B ✅
Codex fleet shell subscribe WebSocket messages — 1 — 1 ✅
Codex fleet shell resume check HTTP decoded — 18 B — 100 B ✅
Codex fleet shell resume check rows — 0 — 0 ✅
Codex stale shell reload HTTP decoded — 42.4 KiB — 53.7 KiB ✅
Codex stale shell reload rows — 27 — 27 ✅
Codex stale shell resume WebSocket decoded — 140 B — 400 B ✅
Codex stale shell resume WebSocket messages — 2 — 2 ✅
Codex stale todo list cold open HTTP decoded — 72.4 KiB — 83.0 KiB ✅
Codex stale todo list cold open rows — 75 — 75 ✅
Codex stale todo list cold open nodes — 2 — 4 ✅
Codex stale todo list cold open subagents — 2 — 4 ✅
Codex stale todo list cold open plans — 1 — 2 ✅
Codex stale todo list cold open providerTurns — 1 — 2 ✅
Codex stale todo list cold open checkpoints — 1 — 2 ✅
Claude short turn resume WebSocket decoded — 10.6 KiB — 12.7 KiB ✅
Claude short turn resume WebSocket messages — 2 — 2 ✅
Claude long turn running, cold open HTTP decoded — 283.3 KiB — 302.7 KiB ✅
Claude long turn running, cold open rows — 75 — 75 ✅
Claude long turn running, history page HTTP decoded — 93.4 KiB — 107.4 KiB ✅
Claude long turn running, history page rows — 75 — 75 ✅
Claude long turn finished, cold open HTTP decoded — 384.2 KiB — 410.2 KiB ✅
Claude long turn finished, cold open rows — 151 — 151 ✅
Claude long turn finished, socket cold open WebSocket decoded — 384.3 KiB — 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages — 2 — 2 ✅
Claude long turn finished, socket cold open rows — 151 — 151 ✅
Claude long turn finished, work page HTTP decoded — 188.1 KiB — 200.2 KiB ✅
Claude long turn finished, work page rows — 150 — 150 ✅
Claude idle thread resume WebSocket decoded — 66 B — 200 B ✅
Claude idle thread resume WebSocket messages — 1 — 1 ✅
Claude fleet shell snapshot HTTP decoded — 43.0 KiB — 53.7 KiB ✅
Claude fleet shell snapshot rows — 27 — 27 ✅
Claude fleet shell subscribe WebSocket decoded — 66 B — 200 B ✅
Claude fleet shell subscribe WebSocket messages — 1 — 1 ✅
Claude fleet shell resume check HTTP decoded — 18 B — 100 B ✅
Claude fleet shell resume check rows — 0 — 0 ✅
Claude stale shell reload HTTP decoded — 43.0 KiB — 53.7 KiB ✅
Claude stale shell reload rows — 27 — 27 ✅
Claude stale shell resume WebSocket decoded — 140 B — 400 B ✅
Claude stale shell resume WebSocket messages — 2 — 2 ✅
Claude stale todo list cold open HTTP decoded — 73.4 KiB — 83.0 KiB ✅
Claude stale todo list cold open rows — 75 — 75 ✅
Claude stale todo list cold open nodes — 2 — 4 ✅
Claude stale todo list cold open subagents — 2 — 4 ✅
Claude stale todo list cold open plans — 1 — 2 ✅
Claude stale todo list cold open providerTurns — 1 — 2 ✅
Claude stale todo list cold open checkpoints — 1 — 2 ✅

Baseline: unavailable · PR result: b3b6383 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@Supermaxman
Supermaxman merged commit fc71bbc into t4 Nov 24, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant