Repository navigation
Description
Summary
When a mobile pull request diff grows beyond the offline cache's per-answer limit, the app leaves its earlier cached diff under the same key. Reopening that review without a connection can therefore show the earlier changes even though a newer answer was already loaded online. A focused test of the mobile database service reproduced the retained row; the user-visible path is established from the mobile query and offline-read code.
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/mobile
Steps to reproduce
- Save the script below as
repro.shand runsh repro.sh /path/to/t3code-checkouton the stated commit with installed dependencies andvpavailable. The script creates one temporary test beside the mobile database service, invokesvp test runagainst it, and removes the test on exit. - The test saves and reloads a small pull request answer as a setup control, then saves an oversized answer to the same key and reloads it.
The database failure reproduced on both focused runs. An app or device run was not performed.
The script prints its tool versions, stores test inputs and test state in a temporary directory, and leaves the checkout unchanged. Exit 1 and RESULT: defect reproduced mean the old answer survived; exit 0 and RESULT: expected behavior mean it was removed; exit 2 and RESULT: inconclusive mean the setup or control failed.
Reproduction script: repro.sh
#!/bin/sh
set -u
checkout=${1:?Pass the checkout path}
test_path="$checkout/apps/mobile/src/persistence/mobile-database.m04-01.test.ts"
scratch=$(mktemp -d)
created=0
cleanup() {
if [ "$created" -eq 1 ]; then rm -f "$test_path"; fi
rm -rf "$scratch"
}
trap cleanup EXIT HUP INT TERM
printf 'node: %s\n' "$(node --version)"
printf 'vp: %s\n' "$(vp --version)"
if [ -e "$test_path" ]; then
printf 'RESULT: inconclusive\n'
exit 2
fi
mkdir -p "$scratch/home" "$scratch/tmp" "$scratch/t3"
cat > "$scratch/probe.test.ts" <<'TEST'
import { it } from "@effect/vitest";
import * as Effect from "effect/Effect";
import * as Option from "effect/Option";
import { vi } from "vite-plus/test";
const openDatabaseAsync = vi.hoisted(() => vi.fn());
vi.mock("expo-sqlite", () => ({ openDatabaseAsync }));
import * as MobileDatabase from "./mobile-database";
it.effect("checks an oversized replacement after a successful small save", () =>
Effect.scoped(Effect.gen(function* () {
const { DatabaseSync } = yield* Effect.promise(() => import("node:sqlite"));
const sqlite = new DatabaseSync(":memory:");
sqlite.exec("PRAGMA user_version = 1");
const native = {
execAsync: async (sql: string) => { sqlite.exec(sql); },
runAsync: async (sql: string, ...args: Array<string | number>) => sqlite.prepare(sql).run(...args),
getFirstAsync: async (sql: string, ...args: Array<string | number>) => sqlite.prepare(sql).get(...args),
getAllAsync: async (sql: string, ...args: Array<string | number>) => sqlite.prepare(sql).all(...args),
withExclusiveTransactionAsync: async (run: (transaction: unknown) => Promise<void>) => { await run(native); },
closeAsync: async () => { sqlite.close(); },
};
openDatabaseAsync.mockResolvedValueOnce(native);
const database = yield* MobileDatabase.make;
const environment = "probe" as import("@t3tools/contracts").EnvironmentId;
yield* database.saveCache(environment, "pull-request", "v1:diff", 1, "small");
const control = yield* database.loadCache(environment, "pull-request", "v1:diff");
if (!Option.isSome(control) || control.value !== "small") throw new Error("CONTROL_FAILED");
yield* database.saveCache(environment, "pull-request", "v1:diff", 1, "x".repeat(4 * 1024 * 1024 + 1));
const after = yield* database.loadCache(environment, "pull-request", "v1:diff");
if (Option.isSome(after)) throw new Error(`DEFECT_REPRODUCED: cached ${after.value} after oversized answer`);
})),
);
TEST
cp "$scratch/probe.test.ts" "$test_path"
created=1
if (cd "$checkout" && HOME="$scratch/home" TMPDIR="$scratch/tmp" T3CODE_HOME="$scratch/t3" vp test run apps/mobile/src/persistence/mobile-database.m04-01.test.ts > "$scratch/run.log" 2>&1); then
grep -E 'Test Files|Tests ' "$scratch/run.log" || true
printf 'RESULT: expected behavior\n'
exit 0
fi
if grep -q 'DEFECT_REPRODUCED: cached small after oversized answer' "$scratch/run.log"; then
grep -E 'DEFECT_REPRODUCED|Test Files|Tests ' "$scratch/run.log" | head -5
printf 'RESULT: defect reproduced\n'
exit 1
fi
tail -25 "$scratch/run.log"
printf 'RESULT: inconclusive\n'
exit 2Expected behavior
After an answer is too large to store, a later offline read of that cache key should not return its superseded predecessor. The web implementation of the same EnvironmentQueryStore limit deletes the prior entry in this case, and its test expects an empty load (apps/web/src/connection/storage.ts#L351-L377, apps/web/src/connection/storage.browser.test.ts#L63-L70). The mobile user guide promises that saved diff pages remain readable after a restart and refresh after reconnection, so a saved page must represent the latest cacheable answer for its key (docs/user/source-control.md#L205-L212).
Actual behavior
In a focused run against MobileDatabase, saving small for a pull request cache key and then saving a 4 MiB + 1 byte replacement for that same key leaves loadCache returning small. The oversize check exits before the upsert and prune, while the load path accepts the prior row for 30 days (apps/mobile/src/persistence/mobile-database.ts#L169-L185, apps/mobile/src/persistence/mobile-database.ts#L197-L242). Source trace: mobile uses this database as its pull request EnvironmentQueryStore, whose saved answer is returned when the environment is disconnected (apps/mobile/src/connection/pull-request-cache-store.ts#L7-L20, packages/client-runtime/src/state/runtime.ts#L793-L815). A device display was not run.
Impact and scope
Impact: P2 - a bounded, consequential offline review error: a previously cached pull request answer can be shown after a newer answer for the same key exceeded 4 MiB. Reconnecting and refreshing obtains the live answer when the environment is available.
The mobile Changes screen requests the diff without a commit for the current pull request, making the first-page cache key stable as that review changes (apps/mobile/src/features/pull-requests/usePullRequestDiff.ts#L88-L115, packages/client-runtime/src/state/runtime.ts#L793-L795). The diff query persists its result (packages/client-runtime/src/state/pullRequests.ts#L794-L799). GitHub diff reads allow up to 8 MiB, so the 4 MiB mobile cache threshold is reachable for a successful diff response (packages/source-control-github/src/server/GitHubPullRequestApi.ts#L375-L381, packages/source-control-github/src/server/GitHubPullRequestApi.ts#L2225-L2239). Frequency on real reviews is NOT_ENOUGH_INFO; no device or live review was used to measure it. A live connected answer replaces the old display, but the offline cached row persists until a later small answer replaces it or its 30-day read window expires.
Earliest failure stage
State or storage
Analysis or suspected cause
Source: the size guard returns before deleting or updating the row for the same key, and the offline load checks only the row's age. The mobile and web stores share the same persistence interface but disagree on whether an oversized replacement invalidates its predecessor.
Additional context
The database service was imported from the checkout, not reimplemented in the test. The database failure reproduced in both focused runs; a device display was not run. Failure source: focused database test and cited source trace. Expected source: the web store contract and mobile user guide cited above. Evidence provenance: observed and static source trace. Local verification: reproduced. Reproduction completeness: complete for the database failure; device display remains untested. Missing fact: frequency on real reviews requires a device or live review run.
Impact
Minor bug or occasional failure
Version or commit
main @ c00a373
Environment
macOS arm64; Node.js v26.12.1; vp v1.5.1; vite-plus v1.4.0; Vitest v5.0.5; node:sqlite in-memory substitute for Expo SQLite.
Logs or stack traces
node: v26.12.1
vp: vp v1.5.1
vite-plus v1.4.0
vitest v5.0.5
Error: DEFECT_REPRODUCED: cached small after oversized answer
Test Files 1 failed (1)
RESULT: defect reproducedScreenshots, recordings, or supporting files
No response
Workaround
Reconnect and refresh the review while the environment is available to obtain the live answer.
References
- feat(mobile): keep pull requests available offline #18351 — introduced mobile offline pull request caching and its response limit.
- perf(pr): pull requests paint from data already held, on web, desktop and mobile #27798 — added the web deletion rule and regression test for an oversized replacement; the mobile database file was not changed.
Activity
juliusmarminge commentedon Nov 13, 2026
I tried to reproduce this on the current build and could not.
On origin/main 95cb068 I added a test to the existing apps/mobile/src/persistence/mobile-database.test.ts. It runs the real MobileDatabase service against an in-memory node:sqlite database standing in for expo-sqlite, as the existing test does. It saves 'small' as the pull-request cache entry for key 'v1:diff', then saves a 4 MiB + 1 byte payload under the same key, then calls loadCache. Ran
vp test run apps/mobile/src/persistence/mobile-database.test.ts: the new test fails with loadCache returning Option.some('small') where Option.none() was expected, and the existing test passes. No device run: it would need a live pull request with a diff over 4 MiB plus a leased device with the connection cut, which costs too much for a storage defect the test already shows at the service the app uses.Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.