Skip to content

feat(java): proxy sessions with identity dedup and cleanup#369

Merged
pratyush618 merged 2 commits into
masterfrom
feat/java-proxy-sessions
Jul 6, 2026
Merged

feat(java): proxy sessions with identity dedup and cleanup#369
pratyush618 merged 2 commits into
masterfrom
feat/java-proxy-sessions

Conversation

@pratyush618

@pratyush618 pratyush618 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a unit-of-work session layer to the proxy system, giving it identity dedup and a cleanup lifecycle — previously N refs to the same resource meant N handler calls, N instances, and no way to release anything.

  • New ProxySession (AutoCloseable, thread-confined like TaskScope), created via proxies.session():
    • deconstruct memoizes by (instance identity, purpose) — deconstructing the same object again returns the same signed ref without invoking the handler twice. Purpose is part of the key so a ref bound to one purpose is never handed out for another; the first call's TTL wins per key.
    • reconstruct/resolve memoize by the ref's signature (the HMAC covers handler, canonical reference, expiry, and purpose, so equal signatures mean equal content) — every ref to the same resource resolves to one shared instance, reconstructed once. Signature, expiry, and purpose are re-verified on every call, memo hits included, so a ref that expires mid-session stops resolving.
    • close() runs the new ProxyHandler.cleanup(value) hook once per unique reconstructed instance, LIFO, with per-entry error isolation; idempotent; use-after-close throws.
  • ProxyHandler gains default void cleanup(T value) {} — binary-compatible with every existing handler; only session-reconstructed instances participate (direct Proxies.reconstruct stays lifecycle-free, documented).
  • Proxies refactor: verification and handler lookup extracted into package-private verify/handlerFor (error precedence unchanged); public API otherwise untouched and still stateless.

Tests

7 new ProxyTest cases: same-instance deconstruct dedup (handler called once), purposes kept distinct, reconstruct memo (same instance, handler called once), cleanup-once LIFO order + idempotent close, session isolation, re-verify on memo hit with a short TTL, use-after-close rejection. 19/19 green; full ./gradlew build green.

Summary by CodeRabbit

  • New Features

    • Added session-based proxy handling for safer, repeatable use within a scoped lifecycle.
    • Repeated conversions and lookups now reuse cached results within a session for more consistent behavior.
    • Added automatic cleanup when a session closes, with predictable reverse-order cleanup.
  • Bug Fixes

    • Improved validation so expired or mismatched proxy references are rejected consistently, even when reused from cache.
    • Prevented proxy sessions from being used after they are closed.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 32 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6fdfe4a7-f1fa-4c40-9e70-424cb7c0e8ad

📥 Commits

Reviewing files that changed from the base of the PR and between d26ce71 and 92f0096.

📒 Files selected for processing (2)
  • sdks/java/src/main/java/org/byteveda/taskito/proxies/ProxySession.java
  • sdks/java/src/test/java/org/byteveda/taskito/ProxyTest.java
📝 Walkthrough

Walkthrough

This PR refactors Proxies.reconstruct to use a new handlerFor helper and delegated verify call, adds a session() factory method, introduces a cleanup default method on ProxyHandler, and adds a new ProxySession class providing memoized deconstruct/reconstruct with LIFO cleanup on close.

Changes

ProxySession feature

Layer / File(s) Summary
Proxies refactor and session() factory
sdks/java/src/main/java/org/byteveda/taskito/proxies/Proxies.java
reconstruct now resolves handlers via a new handlerFor helper and delegates validation to verify; a new session() method constructs a ProxySession.
ProxyHandler cleanup hook
sdks/java/src/main/java/org/byteveda/taskito/proxies/ProxyHandler.java
A default no-op cleanup(T value) method is added, invoked once per unique instance in LIFO order when a ProxySession closes.
ProxySession core implementation
sdks/java/src/main/java/org/byteveda/taskito/proxies/ProxySession.java
New ProxySession class implements AutoCloseable, memoizes deconstruct by instance identity/purpose, memoizes reconstruct by ref signature while scheduling cleanup, provides resolve casting helpers, and runs cleanups LIFO exactly once on close(), enforcing a closed lifecycle via ensureOpen().
Session behavior tests
sdks/java/src/test/java/org/byteveda/taskito/ProxyTest.java
Adds a CountingFileHandler and tests covering deconstruct dedup, purpose isolation, reconstruct memoization, LIFO cleanup idempotency, session isolation, TTL re-verification on memo hits, and use-after-close rejection.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ProxySession
  participant Proxies
  participant ProxyHandler

  Caller->>ProxySession: reconstruct(ref)
  ProxySession->>ProxySession: ensureOpen()
  ProxySession->>Proxies: verify(ref, expectedPurpose)
  Proxies->>ProxyHandler: handlerFor(ref.handler())
  ProxyHandler-->>Proxies: reconstruct(ref.reference())
  Proxies-->>ProxySession: value
  ProxySession->>ProxySession: memoize value, push cleanup action
  ProxySession-->>Caller: value

  Caller->>ProxySession: close()
  ProxySession->>ProxyHandler: cleanup(value) [LIFO order]
  ProxySession->>ProxySession: clear memoization state
Loading

Possibly related PRs

  • ByteVeda/taskito#349: Modifies the same Proxies.reconstruct handler lookup and validation flow that this PR builds upon for the session-based refactor.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding proxy sessions with identity deduplication and cleanup.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/java-proxy-sessions

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sdks/java/src/main/java/org/byteveda/taskito/proxies/ProxySession.java`:
- Around line 115-132: ProxySession.close() only catches RuntimeException during
cleanup, so an Error from cleanup.run() can abort the teardown loop and leave
remaining cleanups permanently undrained because closed is already true. Update
the close() cleanup loop in ProxySession to catch Throwable instead of
RuntimeException, keep logging the failure with LOG.log(Level.WARNING, ...), and
continue draining cleanups so every pending resource is torn down in LIFO order
even if one cleanup fails.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 99052d4c-8210-44b2-8aef-2986247144cf

📥 Commits

Reviewing files that changed from the base of the PR and between 07cd25b and d26ce71.

📒 Files selected for processing (4)
  • sdks/java/src/main/java/org/byteveda/taskito/proxies/Proxies.java
  • sdks/java/src/main/java/org/byteveda/taskito/proxies/ProxyHandler.java
  • sdks/java/src/main/java/org/byteveda/taskito/proxies/ProxySession.java
  • sdks/java/src/test/java/org/byteveda/taskito/ProxyTest.java

@pratyush618

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@pratyush618 pratyush618 merged commit 7d76999 into master Jul 6, 2026
18 checks passed
@pratyush618 pratyush618 deleted the feat/java-proxy-sessions branch July 6, 2026 05:53
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.

1 participant