Skip to content

fix(storage): honest Promise<number | void> type for commit-latency recorder#1853

Merged
kriszyp merged 1 commit into
mainfrom
fix/commit-latency-promise-type
Jul 23, 2026
Merged

fix(storage): honest Promise<number | void> type for commit-latency recorder#1853
kriszyp merged 1 commit into
mainfrom
fix/commit-latency-promise-type

Conversation

@kriszyp

@kriszyp kriszyp commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary

Fixes the org-wide red main build (tsc TS2345) introduced by #1688.

resources/DatabaseTransaction.ts:367 passed commitResolution to recordCommitLatency(_: Promise<void>, ...), but commitResolution is declared Promise<number | void> | void. The as Promise<void> cast on the transaction.commit() assignment (line 360) was ineffective: TypeScript's assignment narrowing filters the declared union and re-widens to the Promise<number | void> member, so the cast never took effect and the argument stayed Promise<number | void>.

Fix

commit() honestly resolves to number | void — the coordinated-retry RETRY_NOW_VALUE sentinel, which is checked in the resolve callback (line 397). So:

  • Widen recordCommitLatency's parameter to Promise<number | void> (the honest type).
  • Drop the misleading/ineffective as Promise<void> cast and correct the adjacent comment.

recordCommitLatency only records the submit→settle timing and ignores the resolved value, so the per-attempt latency metric is unchanged — the transient-conflict retry still rejects and re-issues commit(), re-arming per attempt.

Where to look

  • resources/DatabaseTransaction.ts:45 — widened recorder parameter.
  • resources/DatabaseTransaction.ts:360 — cast removed; comment corrected.

Tests

  • npm run build (tsc) — clean.
  • unitTests/resources/transactionCommitLatency.test.js — 2 passing.
  • npm run test:unit:resources — 1162 passing, 14 pending.

Refs #1688.

Generated by an LLM (Claude Opus 4.8).

🤖 Generated with Claude Code

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the type of commitResolution in DatabaseTransaction.ts from Promise<void> to Promise<number | void> to correctly match the return type of transaction.commit(), which can resolve to a coordinated-retry sentinel number. It also removes an unnecessary type cast and updates the relevant comments to document this behavior. There are no review comments to address, so no further feedback is provided.

@claude

claude Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Reviewed; no blockers found.

// async `Transaction.commit()` result, which is guaranteed to be a Promise). The parameter matches
// `commit()`'s honest `Promise<number | void>` result (the coordinated-retry sentinel); the resolved
// value is intentionally ignored — only the settle timing is recorded.
function recordCommitLatency(commitResolution: Promise<number | void>, submittedAt: number) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note: three open PRs fix this same recordCommitLatency type error — only one should land.

#1853 (this), #1887, and #1869 all edit these same lines in DatabaseTransaction.ts, so whichever merges first leaves the other two with a conflict. Of the three, this is the cleanest fix: it makes the parameter type honest (Promise<number | void>, matching commit()'s actual result), drops the ineffective as Promise<void> cast, and corrects the comment.

Suggest landing this dedicated fix and dropping the type change from the other two.


Generated by Barber AI

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah ,we are really going to make sure we land this fix!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Update: the duplicate-fix note above is stale.

Since that comment, #1890 (fix(types): widen recordCommitLatency parameter so the build type-checks) closed and #1899 (Fix recordCommitLatency parameter type for the widened commitResolution union) merged — landing the same TS2345 fix with the looser Promise<unknown> | void type. Those were the actual competing PRs, not #1887/#1869 as previously stated (#1869 no longer touches this file; #1887's edit here is unrelated, further down in the same method).

#1853 is now a clean refinement on top of #1899's merged fix: narrows the parameter to the more precise Promise<number | void> (matching commit()'s actual resolved type, including the RETRY_NOW_VALUE sentinel) and updates the adjacent comments. mergeable: true against current main — no conflict.


Generated by Barber AI

…ecorder

The `as Promise<void>` cast on `transaction.commit()` was ineffective:
`commitResolution` is declared `Promise<number | void> | void`, so
assignment narrowing re-widens to the `Promise<number | void>` union
member and `recordCommitLatency(commitResolution, ...)` failed tsc
(TS2345) — the org-wide red main build.

`commit()` genuinely resolves to `number | void` (the coordinated-retry
RETRY_NOW_VALUE sentinel), so widen `recordCommitLatency`'s parameter to
`Promise<number | void>` and drop the misleading cast. The recorder only
times the settle; it ignores the resolved value, so per-attempt recording
is unchanged.

Regression from #1688.

Co-Authored-By: Claude Opus <noreply@anthropic.com>
@kriszyp
kriszyp force-pushed the fix/commit-latency-promise-type branch from 3797a73 to 9093d5c Compare July 22, 2026 18:35
@kriszyp
kriszyp merged commit 2615b09 into main Jul 23, 2026
99 of 100 checks passed
@kriszyp
kriszyp deleted the fix/commit-latency-promise-type branch July 23, 2026 14:59
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.

2 participants