Skip to content

Enhance logging for parameter query results in BucketChecksumS#462

Open
hamzzy wants to merge 2 commits intopowersync-ja:mainfrom
hamzzy:feat/trick-debug-param-query
Open

Enhance logging for parameter query results in BucketChecksumS#462
hamzzy wants to merge 2 commits intopowersync-ja:mainfrom
hamzzy:feat/trick-debug-param-query

Conversation

@hamzzy
Copy link
Contributor

@hamzzy hamzzy commented Jan 13, 2026

Summary

Adds detailed logging for parameter query results to improve debugging when limits are exceeded.

Problem

When parameter query results exceed the configured limit, users only see a generic error message:
[PSYNC_S2305] Too many parameter query results: 1234 (limit of 1000)

This makes it difficult to debug because:

  • Parameter query results include duplicates (before deduplication)
  • Bucket count excludes duplicates (after deduplication)
  • Users can't identify which sync stream definitions are contributing to the limit

Solution

1. Enhanced Normal Logging

Checkpoint logs now include total parameter query results:
New checkpoint: 1 | write: null | buckets: 2 | param_results: 2
Updated checkpoint: 2 | write: null | buckets: 3 | param_results: 3

2. Detailed Error Breakdown

Error messages now show the top 10 sync stream definitions by result count:
[PSYNC_S2305] Too many parameter query results: 60 (limit of 50)
Parameter query results by definition:
projects: 30
tasks: 20
comments: 10

Implementation Details

  • Tracks parameter query results per sync stream definition (before deduplication)
  • Counts are computed in getCheckpointUpdateDynamic()
  • Error breakdown is sorted by count (descending) and limited to top 10
  • Both human-readable messages and structured log data are included

Testing

Added 3 comprehensive test cases:

  • ✅ Logs parameter query results for dynamic buckets
  • ✅ Throws error with breakdown when limit is exceeded
  • ✅ Limits breakdown to top 10 definitions

All tests passing: 17/17 in BucketChecksumState.test.ts

Checklist

  • Tests added and passing
  • Code formatted with Prettier
  • Changeset added
  • Follows existing logging patterns

@changeset-bot
Copy link

changeset-bot bot commented Jan 13, 2026

🦋 Changeset detected

Latest commit: f1cdb21

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@powersync/service-core Patch
@powersync/service-core-tests Patch
@powersync/service-module-core Patch
@powersync/service-module-mongodb-storage Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mssql Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres-storage Patch
@powersync/service-module-postgres Patch
@powersync/service-image Patch
test-client Patch
@powersync/service-schema Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@rkistner rkistner left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! This will help a lot with debugging.

I added some comments, mostly just around creating separate functions to avoid bloating the existing functions too much.

There are also some minor updates to the tests required in the meantime due to refactoring on the main branch.

Comment on lines +257 to +274
message += `buckets: ${allBuckets.length}`;
if (parameterQueryResultsByDefinition) {
const totalParamResults = Array.from(parameterQueryResultsByDefinition.values()).reduce(
(sum, count) => sum + count,
0
);
message += ` | param_results: ${totalParamResults}`;
}
message += ` ${limitedBuckets(allBuckets, 20)}`;
const logData: any = { checkpoint: base.checkpoint, user_id: user_id, buckets: allBuckets.length };
if (parameterQueryResultsByDefinition) {
const totalParamResults = Array.from(parameterQueryResultsByDefinition.values()).reduce(
(sum, count) => sum + count,
0
);
logData.parameter_query_results = totalParamResults;
}
this.logger.info(message, logData);
Copy link
Contributor

Choose a reason for hiding this comment

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

The log message code is getting quite long here - can this be moved to a separate function?

this.logger.error(error.message, {

// Build breakdown of parameter query results by definition
let errorMessage = error.message;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here - can we move the code to generate this message to a separate function?

Comment on lines +566 to +568
if (update.parameterQueryResultsByDefinition.size > 10) {
errorMessage += `\n ... and ${update.parameterQueryResultsByDefinition.size - 10} more`;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

For this, can we log the remaining count, instead of or in addition to the number of definitions?

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.

2 participants

Comments