Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): skip history reads for ineligible idle compaction #23929

Mergedazogz(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/23929/headmerged by maria-rcks View on GitHub

Problem

Every completed run triggers IdleCompactionService.compactWhenDue. It currently loads full run, provider-thread, provider-turn, request and context-transfer history before checking the idle-compaction mode and provider eligibility. Thus onReturn, off, disabled providers, and non-Claude providers can do expensive history reads for work that will immediately be skipped.

During investigation of intermittent reconnects, backend traces showed approximately 20-second writer transactions under this service. getThreadRecords performs the history read and decoding inside that transaction, delaying other database work including authentication.

Change

Read only the thread metadata first and check the resolved compaction mode, Claude driver, and provider/project enabled state before loading history. Handle configured custom instances and the unconfigured default Claude instance. Keep the existing post-read guard and the settings recheck after sleeping.

Scope and approval

This is a focused performance fix for an existing background check, under CONTRIBUTING.md's small, obvious-bug exception. Eligible compaction behavior stays the same. It is separate from #23926, which optimizes a pending-item query used by several readers.

Verification

  • Added service regression cases first: five failed and three passed against the original implementation, because ineligible completions still loaded history.
  • The final suite passes all 12 tests. It verifies zero history reads and zero dispatches for ineligible modes/providers/project settings; enabled default/custom Claude instances still read history and dispatch /compact when due. Completion is synchronized with a Deferred at the operation's span end, without sleeps or polling.
  • vp run check:changed passed formatting, lint, knip, GraphQL generation, server/scripts typechecks and the affected tests.
  • Independent read-only review approved the final patch. Tests use synthetic records and mocked services; no production state is used. End-to-end reconnect behavior and genuinely enabled compaction's large-history cost remain outside this validation.

Built with GPT-6 in Codex.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Approvability

      Verdict: Approved at d8db7bc

      Macroscope's review found this PR approvable — This is a narrowly scoped performance fix that avoids loading full thread history when idle compaction is already ineligible, while preserving the existing eligible compaction path. Regression tests cover the relevant provider, mode, and enablement combinations.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →
      Walkthrough

      IdleCompactionService now checks provider instance, compaction mode, and project enablement before reading thread history. Tests cover history reads and dispatches across eligible and ineligible configurations.

      Changes: Idle compaction eligibility

      Layer / File(s)Summary
      Pre-read eligibility checks
      apps/server/src/orchestration-v2/IdleCompactionService.ts
      The service checks the provider instance, resolved compaction mode, and project enablement before loading thread records.
      Eligibility test matrix
      apps/server/src/orchestration-v2/IdleCompaction.test.ts
      Tests compare history-read and dispatch counts across provider drivers, instance configuration, mode overrides, and project settings.
      Priority: Low

      Estimated code review effort: 2 (Simple) | ~12 minutes

      Change: Bug fix

      Suggested reviewers: t3dotgg

      Merge Risk: Minimal · up to 8aa16

      The change skips unnecessary history reads. No merge-blocking issue was identified.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title "fix(server): skip history reads for ineligible idle compaction" matches the main change. The service now checks compaction mode, Claude driver, and provider/project enablement before it loa…
      Description checkPassedThe description follows the template. It has Problem, Change, Scope and approval, and Verification sections. The Problem section explains the expensive history reads and the 20-second writer transacti…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Title check

      Explanation

      The title "fix(server): skip history reads for ineligible idle compaction" matches the main change. The service now checks compaction mode, Claude driver, and provider/project enablement before it loads thread history. The title uses a conventional commit format and names the affected component.

      Full details: Description check

      Explanation

      The description follows the template. It has Problem, Change, Scope and approval, and Verification sections. The Problem section explains the expensive history reads and the 20-second writer transactions. The Change section explains the gate ordering and the handling of custom and default Claude instances. The Scope section cites the small-fix exception in CONTRIBUTING.md and separates this work from #23926. The Verification section lists the regression cases, the 12-test suite, and the check:changed run. It also states what was not checked. The description does not link a triaged issue or a maintainer approval comment, so the scope claim depends on the small-obvious-bug exception. The template also asks for an agent footer, and the description includes one ("Built with GPT-6 in Codex.").

      Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Usage-based review receipt

      Note

      This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.

      Comment `@coderabbitai help` to get the list of available commands.
    4. Note

      Written by gpt-6.1-sol on behalf of Maria

      thanks @azogz. the early eligibility gate is the right fix, and your regression cases preserve the eligible compaction path. i kept your commit, merged current main, and pushed 125b55615223b47e53cac5cc5878d88aff0e8e4d to this branch.

      i shortened the test matrix by 54 lines without dropping any cases and removed the writer-lock comment because current main routes these reads through the sqlite reader. the final diff is two files: 14 service lines and 148 test lines. no behavior was dropped from the original diff.

      verification:

      • current main still reproduces the bug: seven regression cases fail because they load history. all 12 tests pass with the gate.
      • blacksmith vp run check:changed passed format, lint, both knip checks, graphql generation checks, server/scripts typechecks, and the focused tests.
      • runtime check used the actual service and sqlite-backed projection store against an isolated copy of this vm's database, containing one codex thread. a completed-run event produced the following sql trace for each of onReturn, off, and beforeCacheExpires:
      main:    history reads=1, sql statements=9, dispatches=0
      updated: history reads=0, sql statements=1, dispatches=0
      updated query: thread metadata only
      • two independent read-only reviews approved this exact head with no findings.

      unverified: the small database cannot establish large-history latency or reconnect improvements. actual claude execution and the client/provider completion path were not exercised. eligible default/custom claude dispatch is covered by the service tests. this is a server-only change with no ui changes.

      github ci run 40312967583 ended action_required before starting any jobs, so workflow approval/maintainer action is still needed. the other fork workflows have the same state. seven reported checks are green, but that does not include ci. coderabbit reported its review limit rather than reviewing the new head; no review bot was invoked manually.

    5. maria-rckscommented

      Note

      Written by gpt-6.1-sol on behalf of Maria

      Verified in a real dev environment

      verified the non-claude early-return path on unchanged head 125b55615223b47e53cac5cc5878d88aff0e8e4d in a disposable linux vm. no source changes or pushes were needed.

      • installed and ran github/main (9bc4138923) in a separate worktree first, then stopped its captured process group before starting the exact pr head. both used isolated, empty dev state with seeding disabled.
      • used the repository's playwright with /usr/bin/google-chrome. added a project pointing at a real git repository through the app, selected codex gpt-6.1-sol, and sent a prompt that read README.md through a real provider tool call. no mocks, fixtures, replay provider, or database-created conversations.
      • main reproduced the unnecessary history load after that real completion. the pr completed the same prompt and skipped it. existing server.trace.ndjson parent/child spans establish the sql executed specifically beneath IdleCompactionService.compactWhenDue; no instrumentation was added.
      main / codex / onReturn:           9 sql queries, including history
      pr   / codex / onReturn:           1 sql query, thread metadata only
      pr   / codex / off:                1 sql query, thread metadata only
      pr   / codex / beforeCacheExpires: 1 sql query, thread metadata only
      pr   / codex / after reconnect:    1 sql query, thread metadata only

      all four pr runs and their provider turns persisted as completed with codex/gpt-6.1-sol. no automatic /compact messages appeared. changed settings through the ui. follow-up turns retained the earlier repository result; reloading/reconnecting preserved history and allowed another real turn. the recording shows that last follow-up streaming and completing.

      blacksmith ran vp i && vp test run apps/server/src/orchestration-v2/IdleCompaction.test.ts: all 12 existing tests passed, including eligible default/custom claude cases. github's ci workflow still reports action_required, so this does not claim green ci.

      sql and runtime transcript

      main: real codex repository read completed before the unnecessary history queries

      pr: matching real codex repository read completed with only the metadata query

      pr: real codex follow-up after reconnect, preserving conversation context

      Not verified

      real claude compaction above 200,000 tokens, its cache-expiry timer, and disabled/custom claude instances end to end were not exercised; the live provider used here was codex. the existing service tests cover eligibility combinations, but they do not replace those live checks. native ios/android and electron clients, macos/windows, and tunnel/relay connections were not exercised on this linux web run. this small real conversation proves avoided history queries, not large-history latency or fewer intermittent reconnects.

      captures were inspected; uploaded video playback and seeking were checked in chrome. the inline recording is an animated gif because github renders external mp4 image embeds as broken images. verification used gpt-6.1-sol through the codex harness.

    6. maria-rcks merged thisf0ec739

    7. maria-rcks closed this

Sign in to join this conversation.