feat(expand): periodic mid-expansion progress log #779
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #779"
general
weight: 0.35
arreyder
Summary
Emits a log with live uncompressed db size and growth delta every time the syncer calls
ProgressLog.LogExpandProgress(once per expansion step, rate-limited to the existingWithLogFrequencydefault of 10s), so operators can watch long grant-expansion runs grow in near-real-time instead of learning the final size only afterC1File.Close()→saveC1z. Complements #777 (post-save size visibility) with during-run visibility.Why
A pathological tenant's grant expansion runs for ~10 hours and can grow non-linearly (transitive expansion: each newly-materialised grant can trigger more). With #777 alone we learn the final post-expansion size once saveC1z emits its
c1z: savedline at the end — one data point after a 10-hour burn.This PR gives the signal you actually want for that shape of workload: delta bytes between successive samples. Two logs at 45 GB → 120 GB tell you to abort immediately rather than wait 6 more hours for the final save.
What changed
New capability interface:
pkg/connectorstore/connectorstore.goDBSizeProvider— optional capability: returns current uncompressed working-set bytes. Additive; stores that don't implement it keep working. Placed alongsideLatestFinishedSyncIDFetcher(matches existing pattern for optional store capabilities).pkg/dotc1z/c1file.go(C1File).CurrentDBSizeBytes() (int64, error)— statsdbFilePathplus the-walsidecar if present. WAL matters here: withjournal_mode=WALthe main db file can stay flat while the WAL grows into hundreds of MB during active writes. Non-ENOENTstat errors on the-walsidecar are surfaced (not silently swallowed) so a permission/EIO error can't under-report by hundreds of MB.var _ connectorstore.DBSizeProvider = (C1File)(nil)— compile-time assertion so signature drift fails the build rather than silently disabling the size fields.pkg/sync/progresslog/progresslog.goProgressLoggains optionaldbSize+lastLoggedDBSizefields.WithDBSizeProvider(connectorstore.DBSizeProvider) Option.LogExpandProgress— when a provider is attached, appendsdecompressed_bytes+delta_bytesto the existing"Expanding grants"log. Delta is computed across calls, not from zero (so growth rate is visible per sample).lastActionLogfield — no new env var. Tune viaWithLogFrequency(10s default).pkg/sync/syncer.goNewSyncer, type-assertss.storeagainstconnectorstore.DBSizeProviderand callsprogresslog.WithDBSizeProvider(sp)when the store implements it.dotc1z.C1Filedoes.Why state lives on
ProgressLog, notExpandersyncer.expandGrantsForEntitlementsconstructs a freshExpanderon every step and runsRunSingleSteponce before returning. Any state held on theExpanderresets every step — including any "last log time" tracker, which would always be ~nanoseconds ago and suppress every log.ProgressLogis constructed once per sync and persists across steps, so it's the correct home for cross-step rate-limiting and size-delta accounting.Tests
In
pkg/sync/progresslog/progresslog_test.go:TestLogExpandProgress_SizeFieldsAcrossCalls— first call emits withdelta_bytes == size(baseline 0); calls inside the rate-limit window are suppressed; call after the window reports delta relative to the prior sample (catches the regression where per-step state reset would make delta == full size every time).TestLogExpandProgress_NoSizeProviderOmitsFields— pre-existing behavior preserved when no provider is attached; onlyactions_remainingappears.TestLogExpandProgress_SizeErrorSkipsSizeFields— stat error on the size provider suppresses only the size fields, not the whole log line.TestLogExpandProgress_PerStepExpanderShape— simulates the production call pattern: 50 back-to-back Expander constructions in a ~75ms window with a 15ms rate-limit. Asserts ≥2 logs emit, logs are rate-limited (not one-per-step), and the second log'sdelta_bytes<decompressed_bytes— proving theProgressLogkept its prior sample across steps.In
pkg/dotc1z/c1file_test.go:TestCurrentDBSizeBytes— live sqlite file size grows after bulk writes; defensive error on emptydbFilePath.The test file defines a tiny local
capturingCore(~30 LOC) instead of pulling inzaptest/observersince that dependency isn't in the vendor tree.Compat
NewExpandersignature unchanged.DBSizeProvideris an optional interface — nothing requires implementing it."Expanding grants"with the existingactions_remainingfield; the new size fields are additive.WithLogFrequencyknob (10s default) as every other progress log — no new env var.Next steps (follow-ups, not in scope)
CurrentDBSizeBytes()hook to abort* instead of only log when size crosses a configurable ceiling. Shape: newBATON_MAX_EXPANSION_DB_BYTESenv var (default: off), newErrExpansionSizeExceededsentinel wrapping the observed size and ceiling, abort check threaded throughExpander.RunSingleStep. Abort-on-overrun semantics (not partial expansion). ~50 LOC + tests. Tune the default ceiling against the histogram this PR feeds, not by guessing. Tracked as OPS-1258.DecoderMaxDecodedSize(c1) — today the decoder cap is gated by the process-wideBATON_DECODER_MAX_DECODED_SIZE_MBenv var, which is too coarse for multi-tenantbe-temporal-sync/be-temporal-workertopology (raising it for one pathological tenant raises it for everyone). Add a tenant-keyed config value (feature flag or tenant-settings field) and passdotc1z.WithDecoderMaxDecodedSize(tenantLimit)at eachNewDecodercall site in c1, falling back to the existing 3 GiB default. ~20–30 LOC + config surface. Lets ops raise the cap for a specific tenant once this PR's growth log identifies who needs it, without lifting the floor globally. Tracked as CXH-1398.🤖 Generated with Claude Code