Repository navigation
feat: add phase tracking, histograms, and safe config exposure to observability contract - #57
Merged
Merged
Conversation
Add durable per-batch phase tracking (waiting_gate, waiting_merge,
bisecting) to the engine's activeBatch struct, persisting across
Reconcile ticks. Expose phase detail, linger window, and safe resolved
config via new additive fields in the /status JSON response.
New fields (existing active_batches/pending_batches [][]int unchanged):
- active_batch_states: [{prs, phase, phase_since}] per active batch
- linger_since: RFC3339 timestamp while the queue is in the linger window
- config: {config_source, base, merge_style, max_batch, batch_linger,
batch_target, bisect_fanout} — sensitive fields excluded
config_source is 'repo' when a .shunt.yml was found, 'default' otherwise.
Excluded from config: token, instance_url, webhook_secret, bot_email,
bot_user, staging_branch, public_url, lease_holder_id, status_ctx.
Add four new Prometheus histograms (labels: owner, repo, base):
- shunt_linger_seconds: batch-linger window duration
- shunt_gate_seconds{outcome}: gate run duration (labelled by outcome)
- shunt_native_merge_seconds: forge auto-merge wait duration
- shunt_reconcile_seconds: per-queue Reconcile call duration
(only recorded on the lease-holding instance in HA deployments)
Bisect sub-batches are tracked via a bisectOrigins map so startNext()
can assign phase=bisecting without requiring a parameter change.
Gate duration is recorded in checkActive() when outcome is set; native
merge duration uses the existing releasedAt field in recordLanded();
reconcile duration uses a defer placed after the lease check.
Backward compatibility: active_batches and pending_batches remain [][]int.
New JSON fields use omitempty. TestOldJSONShapeUnchanged regression test
confirms the old shape is unaffected.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Extends the observability contract with three categories of additions, all backward-compatible.
1. Per-batch phase tracking
A durable
phasefield (andphaseSincetimestamp) is added to the engine'sactiveBatchstruct. Only phases observable betweenReconcileticks are modelled:waiting_gateoutcome == "").waiting_mergebisectingQueue-level linger state is exposed separately via a
linger_sincetimestamp (not a per-batch phase).2. New JSON fields in
/statusThree additive fields are added to each per-queue JSON object.
active_batchesandpending_batchesremain[][]intand are unchanged.TestOldJSONShapeUnchangedis a regression test that unmarshal-and-checks both fields stay[][]int.active_batch_states—[{prs: []int, phase: string, phase_since: RFC3339}]linger_since— RFC3339; present while the queue is accumulating PRs in the linger window, absent otherwiseconfig— safe resolved configuration subset:{config_source, base, merge_style, max_batch, batch_linger, batch_target, bisect_fanout}config_sourceis"repo"when a.shunt.ymlwas found,"default"otherwise.Explicitly excluded from
config:token,instance_url,webhook_secret,bot_email,bot_user,staging_branch,public_url,lease_holder_id,status_ctx.3. Four new Prometheus histograms
Labels:
{owner, repo, base}. No PR-number or other high-cardinality labels.shunt_linger_secondsshunt_gate_seconds{outcome}shunt_native_merge_secondsshunt_reconcile_secondsReconcilecallshunt_reconcile_secondsis only recorded on the lease-holding instance — thestartcapture and defer are placed after the!heldearly return so standby instances in HA deployments do not skew the histogram.Backward compatibility
active_batchesandpending_batchesremain[][]int./statusfields useomitempty; consumers that only read the old fields are unaffected.SHUNT_*env vars — all additions are always-on read-only observability.Tests
TestOldJSONShapeUnchanged— unmarshals/statusJSON and verifiesactive_batches/pending_batchesare still[][]intTestNewStatusFieldsAppear— verifiesactive_batch_states,linger_since,configappear; verifies sensitive fields are absentTestPrometheusNewHistograms— verifies all 4 new histogram families appear in/metricsTestPhaseTracking,TestWaitingMergePhase— phase transitionsTestLingerSinceExposedInStatus,TestEffectiveConfigExposedInStatus— status fieldsTestGateDurationHistogram,TestNativeMergeDurationHistogram,TestReconcileDurationHistogram,TestLingerDurationHistogram— histogram recordingTestStatusSnapshotCopiesBatchesextended — verifiesActiveBatchStates[0].PRsis isolated from caller mutationsmake lint test build✅go test -race ./...✅Review notes
A code-review pass was run before commit. Two issues were found and fixed:
ObserveQueueStatusnow deep-copies eachActiveBatchState.PRsslice (not just a shallow append), andTestStatusSnapshotCopiesBatchesasserts isolation of the new field.Docs
docs/design.md— new "Observability contract" section with phase table, histogram buckets, and safe config subsetREADME.md— Observability section updated with new histograms and new/statusfieldsCHANGELOG.md—[Unreleased]entry