fix: replace JSON.stringify comparison with structural deep-equal for ProviderModelOptions
JSON.stringify is sensitive to property insertion order, so two semantically identical ProviderModelOptions objects constructed with keys in different orders would serialize to different strings. This caused sameModelOptions to return false incorrectly, triggering unnecessary Claude session restarts that cleared the resume cursor and lost conversation context. Replace with a recursive structural equality check that compares objects by their defined (non-undefined) keys and values regardless of key ordering. Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
1 parent
5c9cfcd4c3
commit
a325efe38a
1 file changed
+14
-1
@@ -75,10 +75,23 @@ const DEFAULT_RUNTIME_MODE: RuntimeMode = "full-access";
|
||||
const WORKTREE_BRANCH_PREFIX = "t3code";
|
||||
const TEMP_WORKTREE_BRANCH_PATTERN = new RegExp(`^${WORKTREE_BRANCH_PREFIX}\\/[0-9a-f]{8}$`);
|
||||
|
||||
function structuralEqual(a: unknown, b: unknown): boolean {
|
||||
if (a === b) return true;
|
||||
if (a == null || b == null) return a === b;
|
||||
if (typeof a !== typeof b) return false;
|
||||
if (typeof a !== "object") return false;
|
||||
const objA = a as Record<string, unknown>;
|
||||
const objB = b as Record<string, unknown>;
|
||||
const keysA = Object.keys(objA).filter((k) => objA[k] !== undefined);
|
||||
const keysB = Object.keys(objB).filter((k) => objB[k] !== undefined);
|
||||
if (keysA.length !== keysB.length) return false;
|
||||
return keysA.every((key) => objB[key] !== undefined && structuralEqual(objA[key], objB[key]));
|
||||
}
|
||||
|
||||
const sameModelOptions = (
|
||||
left: ProviderModelOptions | undefined,
|
||||
right: ProviderModelOptions | undefined,
|
||||
): boolean => JSON.stringify(left ?? null) === JSON.stringify(right ?? null);
|
||||
): boolean => structuralEqual(left ?? null, right ?? null);
|
||||
|
||||
function isUnknownPendingApprovalRequestError(cause: Cause.Cause<ProviderServiceError>): boolean {
|
||||
const error = Cause.squash(cause);
|
||||
|
||||
Reference in new issue
Block a user