Skip to content

Conversation

@saiintbrisson
Copy link
Collaborator

No description provided.

@saiintbrisson saiintbrisson requested a review from a team as a code owner December 4, 2025 13:49
@vercel
Copy link

vercel bot commented Dec 4, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
prediction-swarm Ready Ready Preview Comment Dec 4, 2025 1:49pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 4, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

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 and usage tips.

@PsicoThePato
Copy link
Contributor

LGTM

@saiintbrisson saiintbrisson merged commit dbfdf1c into main Dec 4, 2025
28 checks passed
rodrigooler pushed a commit that referenced this pull request Dec 8, 2025
* feat(page): landing page about section (WEB-376) (#419)

* fix(hover-header): rename "Portal" to "Join" and update button classes for better z-index handling

* fix(view-more): update content for clarity by replacing "meta-coordination" with "coordination" in descriptions

* fix(pred-api): only return reply chain context

* feat: services and apps split (#420)

* feat: prediction-swarm app file organization (#422)

* 🔥 removed llhama cpp dependency

* format-fix

* better scheduling

* chore: delete prophet finder

* chore: delete torus allocator

* feat: services renames (#425)

* fix: get paths from turbo

---------

Co-authored-by: Ed. <ed.sdr@outlook.com>
Co-authored-by: PsicoThePato <jmomcontato@gmail.com>
Co-authored-by: PsicoThePato <40248917+PsicoThePato@users.noreply.github.com>
Co-authored-by: kings177 <yanmendesp@gmail.com>
rodrigooler added a commit that referenced this pull request Dec 10, 2025
* fix(torus-wallet): resolve InvalidWorkBlock error and refactor faucet

Fixes faucet.InvalidWorkBlock error caused by premature unsubscription from
new block updates. Refactors code following best practices including fail-fast
pattern, early returns, immutability, and proper error handling.

Key Changes:
- Fix: Moved unsubscribe from finally block to onFound/onError callbacks
- Fix: Use tryAsync for async operations (queryLastBlock, subscribeNewHeads)
- Feature: Automatic retry (up to 3 attempts) for InvalidWorkBlock errors
- Feature: Custom InvalidWorkBlockError class for recoverable errors
- Refactor: Extract pure functions (handleModuleError, handleDispatchError, etc)
- Refactor: Add readonly properties to MultiWorkerManager
- Refactor: Replace non-null assertions with optional chaining
- Refactor: Add Working/Requesting status messages
- Refactor: Remove emojis from console output
- Refactor: Add BlockData and WorkerMessageData interfaces
- Refactor: Extract constants (MAX_RETRIES, FAUCET_AMOUNT, DEFAULT_WORKER_COUNT)

User Experience:
- Silent retry on InvalidWorkBlock with console.log (no error toast)
- Clear status progression: "Working..." -> "Requesting..."
- Error toast only shown after 3 failed retry attempts
- Improved error messages without emojis

Technical Improvements:
- Early return pattern throughout
- No nested if-else statements
- Fail-fast error handling
- Immutable data structures where possible
- Type-safe error handling with custom error classes
- Proper cleanup of subscriptions and workers

Generated with Claude Code
https://claude.com/claude-code

* style(torus-wallet): apply prettier formatting to faucet components

* fix(torus-wallet): resolve faucet resource leaks and error handling issues

- Add error message display when all retry attempts fail
- Terminate workers immediately on error to prevent resource leaks
- Change event loop to for...of with break to prevent duplicate handler calls
- Ensure manager.terminateAll() is called during cleanup
- Call unsubscribe() when extrinsic transaction fails

These fixes address all code review comments and prevent resource leaks
in the faucet worker management and subscription systems.

* fix(torus-wallet): resolve TypeScript 'possibly undefined' error in manager

- Import assert from tsafe following project conventions
- Add assertion to ensure manager is defined in subscription callback
- This guarantees manager safety without non-null assertion operator (!)

* fix(torus-wallet): resolve CodeRabbit critical issues - null safety and error handling

- Add API null check guard in submit function with user-facing error message
- Wrap call.send() with tryAsync to handle send errors properly
- Declare unsubscribe before send call and assign after await
- Add assert guards to ensure unsubscribe is defined in callbacks
- Prevents hanging promises when send() fails and ensures proper cleanup

Addresses CodeRabbit critical issues:
- Double cast masking null-safety issue now has explicit guard
- Unhandled rejection from call.send() now properly caught and rejected

* fix(torus-wallet): resolve eslint prefer-const violation in faucet

- Change unsubscribe from 'let' to 'const' in tryAsync destructuring
- Simplifies code and follows prefer-const ESLint rule
- unsubscribe is assigned once from tryAsync result

* fix(torus-portal): resolve JSON parsing error in tRPC agent.infinite endpoint

## Problem
The agent.infinite endpoint was returning "Unexpected token '<', '<!DOCTYPE'"
error, indicating the client received HTML error pages instead of JSON responses.
Root causes:
1. Database connection errors weren't being caught, causing unhandled exceptions
2. Environment validation could fail and exit the process without proper error handling
3. Map serialization in namesByKeysLastBlock endpoint
4. tRPC route handler didn't catch top-level exceptions

## Solution
1. Implement lazy environment variable validation with caching to prevent
   process.exit() during module initialization
2. Add proper error handling in blockchain/service initialization functions
   using tryAsync/trySync patterns:
   - cacheCreateWsApi(): Handle RPC connection failures
   - getOrCreateServerHashSigner(): Handle signer initialization failures
   - getorCreateTwitterClient(): Handle Twitter API client failures
3. Convert Map<string, string> to Record<string, string> in
   namesByKeysLastBlock endpoint for guaranteed JSON serializability
4. Add try/catch wrapper in tRPC route handler to catch unhandled exceptions
   and return proper JSON error responses

## Changes
- packages/api/src/trpc.ts: Refactored env loading and service initialization
- packages/api/src/router/agent/agent.ts: Changed Map to Record in
  namesByKeysLastBlock endpoint
- apps/torus-portal/src/app/api/trpc/[trpc]/route.ts: Added error handling
  wrapper to route handler

## Technical Details
- Uses project's tryAsync/trySync patterns for Go-style error handling
- All errors now properly converted to TRPCError with descriptive messages
- Environment variables validated once and cached
- Service initialization functions return Promise<T> for consistent error handling

* feat(page): landing page about section (WEB-376) (#419)

* fix(hover-header): rename "Portal" to "Join" and update button classes for better z-index handling

* fix(view-more): update content for clarity by replacing "meta-coordination" with "coordination" in descriptions

* fix(pred-api): only return reply chain context

* feat: services and apps split (#420)

* feat: prediction-swarm app file organization (#422)

* 🔥 removed llhama cpp dependency

* format-fix

* better scheduling

* chore: delete prophet finder

* chore: delete torus allocator

* feat: services renames (#425)

* fix: get paths from turbo

* Sync dev (#426)

* feat(page): landing page about section (WEB-376) (#419)

* fix(hover-header): rename "Portal" to "Join" and update button classes for better z-index handling

* fix(view-more): update content for clarity by replacing "meta-coordination" with "coordination" in descriptions

* fix(pred-api): only return reply chain context

* feat: services and apps split (#420)

* feat: prediction-swarm app file organization (#422)

* 🔥 removed llhama cpp dependency

* format-fix

* better scheduling

* chore: delete prophet finder

* chore: delete torus allocator

* feat: services renames (#425)

* fix: get paths from turbo

---------

Co-authored-by: Ed. <ed.sdr@outlook.com>
Co-authored-by: PsicoThePato <jmomcontato@gmail.com>
Co-authored-by: PsicoThePato <40248917+PsicoThePato@users.noreply.github.com>
Co-authored-by: kings177 <yanmendesp@gmail.com>

* filter using rest server

* fix: filter deploy

* better api logging

* fix(torus-portal): improve error handling and fix race conditions

- Fix error message typo (TORUS_CURATOR_MNEMONIC -> NEXT_PUBLIC_TORUS_RPC_URL)
- Fix race conditions in cacheCreateWsApi and getOrCreateServerHashSigner
  by caching promises to prevent concurrent initialization attempts
- Add console.error logging for agent loading errors in frontend
- Return empty list instead of error message for better UX

* chore(torus-portal): fix import ordering

* fix(torus-portal): address PR review comments

- Wrap fetchRequestHandler in async IIFE to catch synchronous errors
- Fix JSDoc comment: validateEnvOrExit exits process, not throws

* refactor(api): use ReturnType pattern for env type inference

Replace manual EnvType interface with ReturnType<typeof validateTrpcEnv>.
This pattern is consistent with other apps (prediction-swarm-api) and
eliminates type duplication.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

* fix: resolve lint and typecheck errors across apps and packages

- Replace null/undefined checks with optional chaining operators (?.)
- Add @ts-expect-error annotations for version mismatches in torus-bridge
- Handle undefined field values in form components
- Fix formatting inconsistencies in type definitions and helper functions
- Update imports and references in multiple packages

Fixes issues in:
- prediction-swarm: optional chaining in search-predictor-command
- torus-bridge: wagmi config type casting and cosmos wallet provider
- torus-governance: optional chaining in dao and agent components
- torus-portal: form field undefined handling and graph components
- packages: type definitions and utility functions

---------

Co-authored-by: PsicoThePato <40248917+PsicoThePato@users.noreply.github.com>
Co-authored-by: Yan Mendes <53550620+kings177@users.noreply.github.com>
Co-authored-by: Ed. <ed.sdr@outlook.com>
Co-authored-by: Luiz Carvalho <luizcmpc@gmail.com>
Co-authored-by: PsicoThePato <jmomcontato@gmail.com>
Co-authored-by: kings177 <yanmendesp@gmail.com>
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.

5 participants