Skip to content

Fix operator CLI exit codes, claim-list query validation, stats DTO drift, and feed-definitions caching - #663

Open
Joel234-png wants to merge 1 commit into
Refract-Protocol:mainfrom
Joel234-png:fix/issues-594-595-596-597
Open

Joel234-png wants to merge 1 commit into
Refract-Protocol:mainfrom
Joel234-png:fix/issues-594-595-596-597

Conversation

@Joel234-png

Copy link
Copy Markdown

#597: operator-cli.ts and oracle-ops.ts (src/oracle/consensus/cli.ts) each only ever used two ad-hoc exit codes in practice. Added a shared contract (src/common/cli-exit-codes.ts: 0 success, 1 usage error, 2 remote/operation failure) and made every process.exit / CliResult.exitCode in both scripts conform to it, distinguishing bad invocations (unknown flag/command, missing required arg, missing --yes confirmation, malformed reconstruct query) from failures while actually running (DB error, unreadable/malformed evidence ledger). docs/relayer-key-compromise-runbook.md does not actually invoke either CLI, so the codes are documented in README.md's existing "Operator CLI" section instead, which already documents real invocations of operator-cli.ts.

#596: ListClaimsDto (src/claim/dto/list-claims.dto.ts) is dead code - the real list-claims routes (GET /claims/holder/:address, GET /claims/recent) consume PageQueryDto. No global ValidationPipe exists in src/main.ts at all (src/common/pagination.spec.ts's own "Mirrors main.ts's global pipe" comment confirms one was assumed to exist); enabling it now app-wide was judged too risky for this issue's scope given 23 controllers with no prior validation coverage, so ClaimController gets its own @UsePipes(new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true, transform: true })), matching the existing per-controller pattern already used by ConsensusController. An unknown query key on either route now returns 400 naming that key; existing limit/cursor filters are unaffected. test/contracts/consumers/refract-frontend/ does not exist in this repo, so there was no fixture to update.

#595: GET /claims/stats and /claims/stats/ops already return the typed ClaimStatsResponseDto / ClaimStatsOpsResponseDto via plainToInstance, not an ad-hoc object - that part of the issue didn't match reality. The real stats source is ClaimService.getStats() (an in-memory counter snapshot), not claim.repository.ts, which has no such query. The actual drift: getStats() computes deadLetterClaims and settlementRetries but neither DTO exposed them, so they were silently dropped even from the ops-only response. Added both as @expose()d fields on ClaimStatsOpsResponseDto only, keeping the public DTO unchanged (consistent with settlementConfigured's existing public/ops split). src/index.ts is an unrelated, broken legacy entrypoint (imports ./utils/logger and ./services/heartbeat, neither of which exists, and isn't package.json's actual "main") rather than a types-export barrel, so nothing was exported from it; this repo has no types/exports field in package.json either.

#594: feed-definitions.service.ts already has a self-refreshing in-process cache (this.cache), but its only real callers (getEnabledFeeds, getCachedFeed) have zero callers anywhere else in the codebase - the "every oracle tick" read path the issue describes isn't actually wired to this service. The real, closest-available fix: listLatest() and getLatest(), which ARE called on every admin request (FeedsController's GET routes), hit the database on every call despite the set changing rarely and the cache already existing. Both now read from the cache; update()'s optimistic- concurrency check was moved to a new private fetchLatestFromDb() so it keeps reading the authoritative row (a stale cached version there would silently defeat the conflict check). Did not reuse the existing Redis-backed CacheService - it's TTL/cross-instance by design, which this issue's own scope explicitly says isn't needed, and would be a worse fit than the already-correct, write-invalidated per-process Map.

Closes #594
Closes #595
Closes #596
Closes #597

Summary

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Docs
  • Tests / CI

Checklist

  • I read CONTRIBUTING.md
  • Tests added/updated for the change
  • Local gate passes (lint / typecheck or fmt + clippy + test / build)
  • No secrets, keys, or .env values committed
  • Behavioural changes are documented in the README where relevant

Notes for reviewers

…rift, and feed-definitions caching

Refract-Protocol#597: operator-cli.ts and oracle-ops.ts (src/oracle/consensus/cli.ts) each only
ever used two ad-hoc exit codes in practice. Added a shared contract
(src/common/cli-exit-codes.ts: 0 success, 1 usage error, 2 remote/operation
failure) and made every process.exit / CliResult.exitCode in both scripts
conform to it, distinguishing bad invocations (unknown flag/command, missing
required arg, missing --yes confirmation, malformed reconstruct query) from
failures while actually running (DB error, unreadable/malformed evidence
ledger). docs/relayer-key-compromise-runbook.md does not actually invoke
either CLI, so the codes are documented in README.md's existing "Operator
CLI" section instead, which already documents real invocations of
operator-cli.ts.

Refract-Protocol#596: ListClaimsDto (src/claim/dto/list-claims.dto.ts) is dead code - the
real list-claims routes (GET /claims/holder/:address, GET /claims/recent)
consume PageQueryDto. No global ValidationPipe exists in src/main.ts at all
(src/common/pagination.spec.ts's own "Mirrors main.ts's global pipe" comment
confirms one was assumed to exist); enabling it now app-wide was judged too
risky for this issue's scope given 23 controllers with no prior validation
coverage, so ClaimController gets its own `@UsePipes(new ValidationPipe({
whitelist: true, forbidNonWhitelisted: true, transform: true }))`, matching
the existing per-controller pattern already used by ConsensusController. An
unknown query key on either route now returns 400 naming that key; existing
limit/cursor filters are unaffected. test/contracts/consumers/refract-frontend/
does not exist in this repo, so there was no fixture to update.

Refract-Protocol#595: GET /claims/stats and /claims/stats/ops already return the typed
ClaimStatsResponseDto / ClaimStatsOpsResponseDto via plainToInstance, not an
ad-hoc object - that part of the issue didn't match reality. The real stats
source is ClaimService.getStats() (an in-memory counter snapshot), not
claim.repository.ts, which has no such query. The actual drift: getStats()
computes deadLetterClaims and settlementRetries but neither DTO exposed them,
so they were silently dropped even from the ops-only response. Added both as
@expose()d fields on ClaimStatsOpsResponseDto only, keeping the public DTO
unchanged (consistent with settlementConfigured's existing public/ops split).
src/index.ts is an unrelated, broken legacy entrypoint (imports
./utils/logger and ./services/heartbeat, neither of which exists, and isn't
package.json's actual "main") rather than a types-export barrel, so nothing
was exported from it; this repo has no types/exports field in package.json
either.

Refract-Protocol#594: feed-definitions.service.ts already has a self-refreshing in-process
cache (`this.cache`), but its only real callers (getEnabledFeeds,
getCachedFeed) have zero callers anywhere else in the codebase - the "every
oracle tick" read path the issue describes isn't actually wired to this
service. The real, closest-available fix: listLatest() and getLatest(),
which ARE called on every admin request (FeedsController's GET routes), hit
the database on every call despite the set changing rarely and the cache
already existing. Both now read from the cache; update()'s optimistic-
concurrency check was moved to a new private fetchLatestFromDb() so it keeps
reading the authoritative row (a stale cached version there would silently
defeat the conflict check). Did not reuse the existing Redis-backed
CacheService - it's TTL/cross-instance by design, which this issue's own
scope explicitly says isn't needed, and would be a worse fit than the
already-correct, write-invalidated per-process Map.

Closes Refract-Protocol#594
Closes Refract-Protocol#595
Closes Refract-Protocol#596
Closes Refract-Protocol#597
@drips-wave

drips-wave Bot commented Nov 24, 2026

Copy link
Copy Markdown

@Joel234-png Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant