Skip to content

Staging#559

Merged
equationalapplications merged 12 commits into
mainfrom
staging
Jul 14, 2026
Merged

Staging#559
equationalapplications merged 12 commits into
mainfrom
staging

Conversation

@equationalapplications

Copy link
Copy Markdown
Owner

PR 556

Summary

  • Log promptFeedback on empty model response for better debugging visibility
  • Add test case for empty candidates array retry path
  • Fix wikiLlm test cleanup with try/finally to prevent state leaks

Test plan

  • Existing tests pass
  • New test verifies empty candidates array triggers retry
  • Test cleanup now properly isolated with try/finally

🤖 Generated with Claude Code

PR 557

Summary

Two production fixes found while investigating chat-screen errors (2026-07-13):

1. summarizeText 500s — missing Cloud SQL secret bindings

Every prod summarizeText call has been failing with
Missing required Cloud SQL environment variables: CLOUD_SQL_CONNECTION_NAME, CLOUD_SQL_DB_USER, CLOUD_SQL_DB_PASS, CLOUD_SQL_DB_NAME
since the July credit repricing added userRepository/creditService (Cloud SQL) to the handler without declaring secrets: [...CLOUD_SQL_SECRETS] in its onCall options — the deployed revision has zero CLOUD_SQL_* env vars. Client surfaces this as Failed to summarize conversation context: FirebaseError: INTERNAL.

  • Adds the secrets binding (matching wikiLlm et al.)
  • Regression test asserts the endpoint manifest carries all four secret bindings
  • Audited all function files: only summarizeText had the gap

2. Chat WebSocket first-message timeouts

First message after idle hit the 5s WS connect timeout while the cloud-agent Cloud Run instance cold-started (~7.5s observed; server logs show the 101 upgrade succeeding after the client gave up). Every fresh session stalled 5s then fell back to HTTP.

  • Connect timeout 5s → 10s (covers observed cold start)
  • 60s circuit breaker after transport-level WS failures: WS-blocked networks pay the connect wait once per window, then go straight to HTTP
  • Rejected racing WS+HTTP in parallel: both paths execute the agent, double credit spend

Test plan

  • functions: 350/350 pass (incl. new secrets-binding regression test)
  • client: cloudAgentService 24/24 (incl. new cooldown + fake-timer connect-timeout tests), useAIChat 26/26
  • typecheck clean both packages
  • post-deploy: verify prod summarizeText returns 200 and first chat message of a fresh session streams over WS

🤖 Generated with Claude Code

PR 558

Summary

  • Bump @equationalapplications/core-llm-wiki + expo-llm-wiki to ^4.21.0 for runOntologyBackfill
  • After every successful wiki cloud sync, run one best-effort runOntologyBackfill batch per cloud character so cloud-agent-written and pre-ontology facts get okf_type and join the knowledge graph
  • Backfill failures never fail the sync; WikiBusyError swallowed silently; other errors and stalled batches (scanned > 0 && typed === 0) reported to Crashlytics via existing reportWikiOpForCharacter tag family

Test Plan

  • npm test — 992/992 passing (121 suites)
  • npm run typecheck — clean
  • npm run lint:check — clean
  • Self-reviewed via superpowers:code-reviewer subagent — no critical/important issues; addressed minor nits (typed test fixtures, stalled-check comment)
  • Post-merge manual verification in dev: character with cloud-agent-written facts gets them typed after one manual sync, graph traversal returns them (spec §Rollout)

equationalapplications and others added 12 commits July 13, 2026 12:31
summarizeText gained Cloud SQL usage (userRepository/creditService) in the
July credit repricing but never declared CLOUD_SQL_SECRETS in its onCall
options. The deployed revision therefore had no CLOUD_SQL_* env vars and
every call failed 500 with "Missing required Cloud SQL environment
variables" before reaching the model.

Adds the secrets binding (matching wikiLlm et al.) and a regression test
asserting the endpoint manifest carries all four secret bindings.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
First message after idle hit the 5s WS connect timeout while Cloud Run
cold-started (~7.5s observed), so every fresh session stalled 5s and fell
back to HTTP. Raise the connect timeout to 10s and add a 60s circuit
breaker after transport-level failures so WS-blocked networks pay the
connect wait once per cooldown window instead of on every message.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot review on #557: authTimeout guarded WS open/connect
(WS_CONNECT_TIMEOUT_MS), not the separate auth-timeout path
('WebSocket auth timeout' on close code 4001). Renamed to
connectTimeout throughout.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
fix: summarizeText Cloud SQL secrets + WS cold-start timeout
Adopt expo-llm-wiki 4.21.0 runOntologyBackfill: dep bump plus post-sync
trigger in syncWikiForCloud (covers syncAllToCloud and restoreFromCloud).
Single batch per character per sync; WikiBusyError swallowed; other
errors reported as wiki:<id>:ontology:backfill.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ion spec

Review round: report scanned>0/typed==0 batches via existing reportError
pathway (tag wiki:<id>:ontology:backfill:stalled) so an unclassifiable
backlog looping on the 7-day cooldown is visible in Crashlytics; log full
counters in dev builds. Note that sync triggers are foreground-only, so
OS background-fetch kill limits do not apply; mid-loop suspension loses
at most the in-flight batch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…kfill-adoption

feat: run ontology backfill per cloud character after wiki sync
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Wiki synchronization now performs ontology backfill for cloud-linked characters, helping classify previously untyped facts.
    • Backfill continues safely across characters and reports stalled or failed processing when appropriate.
  • Bug Fixes

    • Improved Cloud Agent reliability by waiting for slow WebSocket connections and temporarily using HTTP after transport failures.
    • Wiki sync and restore flows now avoid backfill when the primary synchronization fails.
  • Security

    • Updated text summarization services to include required database secret configuration.

Walkthrough

The PR adds ontology backfill after successful wiki synchronization, hardens WebSocket timeout and retry fallback behavior, wires Cloud SQL secrets into summarizeText, updates dependencies, and expands related tests and documentation.

Changes

Ontology backfill adoption

Layer / File(s) Summary
Backfill contract and dependency updates
docs/superpowers/plans/..., docs/superpowers/specs/..., package.json
Documents the one-pass backfill contract and upgrades both wiki packages to ^4.21.0.
Backfill test harness and coverage
__tests__/characterSyncWiki.test.ts
Adds richer wiki mocks and tests successful, stalled, busy-error, failure, empty-character, and restore-flow behavior.
Post-sync backfill execution
src/services/characterSyncService.ts, docs/superpowers/plans/...
Runs backfill per cloud character after successful sync, reports relevant failures, skips failed pipelines, and records verification steps.

WebSocket fallback controls

Layer / File(s) Summary
WebSocket timeout and cooldown behavior
src/services/cloudAgentService.ts, __tests__/cloudAgentService.test.ts
Adds connection timeout cleanup, transport-failure cooldowns, and tests for delayed fallback and suppressed retries.

Callable secret configuration

Layer / File(s) Summary
summarizeText secret bindings
functions/src/summarizeText.ts, functions/src/summarizeText.test.ts
Binds CLOUD_SQL_SECRETS to the callable and verifies the endpoint exposes every required secret key.

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

Sequence Diagram(s)

sequenceDiagram
  participant SyncWikiForCloud
  participant WikiOrchestrator
  participant Wiki
  participant CrashReporting
  SyncWikiForCloud->>WikiOrchestrator: syncAll
  WikiOrchestrator-->>SyncWikiForCloud: successful sync
  loop cloud-linked characters
    SyncWikiForCloud->>Wiki: runOntologyBackfill(characterId)
    Wiki-->>SyncWikiForCloud: backfill result
    SyncWikiForCloud->>CrashReporting: report stalled or failed result
  end
Loading

Possibly related PRs

Suggested reviewers: copilot

Poem

I’m a rabbit with typed facts to spare,
Backfilling wikis with careful care.
WebSockets wait, then HTTP hops,
Secret bindings guard the crops.
Tests bloom bright across the flow—
Hop, hop, ship the code we know!

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the main changes and test plan, but it misses most required template sections and checklist fields. Reformat it to match the repository template: add Type of Change, Related Issue, Changes Made, Testing details, Screenshots, Checklist, and Additional Notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is too generic and doesn't communicate the main change in the PR. Rename it to a concise, specific summary of the primary change, such as the wiki backfill or Cloud SQL/WS fixes.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This staging PR bundles a set of production-hardening fixes across the client and Cloud Functions: improving Cloud Agent WebSocket reliability (cold starts + circuit breaker), ensuring summarizeText has required Cloud SQL secret bindings, and adopting ontology backfill after wiki cloud syncs (with docs + tests).

Changes:

  • Client: increase WS connect timeout to 10s and add a 60s cooldown after transport-level WS failures to avoid repeated slow fallbacks.
  • Client: after successful wiki cloud sync, run one best-effort runOntologyBackfill batch per cloud character with stalled-batch + error reporting.
  • Functions: bind Cloud SQL secrets for summarizeText and add a regression test asserting secret bindings are present in the endpoint manifest; bump wiki packages to ^4.21.0.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/services/cloudAgentService.ts Adds WS connect timeout + transport-failure cooldown to reduce first-message timeouts and repeated slow WS attempts.
tests/cloudAgentService.test.ts Adds coverage for WS cooldown behavior and the 10s connect-timeout fallback path.
src/services/characterSyncService.ts Runs best-effort ontology backfill after a successful wiki sync; reports stalled batches and non-busy failures without failing the sync.
tests/characterSyncWiki.test.ts Updates mocks and adds a comprehensive ontology-backfill-after-sync test suite.
functions/src/summarizeText.ts Declares Cloud SQL secret bindings for summarizeText callable configuration.
functions/src/summarizeText.test.ts Adds regression test that asserts Cloud SQL secret bindings appear in the callable’s endpoint manifest.
package.json Bumps @equationalapplications/*-llm-wiki dependencies to ^4.21.0.
package-lock.json Lockfile updates reflecting the wiki dependency bump.
docs/superpowers/specs/2026-07-14-ontology-backfill-adoption-design.md Design spec documenting the backfill adoption decisions and testing matrix.
docs/superpowers/plans/2026-07-14-ontology-backfill-adoption.md Implementation plan for the ontology backfill adoption work.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
__tests__/cloudAgentService.test.ts (1)

421-476: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Solid coverage for the cooldown-skip and connect-timeout paths; consider also testing cooldown expiry.

Both new tests correctly validate: (1) WS is skipped for subsequent calls after a transport failure, and (2) HTTP fallback only triggers after the full 10s connect timeout. Neither test asserts that WebSocket is retried again once WS_RETRY_COOLDOWN_MS (60s) elapses — a regression where the cooldown never expires (e.g., an off-by-something in wsDisabledUntil computation) would go undetected.

Consider extending test 1 (or adding a new case) with fake timers: after the first failure, advance time past 60s, then call callCloudAgent again and assert wsConstructions increments to 2.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@__tests__/cloudAgentService.test.ts` around lines 421 - 476, Extend the
“skips WebSocket entirely for the cooldown window after a transport failure”
test to use fake timers, advance beyond WS_RETRY_COOLDOWN_MS after the initial
failure, then make another call and assert wsConstructions increments to 2.
Preserve the existing assertion that the immediate second call skips WebSocket,
and restore real timers and the original WebSocket afterward.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@__tests__/cloudAgentService.test.ts`:
- Around line 421-476: Extend the “skips WebSocket entirely for the cooldown
window after a transport failure” test to use fake timers, advance beyond
WS_RETRY_COOLDOWN_MS after the initial failure, then make another call and
assert wsConstructions increments to 2. Preserve the existing assertion that the
immediate second call skips WebSocket, and restore real timers and the original
WebSocket afterward.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bfabe5dd-d7fd-460e-95f6-7ef79116784b

📥 Commits

Reviewing files that changed from the base of the PR and between 76c3a33 and 9779683.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (9)
  • __tests__/characterSyncWiki.test.ts
  • __tests__/cloudAgentService.test.ts
  • docs/superpowers/plans/2026-07-14-ontology-backfill-adoption.md
  • docs/superpowers/specs/2026-07-14-ontology-backfill-adoption-design.md
  • functions/src/summarizeText.test.ts
  • functions/src/summarizeText.ts
  • package.json
  • src/services/characterSyncService.ts
  • src/services/cloudAgentService.ts

@equationalapplications
equationalapplications merged commit 58c276a into main Jul 14, 2026
7 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 14, 2026
4 tasks
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.

2 participants