← Back to Pull requests

feat(expand): periodic mid-expansion progress log #779

Closed
unknown closed this pull request without merging on Apr 24, 2026 20:11 UTC
View on GitHub
unknown unknown commented on Apr 22, 2026 19:09 UTC
Author

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 existing WithLogFrequency default of 10s), so operators can watch long grant-expansion runs grow in near-real-time instead of learning the final size only after C1File.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: saved line 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.go


  • DBSizeProvider — optional capability: returns current uncompressed working-set bytes. Additive; stores that don't implement it keep working. Placed alongside LatestFinishedSyncIDFetcher (matches existing pattern for optional store capabilities).
  • pkg/dotc1z/c1file.go


  • (C1File).CurrentDBSizeBytes() (int64, error) — stats dbFilePath plus the -wal sidecar if present. WAL matters here: with journal_mode=WAL the main db file can stay flat while the WAL grows into hundreds of MB during active writes. Non-ENOENT stat errors on the -wal sidecar 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.go


  • ProgressLog gains optional dbSize + lastLoggedDBSize fields.

  • New WithDBSizeProvider(connectorstore.DBSizeProvider) Option.

  • LogExpandProgress — when a provider is attached, appends decompressed_bytes + delta_bytes to the existing "Expanding grants" log. Delta is computed across calls, not from zero (so growth rate is visible per sample).

  • Rate-limiting reuses the existing lastActionLog field — no new env var. Tune via WithLogFrequency (10s default).
  • pkg/sync/syncer.go


  • In NewSyncer, type-asserts s.store against connectorstore.DBSizeProvider and calls progresslog.WithDBSizeProvider(sp) when the store implements it. dotc1z.C1File does.
  • Why state lives on ProgressLog, not Expander


    syncer.expandGrantsForEntitlements constructs a fresh Expander on every step and runs RunSingleStep once before returning. Any state held on the Expander resets every step — including any "last log time" tracker, which would always be ~nanoseconds ago and suppress every log. ProgressLog is 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 with delta_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; only actions_remaining appears.

  • 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's delta_bytes < decompressed_bytes — proving the ProgressLog kept its prior sample across steps.
  • In pkg/dotc1z/c1file_test.go:

  • TestCurrentDBSizeBytes — live sqlite file size grows after bulk writes; defensive error on empty dbFilePath.
  • The test file defines a tiny local capturingCore (~30 LOC) instead of pulling in zaptest/observer since that dependency isn't in the vendor tree.

    Compat

  • Zero API break. NewExpander signature unchanged.

  • DBSizeProvider is an optional interface — nothing requires implementing it.

  • The log message stays "Expanding grants" with the existing actions_remaining field; the new size fields are additive.

  • Rate-limiting uses the same WithLogFrequency knob (10s default) as every other progress log — no new env var.
  • Next steps (follow-ups, not in scope)

  • Bounded expansion (baton-sdk) — reuse the same CurrentDBSizeBytes() hook to abort* instead of only log when size crosses a configurable ceiling. Shape: new BATON_MAX_EXPANSION_DB_BYTES env var (default: off), new ErrExpansionSizeExceeded sentinel wrapping the observed size and ceiling, abort check threaded through Expander.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.

  • Per-tenant DecoderMaxDecodedSize (c1) — today the decoder cap is gated by the process-wide BATON_DECODER_MAX_DECODED_SIZE_MB env var, which is too coarse for multi-tenant be-temporal-sync / be-temporal-worker topology (raising it for one pathological tenant raises it for everyone). Add a tenant-keyed config value (feature flag or tenant-settings field) and pass dotc1z.WithDecoderMaxDecodedSize(tenantLimit) at each NewDecoder call 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

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: arreyder Review duration: 2941m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%