fix(migration): handle plain-text success response from migrateHostname JNI#172
Open
TimeToBuildBob wants to merge 2 commits into
Open
Conversation
…me JNI
The native migrateHostname() returns a plain-text string on success
("Migrated hostname for N bucket(s)") but a JSON error object on failure
({"error": "..."}). The Kotlin code was incorrectly trying to parse the
success response as JSON, which always failed, so setHostnameMigrated()
was never called and migration would retry on every app start.
This also caused two spurious logcat warnings on fresh install:
W Migration result was not valid JSON; will retry on next start
W Hostname migration reported failure; will retry on next start
Fix: check for the known plain-text success prefix first. Only parse JSON
when the result doesn't match success, and extract the "error" field for
a single, informative warning instead of two misleading ones.
Fixes: ActivityWatch#171
When the JSON doesn't contain an 'error' key, optString('error', null)
logged '(null)'. Use result as fallback so the raw payload is always
visible for debugging.
Contributor
Author
|
Addressed Greptile's P2 finding in ad07391: changed Merge recommendation: Ready to ship. Summary:
Converged after 1 Greptile round. |
Contributor
Author
|
@greptileai review |
Contributor
Author
|
All 5 checks now green including E2E tests. Ready for maintainer merge whenever you get a chance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a correctness bug where
setHostnameMigrated()was never called, causing hostname migration to run on every app start indefinitely.Root Cause
The native
migrateHostname()JNI function returns:"Migrated hostname for N bucket(s)"(NOT JSON){"error": "message"}BackgroundServicewas trying to parse the success response as JSON with a"success"boolean key that never exists. This always threw aJSONException, setmigrationSucceeded = false, and skippedsetHostnameMigrated()— so migration would re-run on every subsequent app start.On fresh install this produced two spurious logcat warnings even though migration succeeded normally with 0 buckets:
Fix
Check for the known plain-text success prefix first. Only attempt JSON parsing for the error case, extracting the
"error"field for a single informative warning.Test plan
setHostnameMigrated()is called, no spurious warnings, migration does not re-run on next startunknown/Unknownhostname buckets: migration renames them,setHostnameMigrated()called, migration does not re-runW Hostname migration failed (...)warning, migration retries on next startFixes #171