Skip to content

[WRONG BRANCH] fix(lab): supervise producers through child exit - #269

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-fabric-producer-orphaning
Draft

[WRONG BRANCH] fix(lab): supervise producers through child exit#269
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-fabric-producer-orphaning

Conversation

@luvs01

@luvs01 luvs01 commented Aug 13, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Prevent a child fabric producer from being considered finished solely on an emitted result protocol line so it cannot continue running or mutate files after the parent has accepted a result.

Description

  • Defer final resolution for runIsolatedFabricProducer until the child process actually closes instead of resolving immediately on a parsed result protocol line.
  • Preserve the parsed result in receivedResult and let the child close handler perform the final resolve/reject decision when appropriate.
  • Add an adversarial regression executor fabricEarlyResultPatchExecutor that emits an early result, stays alive, and attempts a late mutation, and add a test producer result remains supervised until the child exits to assert the parent remains authoritative and the late mutation cannot happen.

Testing

  • ✅ Ran the focused fabric test suite with a clean proxy environment using env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u NO_PROXY -u http_proxy -u https_proxy -u all_proxy -u no_proxy node_modules/.bin/bun test tests/lab-fabric-task.test.ts and the file-level tests passed (47 passed).
  • ✅ Ran the targeted single test with a clean proxy environment using env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u NO_PROXY -u http_proxy -u https_proxy -u all_proxy -u no_proxy node_modules/.bin/bun test tests/lab-fabric-task.test.ts --test-name-pattern "producer result remains supervised" which passed.
  • ✅ Ran bun run typecheck and bun run privacy:scan which succeeded.
  • ⚠️ A full bun run test was executed but the end-to-end run encountered unrelated existing test failures/timeouts in other suites in this environment; the focused fabric producer tests described above were exercised and passed.

Codex Task

Summary by CodeRabbit

  • Bug Fixes

    • Improved isolated task handling so processes remain supervised until they fully exit.
    • Prevented late filesystem changes after a task has produced a result.
    • Ensured timeout outcomes are correctly returned when execution continues unexpectedly.
  • Tests

    • Added coverage for tasks that attempt changes after reporting a result.

@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 13, 2026
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The producer stores early result patches and defers promise resolution until the child process closes. Tests verify that continued child activity reaches timeout and prevents a later filesystem mutation.

Changes

Producer supervision

Layer / File(s) Summary
Defer result resolution until child-process close
src/lab/fabric/producer-isolate.ts:114-117
Result messages store the patch in receivedResult without settling the promise. Close handling resolves the result after exit or kill processing.
Validate supervision after early results
tests/lab-fabric-task.test.ts:148-179, tests/lab-fabric-task.test.ts:596-611, tests/lab-fabric-task.test.ts:1132
The fixture emits a valid result before continuing activity. The test expects timeout and verifies that the delayed marker file is absent. The test-suite closing delimiter remains unchanged.

Estimated code review effort: 2 (Simple) | ~10 minutes

Mergeability Score: 🟡 Moderate · up to 26c68

The producer is intended to remain supervised until its child exits, but the regression test may assert too early and pass even if a late file mutation still occurs. Extend the wait beyond the fixture’s 2,500 ms deadline before treating the change as merge-ready.

Sequence Diagram(s)

sequenceDiagram
  participant FabricTask
  participant ProducerIsolate
  participant ChildProcess
  participant Filesystem
  FabricTask->>ProducerIsolate: start isolated producer
  ChildProcess->>ProducerIsolate: emit early result patch
  ProducerIsolate->>ProducerIsolate: store receivedResult
  ChildProcess->>FabricTask: continue activity
  FabricTask->>ChildProcess: terminate after timeout
  ChildProcess->>ProducerIsolate: emit close
  ProducerIsolate->>FabricTask: return timeout outcome
  ChildProcess->>Filesystem: attempt late mutation
  FabricTask->>Filesystem: verify marker is absent
Loading

Suggested reviewers: wibias

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: supervising isolated producers until the child process exits.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/propose-fix-for-fabric-producer-orphaning

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

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@github-actions github-actions Bot changed the title fix(lab): supervise producers through child exit [WRONG BRANCH] fix(lab): supervise producers through child exit Aug 13, 2026
@github-actions
github-actions Bot marked this pull request as draft August 13, 2026 01:05

@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

🤖 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 `@tests/lab-fabric-task.test.ts`:
- Around line 608-609: Increase the delay before the marker assertion in the
relevant test so it exceeds the fixture child deadline and late-write timing
defined by the test setup. Keep the existing
expect(existsSync(marker)).toBe(false) assertion unchanged, ensuring the test
observes whether the child writes after the producer resolves.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 51bda4ae-424e-4cc6-b5c4-c2897bfb38a5

📥 Commits

Reviewing files that changed from the base of the PR and between 1193075 and 26c6856.

📒 Files selected for processing (2)
  • src/lab/fabric/producer-isolate.ts
  • tests/lab-fabric-task.test.ts
💤 Files with no reviewable changes (1)
  • src/lab/fabric/producer-isolate.ts

Comment on lines +608 to +609
await Bun.sleep(750);
expect(existsSync(marker)).toBe(false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Wait past the fixture’s late-write deadline.

Line 165 sets the child deadline to 2,500 ms, and Line 170 writes the marker only after that deadline. If the producer resolves on the early result, the task can return before the child reaches Line 170. Lines 608-609 then wait only 750 ms, so the test can pass even though the child writes the marker later. Wait beyond the fixture deadline before asserting that the marker does not exist.

Suggested fix
-    await Bun.sleep(750);
+    await Bun.sleep(FAST_FABRIC_ISOLATION.totalTimeoutMs + 750);
     expect(existsSync(marker)).toBe(false);
📝 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
await Bun.sleep(750);
expect(existsSync(marker)).toBe(false);
await Bun.sleep(FAST_FABRIC_ISOLATION.totalTimeoutMs + 750);
expect(existsSync(marker)).toBe(false);
🤖 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/lab-fabric-task.test.ts` around lines 608 - 609, Increase the delay
before the marker assertion in the relevant test so it exceeds the fixture child
deadline and late-write timing defined by the test setup. Keep the existing
expect(existsSync(marker)).toBe(false) assertion unchanged, ensuring the test
observes whether the child writes after the producer resolves.

@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: 26c6856d73

ℹ️ 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 on lines 116 to 117
receivedResult = message.patch;
finish(() => resolve({ patch: message.patch, lastActivityAt }));
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Resolve trailing results from the close handler

When a child writes valid result JSON without a final newline and then exits, the close handler parses the buffered result, but this branch now only stores it; the subsequent if (receivedResult) return exits without calling finish. Because the child has already closed, the timers cannot trigger another close event, so the Lab run hangs indefinitely even beyond its total timeout. Resolve the buffered result after parsing it or route it through the common close decision.

AGENTS.md reference: src/AGENTS.md:L17-L17

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant