Skip to content

The oracle summary covers only the oldest 1,000 samples and does not say so #761

Open

Description

@Miracle656

Background

GET /compare/:asset/summary?window=7d reports how far Lens was from an oracle over a window: mean deviation, worst deviation, and time spent outside a band. GET /compare/:asset/history returns the samples themselves. Both are in src/routes/oracle.ts.

Both read their samples through queryOracleComparisonHistory with a limit that defaults to 1000 (src/routes/oracle.ts line 114). The query ends with (src/services/oracleComparison.ts line 300):

ORDER BY timestamp ASC LIMIT $n

So when a window holds more than 1,000 samples, the summary is computed from the oldest 1,000 and the rest are ignored. Nothing in the response says the data was cut. samples reads 1000 and freshestComparison is an old timestamp, which a careful reader might notice. Most will not.

The cut also breaks one figure outright. computeOracleSummaryStatistics treats the last sample it was given as lasting until the end of the window (src/services/oracleComparison.ts, the nextTime = Math.min(Date.now(), windowEnd.getTime()) branch near line 379). If the 1,000th sample is outside the band, all the time between it and the end of the window is counted as "outside the band", even though thousands of unread samples cover that time.

/history has the matching problem: it returns the oldest rows first, has no cursor, and gives no sign that more exist. A client cannot reach the newest data in a busy window except by guessing from.

What to build

  • The summary must describe the whole window. Aggregate in SQL, or read the window in pages. Do not compute a summary from a silently cut list.
  • If you keep any cap, the response must say so: a truncated flag and the number of samples used.
  • Fix the last-sample rule so a cut list can never inflate timeOutsideBandSeconds.
  • Decide what limit means on /summary. If it has no meaning there, remove it from the route and the spec.
  • Make /history pageable with the helpers in src/pagination.ts (parseLimit, encodeCursor, decodeCursor, slicePage): add nextCursor and hasMore, as /pools and /pairs do. Keep the points key.
  • Update openapi.yaml for both routes and regenerate.

Where to look

  • src/routes/oracle.ts lines 26 to 134 and 176 to 269
  • src/services/oracleComparison.ts queryOracleComparisonHistory (line 269) and computeOracleSummaryStatistics (line 321)
  • src/pagination.ts, and src/routes/pools.ts lines 59 to 121 for a route that uses it
  • src/__tests__/oracleHistory.test.ts

Done when

  • A test with more samples than the old limit shows the summary uses all of them, or reports truncated: true with the count
  • A test shows timeOutsideBandSeconds is not inflated when the last sample read is outside the band and later samples exist
  • /compare/:asset/history returns nextCursor and hasMore, and a test pages through a window without a duplicate or a gap
  • The existing oracle history tests pass, or each change is explained
  • openapi.yaml is updated and the generated files are regenerated
  • npx tsc --noEmit and npm test pass

Drips Wave · Complexity: Intermediate · 150 points


Repo: Divinity-Labs/Lens. Install with npm ci, typecheck with npx tsc --noEmit, test with npm test. Tests are vitest. Do not run jest: it reports zero tests and proves nothing.

You cannot reach the production service. Prove your change with local tests and fixtures. Mock the database (pgPool, prisma) the way the existing tests in src/__tests__/ and tests/ do.

Generated files are checked byte for byte by CI. If you add or change a route, edit openapi.yaml by hand and then regenerate the generated files and commit them: npm run openapi:gen (writes openapi.json and the README sections), npm run client:gen (the TypeScript client schema) and, if you touched the GraphQL schema, npm run graphql:schema:gen (writes schema.graphql). The full list is in the scripts section of package.json; also read CONTRIBUTING.md. If a check fails and the diff looks empty, it is line endings: commit with LF.

Prices are high-precision decimals. Do not add a new place where a price or amount goes through parseFloat, Number() or ::float before it reaches the caller.

MCP tools must return exactly the fields the matching REST route returns (tests/mcp-lens.test.ts asserts equality), and the MCP tool modules must not import the database driver directly. Reads are injected.

Do not remove or loosen an existing API-key scope, CORS rule or rate limit, and do not replace src/app.ts wholesale. Past pull requests did both by accident.

Do not weaken a test to make it pass. No real user data, wallet addresses of real users, keys, tokens or connection strings in code, tests or fixtures. Never shorten a Stellar address or contract id; copy it in full from the file that defines it.



Required: Before submitting, join the contributor Telegram so your work can be tracked and counted toward the Stellar Wave: https://t.me/+fxHXq8f1SwlkZDBk

Activity

  1. added
    help wanted
    area:api
    Stellar Wave
    points:150
    on Nov 21, 2026
  2. AbuJulaybeeb commented on Nov 22, 2026

    @AbuJulaybeeb

    @AbuJulaybeeb has applied to work on this issue as part of the Stellar Wave Program's 11th wave.

    Hi maintainer, I would like to take on this issue

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @AbuJulaybeeb to this issue.

  3. drakep commented on Nov 22, 2026

    @drakep
    Contributor

    @drakep has applied to work on this issue as part of the Stellar Wave Program's 11th wave.

    I'd like to work on this. queryOracleComparisonHistory in src/services/oracleComparison.ts ends with ORDER BY timestamp ASC LIMIT, and both /compare/:asset/summary and /history in src/routes/oracle.ts pass a default limit of 1000, so computeOracleSummaryStatistics only sees the oldest rows and its last-sample branch (nextTime = Math.min(Date.now(), windowEnd)) can count the unread tail as outside the band. For /summary I'd read the whole window in keyset pages instead of one capped list, drop limit from that route and the spec, and change the last-sample rule so it never extends past a known later sample. For /history I'd add cursor paging with parseLimit, encodeCursor, decodeCursor and slicePage from src/pagination.ts, returning nextCursor and hasMore next to points the way src/routes/pools.ts does, then update openapi.yaml and regenerate. Tests go in src/tests/oracleHistory.test.ts: more than 1000 mocked samples, an outside-band sample followed by later rows, and a page-through with no duplicates or gaps; I'd run npx tsc --noEmit and npm test, including oracle.test.ts and graphqlOracle.test.ts. ETA 1-2 days.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @drakep to this issue.

  4. ibochielizabeth-spec commented on Nov 22, 2026

    @ibochielizabeth-spec

    @ibochielizabeth-spec has applied to work on this issue as part of the Stellar Wave Program's 11th wave.

    Hello Maintainer,

    I’m interested in contributing to issue #761. I will first examine the existing oracle routes, comparison service, pagination helpers, and tests to understand the current implementation.

    My approach will be to ensure the summary accounts for the entire requested time window rather than silently stopping at 1,000 samples. I will also correct the time-outside-band calculation, implement cursor-based pagination for the history endpoint, and include the appropriate nextCursor and hasMore fields.

    I will update openapi.yaml, regenerate the required files, and add tests covering large sample sets, accurate time calculations, and pagination without duplicates or missing records.

    Finally, I will run npx tsc --noEmit and npm test to verify the changes and avoid regressions.

    I’m committed to delivering a reliable, well-tested solution that follows the repository's contribution guidelines.

    Thank you for the opportunity.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @ibochielizabeth-spec to this issue.

  5. drips-wave commented on Nov 24, 2026

    @drips-wave

    Congratulations, @ibochielizabeth-spec! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on November 25, 2026.

    🧑‍💻 @ibochielizabeth-spec: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

    Warning

    When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

    🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

    🌊 Happy Wave 🌊

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

Metadata

Metadata

Labels

Stellar Wavearea:apidifficulty:intermediatehelp wantedpoints:150

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions