Skip to content

fix: release tenant sessions after proof events - #441

Merged
ajile-in merged 2 commits into
credebl:mainfrom
sign-mark:codex/fix-proof-event-tenant-session
Sep 12, 2026
Merged

fix: release tenant sessions after proof events#441
ajile-in merged 2 commits into
credebl:mainfrom
sign-mark:codex/fix-proof-event-tenant-session

Conversation

@sign-mark

@sign-mark sign-mark commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Proof-state events in shared agents acquire a tenant session to read format data but never release it. Repeated events retain sessions and can exhaust a configured finite session limit; a failed format-data read leaks its session as well.

Use Credo's withTenantAgent to release the session on both success and failure, before webhook or WebSocket delivery. This follows the existing credential-event handler pattern. Dedicated-agent behavior and event payloads are preserved.

Validation:

  • Four regression tests cover consecutive events with a one-session limit, cleanup before delivery and payload preservation, cleanup after a failed read, and dedicated-agent behavior. Before the fix, three tests fail; after the fix, all four pass.
  • Run tests with TS_NODE_TRANSPILE_ONLY=true yarn test --runInBand src/events/__tests__/ProofEvents.test.ts. The environment variable bypasses an existing TypeScript error in the root Jest config's unsupported name option. The tests also passed a separate TypeScript check.
  • An isolated runtime check using the installed Credo 0.6.2 TenantsApi.withTenantAgent released all five acquired sessions, including a failed read. Wallet access and delivery were stubbed; this was not a live wallet integration test.
  • yarn check-types, yarn lint (zero errors; existing warnings), yarn check-format, and git diff --check pass.

Summary by CodeRabbit

  • Bug Fixes
    • Improved tenant session handling during proof event processing.
    • Ensured sessions are released before webhook and WebSocket delivery, helping prevent resource retention.
    • Preserved subsequent event processing when proof format data retrieval fails.
    • Dedicated-agent processing continues without requiring a tenant session.
    • Improved reliability across consecutive proof events and recovery after processing failures.

Signed-off-by: Mark <markniu@sign.global>
@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 60be65e2-f040-4f9c-9a43-dd13cbb741da

📥 Commits

Reviewing files that changed from the base of the PR and between 7899ff3 and 4ef3475.

📒 Files selected for processing (1)
  • src/events/__tests__/ProofEvents.test.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

proofEvents now retrieves tenant-specific proof format data through withTenantAgent. Tests cover session cleanup, delivery ordering, error recovery, repeated events, and dedicated-agent handling.

Changes

Proof event session lifecycle

Layer / File(s) Summary
Tenant-scoped format retrieval
src/events/ProofEvents.ts
The handler imports RestMultiTenantAgentModules and uses withTenantAgent to retrieve tenant-specific format data.
Session lifecycle validation
src/events/__tests__/ProofEvents.test.ts
Tests verify repeated session cleanup, cleanup after errors, release before delivery, and dedicated-agent processing without tenant sessions.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 4ef34

Tenant proof-event sessions are now released on both successful and failed format-data reads without changing dedicated-agent handling or delivery payloads.

🚥 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 clearly and concisely describes the main change: releasing tenant sessions after proof events.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
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

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

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

@ajile-in ajile-in left a comment

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.

Thanks for the fix, Mark — I verified it locally: the 4 tests pass with the exact command in the PR description, yarn check-types is clean, yarn lint is 0 errors (only pre-existing warnings), and format checks pass. The release semantics are confirmed against the installed Credo 0.6.2 withTenantAgent (calls endSession() in a finally, on both success and failure).

A few things to consider (all non-blocking):

  1. Flaky lint on a fresh checkout: the first full yarn lint run right after yarn install crashed in eslint-plugin-import's no-cycle rule (TypeError: Cannot read properties of null) on the test file's @credo-ts/didcomm import. A re-run passed clean. If CI lints on fresh installs, it may hit this — worth watching.

  2. Pre-existing repo issue this PR relies on: jest.config.ts still has the invalid name option, so a bare jest run fails config parse and the TS_NODE_TRANSPILE_ONLY=true workaround is required. Since this PR introduces the repo's first test suite, fixing that config (or switching to a .mjs/JS config) would make yarn test work without the env-var incantation.

  3. Test design: the fixture stubs Credo's withTenantAgent contract rather than using the real API (documented reason: ESM/native deps). The stub's contract matches reality and you note an isolated runtime check — acceptable for a unit test.

  4. Optional: in the failing-read test, you assert webhook/WebSocket are not called after rejection. Consider also asserting a subsequent event delivers a webhook, to lock in end-to-end recovery (the second handleEvent currently only checks endSession).

@ajile-in
ajile-in requested a review from ankita-p17 September 12, 2026 08:24
Signed-off-by: Mark <markniu@sign.global>
@sign-mark

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough verification and feedback.

I addressed item 4 in 4ef3475 by asserting that the event immediately following a failed proof-data read resumes both webhook and WebSocket delivery. This keeps the recovery guarantee aligned with the test name, in addition to verifying that the tenant session is released.

I left items 1–3 unchanged to keep this PR focused: the lint failure did not reproduce on this run, the Jest configuration issue is pre-existing and better handled separately, and the scoped-session stub remains paired with the Credo 0.6.2 runtime verification already documented in the PR.

Validation after the update:

  • Focused test suite: 4/4 passed
  • yarn check-types: passed
  • yarn check-format: passed
  • yarn lint: 0 errors, existing warnings only
  • git diff --check: passed

@sonarqubecloud

Copy link
Copy Markdown

@ajile-in

ajile-in commented Sep 12, 2026

Copy link
Copy Markdown
Member

Merged

@ajile-in
ajile-in merged commit 9af7aa8 into credebl:main Sep 12, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this to Done in Roadmap Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants