Skip to content

flaky: dev-execution nested mutation trace compares separately rounded db_ms #491

Closed

Description

@allisonmahmood

apps/server/src/DevelopmentExecution.test.ts › "commits a callback-free mutation once per key and admits an action's nested mutation" failed on the test (24) job with no code cause. The PR only touched the CLI's refresh path. test (22) passed on the same commit, and test (24) passed on the two earlier runs of the same change.

Failing run: https://github.com/allisonmahmood/patchy-cloud/actions/runs/37061852421/job/111020127976 (PR #489)

The last assertion, assert.isAtLeast(tree[0]!.parent_ms, tree[0]!.child_ms) at line 315, got a parent db_ms of 2 and a child db_ms of 3.

The likely cause is rounding. runtime_invocations.db_ms is an INTEGER, while the measured times are fractional; the parent action's wide event in that run shows "dbMs":2.481965. The parent and child are measured and rounded separately, so at a few milliseconds a parent that only just covers its nested child can be stored below it. Comparing the unrounded values, or allowing a millisecond of rounding, would remove the race without weakening the "child time contributes to the parent" check.

Activity

  1. added
    flaky
    on Oct 2, 2026
  2. allisonmahmood commented on Oct 2, 2026

    @allisonmahmood
    OwnerAuthor

    This was generated by AI during triage.

    Agent Brief

    Category: bug
    Summary: A nested invocation's db_ms can exceed its parent's because the database meter reads the clock separately for each ancestor

    Current behavior:
    Rounding is not the cause. Math.round is monotonic, so a stored parent of 2 with a child of 3 means the unrounded child (at least 2.5ms) really was larger than the unrounded parent (2.481965ms in the failing run).

    The cause is in the analytics DatabaseMeter collector. When a reservation starts, Collector.start() reads the clock for the child and then calls the parent's start(), which takes its own later reading. On release, the child reads the clock and then releases the parent, which reads again. A GC pause or OS preemption between two of those readings gives the parent a shorter interval than the child when the start gap exceeds the release gap. The parent then records less than its child even after both reservations have closed.

    Two independent traces (Opus 5.5 and GPT 6.1 Sol) confirmed the rest of the attribution chain is sound. The child's meter captures the parent's through capability.observe, every company-database reservation forwards to its ancestors, and in this fixture the child settles before the parent takes its reading. Replaying the real collector with a scripted clock that stalls 30µs between the child's and the parent's start readings gives child 2.51ms and parent 2.4801ms, stored as 3 and 2. That is the CI pattern.

    This breaks the documented contract that a nested mutation's connection time contributes to the parent's db_ms. It also skews the stored invocation rows and quiet-query rollups by up to a GC pause per nesting level. The test failure is the symptom.

    Desired behavior:
    Each ancestor's metered interval for a reservation contains the descendant's interval: the ancestor starts no later and stops no earlier. A parent's db_ms therefore never falls below any child's for reservations that have closed, at any nesting depth and whatever stalls happen between clock readings.

    Key interfaces:

    • DatabaseMeter.Collector.start(): start the parent's reservation before taking this collector's start reading. Keep the current release order: stop this collector first, then release the parent. The public Collector shape (start, the idempotent release it returns, and snapshot) does not change, and ConnectionTiming should need no edits.
    • The doc comment on DatabaseMeter.make should state the containment guarantee.

    Acceptance criteria:

    • A focused test in the analytics package builds a parent and a child collector over a scripted, strictly increasing clock whose biggest gap falls between readings in start(). It asserts parent.snapshot() >= child.snapshot() after release. This test fails on the current code.
    • The same guarantee holds for a three-level chain (grandparent ≥ parent ≥ child).
    • The existing isAtLeast(parent_ms, child_ms) assertion in the dev-execution test "commits a callback-free mutation once per key and admits an action's nested mutation" stays unchanged; no tolerance is added.
    • Existing meter consumers' tests (company-database parent/child meter tests, runtime invocation tests) pass unchanged.

    Out of scope:

    • Sharing one timestamp across all ancestors for exact equality. It would change the Collector interface, and containment is all the contract needs.
    • A killed or early-returning parent that takes its reading while a child is still running. The meter deliberately includes open reservations so a killed invocation need not wait for cleanup; changing that is a separate decision.
    • Storing db_ms as a fractional column, or any other change to how runtime_invocations stores durations.
  3. added
    bug
    area:server
    ready-for-agent
    on Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:serverbugflakyready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions