perf: store workspace agent session counts as JSONB - #28126
Merged
Merged
Conversation
This was referenced Aug 13, 2026
EhabY
force-pushed
the
perf/workspace-agent-session-counts-jsonb
branch
from
August 13, 2026 16:29
b654c59 to
102d860
Compare
EhabY
force-pushed
the
perf/workspace-agent-session-counts-jsonb
branch
from
August 18, 2026 13:05
102d860 to
ec55b67
Compare
EhabY
force-pushed
the
perf/workspace-agent-session-counts-jsonb
branch
from
August 19, 2026 11:19
ec55b67 to
a105341
Compare
EhabY
force-pushed
the
perf/workspace-agent-session-counts-jsonb
branch
from
August 19, 2026 14:14
9009c59 to
5b4c776
Compare
EhabY
force-pushed
the
perf/workspace-agent-session-counts-jsonb
branch
from
August 19, 2026 23:25
5b4c776 to
88ce165
Compare
EhabY
force-pushed
the
perf/workspace-agent-session-counts-jsonb
branch
from
August 19, 2026 23:43
88ce165 to
ae67674
Compare
EhabY
force-pushed
the
perf/workspace-agent-session-counts-jsonb
branch
from
August 20, 2026 12:29
ae67674 to
d705373
Compare
EhabY
force-pushed
the
perf/workspace-agent-session-counts-jsonb
branch
from
August 20, 2026 23:22
d705373 to
04e3ac5
Compare
EhabY
force-pushed
the
perf/workspace-agent-session-counts-jsonb
branch
from
August 20, 2026 23:41
04e3ac5 to
0ed88b8
Compare
EhabY
force-pushed
the
perf/workspace-agent-session-counts-jsonb
branch
from
August 20, 2026 23:54
0ed88b8 to
f163971
Compare
EhabY
force-pushed
the
perf/workspace-agent-session-counts-jsonb
branch
from
August 21, 2026 00:04
f163971 to
a20e937
Compare
EhabY
force-pushed
the
perf/workspace-agent-session-counts-jsonb
branch
3 times, most recently
from
August 23, 2026 14:26
99052ce to
93c505d
Compare
EhabY
force-pushed
the
perf/workspace-agent-session-counts-jsonb
branch
4 times, most recently
from
August 23, 2026 18:00
8caca66 to
32f9211
Compare
EhabY
marked this pull request as ready for review
August 23, 2026 19:06
EhabY
force-pushed
the
perf/workspace-agent-session-counts-jsonb
branch
2 times, most recently
from
August 25, 2026 15:24
3b8fc8d to
5b095c0
Compare
code-asher
reviewed
Aug 26, 2026
code-asher
left a comment
Member
There was a problem hiding this comment.
I only got through a couple files, will finish review tomorrow!
code-asher
approved these changes
Aug 31, 2026
Member
|
Ah actually I was going to comment on the warning. Do you know how/if that would surface to the end user? Outputs to stderr or something? I briefly tried testing with the develop script but possibly it swallows some output. |
EhabY
force-pushed
the
perf/workspace-agent-session-counts-jsonb
branch
from
September 1, 2026 23:22
3941985 to
bcb1c60
Compare
Replaces the four session_count_* columns on workspace_agent_stats with a sparse session_counts JSONB object, so counting a new app needs no schema change. Only positive counts are stored, every reader and rollup moves to JSONB, and output column names and API shapes are unchanged. The migration converts every row the rollup has not consumed, however far behind it is, and warns when that backlog spans more than 24 hours. Without a rollup watermark every row converts.
Contributor
Author
|
This follows the existing migration warning behavior, including migration Since it’s advisory and the migration proceeds without intervention, I'd leave that behavior unchanged here and handle notice forwarding separately if we want it. |
EhabY
force-pushed
the
perf/workspace-agent-session-counts-jsonb
branch
from
September 7, 2026 20:11
bcb1c60 to
c8d5de0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the four
session_count_*columns onworkspace_agent_statswith a sparsesession_countsJSONB object, so counting a new app needs no schema change.{}instead of four zeroes, and the template insights covering index drops four bigints from itsINCLUDElist.session_count_sftpTODOs: a new session type is now a new key.Migration
Converts the window
DeleteOldWorkspaceAgentStatsretains,MAX(template_usage_stats.start_time)minus one day. Anything older is already rolled up. When nothing has ever rolled up there is no watermark to fall back on, so every row converts instead of letting old activity roll up as zero minutes later.A backlog the rollup never consumed spanning more than 24 hours usually means the rollup is failing or blocked. The migration proceeds anyway and emits a warning naming the span, with a hint to check coderd logs and
pg_locksafter the upgrade:Measured on 10M rows: a healthy rollup converts ~330k rows in 11s on PG13 in Docker (4.44s on PG17 with tmpfs, 6.13s on durable storage). A rollup 30 days behind, or a deployment that never rolled up, converts all 10M rows in about 3.5 minutes, roughly 21 seconds per million backlogged rows.
Trade-offs
ACCESS EXCLUSIVE, so agent stat writes block for its duration;DROP COLUMNand the index rebuild need the lock regardless. A deployment whose rollup has failed for months converts its whole backlog at ~21s per million rows. The alternative, aborting until the rollup is fixed, blocked the upgrade with no way to trigger a rollup on demand.UpsertTemplateUsageStatsextracts keys per row, every five minutes over the retained window, where it compared four integers. Neither form was indexed; the cost buys schema-free new apps.Depends on #28125. Phase 3 of #27410.