Skip to content

feat(metrics): crew log health instruments, batch 2 - #22227

Merged
iamwhatever merged 1 commit into
mainfrom
feat/22180-crew-log-health-batch2
Oct 20, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
feat/22180-crew-log-health-batch2

Conversation

@chenmingwei23

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: an operator can see whether the crew log is keeping up -- how big its backlog is, whether savepoints are landing, and whether a fold subscriber is failing silently.

Main has no crew log metric at all. The crew log is the durable record every fold, every dashboard read and every resumed session is built from, so when a board looks stale there is nothing to look at: the in-process WriterStats and a handful of warning logs are the only evidence, and neither is sampled over time. "The log is slow" and "the log is stuck" are indistinguishable from outside the process, and a bus subscriber that raises on every published fold is invisible -- the publisher is told nothing by design, and a log line carries no rate and no total.

Why it matters

The failure this closes is a silent one. A saturated write-behind, a savepoint store that refuses every payload, a backed-up fold queue and a subscriber raising on every fold all present identically to an operator: a dashboard whose numbers lag. Each needs a different response and today none can be told apart without attaching to the process. The two gauges separate a backlog in the write-behind from one in the fold queue; the savepoint counter says whether resume state is being persisted at all, which decides whether a restart costs a cold fold; the subscriber-error counter turns a silent riser into a number.

Not a goal

  • kirocrew.crew_log.append.bytes, kirocrew.crew_log.append.batch and kirocrew.crew_log.fold.lag are deliberately NOT shipped. Every available source for each is work on the crew log write path. The "What changed" section walks each one; the short version is that this PR adds nothing at all to that path rather than buying a byte count with an instruction on it.
  • The first batch of the same area (write.lost, fold.apply, fold.start). Separate PR.
  • Where these numbers are sent and which of them leave the machine. Decided elsewhere; everything here stays behind telemetry.enabled.
  • Any change to what the crew log does. This PR adds no behaviour to the log itself.

What changed (motivation -> approach -> change)

The constraint that decided everything, including the omissions: recording a crew log metric must add no work to the write path. An append reaches disk on CrewLogWriter._write_batch or on the write-behind's inline fast path, and both sit on the latency path of a turn that commits an entry. src/kiro_crew/crew_log/writer.py and src/kiro_crew/crew_log/store_segment_writes.py are therefore byte-identical to main in this diff, and four tests hold them that way.

What ships. Four instruments:

  • kirocrew.crew_log.eager.queue_depth and kirocrew.crew_log.writer.buffered -- observable gauges read from live state when a reader collects, never up/down counters a crash can leave drifting. Both answer absent rather than zero when their subsystem does not exist in the process, because "no fold thread" and "an empty queue" are different facts. Neither reader imports anything: each resolves its source from sys.modules and answers None when it is not loaded, so a collection every export interval cannot be the thing that pulls the storage layer into a process that has the crew log switched off. The backlog reader also reads the installed write-behind directly rather than through the accessor that would build one -- telemetry must not bring a subsystem into being.
  • kirocrew.crew_log.savepoint.write{kind,outcome,bucket} -- one point per pass that actually offered a payload to the savepoint store, from checkpoint.save and checkpoint.save_slot. A pass that returned before writing records nothing: no write earned yet, no witness, the unit removed, the lease contended, an unserializable state. Those are refusals, and counting them as failures would read as a failing disk. For the same reason outcome compares what landed against what was OFFERED, not against the whole bundle -- a session pass skips any fold whose boundary its witness does not certify, so holding the pass to those too would report a refusal as a failure. Whether the bundle may then claim a savepoint is a stricter question, answered separately in save as before. Both points are taken in a finally, so a raise through the store counts as failed rather than going unrecorded, and both are emitted after release_lease: the first get_recorder() of a process builds the SDK synchronously, and doing that under a held lease would lengthen the window in which a removal of that unit is refused.
  • kirocrew.crew_log.bus.subscriber_error{kind} -- the two branches that swallow a subscriber's exception. Failure path only, and the count is what the log line cannot give: a WARNING per failed event carries neither a rate nor a total.

The one honest caveat, stated rather than papered over. bus.subscriber_error is the only call here a crew log write thread can reach. tree_advanced is published from the session-tree projection, which a session/opened or session/spawned job advances while the write-behind is running that job, so a subscriber of that kind runs on the write thread. Three things bound it: a subscriber that returns normally costs nothing at all; the raising path already formats and emits a WARNING, which costs more than the counter beside it; and the counter resolves the metrics module from sys.modules rather than importing it, so a write thread can never trigger the first load of the facade, its config read or its SDK build. fold_advanced is published only from the eager fold worker. Both bounds have tests.

Why append.bytes is not here. Three sources were considered and all three are either work on the write path or wrong:

  1. Count at the write. A counter.add, or an integer field on the batch pass. This is work on exactly the thread the constraint protects, so it is out regardless of how small it is.
  2. Count in the sync funnel. store_segment_writes.py::_write_then_sync is the one place every byte passes through and has the exact length already encoded, which makes it the most accurate option -- and it is still on the write path. Out for the same reason.
  3. Derive it on the reader thread from what the write-behind already keeps. This is the only candidate that touches nothing, and it is not exact. The only byte figures the write-behind holds are the LIVE pending totals (_pending_total_bytes, _pending_bytes); recovering "written" from them needs a cumulative accepted total, which does not exist, so it would take a new field on the enqueue side -- itself on the turn path. And it would still be wrong three ways: the inline fast path runs a job without ever buffering it, so its bytes never enter the pending total at all; there is no cumulative dropped-byte figure to subtract, because a unit's loss debt is consumed when its marker is written; and the underlying nbytes is the producer's size hint, which is a CHARACTER count carried by only the two body-bearing entry types -- so a non-ASCII message would be under-reported by roughly a third under a metric whose unit says bytes, and turn/started, session/*, work/recorded and the rest would contribute zero.

append.batch (write + fsync time) and fold.lag are out for the first reason alone: nothing keeps per-batch timing or enqueue time today, and the only way to produce either is a time.monotonic() pair on that path.

A metric that is absent costs a question nobody can answer yet. A metric that is present and wrong costs more, and an operator cannot tell which one they are reading. So these three wait for a source that is both exact and off the write path, and TestOmissionsAreDeliberate keeps them out until one exists -- a test rather than a comment, because "every source was on the write path" is a decision a later reader cannot reconstruct from the code that is here, and a plausible-looking source is exactly what would get one re-added.

Vocabulary. Every attribute value comes from a closed enum with other as a member, so an unrecognised value maps into the enum rather than past it. savepoint.write is at most 24 series and bus.subscriber_error at most 3. No unit id, slot key, session id, fold name, path or exception text is ever an attribute.

Backwards compatibility

Compatible: every instrument is additive and no existing behaviour changes. _write_batch, submit, _write_then_sync and WriterStats are untouched; the only edits to existing functions add a counter call on a branch that already existed, plus one new read-only helper (eager.queue_depth).

Removes nothing: no field, key, record, function or path is deleted, renamed or narrowed.

Tests

test/metrics/test_crew_log_health.py, 58 cases, grouped by the guarantee each locks in.

The write path gained nothing. TestTheWritePathIsUntouched asserts it four ways, because the claim has four parts. A real batch pass is driven with the entry point patched, counting every metrics call and every clock read strictly between its entry and its exit -- both must be zero -- and then driven again with a job that publishes tree_advanced to a well-behaved subscriber, the one indirect route from that thread to this module. _write_batch is read from the parsed source and no call it makes may name a clock, a counter, a recorder, a metric or a lock other than the write-behind's own, so a call added later on a branch no test drives still reddens. _write_then_sync is read the same way and may contain no global and no augmented assignment, which is what keeps an accumulator from reappearing in the funnel. And both modules must import nothing from kiro_crew.metrics at all, lazily or otherwise.

The omissions stay omitted. TestOmissionsAreDeliberate pins the shipped name list exactly, asserts no registered name contains append.bytes, append.batch or fold.lag, and asserts the metrics doc promises none of them -- so re-adding one without a source off the write path fails here rather than sliding past review.

Nothing a collection does reaches the crew log. Each reader answers None with its source absent from sys.modules, and a parsed-source case asserts neither reader contains an import statement at all.

Refusals are not failures. A fold skipped at another boundary counts as written. A parsed-source case asserts save's outcome expression compares against what was offered and contains no len(; another asserts both call sites sit inside a finally and after release_lease, since a point moved out of either stops being correct in a way no behavioural test over a store that never raises would notice.

The rest of the acceptance list. Session vs slot kind, and both separable; a save that raises counts failed and the raise propagates; each bucket edge, from an injected clock pair and never a sleep, plus a clock that went backwards and a NaN; one raising subscriber is one point, a second raise is a second point, a non-raising subscriber is none, an unknown event kind maps to other, and the publisher still learns nothing; an empty queue reports zero while an absent one reports nothing; the gauges equal live state at collection; a raising probe is a gap rather than an exporter failure; a telemetry failure never reaches the savepoint or the bus; with telemetry off nothing is recorded and no instrument is created; and a meter that blows up at registration is logged and swallowed.

Also run: the four crew log suites this touches (bus, checkpoint, slot savepoint, write-behind) and the provider suite -- 257 cases with the new file, all passing -- plus flake8, isort, black, mypy over src/kiro_crew/ (3304 files) and scripts/docs_lint.py.

Manual verification

N/A -- unit coverage sufficient. Both gauges are exercised through a real in-memory SDK pipeline (InMemoryMetricReader + MeterProvider), and both counters are driven through their production call sites, so no path here is reachable only by an integration run.

Related Issues

Part of the crew log health section of the usage-metrics work (second batch, minus fold.lag).

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision b3e10ff06fba5b6ce6d71f634699c49f65256fc6 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 19, 2026
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of b3e10ff06fba5b6ce6d71f634699c49f65256fc6 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check that the test pinning writer.py and store_segment_writes.py as byte-identical to main is a guard against drift, not a hard rule against ever adding write-path telemetry.

[DESIGN-REVIEWED] b3e10ff

Description read

[DESCRIPTION-READ] 20eadfe5ca5a7babd42c707a1bf9a5bf95c5ad14c086f6916e8b1a36ed58e929

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of b3e10ff06fba5b6ce6d71f634699c49f65256fc6 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

Every design rule in crew_log_health.py cites "RFC section 6.5" and "RFC rule 2/3/5", but no document on the base contains them, so readers are pointed at a source that isn't there.

Not justified as shipped

  • Item 6 — inherited: the module docstring says "This module covers the second batch of RFC section 6.5" and the code leans on "RFC rule 2", "rule 3" and "rule 5". I grepped docs/ for kirocrew.crew_log, fold.apply and write.lost. The only match is metrics.md, which this diff edits. None of the 116 base RFCs names these instruments.
    Subtraction: delete the "RFC 6.5" and "RFC rule N" citations in crew_log_health.py, and let each rule stand on the reason already written beside it.
    Clears when: the citations are removed, or the RFC path on the base is named.
  • Item 7 — rides along: TestOmissionsAreDeliberate fails any future append.bytes, append.batch or fold.lag instrument. A deferral the description calls temporary ("wait for a source") becomes a test that blocks future work. It stays at inventory level because it ships no product surface.

What this change ships

Inventory (7 items) — 5 justified

Intent: an operator can tell from metrics whether the crew log is backlogged, persisting savepoints, or has a failing subscriber. ADDITION.

  1. A savepoint-write counter (kind, outcome, duration band) on session and slot savepoints — justified
  2. An eager fold queue depth gauge, absent when no queue exists — justified
  3. A gauge for entries the write-behind is holding, absent when no writer was built — justified
  4. A counter for bus subscribers that raise, beside the existing WARNING — justified
  5. New public eager.queue_depth() accessor, one consumer (the gauge) — justified
  6. Docstrings and comments cite RFC 6.5 rules that no base RFC contains — inherited
  7. A test that keeps three named metrics from ever being registered — rides along

[FIRST-PRINCIPLES-REVIEWED] b3e10ff

Description read

[DESCRIPTION-READ] c6bc19904673417afc7ca365d5545e2abec8ac6f57996ffa0eb03114f7f12eee

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed b3e10ff06fba5b6ce6d71f634699c49f65256fc6 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] b3e10ff

Verdict parsed from the review's SHA-scoped output markers for commit b3e10ff06fba5b6ce6d71f634699c49f65256fc6.

False positive or not applicable? A repository writer can comment:
/ai-review override fable b3e10ff06fba5b6ce6d71f634699c49f65256fc6: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of b3e10ff06fba5b6ce6d71f634699c49f65256fc6 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] b3e10ff

False positive or not applicable? A repository writer can comment:
/ai-review override gpt b3e10ff06fba5b6ce6d71f634699c49f65256fc6: <one-sentence reason>

@chenmingwei23
chenmingwei23 force-pushed the feat/22180-crew-log-health-batch2 branch from 4567581 to ac25890 Compare October 19, 2026 16:41
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 19, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/22180-crew-log-health-batch2 branch from ac25890 to 63e68c2 Compare October 19, 2026 16:53
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 19, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/22180-crew-log-health-batch2 branch from 63e68c2 to 9ab5a3b Compare October 19, 2026 17:01
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 19, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the careful write-up. The instruments are well bounded and the call sites are correct as far as I can trace them. I am leaving a comment rather than an approval, because three things need a maintainer before this can merge.

1. The design this implements is not agreed yet. The module docstring and the closed enums cite "RFC section 6.5" and "RFC rule 2". That RFC is #22180, which is still open with no review. The metric names, the attribute sets and the bucket banding on savepoint.write are product decisions, so a maintainer design sign-off on #22180 must come first. The First Principles lane makes the same point about bucket: the stated goal is "whether savepoints are landing", and the latency bands answer a different question. If the RFC lands with bucket, that concern goes away.

2. Merge order with #22226. Both PRs add metrics/crew_log_health.py and test/metrics/test_crew_log_health.py as new files, so the second to merge has an add/add conflict on both. test_the_four_shipped_names_are_exactly_these pins ALL_METRIC_NAMES to the four names here, so it must hold the union after the rebase. #22226 also edits crew_log/writer.py (the _dropped_count accounting). That is fine for this PR's AST checks, but it makes the "byte-identical to the base branch" claim untrue after the rebase (inline 2). Suggested order: #22180, then #22226, then this PR rebased on top. Both PRs also touch docs/system-specs/modules/metrics.md and metrics/provider.py with #22217, #22218, #22219, #22220 and #22223.

3. CI. The red Fast Gate on this head is the Harness Parity Gate failing on the ACP_BACKENDS_MEMBER_CAPABILITIES [claude] allowlist entry, and Coverage Gate fails behind it. This diff touches no backend file, so neither failure comes from this change. Main carries the same failure until #22178 merges. A rerun after that is needed for readiness: passed.

Agreed with the First Principles lane on one smaller point: _observations copies process_gauges._observations, and the reason given ("stays loadable when the SDK is absent") does not hold, because process_gauges also imports opentelemetry inside the function. Importing the existing helper removes the copy.

What I checked on head 9ab5a3b: the full diff; the callers of checkpoint.save and save_slot on main (the session and slot projection folds, not the write-behind), which answers the Design Review question; get_recorder and emit_counter on main for what the bus counter can reach on a write thread; the failing check logs; and the overlapping open PRs. I did not run the tests locally.

calls: list = []
try:
bus.subscribe(bus.TREE_ADVANCED, lambda e: (_ for _ in ()).throw(RuntimeError("x")))
with patch.dict(sys.modules, {"kiro_crew.metrics.crew_log_health": None}):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 This test stays green if the bus site is changed to an import, so it does not guard the property it names.

The test sets sys.modules["kiro_crew.metrics.crew_log_health"] = None and asserts that the counter was not called. Suppose _count_subscriber_error is changed to from kiro_crew.metrics import crew_log_health as health. With a None entry in sys.modules, that import raises ImportError. The bare except Exception: pass in _count_subscriber_error catches it, and calls stays empty. So the regression this test exists to catch, a write thread doing the first import of the metrics facade, passes it.

with patch.dict(sys.modules, {"kiro_crew.metrics.crew_log_health": None}):
    with patch.object(clh, "bus_subscriber_error", calls.append):
        bus.publish(bus.TREE_ADVANCED, object())

Suggestion: pop the module instead of setting it to None, publish from a raising subscriber, then assert "kiro_crew.metrics.crew_log_health" not in sys.modules. Or add a parsed-source check that _count_subscriber_error contains no ast.Import or ast.ImportFrom node, like the check you already have for the two readers. If the import variant turns this test red, I will withdraw this.

"""The hard constraint: not one line of the write path is this change's.

Four assertions, because the claim has four parts: the two files that carry
the write path are byte-identical to the base branch; driving a real batch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 The docstring and the PR description say the write path files are held "byte-identical to the base branch", but no test checks that.

The four tests in this class check imports, calls in _write_batch, global and augmented assignment in _write_then_sync, and a driven batch pass. None of them compares the files with the base. That is the right design, because #22226 edits crew_log/writer.py and a byte check would block it. But the claim is then not true after either PR merges, and a later reader can take it as a guarantee.

Suggestion: say what the tests hold, for example "the write path gains no metrics import, no clock read and no counter call", and remove "byte-identical" here and in the description.

@chenmingwei23
chenmingwei23 force-pushed the feat/22180-crew-log-health-batch2 branch from 9ab5a3b to 58136ed Compare October 19, 2026 17:11
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 19, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Answering First Principles item 4 (bucket on kirocrew.crew_log.savepoint.write), and leaving the attribute in.

The lane is right that the support is not findable from this PR alone, and that is the gap worth closing rather than the attribute. The source is #22180, section 6.5, whose second-batch table specifies this metric as savepoint.write with attributes kind / outcome / bucket. The same document's section 4 states the rule the attribute follows -- a duration is a counter with a small closed bucket whose edges are stated in code and docs, never a histogram, because explicit histogram buckets do not survive every backend -- and the four edges here (lt_10ms / lt_100ms / lt_1s / ge_1s) are the set it uses for the sibling fold metric, so the two read on one axis.

On the cost the item prices: the clock pair is on the fold and read path, roughly once per 256 entries, and never on a crew log write thread. TestTheSavepointCounterIsOffTheWriteThread now pins that from the call graph rather than by assertion -- savepoints.save is reached only from projection_session.fold_session and save_slot only from projection_slot_memo._persist_slot_fold, and no emit*.py module names either -- so a change that folded a session from inside a write job would redden rather than quietly put a time.monotonic() pair on that thread.

Item 7 of the same verdict is fixed in 58136ed8d07599dfc6705324a7c68b9503fcdb4a: the duplicate _observations wrapper is deleted and process_gauges._observations imported instead. The reason the copy carried was also wrong, as the item says -- process_gauges defers its OTEL import exactly the same way -- so nothing was keeping this module loadable that the shared helper does not.

Why bucket stays rather than being deferred to a follow-up: the four series it adds are specified together with the metric, and splitting them out would ship a counter whose shape then changes once a consumer has read it.

@chenmingwei23
chenmingwei23 force-pushed the feat/22180-crew-log-health-batch2 branch from 58136ed to 3ce5d01 Compare October 19, 2026 17:24
Add kirocrew.crew_log.savepoint.write, .eager.queue_depth, .writer.buffered
and .bus.subscriber_error. append.bytes, append.batch and fold.lag are
omitted: every source for them is work on the crew log write path, which
this change leaves untouched byte for byte.
@chenmingwei23
chenmingwei23 force-pushed the feat/22180-crew-log-health-batch2 branch from 3ce5d01 to b3e10ff Compare October 19, 2026 17:53

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the update. Rebased on current main, and two earlier points are resolved on head b3e10ff:

  • _observations is now imported from process_gauges inside register_crew_log_health_instruments instead of copied. The signatures match and the deferred import keeps the module loadable without the SDK.
  • TestTheSavepointCounterIsOffTheWriteThread now asserts from the call graph that only the session and slot fold modules call savepoints.save / savepoints.save_slot, and that no emit*.py module folds a session. I checked that both fold modules import checkpoint as savepoints, so the qualified match does find them. That covers the Design Review question about the facade import on a write thread.

I am still leaving a comment rather than an approval:

1. The design is not agreed yet. This implements section 6.5 of #22180, which is still open with no review. The metric names, attributes and the bucket banding are product decisions, so a maintainer design sign-off on #22180 has to come first.

2. Merge order with #22226 is unchanged. Both PRs still add metrics/crew_log_health.py and test/metrics/test_crew_log_health.py as new files, so the second to merge gets an add/add conflict on both. #22226 also edits crew_log/writer.py, projection_session.py and projection_slot_memo.py. After the rebase, test_the_four_shipped_names_are_exactly_these must hold the union of names, and test_the_savepoint_writers_are_reached_from_only_the_fold_path should be rerun against those projection edits. Suggested order: #22180, then #22226, then this PR rebased on top.

3. The two test points from my last review still apply (inline). Neither the sys.modules[...] = None test nor the "byte-identical to the base branch" wording changed in this push.

4. CI. The rebase picks up the fix for the main-wide Harness Parity red. Checks on this head are still running and readiness is checking, so I have not verified that it turns green.

What I checked: the diff between the previous head 9ab5a3b and b3e10ff for the files this PR owns (only crew_log_health.py and the test file changed), process_gauges._observations on this head, the savepoint call sites in both fold modules, and the current state of #22180 and #22226. I did not run the tests locally.

calls: list = []
try:
bus.subscribe(bus.TREE_ADVANCED, lambda e: (_ for _ in ()).throw(RuntimeError("x")))
with patch.dict(sys.modules, {"kiro_crew.metrics.crew_log_health": None}):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Still open from the last review: this test stays green if the bus site is changed to an import, so it does not guard the property it names.

With sys.modules["kiro_crew.metrics.crew_log_health"] = None, a future from kiro_crew.metrics import crew_log_health inside _count_subscriber_error raises ImportError. The bare except Exception: pass there swallows it and calls stays empty, so the regression this test exists for (a write thread doing the first import of the metrics facade) passes.

Suggestion: pop the module instead of setting it to None, publish from a raising subscriber, then assert "kiro_crew.metrics.crew_log_health" not in sys.modules. Or add a parsed-source check that _count_subscriber_error has no ast.Import or ast.ImportFrom node, like the one you already have for the two readers.

"""The hard constraint: not one line of the write path is this change's.

Four assertions, because the claim has four parts: the two files that carry
the write path are byte-identical to the base branch; driving a real batch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Still open from the last review: "byte-identical to the base branch" is not what these tests check.

The tests in this class check imports, calls in _write_batch, global and augmented assignment in _write_then_sync, and a driven batch. None compares the files with the base, which is the right design because #22226 edits crew_log/writer.py. The claim becomes untrue once either PR merges, and a later reader can take it as a guarantee.

Suggestion: state what the tests hold, for example "the write path gains no metrics import, no clock read and no counter call", and drop "byte-identical" here and in the PR description.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 19, 2026

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed head b3e10ff. Approve on the code; merging waits on the design decision for #22180 and on a rebase onto #22226 after it merges.

The label sets are closed and fold onto other. The two gauges have no attributes. The write path files are unchanged, and the savepoint counter is reported after the lease is released.

Before merge (ordering):

  • A trial merge onto #22226 conflicts in metrics/crew_log_health.py, its test file and metrics/provider.py. Both PRs define the same four bucket bands and their own fallback helpers; please keep one copy, and make test_the_four_shipped_names_are_exactly_these list all seven names.
  • #22226 imports the crew_log_health module on the fold worker at startup and on every fold, whatever the telemetry setting. After both land, bus._count_subscriber_error can find the module in sys.modules before the recorder is built and run the first get_recorder() build on a crew log write thread. Please add a recorder-already-built check there, and re-run the call-graph tests on the merged tree.

Follow-ups, not blocking:

  • test_a_raising_subscriber_on_that_thread_cannot_trigger_a_first_import still passes if the bus uses a plain module import instead of the sys.modules lookup, because the patched sys.modules entry makes that import raise and the bare except swallows it. Popping the module, or asserting it was not imported, would close this.
  • Please drop "byte-identical to the base branch" from the test docstring and the PR description, since it stops being true once #22226 lands.

@iamwhatever
iamwhatever merged commit e283043 into main Oct 20, 2026
105 checks passed
@iamwhatever
iamwhatever deleted the feat/22180-crew-log-health-batch2 branch October 20, 2026 00:58
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 20, 2026
@buluoray buluoray mentioned this pull request Oct 20, 2026
5 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants