Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): narrow watched reads and release settlement transactions #21628

Openjuliusmarmingewants to merge 1 commit intossh-relay-remote-14/shell-transport fromssh-relay-remote-14/background-readsopened View on GitHub

juliusmarmingecommented

The PR-watch sweep decoded every thread with links, including threads without a watch. Settlement reads also held the shared SQLite connection through schema decoding and background-work derivation.

Filter canonical watched threads before decoding, with SQL/memory parity, and opt in only the watch sweep. Keep full link lists, settled watches and ordinary unwatched-link synchronization. Read settlement rows in one transaction, then release it before decoding/deriving. Yield between measured 64-row batches in these two full-thread background reads.

Rebuilt from @maria-rcks’s #18979. Main already separates shell snapshot reads from decoding. Storage cleanup already uses its reader-worker path; the original compactPullRequests option does not exist here, so that old one-line change and its missing compaction prerequisites were omitted.

Verification: owning cases 38→39 across three existing files, 100 focused cases across eight files pass; scoped server types, changed-file lint and formatting pass. One independent Codex/Claude full-layer review round found no issues. Includes actual watch lifecycle/sync tests and a schema-invalid unwatched payload proving SQL exclusion happens before decode.

Isolated actual-store SQLite probe, 5,000 synthetic threads with eight links each and watches on 10%: watched reads returned 5,000→500 rows, taking 292–321 ms before versus 86–91 ms after over three warm samples. The first queued callback still waited about 69 ms after the change. Decode-only batches of 64 gave the callback a turn in 2.26–2.40 ms versus 9.39–32.17 ms without explicit batches. These are synthetic single-machine samples; no general latency, p95 or settlement-throughput claim. Initial synchronous SQLite work and a single large row can still stall the event loop.

A separate probe signalled the first candidate payload access and queued an insert through the same SQL connection. Before, the insert completed after all 5,000 decodes and read completion; after, it completed at 64 decodes while the read continued. Both persisted the insert and returned 5,000 candidates. Instrumentation lived only in an external scratch probe; no production seam or implementation-coupled committed test. Profiles and writer proof.

Backend behavior has no new visual control; service tests and actual SQLite output are the proof. Fixture has no provider/pending-item population. macOS, Windows, Electron desktop, iOS, Android and actual relay/tunnel deployments remain unverified.

Implementation and tests: Codex gpt-6.1-sol and gpt-6-astra in T3 Code; adversarial review: Codex gpt-6-sol and Claude claude-opus-5-5.

    1. juliusmarminge added labelsmacroscope-review

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs Human Approval

      Macroscope's review found this PR requires human approval — This production performance change adds an automatically enabled watched-only gate that skips full thread decoding and downstream sweep work for unwatched threads, alongside changes to transaction lifetime and scheduling. The behavior is narrowly implemented and tested, but the automatic processing gate warrants human review.

      No code changes detected at e586475. Prior analysis still applies.

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

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

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

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire—5.0 KiB—6.8 KiB✅
      CodexThread snapshot wire—3.8 KiB—4.9 KiB✅
      CodexLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      CodexLive turn WebSocket decoded—20.9 KiB—29.3 KiB✅
      CodexLive turn messages—2—8✅
      ClaudeTotal thread wire—5.0 KiB—6.8 KiB✅
      ClaudeThread snapshot wire—3.8 KiB—4.9 KiB✅
      ClaudeLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      ClaudeLive turn WebSocket decoded—21.2 KiB—29.3 KiB✅
      ClaudeLive turn messages—2—8✅

      Baseline: unavailable · PR result: e586475 · 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.

    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Important

      Review skipped

      Review was skipped as selected files did not have any reviewable changes.

      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Team
      • Run ID: a6a3b14e-81af-4d70-9e82-971601041d2a
      📥 Commits

      Reviewing files that changed from the base of the PR and between 58a0b9ef4c3285b64e4a8b4a37d275a0f93f4ea3 and e58647500e6f0fb713b140edf3dd1a10d6bc2f21.

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Team
      • Run ID: 71b9e3a2-f105-4141-a2ac-25d8dc993e0d
      📥 Commits

      Reviewing files that changed from the base of the PR and between 64cb539f4bde4a2ec1f6a3f75071bca6e1ebf057 and 9123df40327aa70e04021a3dc9495358406c91b5.

      📒 Files selected for processing: 3
      • apps/server/src/orchestration-v2/ProjectionSettlement.test.ts
      • apps/server/src/orchestration-v2/ProjectionStore.ts
      • apps/server/src/orchestration-v2/PullRequestWatchReactor.ts

      Limit details: You’ve used all 10 included reviews currently available.

      📝 Walkthrough

      The projection store now supports optional filtering for threads with watched pull requests. The watch reactor uses that filter. Settlement-candidate reads now load associated rows only when candidates exist and decode them after the transaction.

      Changes: Projection store reads

      Layer / File(s)Summary
      Settlement candidate reads
      apps/server/src/orchestration-v2/ProjectionStore.ts
      Settlement-candidate reads load associated rows only when candidates exist, then decode and derive candidates after the transaction. Row decoding yields after each 64 rows.
      Watched pull-request filtering
      apps/server/src/orchestration-v2/ProjectionStore.ts, apps/server/src/orchestration-v2/ProjectionSettlement.test.ts
      Both store implementations accept the optional watchedOnly filter. SQL applies it before decoding. Tests cover default and watched-only results, including filtering by thread ID and malformed unwatched payloads.
      Watch reactor integration
      apps/server/src/orchestration-v2/PullRequestWatchReactor.ts
      The sweep requests threads with watched pull requests.

      Priority: ⬇️ Low

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Refactor

      Suggested reviewers: t3dotgg

      Merge Risk: ⚪ Minimal · up to 9123d

      The watched-thread read optimization and settlement-read change have no identified issue that should delay merging beyond normal checks.

      Pre-merge checks: Passed 3 · Failed 1
      Failed Failed checks: 1 warning
      Check nameStatusExplanationResolution
      Description checkWarningThe description explains the problem, implementation, verification, performance measurements, limitations, and agent usage. It does not provide the required scope and approval information, such as a t…Add a Scope and approval section. Link the triaged issue or maintainer approval with the approval comment. If this is an obvious focused fix without prior approval, explain why it qualifies for that exemption.
      Passed Passed checks: 3 passed
      Check nameStatusExplanation
      Title checkPassedThe title clearly summarizes the main changes: narrowing watched reads and releasing settlement transactions.
      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: Description check

      Explanation

      The description explains the problem, implementation, verification, performance measurements, limitations, and agent usage. It does not provide the required scope and approval information, such as a triaged issue, maintainer approval, or a clear exemption rationale.

      Resolution

      Add a Scope and approval section. Link the triaged issue or maintainer approval with the approval comment. If this is an obvious focused fix without prior approval, explain why it qualifies for that exemption.

      ✨ Finishing Touches
      📝 Generate docstrings
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Comment `@coderabbitai help` to get the list of available commands.

Sign in to join this conversation.