Skip to content

test(core): drive session wall time and deadlines from one clock - #521

Merged
lg2m merged 3 commits into
mainfrom
test/injected-clock
Nov 1, 2026
Merged

lg2m merged 3 commits into
mainfrom
test/injected-clock

Conversation

@lg2m

@lg2m lg2m commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Change

Test-only. Session wall time and run deadlines now follow one clock under test.

  • Under #[cfg(test)], now_ms() derives wall time from tokio's Instant plus a fixed base. tokio::time::advance now moves the calendar, the goal deadlines and the run deadlines together. The production now_ms() is still SystemTime::now(). There is no new public API and no SessionRuntimeOptions field.
  • The store thread enters the test's runtime handle so it reads the same clock. On a current-thread (paused) runtime, each store job holds a spawn_blocking placeholder until it settles. This keeps tokio from auto-advancing paused time while the real store thread commits. Every cfg(test) addition is in store.rs and store/worker.rs.
  • goal_driver_soak::Epoch is gone. The few tests that need a calendar held still while monotonic time moves now use PinnedCalendar in sessions/tests.rs: the multi-day soak child process, the goal-check and audit calendar-expiry tests, and the wall_clock_lags row.
  • Removed every Epoch + advance pairing (approvals ~1910, ~2549, ~2583; goal_admission twenty-minute wait).
  • Removed the keep-clock busy loops: deadlines ~228 and ~899, and goal_admission.rs:38 (D20).
  • D10: six deadlines tests that waited out real 0.3–1.5 s budgets now run with start_paused.
  • duration_expires_during_shell_execution… used to poll for the shell's marker file in a yield loop on the runtime thread. It now waits in a bounded spawn_blocking task, which also keeps paused time from auto-advancing during the wait.
  • a_childs_timed_out_hold_pauses_the_goal… (fix(core): pause the goal when a held approval times out after its expired owner cancelled the run #515) failed 30/100 under load. The cause was not the clock: the scheduler claimed the child run on the depth-1 pool before the test could. The test now holds child_permits[0] too.
  • xtask/src/legacy-sleeps.txt: line numbers moved, entries otherwise unchanged (11/11 sleeps).

Verification

Stress: 100 iterations per test, pinned to one core with three busy loops (findings A1 recipe), via cargo nextest run --archive-file … --stress-count 100.

Test Before After
deadlines::duration_expires_during_shell_execution_and_drains_before_session_reuse 100/100 100/100 (on HEAD)
deadlines::duration_cancels_read_only_and_mutating_external_calls 100/100 100/100
deadlines::duration_waits_for_blocking_attachment_guidance_and_skill_cleanup 100/100 100/100
deadlines::duration_withdraws_pending_approval…, …does_not_restart_for_output_repair, completed_compaction…, …cancels_context_preparation…, …cancels_automatic_compaction… not run 100/100 each
approvals::goal_approval_timeout_reopens_and_resumes_once… 100/100 100/100
approvals::goal_parent_deadline_preserves_a_sponsored_childs_unanswered_approval 100/100 100/100
approvals::a_childs_timed_out_hold_pauses_the_goal_after_its_expired_owner_cancelled_it 70/100 100/100
goal_admission::loading_exhaustion_without_work_blocks_after_three_attempts 100/100 100/100
goal_admission::twenty_minute_permit_wait_reclamps_unbounded_prompts_and_goal_runs 100/100 100/100
goal_check::goal_check_calendar_expiry_during_policy_wait… 100/100 100/100
goal_model_audit::goal_model_audit_late_and_stale_confirmation_cannot_achieve 100/100 100/100

On this host the two-clock tests did not reproduce a flake before the change. Their gain is that they no longer depend on scheduling: there are no busy loops and no clock pairing.

Times, warm local runs, cargo nextest run -p qq-core:

Test Before After
completed_compaction_does_not_restart_the_original_duration 1.67 s 0.22 s
duration_cancels_automatic_compaction_and_settles_the_original_prompt 1.18 s 0.21 s
duration_withdraws_pending_approval_without_executing_the_tool 0.54 s 0.04 s
duration_does_not_restart_for_output_repair 0.54 s 0.04 s
duration_cancels_context_preparation_before_any_provider_request 0.34 s 0.04 s
goal_admission twenty_minute_permit_wait… 0.07 s 0.15 s

Whole qq-core suite: 21.0 s before, 20.5 s after.

  • cargo xtask check: passed (fmt, lint, clippy, nextest over qq, qq-client, qq-core, qq-host, qq-server, qq-tui, xtask).
  • I briefly turned the store-job hold off: 8 paused tests failed or hung. The hold is load-bearing.

Known impact

None for users. Two tests stay on real time:

  • duration_waits_for_blocking_attachment_guidance_and_skill_cleanup (2.4 s). It asserts that nothing finishes within 750 ms while a blocking task is held, which is an A6-style negative wait.
  • duration_stops_shell_while_output_persistence_is_blocked (1.0 s). It runs a real shell.

duration_cancels_read_only_and_mutating_external_calls keeps a short pause/advance/resume window. Its mutating case takes an undo snapshot with real git, which cannot run under start_paused. Neither file pairs the two clocks any more. No tests deleted.

lg2m added 2 commits October 31, 2026 21:42
Under test, now_ms() derives wall time from tokio's Instant, so tokio::time::advance moves both clocks. Store jobs hold paused auto-advance while the store thread works. Tests drop the Epoch/advance pairing and keep-clock busy loops; the real-duration deadlines tests use paused time.
@lg2m lg2m added the ci:full label Nov 1, 2026
@lg2m

lg2m commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T06:59:50.668333Z bbb3265 Manual request
ℹ️ 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" 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.

@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: 1d89021f54

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

@lg2m

lg2m commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: bbb326598d

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

@lg2m
lg2m merged commit 3c22b86 into main Nov 1, 2026
10 checks passed
@lg2m
lg2m deleted the test/injected-clock branch November 1, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant