Skip to content

fix(app-session): support Grok Bot 1.3.0 gateway descriptor v4 - #175

Open
JidaDiao wants to merge 1 commit into
ScriptedAlchemy:mainfrom
JidaDiao:fix/descriptor-v4
Open

JidaDiao wants to merge 1 commit into
ScriptedAlchemy:mainfrom
JidaDiao:fix/descriptor-v4

Conversation

@JidaDiao

Copy link
Copy Markdown

Fixes #174

Summary

Adds support for the version 4 gateway-descriptor.json format written by Grok Bot desktop 1.3.0 while preserving existing account selection, ambiguity, and unsupported-version safeguards.

What changed

  • src/core/app-session.js
    • Accept gateway descriptor version: 4 alongside existing entries-map versions (2, 3, 4), keeping version >= 5 rejected with UNSUPPORTED_VERSION.
    • Validate the v4 outer entry structure (savedAtMs must be a finite number; missing/invalid values fail closed with INVALID_ENTRY before touching Keychain, Secret Service, or Windows DPAPI).
    • Enforce the desktop app's 7-day outer savedAtMs TTL (10080 * 60 * 1000 ms, configurable via maxAgeMs / now) before decrypting, throwing EXPIRED_DESCRIPTOR when stale.
    • Validate decrypted descriptor fields: non-blank string baseUrl and token, string-valued headers map (when present, supporting v4 headers such as x-anyrun-port-token, x-sand-gateway-token, and authorization), and optional finite numeric authorizationRefreshAtMs (throwing EXPIRED_DESCRIPTOR once now() >= authorizationRefreshAtMs).
    • Keep EMPTY_ENTRIES, AMBIGUOUS_ENTRIES, and MISSING_ENCRYPTED_PAYLOAD semantics intact.
  • src/core/gateway.js
    • In sessionFromApp, fall through to EnsureSandBox when an expired cached descriptor (EXPIRED_DESCRIPTOR) is accompanied by active app credentials, matching desktop behavior.
    • Preserve error.code when wrapping session errors in GatewayError so callers can distinguish EXPIRED_DESCRIPTOR / INVALID_ENTRY when fallback is unavailable.
  • Tests, changeset, and distribution
    • Added synthetic-fixture unit tests covering v4 macOS, Linux (v10/v11), and Windows DPAPI loading/rejection, 7-day savedAtMs TTL boundary, authorizationRefreshAtMs expiry, invalid headers/blank fields, gbot doctor --json v4 reporting, and connectGateway fallback vs fail-closed behavior (test/app-session.test.js, test/doctor.test.js, test/gateway-reconnect.test.js).
    • Added .changeset/gateway-descriptor-v4.md and rebuilt artifact/.

Verification

  • npm run check (validate, build, validate:artifact, tsc --noEmit, test:unit, test:routes):
    • Unit tests: 527 passed, 0 failed, 1 skipped
    • Route tests: 97 passed, 0 failed
  • npx changeset status --since=origin/main --verbose: passed (grok-bot-cli patch bump)
  • All tests use synthetic fixtures only; no real tokens, account identifiers, or local paths are included.

@changeset-bot

changeset-bot Bot commented Nov 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 25e5295

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

This PR includes changesets to release 1 package
Name Type
grok-bot-cli 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

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.

Grok Bot 1.3.0 gateway descriptor v4 is rejected by grok-bot-cli 0.12.4/0.12.5

1 participant