Fix remote session state after clear and skill activation - #876
Conversation
PR 1jehuang#876 added a new `active_skill: Option<String>` field to the `Request::Message` variant (crates/jcode-protocol/src/wire.rs) and updated every call site — except `src/cli/acp.rs:874`, which was missed and broke compilation with E0063: error[E0063]: missing field `active_skill` in initializer of `jcode_tui::protocol::Request` --> src/cli/acp.rs:874:20 874 | .send(&Request::Message { | ^^^^^^^^^^^^^^^^ missing `active_skill` The ACP (Agent Client Protocol) path has no skill concept, so `active_skill: None` is the correct value — matching what every other non-skill call site uses (client_api.rs, communicate_tests.rs, client_lifecycle_tests.rs, randomized.rs).
Greptile SummaryThis change propagates remote skill selections to the daemon and resets cleared remote sessions as new swarm roots. Testing reproduced a concurrency defect in Confidence Score: 4/5Not safe to merge until concurrent messages cannot overwrite each other's selected skill. The behavior was reproduced deterministically through the real message-processing and provider paths: the first queued request selected alpha, but both resulting turns used beta. Files Needing Attention:
What T-Rex did
|
| if !agent | ||
| .lock() | ||
| .await | ||
| .set_remote_active_skill(active_skill.clone()) |
There was a problem hiding this comment.
Shared active skill is overwritten between queued turns
active_skill is written to the session-wide Agent before the message task is spawned, while the task later reacquires that same agent lock to build and run the turn. Another client attached to the same session can submit a message with a different skill during that gap. In a deterministic two-request run, the first request selected skill-alpha, the second selected skill-beta, and both provider turns used beta. The first client can therefore receive a response generated with a different skill than it selected. Keep the selected skill request-scoped, or capture and apply it atomically inside the spawned turn before prompt construction.
Artifacts
Focused active-skill interleaving harness
- Review-authored Rust test source that holds the shared mutex, queues alpha then beta requests, releases it, and records the skills observed by both real provider turns.
Focused interleaving execution output
- Captured output from the executed Cargo test showing the observed values `[(false, true), (false, true)]` and exit code 0, confirming both turns used beta.
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-app-core/src/server/client_lifecycle.rs
Line: 2876-2879
Comment:
**Shared active skill is overwritten between queued turns**
`active_skill` is written to the session-wide `Agent` before the message task is spawned, while the task later reacquires that same agent lock to build and run the turn. Another client attached to the same session can submit a message with a different skill during that gap. In a deterministic two-request run, the first request selected `skill-alpha`, the second selected `skill-beta`, and both provider turns used beta. The first client can therefore receive a response generated with a different skill than it selected. Keep the selected skill request-scoped, or capture and apply it atomically inside the spawned turn before prompt construction.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.|
The Fix: add --- a/src/cli/acp.rs
+++ b/src/cli/acp.rs
@@ -875,6 +875,7 @@
.send(&Request::Message {
id: prompt_id,
content: text,
images,
system_reminder: None,
+ active_skill: None,
no_reply: false,
})The ACP (Agent Client Protocol) path has no skill concept, so I have a fix branch on my fork ( |
Summary
/clear, without restoring old plan participationVerification
cargo test -p jcode-app-core handle_clear_session_replaces_runtime_handles_and_updates_shutdown_registration --libcargo test -p jcode-protocol test_message_request_roundtrip_preserves_images_and_system_reminder --libcargo test -p jcode-tui remote_skill_invocation_with_prompt_sends_remote_turn --libcargo check -p jcode-protocol -p jcode-app-core -p jcode-tui --all-targetsFixes #874
Fixes #873
--- — Jcode agent (automated triage), on behalf of @1jehuang