Skip to content

Add budgetMs(), cause(), value generics and values-only wire codec (0.5.0) - #32

Merged
rasuvaeff merged 1 commit into
masterfrom
feat/review-2026-11-20
Nov 20, 2026
Merged

rasuvaeff merged 1 commit into
masterfrom
feat/review-2026-11-20

Conversation

@rasuvaeff

@rasuvaeff rasuvaeff commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Wave 2 of the 2026-11-20 code-quality review.

  • Context::budgetMs(): ?int — remaining budget in whole ms (min 1), read before the active check; WireCodec::encode() uses it.
  • Context::cause(): ?TerminationCause — why a context ended, observing pending requests and the deadline.
  • WireCodec::encodeValues() / decodeValues() — values only, for transports that carry the deadline themselves; encode()/decode() are built on them.
  • Static WireCodec::budgetFromWire() — the single incoming-budget rule, so context-http's budget header can share it (Use a single rule for validating the budget header context-http#17). Accepted input unchanged.
  • Generics on withValue()/value() (class-string<T> → T|null), pinned by a psalm type fixture in tests/Types (red without the annotations). The runtime key check stays behind a private helper so psalm does not call it redundant and rector does not inline it.
  • Dead Context::$parent link and its fallback removed.
  • ContextState::__destruct() gives the pending-request counter back when a state is collected with an unobserved request; seconds→ns conversion is one private helper.

Local mutation (--with-uncovered, zend.assertions=-1): MSI 94% (gate 90). Lazy rollouts: none needed (all already in place).

Fixes #23
Fixes #24
Fixes #25
Fixes #26
Fixes #28
Fixes #29

Summary by Sourcery

Improve context budgeting, termination inspection, typed values, and transport serialization for the 0.5.0 release.

New Features:

  • Add context budget and termination-cause inspection APIs for adapters and callers.
  • Add values-only wire encoding and decoding for transports that manage deadlines separately.
  • Add generic type inference for context values and centralize incoming wire-budget validation.

Bug Fixes:

  • Release pending cancellation requests when their context state is garbage-collected without observation.

Enhancements:

  • Remove redundant parent links from contexts and consolidate duration conversion logic.

Documentation:

  • Document the new context inspection APIs, values-only wire codec, wire-budget rules, and inferred value types in English and Russian guides.
  • Record the 0.5.0 release changes in the changelog.

Tests:

  • Expand context and wire-codec coverage for budgets, causes, values-only transport behavior, malformed inputs, garbage collection, and generic value types.

@sourcery-ai

sourcery-ai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Sorry @rasuvaeff, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 6 days by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: da948980-253c-4d97-a017-af35756da6a2
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sourcery-ai

sourcery-ai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Reviewer's Guide

API

Expose typed context values and termination inspection, and add a positive-millisecond budget that checks activity after reading the remainder.

  • src/Context.php L190-208, L234-251, L395-423 (+4 small edits)

Add values-only wire methods and centralize parsing of incoming budgets while keeping encode and decode built on those operations.

  • src/WireCodec.php L65-79, L105-121, L137-148 (+1 small edits)

Implementation

Remove the retained parent context link and consolidate seconds-to-nanoseconds conversion for timeout, reserve, and sleep calculations.

  • src/Context.php L16-450 (7 small edits)

Release the process-wide pending-request count when an unobserved request's state is destroyed.

  • src/Internal/ContextState.php L32-48

Configuration

Include the Psalm type fixture in the analyzed project files so the context value generics are checked.

  • psalm.xml L9

Documentation

Document the new budget, cause, values-only codec, and typed-value APIs, and update release notes and review guidance.

  • AGENTS.md L76-77
  • CHANGELOG.md L8-32
  • README.md L119-127, L245-257, L285-289 (+4 small edits)
  • README.ru.md L123-131, L253-265, L294-298 (+4 small edits)
  • llms.txt L107-118

Tests

Cover context cause and budget behavior, value propagation and typing, pending-request cleanup, and the values-only codec and budget parser.

  • tests/ContextRequestCancelTest.php L184-201
  • tests/ContextTest.php L296-424
  • tests/Types/ContextValueTypes.php L1-19
  • tests/WireCodecTest.php L137-191, L340-432

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@rasuvaeff
rasuvaeff merged commit 493a510 into master Nov 20, 2026
12 checks passed
@rasuvaeff
rasuvaeff deleted the feat/review-2026-11-20 branch November 20, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment