← Back to Pull requests

fix(external): preserve child events across engine spawn races #62

Merged
free6589 merged 10 files (346 lines) on Nov 30, 2026 15:07 UTC
View on GitHub
free6589 free6589 commented on Nov 30, 2026 13:50 UTC
Author

What this fixes

The foreign-child bridge previously discarded every event from an unknown child while its parent had an engine spawn in flight. It did this to avoid racing the engine's own child claim.

That avoided duplicate rows, but created a correctness hole: a genuinely foreign child whose entire turn/start → image/tool result → turn/end lifecycle happened inside that window disappeared completely from the parent progress view.

The bridge now buffers only essential lifecycle/image events for unknown children while the window is open. When the final pending engine spawn closes:

  • engine-claimed children are discarded safely;

  • genuinely foreign children are replayed through the normal bridge path;

  • disposed buffered children are retired so they cannot reappear as ghost rows.
  • The buffer is bounded per child and by child count, so it is not a transcript cache.

    Tests

    Adds a regression test for a foreign child whose entire lifecycle, including an image-bearing event, occurs inside the spawn race window.

    Diff: 346 lines (+295 / -51) across 10 files Reviewer: chatgpt-codex-connector[bot] Review duration: 76m
    All Vouch review confidence checks passed
    Residual risk 0.12 = Change Risk (0.51) × (1 − Review Confidence (0.76)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.51 · 346 lines diff across 10 files
    0.51
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.56 · 2 substantive comment(s)
    0.56
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    76%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.350
    Real PR Conversation Timeline
    4 items
    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Nov 30, 2026 13:50 UTC
    Bot

    <!-- codex-pull-request-review-summary -->
    <!-- codex-review-state:v1 {"code_review":{"commit_sha":"5e81b44e8d11472bd4a7dbdf44f7f1405f2c7214","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} -->

    <details>
    <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary>

    This comment shows the latest Codex review activity on this pull request.

    | Review | Status | Commit | Review trigger |
    | --- | --- | --- | --- |
    | 📝 Code Review | ✅ Completed <relative-time datetime="2026-11-30T13:58:28.082891Z">2026-11-30T13:58:28.082891Z</relative-time> | 5e81b44 | New commits |

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    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" or "@codex security review".
  • Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

    </details>

    </details>

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Nov 30, 2026 13:54 UTC
    Code Review
    src/external.ts:1
    @@ -399,6 +418,35 @@ export function installExternalBridge(input: ExternalBridgeInput): () => void {
         return false
       }
     
    +  /** Buffer one race-window event without retaining an unbounded transcript. */
    +  const bufferPendingEvent = (childId: string, parentId: string, event: ObservedEvent): void => {
    +    const existing = pendingChildren.get(childId)
    +    const eventType = typeof event.type === 'string' ? event.type : ''
    +    const isLifecycle = eventType === 'turn/start' || eventType === 'turn/end'
    +    const hasImage = externalImagesOf(event.data).length > 0
    +    if (!isLifecycle && !hasImage) return
    +    if (existing === undefined) {
    +      if (pendingChildren.size >= EXTERNAL_PENDING_CHILD_LIMIT) {
    +        warnOnce('external-pending-capacity', `foreign-child spawn-race buffer reached its ${EXTERNAL_PENDING_CHILD_LIMIT}-child limit; dropping another race-window row`)
    +        return
    +      }
    +      const fresh: BufferedChild = { parentId, events: [] }
    +      pendingChildren.set(childId, fresh)
    +      pendingChildOrder.push(childId)
    +    }
    +    const target = pendingChildren.get(childId)
    +    if (target === undefined || target.events.length >= EXTERNAL_PENDING_EVENT_LIMIT) return

    <sub><sub>!P2 Badge</sub></sub> Preserve terminal events when the pending buffer fills

    If a child emits more than 32 image-bearing events while the spawn window remains open, this check also drops its later turn/end. Replaying the buffer then creates a progress row without settling it, so the row remains running until the child is disposed; reserve space for lifecycle events or evict image events instead.

    Useful? React with 👍 / 👎.

    <!-- codex-code-review-finding:v1 -->

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Nov 30, 2026 13:54 UTC
    Reviewer

    <!-- codex-review-receipt:v1 -->

    💡 Codex Review

    Here are some automated review suggestions for this pull request.

    Reviewed commit: aba006871c

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

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

    </details>

    Assignees
    free6589 free6589
    Labels
    risk: low confidence: 76% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 51.2% (MEDIUM) · Higher = larger blast radius
    51.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 76% · Lower = rushed or shallow review
    76%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 12.3% · Safe to merge
    12.3%