Skip to content

fix(analytics): a nested invocation's db_ms no longer exceeds its parent's - #497

Merged
allisonmahmood merged 1 commit into
mainfrom
t3code/12e48e61
Oct 3, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
t3code/12e48e61

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

A nested mutation's db_ms could come out larger than its parent action's, which breaks the documented contract that a child's connection time counts toward the parent. It showed up as a CI failure in the dev-execution test (parent 2, child 3). In production it skews invocation rows and the quiet-query rollups by up to one GC pause per nesting level.

The cause was the order of clock reads in DatabaseMeter. When a reservation started, the child read the clock before starting its parent, so a stall between those two reads gave the parent a shorter interval than the child.

Collector.start() now starts the parent before taking its own reading. Release already stops the child before releasing the parent, so every ancestor's interval now contains its descendant's, at any depth and wherever a stall falls. The Collector interface, ConnectionTiming and the dev-execution assertion are unchanged, and no tolerance was added.

New tests in packages/analytics run two- and three-level chains over a scripted clock that stalls between the reads inside start(). Both fail on the old ordering.

Closes #491

Made by Claude Opus 5.5 via Claude Code; reviewed by GPT 6.1 Sol via codex.

@github-actions github-actions Bot added area:server Touches the server area size:s Under 100 changed lines labels Oct 2, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Codex review (GPT 6.1 Sol, read-only), ed814fe: no concrete defects found.

It traced the new order: ancestors start first and the child releases first, so ancestor.start ≤ descendant.start ≤ descendant.end ≤ ancestor.end holds at every depth, wherever the stalls fall. Rounding keeps the inequality. It found no regression in ConnectionTiming, Invocation or InvocationCapabilities for snapshots while open, idempotent release, same-tick concurrent reservations or killed invocations.

Both new tests failed with the old ordering restored (parent/child 0.002/0.031 ms) and passed on the fix. It also ran 90 more combinations of depth and stall placement, all of which held.

…ent's

The meter's start read this collector's clock before starting the parent,
so a stall between those readings gave the parent a shorter interval than
its child. Start ancestors first; release already stops this collector
before its parent, so each ancestor's interval now contains its child's.

Closes #491

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@allisonmahmood
allisonmahmood merged commit b320800 into main Oct 3, 2026
13 checks passed
@allisonmahmood
allisonmahmood deleted the t3code/12e48e61 branch October 3, 2026 19:34
allisonmahmood added a commit that referenced this pull request Oct 3, 2026
…wice (#496)

# What changed

The nested CSS watch test in `pageImports.test.ts` flaked on CI (`test
(22)` on #485). It read one watcher result per file write. A plain write
truncates and then writes, which can trigger two rebuilds, so a stale
duplicate refusal could stand in for the fixed build.

The test now saves by renaming a complete file into place, and its
`next()` skips a result identical to the one it last returned. These are
the mitigations the dev server's watch test already uses (`save` and
`inspectedChanges` in `devServerWatch.test.ts`). Assertions stay outside
the wait, so a new error or unexpected CSS still fails. No production
code changes; triage found no production defect.

Closes #487

## How it was verified

- [x] `pnpm test` passes locally
- [x] Added or updated tests covering this change

- Temporary checks (not shipped): pushing a duplicate refusal into the
queue before and after the fix write fails the old test, and the new
test reaches the blue build. The new test still fails on a differing
refusal after the fix, or on a fix that writes green instead of blue.
- `isDeepStrictEqual` treats two `LocalError` refusals with the same
code and message as equal, and different ones as unequal, on Node
22.22.0 and 24.20.0.
- Looped 50 times each on Node 22.22.0 and 24.20.0, run concurrently:
100/100 passed.
- `pnpm verify`: format, lint, typecheck, test (1625/1625),
postgres-concurrency, cli-smoke, tier2-smoke and browser pass.
- After rebasing onto `b320800` (#497), which adds an unrelated
`it.each` build test to the same file: looped 25 times each on Node
22.22.0 and 24.20.0, 50/50 passed; format, lint and test typecheck pass.

## Release impact

- [ ] **Breaking**
- [x] **Not breaking**: test only.

## Review

- GPT 6.1 Sol (codex): no findings.
- `/code-review` standards and spec passes: no hard findings. The file's
node-builtin waiver reason now covers the deep comparison.

Made by Claude Opus 5.5 via Claude Code; reviewed by GPT 6.1 Sol via
codex.

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:server Touches the server area size:s Under 100 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant