Skip to content

fix(plugin-host): fence passive proposal outcomes before finish - #1235

Closed
i386 wants to merge 5 commits into
mainfrom
agent/proposal-lifecycle-fence
Closed

fix(plugin-host): fence passive proposal outcomes before finish#1235
i386 wants to merge 5 commits into
mainfrom
agent/proposal-lifecycle-fence

Conversation

@i386

@i386 i386 commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

The native serving plugin host dispatches proposal report/discard callbacks on a passive worker, while generation lifecycle callbacks run on the primary worker. A passive outcome could therefore still be pending when finish_generation ran, leaving Cacheline with an unresolved proposal and poisoning the next request.

This PR:

  • adds a reserved-capacity passive fence before finish_generation;
  • routes normal proposal reports/discards through terminal-reserved capacity;
  • retains generated-token tracking when finish fails so abort recovery remains possible;
  • adds a regression test proving a slow passive discard completes before finalization.

The proposal deadline path remains independent of passive callback latency.

Verification

  • cargo fmt --all -- --check
  • cargo test -p mesh-native-serving-plugin-host (25 passed)

This is intended to be cherry-picked into general-inference/mesh-llm-private main after the public PR lands.

Summary by CodeRabbit

  • Bug Fixes

    • Improved generation completion handling so tracked state is retained when finishing fails.
    • Ensured completion callbacks wait for pending reports and discard operations, preserving event order.
    • Improved reliability of proposal report and discard processing during generation completion.
    • Prevented expired proposals and late candidates from being dispatched.
  • Tests

    • Added regression coverage for completion ordering, passive operations, concurrent proposals, expired proposals, and saturated queues.
    • Enhanced test event tracking and callback synchronization for generation completion.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e52d5423-9e26-41cd-b328-8e31da20f335

📥 Commits

Reviewing files that changed from the base of the PR and between 6770bc7 and de10b1e.

📒 Files selected for processing (6)
  • crates/mesh-native-serving-plugin-host/Cargo.toml
  • crates/mesh-native-serving-plugin-host/src/plugin_dispatch.rs
  • crates/mesh-native-serving-plugin-host/src/plugin_dispatch/tests.rs
  • crates/mesh-native-serving-plugin-host/src/test_support.rs
  • crates/skippy-server/Cargo.toml
  • crates/skippy-server/src/frontend/linear_proposal.rs

📝 Walkthrough

Walkthrough

Native plugin finishing waits for queued passive work. Terminal reports and discards use reserved queue capacity. Failed native finishes retain generation state. Tests cover callback ordering, deadlines, and fence capacity.

Changes

Native finish ordering

Layer / File(s) Summary
Passive fence dispatch
crates/mesh-native-serving-plugin-host/src/plugin_dispatch.rs
Adds terminal Fence commands, reserved queue capacity, passive acknowledgements, and deadline checks before proposal callbacks.
Terminal command integration
crates/mesh-native-serving-plugin-host/src/lib.rs
Proposal reports and discards use terminal enqueueing. Committed-token state is removed only after successful native finishing.
Ordering validation
crates/mesh-native-serving-plugin-host/src/plugin_dispatch/tests.rs, crates/mesh-native-serving-plugin-host/src/test_support.rs, crates/mesh-native-serving-plugin-host/Cargo.toml, crates/skippy-server/Cargo.toml, crates/skippy-server/src/frontend/linear_proposal.rs
Adds gated callback support, ordering and deadline tests, queue-capacity coverage, and test-support receipt fixtures.

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

Sequence Diagram(s)

sequenceDiagram
  participant PluginDriver
  participant PassiveWorker
  participant NativePlugin
  PluginDriver->>PassiveWorker: enqueue report or discard
  PluginDriver->>PassiveWorker: enqueue terminal Fence
  PassiveWorker-->>PluginDriver: acknowledge Fence
  PluginDriver->>NativePlugin: invoke proposal callback
  PluginDriver->>NativePlugin: invoke finish_generation
Loading

Possibly related PRs

Suggested labels: blocker

Suggested reviewers: ndizazzo, michaelneale

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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 describes fencing passive proposal outcomes before finish generation, which is the main change.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/proposal-lifecycle-fence

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@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: 2

🤖 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 `@crates/mesh-native-serving-plugin-host/src/plugin_dispatch.rs`:
- Around line 318-335: Reserve one terminal queue slot exclusively for Fence:
update enqueue_terminal and the disposition enqueue path to allow Report/Discard
only up to the terminal capacity minus one, while the Fence path uses the full
PLUGIN_TERMINAL_RESERVE capacity. Preserve existing error handling and ensure
finish_after_passive_fence can enqueue its fence after dispositions fill their
reduced limit.

In `@crates/mesh-native-serving-plugin-host/src/plugin_dispatch/tests.rs`:
- Around line 267-272: The test currently bypasses the production dispatch path
by calling finish_after_passive_fence directly. Update the test around the
spawned finish thread to enqueue PluginCommand::Finish through PluginDriver,
then assert the fake plugin event log records "discard" before "finish",
exercising plugin_worker’s Finish handling.
🪄 Autofix

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: afa27334-95f0-4c59-9391-f44d937b0cfd

📥 Commits

Reviewing files that changed from the base of the PR and between bdd0beb and 5164df9.

📒 Files selected for processing (4)
  • crates/mesh-native-serving-plugin-host/src/lib.rs
  • crates/mesh-native-serving-plugin-host/src/plugin_dispatch.rs
  • crates/mesh-native-serving-plugin-host/src/plugin_dispatch/tests.rs
  • crates/mesh-native-serving-plugin-host/src/test_support.rs

Comment thread crates/mesh-native-serving-plugin-host/src/plugin_dispatch.rs
Comment thread crates/mesh-native-serving-plugin-host/src/plugin_dispatch/tests.rs
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Fixes Applied Successfully

Fixed 2 file(s) based on 2 unresolved review comments.

Files modified:

  • crates/mesh-native-serving-plugin-host/src/plugin_dispatch.rs
  • crates/mesh-native-serving-plugin-host/src/plugin_dispatch/tests.rs

Commit: 098254f373cd906cccb9a0f536dbb68b11c2c98a

The changes have been pushed to the agent/proposal-lifecycle-fence branch.

Time taken: 8m 41s

Fixed 2 file(s) based on 2 unresolved review comments.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
@coderabbitai coderabbitai Bot added the blocker blocking other PRs label Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocker blocking other PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant