Skip to content

engine: held leases stop re-reading the floor; one group commit for closing chats; clock leaves with its window (r7) - #2517

Merged
santoshkumarradha merged 5 commits into
factory/general-intakefrom
perf/r7-idle-quit
Nov 8, 2026
Merged

santoshkumarradha merged 5 commits into
factory/general-intakefrom
perf/r7-idle-quit

Conversation

@santoshkumarradha

@santoshkumarradha santoshkumarradha commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Engine findings from WorkAF live e2e round 7: idle CPU with held leases, slow quit, and a codeaf clock that outlived its engine.

Idle CPU

Idle engine CPU over 120 s. Setup: 86 jobs (84 of r7's final documents plus 2 native jobs whose step holds its lease), about 43 open job chats, 15 runner slots and a stub model. Measurement starts 200 s after the engine starts. Rig: r7rig.py (scratch).

linux/arm64 macOS (mac-studio)
before (1436ad765) 11.12% 24.09%
after (ef7953101) 1.78% 6.25%

macOS is still above the 5% bar. What remains in its steady profile is mostly file-status calls:

  • settleJobs' hydrated list every 5 s: 11%
  • each held job's flush re-reading its job: 10%
  • the presence beat

With 43 chats that each ran 15 tool calls, the same build reads 7.6%.

What changed:

  • A renewal wakes no pull. Each held lease rewrote leases.json every 2 s, which woke all 15 open pulls to re-list the floor. The root watch now compares lease.RenewalShape, the document without its heartbeat and expiry fields. Runner folders and events.jsonl no longer wake pulls either.
  • One floor reading shared by every slot. Desk.floorQueue keeps the sorted queue and re-reads only job files that changed. This replaces 15 ListSaved deep copies per change.
  • A job already held at its budget is not re-saved by every look. With a reply pending, each re-save woke every pull, so the floor never went quiet.
  • Beats settle less often. Lease heartbeats and presence beats settle the floor at most every 5 s. Pulls and reports still settle within 1 s; a 5 s window for every request had delayed Auto's publish.
  • Fewer repeated reads. thread.Read returns its last answer for a manager journal that is unchanged. liveMirrors lists the mirror folders once per change of them instead of globbing for every job chat's budget watch.
  • Profiling steady idle. CODEAF_DIAGNOSTIC_PROFILE_DELAY (1..3600 s) opens the developer profile window later, so a steady idle can be captured.

Quit

Not reproduced. The rig quits in 1.4–1.8 s, exit 0, before and after, on both hosts. That includes 42 chats with 15 tool calls each in separate checkouts. The cause of r7's 28–30 s is still unproven.

One real serialization is fixed: cellstore's group commit synced only the flushing chat's records while every other closing chat waited behind its single slot. Whoever holds the slot now syncs every chat's owed records, each path once per pass. A chat whose snapshot failed keeps its records owed and is told. Test: TestOneGroupCommitSavesEveryChatClosingAtOnce (48 chats).

Clock

Reproduced and fixed. Before, codeaf clock stayed alive while any window was open, including after its engine exited. It now leaves once the window that started it is gone and no run is in hand; any open window starts the next within half a minute. Test: TestAClockLeavesWithTheWindowThatStartedIt. On both hosts, no clock was left after the engine quit.

Tests

Deterministic tests cover each change:

  • TestARenewalWakesNoPullAndARealChangeWakesThemAll
  • TestSlotsWokenByOneChangeShareOneReadingOfIt
  • TestALookLeavesAJobAtItsBudgetAsItIsOnDisk
  • TestARunnersRequestsSettleTheFloorAtMostOnceASettleWindow
  • TestAnUnchangedJournalIsParsedOnceAndAnAppendedLineIsRead
  • TestAJobChatsHoldersListTheMirrorFoldersOncePerChangeOfThem
  • the group-commit and clock tests above
  • the diagprofile delay test

The full internal/factory/worker package also passes.

make pr-ready BASE=origin/factory/general-intake passed on ef7953101. The last commit only changes PERF.md. Change entry: docs/changes/unreleased/2517-r7-idle-holds-quit-clock.md.

🤖 Generated with Claude Code

santoshkumarradha and others added 5 commits November 8, 2026 10:41
…oup commit saves every closing chat; the clock leaves with its window (r7)

Idle (r7 finding 2): each held job's runner renews its lease every 2 s, which
rewrote leases.json, woke every open pull and, with a hold present, made all
15 slots list and deep-copy all 86 jobs once a second.

- the root watch compares lease.RenewalShape; a renewal, a runner's folders
  and events.jsonl wake no pull
- Desk.floorQueue: one reading of a change shared by every slot; unchanged
  jobs are reused, only changed files are read, sorted only on change;
  OverLimit reads it too
- a job already held at its budget with a reply pending is no longer saved
  unchanged on every look (a write loop)
- runner requests settle the floor every 5 s, not every 1 s
- CODEAF_DIAGNOSTIC_PROFILE_DELAY opens the profile window later

Quit (finding 7): cellstore's one flush slot synced only its own chat's
records while every other closing chat queued; whoever holds it now syncs
every chat's owed records once.

Clock (finding 9): codeaf clock leaves once the window that started it is
gone and nothing is in hand.
…changed manager journal is parsed once (r7)

The 5 s settle window delayed Auto's publish after its proof (worker
TestAutoPipelinePassesPlanGateAndPublishesWithoutUserApproval and
TestRecoveryAutoPipelineRepairsTransientFailureAndUpdatesTheSamePR timed
out). Only lease heartbeats and presence now wait five seconds; pulls and
reports settle within a second as before. thread.Read hands back the last
answer for a journal whose file and folder are unchanged.
…nce per change of them (r7)

Every open job chat's budget watch globbed workers/*/*/<job>.json every
few seconds; on macOS with 43 chats that was a fifth of the idle engine.
@santoshkumarradha
santoshkumarradha marked this pull request as ready for review November 8, 2026 16:40
@santoshkumarradha
santoshkumarradha merged commit 7650c2a into factory/general-intake Nov 8, 2026
1 check passed
@santoshkumarradha
santoshkumarradha deleted the perf/r7-idle-quit branch November 8, 2026 16:40
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.

1 participant