Skip to content

perf(server): skip full thread loads on projection and ingestion - #230

Merged
leoisadev1 merged 4 commits into
mainfrom
perf/narrow-projection-queries
Sep 11, 2026
Merged

perf(server): skip full thread loads on projection and ingestion#230
leoisadev1 merged 4 commits into
mainfrom
perf/narrow-projection-queries

Conversation

@leoisadev1

@leoisadev1 leoisadev1 commented Sep 10, 2026

Copy link
Copy Markdown
Member

Problem

Thread shell refresh, client snapshots, and provider reactors decoded every persisted message, plan, and activity payload to compute a few summary fields. Large tool outputs made those reads cost more memory than the result required.

Adaptation

Ported the remaining narrow projection and ingestion lookups from T3 Code, keeping Akeru bot, group, channel, author, reaction, and delegation fields.

  • Shell refresh uses SQL for latest user-message time, pending approval count, and actionable-plan status, plus user-input lifecycle rows only.
  • Client snapshots load activity payloads in 25-row primary-key batches and project each batch before the next read.
  • Metadata commands read the thread shell. Turn start reads one message and an existence check for other non-compaction user messages.
  • Runtime ingestion uses a joined thread context, including Akeru ownership fields, and keyed message, plan, and task-activity lookups.
  • Controller helpers now take the shell ownership fields they actually read (id, botId, groupId, respondingBotId, interactionMode) instead of a full OrchestrationThread.
  • Task-title fallback reads projection activity kind and payload, so records keyed by activityId compile.
  • Live thread.activity-appended stays O(1) when the current array was produced by the reducer and is already sorted.
  • upsertMany exists for projector cursors. Runtime projectEvent still commits each projector separately because attachment cleanup runs after each projector transaction. Combining those commits is shared with checkpoint attachment-transaction work and is not in this PR.

Upstream

Adapted from pingdotgg/t3code:

  • #9000 bound snapshot activity payload memory
  • #8988 skip unused tool payloads
  • #9152 incremental message-sent and activity appends
  • #9662 SQL latest user-message time and pending approval count
  • #9671 cursor upsertMany API only
  • #9706 joined thread runtime context
  • #9758 shell reads for metadata commands
  • #10108 turn-start message query
  • #10120 keyed completion lookups
  • #10341 plan-status metadata without markdown bodies

Scope

This PR is projection and ingestion query narrowing only. Logging (pingdotgg#8187 remaining) is #240. Incremental transcript scans (pingdotgg#9024) are still separate. Checkpoint attachment cleanup after outer command commit is owned by the checkpoint-safety work.

Verification

Focused tests:

  • 154 tests across ProviderCommandReactor and ProviderRuntimeIngestion after the helper-contract repair, including shell-only identity and projection activityId title lookup
  • Server typecheck: no error TS on akeru-bot after the repair
  • Targeted lint and format

Isolated browser on a354e64f2, home /tmp/akeru-ui.cGmS1M, web 6836 / server 14876:

  • Scout history rendered from projected messages, then a live send projected the user line and a completed error reply into the thread and roster preview
  • Thumbs-up reaction persisted on the user message and survived reconnect
  • Group Projection check (Scout boss, Relay specialist) rendered from the roster; a live send showed Scout is working, then a completed Scout error reply
  • Reconnect via /bots/ui-scout restored Scout history plus the reaction; opening the group from the roster restored group history
  • Hard navigation straight to /groups/... before the roster store is populated still crashes GroupThreadLanding (useReplyPlaybackThread after if (!group) return null). That hook-order bug is pre-existing and not introduced here
  • Live successful provider streaming and delegation cards were not available: this isolated fixture has no working provider credentials, so turns complete with the local failure reply instead of a provider stream or a delegation record

Implemented and verified by Grok 4.6 High in Grok Build via Orca.

Thread shell refresh, snapshots, and provider reactors were decoding every message, plan, and activity payload to compute a few summary fields. That cost grew with tool output size.

Use SQL aggregates and keyed lookups instead. Client snapshots load activity payloads in 25-row batches. Metadata commands read the thread shell. Turn start reads one message. Runtime ingestion uses a joined thread context plus message, plan, and task-activity lookups. Live activity appends stay O(1) when already sorted. Cursor upsertMany is available; runtime projectEvent still commits per projector so attachment cleanup stays after each projector transaction.

Adapted from pingdotgg/t3code pingdotgg#9000 pingdotgg#8988 pingdotgg#9152 pingdotgg#9662 pingdotgg#9671 pingdotgg#9706 pingdotgg#9758 pingdotgg#10108 pingdotgg#10120 pingdotgg#10341.
@vercel

vercel Bot commented Sep 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
akeru-bot-landing Building Building Preview Sep 10, 2026 6:01pm UTC

Request Review

@github-actions github-actions Bot added type:provider Agent provider contribution. size:XXL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Sep 10, 2026
@greptile-apps

greptile-apps Bot commented Sep 10, 2026

Copy link
Copy Markdown

Greptile Summary

This PR replaces full thread-history decoding in projection and provider-ingestion paths with bounded, purpose-specific persistence queries while preserving client snapshot and runtime behavior.

  • Computes shell summary fields through narrow message, plan, approval, and activity lifecycle queries.
  • Loads and projects client activity payloads in bounded batches within the snapshot transaction.
  • Uses joined runtime context and keyed message, plan, and task-activity lookups during provider ingestion.
  • Narrows controller helper contracts to the shell ownership fields they consume.
  • Adds an indexed fast path for already-sorted live activity appends.
  • The earlier activity-identifier type issue is fixed.

Confidence Score: 5/5

Safe to merge; no outstanding blocking issues remain.

The prior activity-identifier finding was resolved by greptile-apps[bot] without explanation. The current code passes the repository's full projected activity shape to the task-title helper, which only requires its kind and payload fields.

Reviews (4): Last reviewed commit: "Merge branch 'main' into perf/narrow-pro..." | Re-trigger Greptile

Comment thread apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts
Controller helpers still required a full OrchestrationThread after the shell lookup, and task-title fallback passed projection activity records into a helper typed on activity.id. Narrow those signatures to the fields they actually read.

Grok 4.6 High via Grok Build.
Greptile reproduced TS2739/TS2345: turn-start helpers still required a full OrchestrationThread after the shell lookup, and task-title fallback passed projection activityId records into a helper typed on activity.id. The helpers now take the Akeru ownership and payload fields they actually read.

Grok 4.6 High via Grok Build.
@leoisadev1
leoisadev1 merged commit 8c430fc into main Sep 11, 2026
11 checks passed
@leoisadev1
leoisadev1 deleted the perf/narrow-projection-queries branch September 11, 2026 11:02
@github-actions github-actions Bot mentioned this pull request Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL type:provider Agent provider contribution. vouch:trusted PR 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