Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(mobile): keep agent widgets updated in the background #14608

Closedjakeleventhal(GitHub profile, opens in a new tab)wants to merge 9 commits intomain fromrefs/pull/14608/headopened View on GitHub

The iOS Agent Activity widget could render blank and keep showing an old “Working” snapshot after T3 closed. This change embeds the native layouts and lets the widget extension fetch current linked agent activity directly from the relay, independently of the app’s JavaScript runtime.

The relay registers an install/account-scoped read capability, stores its hash, and queues WidgetKit refresh pushes when agent activity changes. On iOS 26+, the extension registers its WidgetKit push token and receives quiet refresh requests. Scheduled native reads request another refresh after five minutes; iOS controls the actual timing and budgets both mechanisms. Successful reads renew freshness, including unchanged results. After an hour without a confirmed relay read, unfinished rows become out of date; Done and Failed outcomes stay intact. Direct-only observations retain their ten-minute deadline.

Foreground reconciliation preserves live environment precedence, handles older relay responses with an unavailable count when needed, and clears previous-account content. The native configuration survives app suspension. The read capability is stored in the shared Keychain. Sign-out and identity changes clear cached rows and request capability revocation independently of the former Clerk session; existing device unregistration remains in place. Widget refreshes are enqueued before other target deliveries so an Android delivery failure cannot suppress them. The change includes the relay migration, generated extension entitlements, and native fingerprint inputs. It requires a compatible native rebuild and relay deployment.

Continues the original widget work from #6464. Following Julius’s request, work moved back here from the closed replacement #14848; #14830 remains closed. Rebased onto current main without conflicts.

Validation

  • 296 focused tests passed across 15 files covering mobile registration/reconciliation/layouts/timelines, relay refresh/registration/publication/APNs delivery, HTTP handlers, client requests, and contracts.
  • Native Swift behavior checks passed for unchanged-result renewal, source reconciliation, expiration, terminal preservation, and property-list storage.
  • Scoped formatting/lint and mobile, relay, client-runtime, and contracts typechecks passed.
  • A fresh compatible native build succeeded on iPhone 18 Pro Max, iOS 27.0. With T3 terminated and Metro stopped, real native scheduled reads changed isolated test agents from Working → Approval → Done. Reads at 17:16:39 and 17:21:59 UTC fetched the new states; the widget stayed fresh beyond the app’s original ten-minute deadline.
  • The scheduled-update recording predates the final rebase and review fixes. It demonstrates native background fetching, not the later Keychain or cleanup changes. Review fixes passed 114 focused relay/contracts tests, 91 mobile coordinator tests, and native Swift cleanup checks. Scoped typechecks/lint passed. CI found and corrected a Swift collection-alignment violation in the Keychain helper. A credential-only edit was also verified to change the Expo fingerprint through its automatically tracked native module directory. The new iOS build containing shared Keychain access succeeded. Cross-target Keychain reads and native sign-out behavior have not yet been observed at runtime: the simulator host disconnected immediately after the build. The Swift cleanup checks cover cached timeline erasure and preparation of the capability-revocation request.
  • The recording uses synthetic agent states and the production native widget/relay refresh service with isolated persistence. It does not exercise real agent approval or input workflows. APNs request construction, routing, token revocation, and queue handling are tested; real WidgetKit push delivery and the requested two-thread push sequence remain unverified. This draft does not claim push-path recording proof.

Native evidence

Baseline before: the original native client had no Agent Activity layout before publication.

Before: missing widget layout

Current build: Working while T3 is closed.

Working

After a native background read:

Approval

After the next native background read:

Done

40-second recording, accelerated 12× · Full uninterrupted seven-minute recording · Timestamped native relay reads

Implementation and validation by GPT-6.1-sol through the Codex harness in T3 Code.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This is a substantial new background-refresh capability spanning WidgetKit, mobile state management, relay authentication, APNs delivery, and database/API changes, including automatic product behavior and sensitive credential handling. Unresolved High and Medium findings also indicate signed-build refresh failures, stale-widget cases, and OTA compatibility risk.

      Not approved because:

      • 3 blocking correctness issues found at or above your repo's Minimum Blocking Severity
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml

      Review profile: CHILL

      Plan: Advanced

      Run ID: 9eb11938-b867-4f0a-82fd-0b72083096b6

      📥 Commits

      Reviewing files that changed from the base of the PR and between 75516424e7bd367fd28ec7ac8a7eb2d9466aafa5 and eba1c86b15897c6b765cf1e68dcbc01ca948441c.

      📒 Files selected for processing (7)
      • apps/mobile/app.config.ts
      • apps/mobile/src/features/agent-awareness/agentLiveActivity.ios.ts
      • apps/mobile/src/features/agent-awareness/liveWidgetActivity.ts
      • apps/mobile/src/features/agent-awareness/remoteRegistration.test.ts
      • apps/mobile/src/features/agent-awareness/remoteRegistration.ts
      • apps/mobile/src/widgets/AgentActivity.test.ts
      • apps/mobile/src/widgets/AgentActivity.tsx
      🚧 Files skipped from review as they are similar to previous changes (1)
      • apps/mobile/src/features/agent-awareness/remoteRegistration.test.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


      📝 Walkthrough

      Walkthrough

      The mobile app now renders agent activity in home-screen and accessory widgets, observes local shell activity, and reconciles it with relay snapshots. Snapshot requests can exclude selected environments. Registration and Live Activity flows also refresh the widget.

      Changes

      Agent activity widgets and relay reconciliation

      Layer / File(s)Summary
      Widget presentation and publication
      apps/mobile/src/widgets/AgentActivity.tsx, apps/mobile/src/widgets/AgentActivity.test.ts, apps/mobile/src/features/agent-awareness/agentLiveActivity.ios.ts, apps/mobile/src/features/agent-awareness/agentLiveActivity.ts, apps/mobile/src/features/showcase/showcaseAgentActivity.ts, apps/mobile/app.config.ts
      AgentActivity renders widget-family layouts as well as Live Activity layouts. Its props support unknown counts and stale observations. The iOS widget configuration includes an initial layout, and the publisher reports whether its snapshot update succeeds. Tests cover layouts, labels, deep links, and publication.
      Local activity collection and reconciliation
      apps/mobile/src/features/agent-awareness/liveWidgetActivity.ts, apps/mobile/src/features/agent-awareness/liveWidgetActivity.test.ts
      The app collects activity from enabled environments with live shells, expires older completed and failed rows, and reconciles local rows with relay data. It determines whether the count is known and retains local observations until relay data confirms them.
      Excluded-environment snapshot API
      packages/contracts/src/relay.ts, packages/contracts/src/relay.test.ts, packages/client-runtime/src/relay/managedRelay.ts, packages/client-runtime/src/relay/managedRelay.test.ts, infra/relay/src/agentActivity/MobileRegistrations.ts, infra/relay/src/agentActivity/MobileRegistrations.test.ts, infra/relay/src/http/Api.ts
      Snapshot contracts and requests support optional excluded environment IDs. The relay deduplicates exclusions and filters matching environments from its aggregate. Tests cover query parsing, request construction, and filtered snapshots.
      Widget observer and Live Activity coordination
      apps/mobile/src/features/agent-awareness/remoteRegistration.ts, apps/mobile/src/features/agent-awareness/remoteRegistration.test.ts
      Registration observes local activity, refreshes relay snapshots, and publishes reconciled widget state. Refreshes account for changing scope and lifecycle state. Live Activity registration and priming also refresh the widget, with checks for stale registration work.

      Priority: ➖ Normal

      Estimated code review effort: 4 (Complex) | ~60 minutes

      Change: Bug fix

      Sequence Diagram(s)

      sequenceDiagram
        participant remoteRegistration
        participant liveWidgetActivity
        participant ManagedRelayClient
        participant MobileRegistrations
        participant AgentActivityWidget
        remoteRegistration->>liveWidgetActivity: Observe local activities
        remoteRegistration->>ManagedRelayClient: Request snapshot with excluded environment IDs
        ManagedRelayClient->>MobileRegistrations: Send snapshot request
        MobileRegistrations-->>ManagedRelayClient: Return filtered snapshot
        ManagedRelayClient-->>remoteRegistration: Return snapshot
        remoteRegistration->>AgentActivityWidget: Publish reconciled widget props

      Possibly related PRs

      • pingdotgg/t3code#6464: Introduced Agent Activity widget layouts, native registration, publication, and reconciliation that this change updates.

      Suggested reviewers: juliusmarminge

      Merge Risk: ⚪ Minimal · up to eba1c

      No actionable code issue remains from this review; merge after normal checks and confirmation of the outstanding scope approval.

      Security Architecture Review

      Security architecture risk: 🔵 Low · up to eba1c

      The inspected implementation keeps activity reads account-scoped and guards against publishing responses from a previous session. The additional widget surfaces display activity metadata rather than granting agent or service authority. Remaining uncertainty concerns native cleanup behavior and precisely which changes originated in this PR.

      Retained concerns No architecture-level concerns identified.

      Security review details

      Security Blast Radius

      • inferred — The inspected data path is bounded to the authenticated user's relay activity and enabled local environments, followed by display on that device's configured widget surfaces. Its security-relevant outcome is metadata visibility; the inspected publication path does not grant agent execution authority.

      Trust Boundaries and Controls

      • observed — The relay derives user identity from the authenticated principal and requires the mobile registration scope and token-bound DPoP proof. Exclusions filter rows after user-scoped selection rather than selecting another user's activity.
      • observed — Activity deep links encode environment and thread identifiers into an internal route. The renderer rejects non-relative and double-slash links before attaching the fixed t3code scheme. This constrains widget link construction, but does not establish authorization inside the uninspected native route handler.

      Resilience and Maintainability Implications

      • observed — Session changes clear observed state and invalidate refresh generations. Sign-out and new-session setup request idle widget content, while delayed reads check account and refresh generations before applying results. Native publication catches update failures and caches content only after reported success; these source controls do not prove native timeline erasure on a device.

      Hardening Proposals

      • proposed — Validate sign-out, account switching, process restart, and failed native snapshot updates on a device, including whether previous-account metadata can remain in a persisted widget timeline. This would close the native cleanup evidence gap rather than establish a currently verified defect.
      🚥 Pre-merge checks | ✅ 3 | ❌ 2

      ❌ Failed checks (2 warnings)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 19.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 46 functions across 17 files.Write docstrings for the functions missing them to satisfy the coverage threshold.
      Description check⚠️ WarningThe description explains the problem, implementation, and extensive verification results. However, it does not provide the required explicit scope and approval evidence. It references related pull req…Add a Scope and approval section that links the triaged issue or maintainer approval comment. The section must explicitly confirm approval for the live-shell precedence, retained observations, filtered relay API, and legacy fallback, or exp…
      ✅ Passed checks (3 passed)
      Check nameStatusExplanation
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly identifies the main change: keeping mobile agent widgets updated in the background.
      Full details: Description check

      Explanation

      The description explains the problem, implementation, and extensive verification results. However, it does not provide the required explicit scope and approval evidence. It references related pull requests and discussions, but it does not link a maintainer approval for the broader live-shell, retained-observation, and filtered-relay decisions.

      Resolution

      Add a Scope and approval section that links the triaged issue or maintainer approval comment. The section must explicitly confirm approval for the live-shell precedence, retained observations, filtered relay API, and legacy fallback, or explain why this focused fix qualifies for an approval exemption.

      • Fix all pre-merge checks with AI
      ✨ Finishing Touches 💡 1
      🛠️ Fix failing CI checks 💡
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Autopilot is currently an internal CodeRabbit preview.


      Comment `@coderabbitai help` to get the list of available commands.
    4. Note

      This comment is posted by Julius' dot

      The new native captures and activity/reconnect recording address the earlier evidence request. Could a maintainer confirm the scope approval recorded in #6464's “Maintainer verification” section for live-shell precedence, retained observations, and the filtered relay API with legacy fallback, or link the approval itself? The actual comment on #6641 establishes the blank-widget failure, but does not explicitly settle those broader choices. This is the remaining prior-approval question; leaving this open pending confirmation.

    5. juliusmarminge requested changes

      Requesting changes on eba1c86 before merging.

      The remaining blocker is home-screen widget freshness. The iOS adapter publishes only a single snapshot. After starting a turn and leaving the app, a relay-only row can continue to say "Working" indefinitely because nothing ages it out. Locally observed rows instead become "Last observed" immediately on backgrounding, so their normal home-screen presentation is always stale. The rendering and account-isolation fixes are useful, but they do not address this behavior.

      Please publish a timeline with a current entry and a future expiration entry, following the existing subscriptionUsageTimeline pattern. After the freshness window, unfinished rows should become out of date with an "Open T3 to refresh" hint, and the count must stop presenting itself as current. Completed and failed rows should keep their terminal outcomes. Normal backgrounding should not immediately expire a fresh observation; genuinely disconnected or already stale observations should retain that distinction. A timeline marks old information honestly; it does not fetch a turn's completion while the app is closed.

      Cover both timeline degradation and publication renewal. The current content deduplication ignores timestamps, so a successful fresh read with unchanged rows must still renew the expiration. Verify that an unchanged confirmed observation resets the deadline, an old or failed read does not, and terminal rows remain terminal. Verify the scheduled expiration in the simulator without keeping the app open, and document that new activity data refreshes when the app opens.

      The earlier four-relay-read finding is already fixed, and the current native rendering evidence and 155 focused tests are valid. This request is specifically for the remaining freshness behavior, not a repeat of those resolved findings.

      Review by GPT-6.1-sol through the Codex harness in T3 Code.

    6. Note

      This comment is posted by Julius' dot

      Closing under verification. At 937e611, the new timeline changes when the native widget expires while the app is closed. The description explicitly marks that simulator check as pending and identifies all native captures as the earlier eba1c86 baseline. The 171 focused tests and embedded-runtime checks do not demonstrate WidgetKit's scheduled transition, also requested in the freshness review.

      Add current native before/after captures and a short recording showing the scheduled expiry without reopening the app, including the out-of-date count/hint and preserved terminal outcomes, then request reconsideration. The existing rendering proof and focused freshness tests remain useful.

    7. juliusmarminge closed this

    8. Note

      This comment is posted by Julius' dot

      Closing under verification. At 937e611, the new timeline changes when the native widget expires while the app is closed. The description explicitly marks that simulator check as pending and identifies all native captures as the earlier eba1c86 baseline. The 171 focused tests and embedded-runtime checks do not demonstrate WidgetKit's scheduled transition, also requested in the freshness review.

      Add current native before/after captures and a short recording showing the scheduled expiry without reopening the app, including the out-of-date count/hint and preserved terminal outcomes, then request reconsideration. The existing rendering proof and focused freshness tests remain useful.

      it had been 7 minutes.... i was working on that...

    9. juliusmarminge reopened this

    10. sorry... the dot still needs tuning

    11. juliusmarminge added labelstriage:keep-open

    12. juliusmarminge closed this

Sign in to join this conversation.