Skip to content

Prelaunch hardening cleanup#297

Merged
zvadaadam merged 4 commits into
mainfrom
zvadaadam/san-juan-v9
May 18, 2026
Merged

Prelaunch hardening cleanup#297
zvadaadam merged 4 commits into
mainfrom
zvadaadam/san-juan-v9

Conversation

@zvadaadam

@zvadaadam zvadaadam commented May 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • replace post-launch-style schema migrations with a pre-launch reset policy and stale local DB validation
  • widen static quality coverage across apps/packages/shared/scripts/test while keeping existing debt warning-level
  • gate iOS Simulator availability from backend capability truth instead of frontend platform sniffing
  • extract one-shot query request dispatch from the large query engine and document the mega-goal audit trail

Verification

  • bun run typecheck
  • bun run lint (0 errors, known 430 warnings)
  • PYTHON=/usr/bin/python3 bun run test
  • git diff --check

Summary by CodeRabbit

Release Notes

  • New Features

    • iOS Simulator availability detection—the app now determines simulator support based on your system configuration and reports runtime availability status to the UI
  • Bug Fixes

    • Pre-launch database schema validation to detect incompatible local databases and guide users to reset them
  • Chores

    • Improved test coverage for simulator capabilities and database initialization
    • Enhanced configuration linting across the codebase

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c7be8aed-21ed-4a7a-a82a-6053df00a1a2

📥 Commits

Reviewing files that changed from the base of the PR and between b72c29c and 4ecf932.

📒 Files selected for processing (2)
  • apps/backend/src/services/simulator-context.ts
  • apps/backend/test/unit/services/simulator-capabilities.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/backend/test/unit/services/simulator-capabilities.test.ts
  • apps/backend/src/services/simulator-context.ts

📝 Walkthrough

Walkthrough

This PR implements prelaunch hardening across three dimensions: (1) schema reset policy replaces migration replay; (2) backend capability reporting gates simulator UI; (3) ESLint modernization with flat-config and expanded coverage. Supporting changes thread relay-client context through request dispatch and refactor tests.

Changes

Prelaunch Hardening Implementation

Layer / File(s) Summary
Pre-launch schema reset policy
shared/schema.ts, apps/backend/cli.ts, apps/backend/src/lib/database.ts, apps/backend/test/unit/lib/database.test.ts, apps/backend/test/unit/shared/schema.test.ts
Database initialization now executes SCHEMA_SQL and validates PRELAUNCH_REQUIRED_COLUMNS instead of replaying migrations. Stale local DBs must be reset by deleting deus.db or setting DATABASE_PATH to a fresh file. CLI and schema test coverage updated.
Simulator capability detection
shared/types/simulator.ts, apps/backend/src/services/simulator-context.ts, apps/backend/test/unit/services/simulator-capabilities.test.ts
Backend evaluates simulator availability based on platform (macOS), simctl toolchain, relay-client status, and simbridge presence. Returns SimulatorCapabilities with available flag and optional unavailableReason.
Request dispatcher and context threading
apps/backend/src/services/query-request-dispatcher.ts, apps/backend/src/services/query-engine.ts, apps/backend/src/services/agent/commands.ts, shared/events.ts
New dispatcher module routes one-shot requests to HTTP endpoints. Query engine threads { relayClient: boolean } context into request/command handlers. sim:start command now checks simulator capabilities before starting stream.
Frontend simulator UI gating
apps/web/src/features/simulator/api/simulator.queries.ts, apps/web/src/features/simulator/api/simulator.service.ts, apps/web/src/app/layouts/content-tabs.ts, apps/web/src/app/layouts/MainContent.tsx, apps/web/src/app/layouts/ContentTabBar.tsx, apps/web/src/app/layouts/ContentView.tsx, apps/web/src/platform/capabilities.ts, apps/web/src/features/settings/ui/sections/ExperimentalSection.tsx
New useSimulatorCapabilities hook fetches backend capabilities. Simulator tab visibility now depends on both experimental_simulator setting and backend available flag. Removed frontend nativeSimulator capability in favor of backend-driven state.
ESLint flat-config modernization
eslint.config.mjs, package.json
Refactored single broad config into targeted blocks by environment (TypeScript, React, Node, browser, workers, tests). Expanded linting scope to packages, shared, scripts, and test directories. Removed obsolete /* eslint-env browser */ directives from apps/web/src/features/browser/*.
Tests and cleanup
apps/backend/test/unit/services/event-persistence-integration.test.ts, apps/backend/test/unit/services/query-request-dispatcher.test.ts, apps/backend/test/unit/services/agent-commands-simulator.test.ts, apps/backend/test/unit/shared/events.test.ts, test/unit/session/subagentMessageList.test.ts, test/unit/session/calculateTurnStats.test.ts, test/unit/workspace/workspaceStore.test.ts, test/unit/workspace/content-tabs.test.ts, apps/backend/test/unit/runtime/agent-process.test.ts, DEVELOPMENT.md, .gitignore
Updated tests for schema validation, capability reporting, and tab visibility. Refactored message list test to use typed Part objects. Added development guide section on database schema policy.

🐰 Pre-launch stones now set in place,
Schema resets clear the stale database trace,
Simulator talks back with honest word,
Frontend heeds what backend has heard,
ESLint watches with discerning eye—
The system's stronger as it marches by!

🎯 3 (Moderate) | ⏱️ ~25 minutes

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 24.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and clearly summarizes the main objective of the PR: implementing pre-launch schema hardening and cleanup, which is the primary theme across database schema validation, stale DB detection, and related infrastructure changes.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch zvadaadam/san-juan-v9

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

@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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/web/src/features/simulator/api/simulator.queries.ts (1)

13-18: ⚡ Quick win

Use infinite staleness for this WebSocket-backed capability query.

This hook is consuming backend state over the WS protocol, so staleTime: 30_000 is out of policy and adds avoidable refetch churn. Use Infinity here.

♻️ Proposed change
   const query = useQuery({
     queryKey: SIMULATOR_CAPABILITIES_QUERY_KEY,
     queryFn: () => simulatorService.getCapabilities(),
-    staleTime: 30_000,
+    staleTime: Infinity,
     refetchOnWindowFocus: false,
     enabled: options.enabled ?? true,
   });
As per coding guidelines: "Frontend subscribes to server state via WebSocket using `useQuerySubscription()` with `staleTime: Infinity` and `refetchOnWindowFocus: false`" and "Set `staleTime: Infinity` and `refetchOnWindowFocus: false` for WebSocket-managed server state since the WebSocket handles freshness".
🤖 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 `@apps/web/src/features/simulator/api/simulator.queries.ts` around lines 13 -
18, The query for SIMULATOR_CAPABILITIES_QUERY_KEY (created with useQuery and
calling simulatorService.getCapabilities) is WebSocket-backed and should use
infinite staleness; change staleTime from 30_000 to Infinity and keep
refetchOnWindowFocus: false (or switch to useQuerySubscription if codebase
standard prefers that hook) while leaving enabled: options.enabled ?? true
intact.
🤖 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.

Inline comments:
In `@apps/backend/src/services/simulator-context.ts`:
- Around line 163-167: hasSimulatorToolchain currently checks
SIM_ENV["DEVELOPER_DIR"]/usr/bin/simctl which can miss valid setups; replace
this filesystem check in function hasSimulatorToolchain with invoking xcrun
--find simctl (e.g., via child_process.execSync or spawnSync) and return true if
the command succeeds and yields a path, otherwise return false; ensure you catch
errors from exec/spawn and treat them as non-existent, and update any imports to
include child_process if needed.

---

Nitpick comments:
In `@apps/web/src/features/simulator/api/simulator.queries.ts`:
- Around line 13-18: The query for SIMULATOR_CAPABILITIES_QUERY_KEY (created
with useQuery and calling simulatorService.getCapabilities) is WebSocket-backed
and should use infinite staleness; change staleTime from 30_000 to Infinity and
keep refetchOnWindowFocus: false (or switch to useQuerySubscription if codebase
standard prefers that hook) while leaving enabled: options.enabled ?? true
intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6221d55c-5411-4f7a-a454-460a05bb04fc

📥 Commits

Reviewing files that changed from the base of the PR and between 6d5fd4f and b20b7e4.

📒 Files selected for processing (48)
  • .megagoal/prelaunch-hardening/NOTES.md
  • .megagoal/prelaunch-hardening/ROADMAP.md
  • .megagoal/prelaunch-hardening/goals/01-prelaunch-schema-cleanup.md
  • .megagoal/prelaunch-hardening/goals/02-static-quality-gate-coverage.md
  • .megagoal/prelaunch-hardening/goals/03-simulator-capability-truth.md
  • .megagoal/prelaunch-hardening/goals/04-high-risk-complexity-pass.md
  • .megagoal/prelaunch-hardening/goals/05-final-ship-gate.md
  • DEVELOPMENT.md
  • apps/backend/cli.ts
  • apps/backend/src/lib/database.ts
  • apps/backend/src/services/agent/commands.ts
  • apps/backend/src/services/query-engine.ts
  • apps/backend/src/services/query-request-dispatcher.ts
  • apps/backend/src/services/simulator-context.ts
  • apps/backend/test/unit/lib/database.test.ts
  • apps/backend/test/unit/runtime/agent-process.test.ts
  • apps/backend/test/unit/services/agent-commands-simulator.test.ts
  • apps/backend/test/unit/services/event-persistence-integration.test.ts
  • apps/backend/test/unit/services/query-request-dispatcher.test.ts
  • apps/backend/test/unit/services/simulator-capabilities.test.ts
  • apps/backend/test/unit/shared/events.test.ts
  • apps/backend/test/unit/shared/schema.test.ts
  • apps/web/src/app/layouts/ContentTabBar.tsx
  • apps/web/src/app/layouts/ContentView.tsx
  • apps/web/src/app/layouts/MainContent.tsx
  • apps/web/src/app/layouts/content-tabs.ts
  • apps/web/src/features/browser/hooks/useWebview.ts
  • apps/web/src/features/browser/ui/BrowserTab.tsx
  • apps/web/src/features/browser/ui/FocusModeOverlay.tsx
  • apps/web/src/features/browser/ui/InspectPromptOverlay.tsx
  • apps/web/src/features/browser/webview-manager.ts
  • apps/web/src/features/settings/ui/sections/ExperimentalSection.tsx
  • apps/web/src/features/simulator/api/simulator.queries.ts
  • apps/web/src/features/simulator/api/simulator.service.ts
  • apps/web/src/features/simulator/index.ts
  • apps/web/src/platform/capabilities.ts
  • docs/codebase-audit-2026-05-18.md
  • eslint.config.mjs
  • package.json
  • shared/events.ts
  • shared/schema.ts
  • shared/types/index.ts
  • shared/types/simulator.ts
  • test/unit/session/calculateTurnStats.test.ts
  • test/unit/session/subagentMessageList.test.ts
  • test/unit/shared/chatInsertStore.test.ts
  • test/unit/workspace/content-tabs.test.ts
  • test/unit/workspace/workspaceStore.test.ts
💤 Files with no reviewable changes (7)
  • apps/web/src/features/browser/ui/BrowserTab.tsx
  • apps/web/src/features/browser/ui/FocusModeOverlay.tsx
  • apps/web/src/features/browser/ui/InspectPromptOverlay.tsx
  • test/unit/shared/chatInsertStore.test.ts
  • apps/web/src/features/browser/webview-manager.ts
  • apps/web/src/platform/capabilities.ts
  • apps/web/src/features/browser/hooks/useWebview.ts

Comment thread apps/backend/src/services/simulator-context.ts

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b20b7e4fcd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread shared/schema.ts

export const PRELAUNCH_REQUIRED_COLUMNS = {
workspaces: ["status"],
sessions: ["agent_harness", "error_category"],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reset stale Codex harness values

For local databases that already have sessions.agent_harness but still contain the old value codex, this column-only prelaunch gate passes even though the removed migration used to rewrite those rows to codex-sdk. Existing sessions with messages then hit the harness-lock path in sendMessage and are rejected as Cannot switch agent from codex to codex-sdk, instead of getting the intended reset hint or working after migration. Please either validate/fail on stale agent_harness = 'codex' rows here or keep the data rewrite before accepting the DB.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 7751b36. Backend startup now fails fast with the pre-launch reset hint when a current-shape local DB still contains stale sessions.agent_harness = codex rows, so those sessions cannot later trip the harness-lock path.

function hasSimulatorToolchain(): boolean {
const developerDir = SIM_ENV["DEVELOPER_DIR"];
if (!developerDir) return false;
return existsSync(join(developerDir, "usr/bin", "simctl"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include simbridge in simulator availability

On a macOS backend with Xcode installed but without the simbridge helper built or packaged, this reports simulator streaming as available even though startStream immediately fails with simbridge binary not found. Since the frontend now uses simulatorCapabilities to enable the setting/tab, these installs get an apparently supported simulator UI that cannot start a stream. Please include the same findSimBridgePath() check in the capability result, or return an unavailable reason when the stream helper is missing.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 7751b36. Simulator capabilities now require findSimBridgePath() to resolve before reporting availability, and the capability tests cover the missing-simbridge case.

@zvadaadam

Copy link
Copy Markdown
Owner Author

Greenlight — Round 1

Fixed all 3 actionable AI review comments in 7751b361:

  • resolved simulator toolchain detection through xcrun --find simctl
  • made simulator availability require the simbridge helper
  • failed stale pre-launch DBs with agent_harness = codex using the reset hint

Verification before push:

  • bun run typecheck
  • bun run lint (0 errors, known 430 warnings)
  • PYTHON=/usr/bin/python3 bun run test
  • git diff --check

@zvadaadam zvadaadam merged commit 3a60665 into main May 18, 2026
7 checks passed
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.

1 participant