Skip to content

perf(j5): field-scoped thread reads in the Crew services - #917

Merged
Jacksondr5 merged 2 commits into
j5/mainfrom
j5/278-field-scoped-reads-part2
Nov 3, 2026
Merged

Jacksondr5 merged 2 commits into
j5/mainfrom
j5/278-field-scoped-reads-part2

Conversation

@Jacksondr5

@Jacksondr5 Jacksondr5 commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Problem

Every J5 full-thread read waits behind event commits, because getThreadProjection reads on the writer connection while getThreadRecords uses a separate reader (upstream pingdotgg#23902). Part 1 (#810) moved everything outside the Crew services. This moves the rest. Closes #278.

What changed

Every remaining full read in J5 server code outside tests now loads only the fields it uses:

Site Read now
CrewLaunchReporter.post, coversFailure (Captain) messages, filtered to the launch notice's id
CrewLaunchReporter.refreshSeat runs, then turnItems filtered to the chosen run, only when the verdict reads items
CrewLaunchReporter.dropSeatsNeverCreated, CrewLaunchService seat, CrewProposalService ×2 getThreadRecordsIfPresent(id, [])
SpawnAgentService caller and child, preflightCrewCaptain getThreadRecords(id, [])
j5_stop_agent target runs
CrewCaptainArchiveCascade.moveSeats getThreadShell: upstream's SQL shell, no more threadShellFromProjection
j5_list_participants getShellSnapshot({ threadIds }) for the project's agents, instead of every thread

getThreadProjectionIfPresent had no callers left, so it is deleted.

refreshSeat makes two reads because it needs the run before it can filter items by run. It reads runs first, so the items are at least as new as the run's status.

Left as is

  • RosterService keeps the whole shell snapshot, because it joins every membership and a threadIds list would name nearly every thread.
  • nativeQuestionInboxRead is already location: "active", and it only reads records for threads with a pending request.
  • test-support/devDeliverySeed.ts is test support.

Forks. getThreadProjection follows a fork's history only for visibleTurnItems, and no J5 server code reads that field. So no swapped site sees different rows on a fork.

One behaviour change, approved by the Captain. getThreadShell returns null for a deleted thread, so the settle and unsettle cascade now skips a deleted seat. Before, the orchestrator rejected the command on that seat (Thread is deleted), and the remaining seats of that Crew didn't move. Now those seats still follow the Captain. Nothing else changes.

Tests

Fakes on these paths moved to the new reads. Real-store tests cover the places where a swap changes which rows are read:

  • Cascade, on the SQL shell: a deleted seat comes first, then seats held by activityRunStatus, pendingRuntimeRequest and a queued turn start, and an archived seat. Only the idle seat after them settles.
  • Reporter, on the SQL store: an earlier run's activity doesn't count for the brief run, and a failed brief run reports its own error, not the earlier run's. coversFailure finds the notice by id, so a look-alike message on the Captain doesn't count. Breaking the turnItemRunId filter or the messageIds filter fails this test: checked by mutating each.
  • Shell snapshot by ids: returns active and archived shells, and nothing for an empty list, which is what a project with no agents asks for.

Live testing

Server-only change, so no UI. I ran this myself on an isolated j5-live-test server at 97c107fdfb, on Claude Haiku only. A Crew seat can't spawn a separate tester.

# Captain asked in plain words for a Crew of two and a Peer Agent, then the roster was approved in the UI
thread peer-hello  claude-haiku-5-5  runs=completed
thread joker       claude-haiku-5-5  runs=completed
thread summary     claude-haiku-5-5  runs=completed
peer.txt, joke.txt, summary.txt written

# Captain's launch report
<j5_crew_gate> decision: approved  launch: 2 created and waiting for work, 0 started, 0 failed, 0 not created
# Seat finishes
<j5_seat_finished> run_status: completed  seat: summary  crew: joke-and-summary
<j5_seat_finished> run_status: completed  seat: joker    crew: joke-and-summary

# Second turn: j5_list_participants listed the project; j5_stop_agent on the idle peer returned already_idle
# A second proposal, declined in the UI
<j5_crew_gate> decision: declined

# Captain settled from the thread menu
thread Create Crew and Peer Agent Files  settled=settled
thread joker    settled=settled
thread summary  settled=settled
thread peer-hello  settled=null   (not a seat)
INFO J5 Captain settled; its Crew's seats followed
# Server log: no WARN or ERROR lines

Head vs tested commit. The head differs from the tested commit only in test fakes and two code comments. Nothing an agent or a person sees changed, so I did not re-test.

Not exercised live, and why: a failed seat, a seat in a real launch window with a brief running (this launch's seats were created waiting for work), and a deleted seat in the cascade. Tests cover all three. No Codex turn: the turn path and adapters are unchanged. No restart: stored state is unchanged.

Checklist

  • One concern: the description has no "also"
  • Tests cover the changed behavior (backend changes ship with focused tests)
  • UI changes: before/after screenshots above, and a video for motion or interaction (no UI change)
  • Live testing: the section above says what ran live and what did not
  • Upstream-owned files: none edited
  • Upstream product: no change to what upstream's product does
  • Surfaces: server-only reads; no contract, client, provider or connection-mode change
  • Docs: no product or user doc describes these reads

vp run check:changed: format, lint, knip, graphql, typecheck and the 7 test files beside the changes pass. The whole of apps/server/src/j5: 192 test files pass and 1 is skipped (1599 tests pass, 1 skipped) at 087a15929e. The head adds only a one-line comment change after that.

Built by Claude Opus 5.5 in Claude Code (J5 Code Crew builder seat).

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
j5-code Ready Ready Preview Nov 3, 2026 3:00am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 14 billable files and costs up to $3.50.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 36 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available. Your 55 included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between b85f262 and f0f6dda.

Files selected for processing: 14
  • apps/server/src/j5/a2a/CrewCaptainArchiveCascade.test.ts
  • apps/server/src/j5/a2a/CrewCaptainArchiveCascade.ts
  • apps/server/src/j5/a2a/CrewLaunchReporter.test.ts
  • apps/server/src/j5/a2a/CrewLaunchReporter.ts
  • apps/server/src/j5/a2a/CrewLaunchService.test.ts
  • apps/server/src/j5/a2a/CrewLaunchService.ts
  • apps/server/src/j5/a2a/CrewProposalService.test.ts
  • apps/server/src/j5/a2a/CrewProposalService.ts
  • apps/server/src/j5/a2a/SpawnAgentService.ts
  • apps/server/src/j5/a2a/mcp/handlers.test.ts
  • apps/server/src/j5/a2a/mcp/handlers.ts
  • apps/server/src/j5/a2a/mcp/outsideAgent.test.ts
  • apps/server/src/j5/a2a/spawnWorkspace.test.ts
  • apps/server/src/j5/a2a/threadProjectionReads.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@github-actions github-actions Bot added the vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. label Nov 3, 2026
@github-actions github-actions Bot added the size:L 100-499 effective changed lines (test files excluded in mixed PRs). label Nov 3, 2026

@Jacksondr5 Jacksondr5 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combined review from the panel (Claude Opus 5.5 lead, GPT Sol 6.1), at 087a15929e. No correctness findings. Two wording notes below, neither blocking.

Checked in source

  • Inventory: all 12 production full reads moved, and getThreadProjectionIfPresent is gone. The only J5 callers of getThreadProjection left are in test-support/devDeliverySeed.ts. RosterService and nativeQuestionInboxRead stay as the PR body explains.
  • Fields: each site loads only what it uses. j5_stop_agent correctly keeps runs.
  • Filters: messageIds and turnItemRunId drop only rows the callers already discarded, and the real-store test covers both. refreshSeat's run selection and status branches are unchanged, and reading runs first means its items are at least as new.
  • Forks: getThreadProjection differs from getThreadRecords only in visibleTurnItems, and no J5 production code reads that field.
  • Not-found and deleted threads: getThreadRecordsIfPresent keeps the same not-found rule and still returns deleted threads, so the deletedAt checks hold.
  • Reader connection: no swapped read runs inside a writer transaction. crews.serialize is a keyed lock, not a transaction. The reads that follow a dispatch happen after it has committed.
  • Settle cascade on the SQL shell: shellFromState supplies every field isAutoSettlementCandidate reads, and the settlement candidates path uses the same derivePendingBackgroundWork. The deleted-seat skip is the only behaviour change, and the Captain approved it.
  • j5_list_participants: the threadIds predicate matches the localRows predicate, so every shell the listing uses is still loaded, active and archived alike.
  • Spans and tests: Effect.fn spans are preserved, and fakes on these paths moved to the new reads.

Non-blocking notes

  1. CrewLaunchReporter.ts, refreshSeat: the comment "so a run that has failed already has its error item here", repeated in the PR body, promises more than the code does. runFailures.ts says a run can end failed with no error item. Suggested wording: "Read after the run, so the items are at least as new as its status." There's no runtime effect.
  2. PR body: the behaviour change is described as the "settle cascade", but moveSeats also serves unsettle. A settled deleted seat used to be rejected on a Captain's unsettle, and it's now skipped too. Please say "settle and unsettle". The new test covers the settle direction, and both directions use the same null check.

Validation so far

  • Sol ran CrewLaunchReporter.test.ts, CrewCaptainArchiveCascade.test.ts and a2a/mcp/handlers.test.ts at this head: 38 tests passed.
  • Opus reviewed from source and ran no tests.
  • The full apps/server/src/j5 suite hasn't passed in one complete run at this head, as the PR body says. CI's server shards were still pending when this was posted and will be the first complete run, so this review doesn't vouch for them.

Reviewed by Claude Opus 5.5 and GPT Sol 6.1 in J5 Code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jacksondr5
Jacksondr5 merged commit c7af58e into j5/main Nov 3, 2026
37 checks passed
@Jacksondr5
Jacksondr5 deleted the j5/278-field-scoped-reads-part2 branch November 3, 2026 03:16

This branch was successfully deployed

1 active deployment
Preview — f0f6dda6 Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 effective changed lines (test files excluded in mixed PRs). 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.

Performance: move J5 full-thread reads to field-scoped reads

1 participant