Skip to content

refactor: realign runtime shell around upstream bootstrap data#4

Merged
bdtran2002 merged 20 commits intomainfrom
upstream-port-audit
Apr 22, 2026
Merged

refactor: realign runtime shell around upstream bootstrap data#4
bdtran2002 merged 20 commits intomainfrom
upstream-port-audit

Conversation

@bdtran2002
Copy link
Copy Markdown
Owner

@bdtran2002 bdtran2002 commented Apr 22, 2026

Summary

  • freeze the old burger TypeScript runtime path as legacy scaffolding and document the active upstream runtime path
  • move Burgers, Inc. bootstrap data and packets behind an upstream-derived generated snapshot instead of hand-authoring them in the bridge/runtime shell
  • thin the active runtime shell by removing synthetic polling/copy/state duplication and centralizing shared bootstrap/session helpers

Verification

  • npm test
  • npx tsc -p tsconfig.json --noEmit
  • npm exec eslint src/features/runtime-frame/upstream-runtime.ts src/features/runtime-frame/upstream-runtime-copy.ts

Summary by CodeRabbit

  • New Features

    • Runtime now displays as "upstream-derived," with updated messaging and simplified interface.
  • Bug Fixes

    • Improved checkpoint restoration and session state management.
    • Enhanced session reuse detection for more reliable resume functionality.
  • Refactor

    • Streamlined runtime display by removing unused metadata and UI elements.
    • Consolidated bootstrap and checkpoint workflows for cleaner runtime initialization.

@bdtran2002
Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

📝 Walkthrough

Walkthrough

This refactoring simplifies the ForkOrFry runtime by removing Godot bridge snapshot polling, local bootstrap generation, and legacy burger-runtime scaffolding references. It introduces new state management helpers for bridge snapshot and session handling, reorganizes boot/resume logic into dedicated constructors, and updates documentation to establish upstream-runtime.ts as the canonical active runtime with upstream code porting as the primary development approach.

Changes

Cohort / File(s) Summary
Documentation & Architecture
AGENTS.md, docs/pivot-analysis.md, docs/runtime-host-branch-log.md
Updated development approach to designate upstream-derived runtime as canonical, mark burger-runtime as legacy migration scaffolding, specify runtime-frame/upstream-runtime.ts as active shipped runtime, and revise conversion workflow execution order.
Runtime Bridge Simplification
extension/src/features/runtime-frame/upstream-bridge.ts
Removed UPSTREAM_PROTOCOL_MAJOR, createLocalBootstrapPayload(), hardcoded burgers_inc bootstrap logic, and payload field from UpstreamBridgeSnapshot. Now requires externally provided bootstrap payloads.
State Management Refactoring
extension/src/features/runtime-frame/upstream-runtime-state.ts
Removed UpstreamGodotBridgeSnapshot and related godot bridge fields. Added new public helpers: bridge snapshot lifecycle functions (createInitialUpstreamBridgeSnapshot, restoreUpstreamBridgeSnapshotForSession, acknowledgeUpstreamBridgeSnapshot, errorUpstreamBridgeSnapshot), session resolution (resolveUpstreamRuntimeSessionState), gameplay packet utilities (trimUpstreamRuntimeGameplayPackets, summarizeUpstreamRuntimeGameplayPackets), and state constructors (createBootUpstreamRuntimeState, createResumeUpstreamRuntimeState).
Runtime Logic Consolidation
extension/src/features/runtime-frame/upstream-runtime.ts, extension/src/features/runtime-frame/upstream-checkpoint.ts
Removed godot bridge polling/sync logic and bootstrap generation. Refactored boot/resume flows to use new state constructors. Delegated packet trimming/summary to centralized utilities. Consolidated bootstrap + checkpoint sending flows.
Runtime Copy Updates
extension/src/features/runtime-frame/upstream-runtime-copy.ts, extension/src/features/runtime-host/copy.ts
Removed metadata fields, UI elements, capabilities list, and Godot-bridge-specific terminology. Updated labels to use "export" and "upstream-derived" terminology; simplified phase labels and summary functions.
Test Coverage
extension/tests/upstream-runtime.test.ts
Removed fixtures and tests for godot bridge snapshot handling. Added test coverage for new bridge snapshot state management, session reuse detection, and boot/resume state constructors. Updated bootstrap payload tests to use generated burgers-inc helpers.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 Godot ghosts and burger scaffolds fade,
Clean state machines in helpers made,
No more polling, bootstrap spins with grace,
Upstream port now owns the place!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 clearly and concisely summarizes the main refactoring change: realigning the runtime shell to use upstream bootstrap data instead of hand-authored local bootstrap logic.
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 upstream-port-audit

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@extension/src/features/runtime-frame/upstream-runtime-state.ts`:
- Around line 102-116: In summarizeUpstreamRuntimeGameplayPackets, totalCount
currently uses packets.length which includes invalid entries; change it to count
only validated packets by introducing a validatedCount (or reuse actionCounts
size) that you increment inside the loop only when
isUpstreamRuntimeGameplayPacket(packet) is true, then return totalCount:
validatedCount (instead of packets.length) along with lastAction and
actionCounts so the summary reflects only validated gameplay packets.
- Around line 166-178: createResumeUpstreamRuntimeState currently preserves
restored.bridgeState when exportUrl is missing, which can rehydrate a stale
'error' state even though
resolveUpstreamRuntimeSessionState/restoreUpstreamBridgeSnapshotForSession drops
lastError; change the bridgeState assignment so that if restored.exportUrl is
truthy you set 'waiting' as before, otherwise normalize: if restored.bridgeState
=== 'error' set bridgeState to 'ready' else keep restored.bridgeState. Update
the bridgeState expression in createResumeUpstreamRuntimeState to use that
conditional (you can still use resolvedSession.bridgeSnapshot/resolvedSession
from resolveUpstreamRuntimeSessionState to locate the callsite).
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e30591cf-73fa-419e-bcda-cb3c1421e90d

📥 Commits

Reviewing files that changed from the base of the PR and between e10288e and d3c11e7.

⛔ Files ignored due to path filters (1)
  • extension/upstream/generated/burgers-inc-bootstrap.ts is excluded by !**/generated/**
📒 Files selected for processing (10)
  • AGENTS.md
  • docs/pivot-analysis.md
  • docs/runtime-host-branch-log.md
  • extension/src/features/runtime-frame/upstream-bridge.ts
  • extension/src/features/runtime-frame/upstream-checkpoint.ts
  • extension/src/features/runtime-frame/upstream-runtime-copy.ts
  • extension/src/features/runtime-frame/upstream-runtime-state.ts
  • extension/src/features/runtime-frame/upstream-runtime.ts
  • extension/src/features/runtime-host/copy.ts
  • extension/tests/upstream-runtime.test.ts
💤 Files with no reviewable changes (1)
  • extension/src/features/runtime-frame/upstream-bridge.ts

Comment on lines +102 to +116
export function summarizeUpstreamRuntimeGameplayPackets(packets: UpstreamRuntimeState['gameplayPackets']) {
const actionCounts: Record<string, number> = {}
let lastAction: string | null = null

for (const packet of packets) {
if (!isUpstreamRuntimeGameplayPacket(packet)) continue
actionCounts[packet.action] = (actionCounts[packet.action] ?? 0) + 1
lastAction = packet.action
}

return {
totalCount: packets.length,
lastAction,
actionCounts,
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Count only validated packets in the summary.

totalCount currently uses the raw array length even though invalid entries are skipped for actionCounts and lastAction. If restored state ever contains malformed packets, the summary becomes self-contradictory.

Proposed fix
 export function summarizeUpstreamRuntimeGameplayPackets(packets: UpstreamRuntimeState['gameplayPackets']) {
   const actionCounts: Record<string, number> = {}
   let lastAction: string | null = null
+  let totalCount = 0
 
   for (const packet of packets) {
     if (!isUpstreamRuntimeGameplayPacket(packet)) continue
+    totalCount += 1
     actionCounts[packet.action] = (actionCounts[packet.action] ?? 0) + 1
     lastAction = packet.action
   }
 
   return {
-    totalCount: packets.length,
+    totalCount,
     lastAction,
     actionCounts,
   }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function summarizeUpstreamRuntimeGameplayPackets(packets: UpstreamRuntimeState['gameplayPackets']) {
const actionCounts: Record<string, number> = {}
let lastAction: string | null = null
for (const packet of packets) {
if (!isUpstreamRuntimeGameplayPacket(packet)) continue
actionCounts[packet.action] = (actionCounts[packet.action] ?? 0) + 1
lastAction = packet.action
}
return {
totalCount: packets.length,
lastAction,
actionCounts,
}
export function summarizeUpstreamRuntimeGameplayPackets(packets: UpstreamRuntimeState['gameplayPackets']) {
const actionCounts: Record<string, number> = {}
let lastAction: string | null = null
let totalCount = 0
for (const packet of packets) {
if (!isUpstreamRuntimeGameplayPacket(packet)) continue
totalCount += 1
actionCounts[packet.action] = (actionCounts[packet.action] ?? 0) + 1
lastAction = packet.action
}
return {
totalCount,
lastAction,
actionCounts,
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@extension/src/features/runtime-frame/upstream-runtime-state.ts` around lines
102 - 116, In summarizeUpstreamRuntimeGameplayPackets, totalCount currently uses
packets.length which includes invalid entries; change it to count only validated
packets by introducing a validatedCount (or reuse actionCounts size) that you
increment inside the loop only when isUpstreamRuntimeGameplayPacket(packet) is
true, then return totalCount: validatedCount (instead of packets.length) along
with lastAction and actionCounts so the summary reflects only validated gameplay
packets.

Comment on lines +166 to +178
export function createResumeUpstreamRuntimeState(restored: UpstreamRuntimeState, fallbackSessionId: string): UpstreamRuntimeState {
const resolvedSession = resolveUpstreamRuntimeSessionState(restored.bridgeSnapshot, restored.sessionId || fallbackSessionId)

return {
...restored,
sessionId: resolvedSession.sessionId,
phase: restored.exportUrl ? 'running' : 'ready',
bridgeState: (restored.exportUrl ? 'waiting' : restored.bridgeState),
bridgeSnapshot: resolvedSession.bridgeSnapshot,
detail: resolvedSession.reused
? describeUpstreamRuntimeSession(resolvedSession.sessionId, true)
: restored.exportUrl ? 'Bundled Godot runtime loaded.' : 'Ready.',
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Normalize bridgeState when resume clears bridge errors.

restoreUpstreamBridgeSnapshotForSession() always drops lastError, but this branch keeps restored.bridgeState unchanged when exportUrl is missing. A persisted 'error' state would then resume as phase: 'ready'/detail: 'Ready.' with bridgeState: 'error', which is internally inconsistent and can strand the host on an error path.

Proposed fix
 export function createResumeUpstreamRuntimeState(restored: UpstreamRuntimeState, fallbackSessionId: string): UpstreamRuntimeState {
   const resolvedSession = resolveUpstreamRuntimeSessionState(restored.bridgeSnapshot, restored.sessionId || fallbackSessionId)
+  const bridgeState =
+    restored.exportUrl
+      ? 'waiting'
+      : restored.bridgeState === 'error'
+        ? 'idle'
+        : restored.bridgeState
 
   return {
     ...restored,
     sessionId: resolvedSession.sessionId,
     phase: restored.exportUrl ? 'running' : 'ready',
-    bridgeState: (restored.exportUrl ? 'waiting' : restored.bridgeState),
+    bridgeState,
     bridgeSnapshot: resolvedSession.bridgeSnapshot,
     detail: resolvedSession.reused
       ? describeUpstreamRuntimeSession(resolvedSession.sessionId, true)
       : restored.exportUrl ? 'Bundled Godot runtime loaded.' : 'Ready.',
   }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@extension/src/features/runtime-frame/upstream-runtime-state.ts` around lines
166 - 178, createResumeUpstreamRuntimeState currently preserves
restored.bridgeState when exportUrl is missing, which can rehydrate a stale
'error' state even though
resolveUpstreamRuntimeSessionState/restoreUpstreamBridgeSnapshotForSession drops
lastError; change the bridgeState assignment so that if restored.exportUrl is
truthy you set 'waiting' as before, otherwise normalize: if restored.bridgeState
=== 'error' set bridgeState to 'ready' else keep restored.bridgeState. Update
the bridgeState expression in createResumeUpstreamRuntimeState to use that
conditional (you can still use resolvedSession.bridgeSnapshot/resolvedSession
from resolveUpstreamRuntimeSessionState to locate the callsite).

@bdtran2002 bdtran2002 merged commit 0b87bd7 into main Apr 22, 2026
3 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Apr 22, 2026
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