Skip to content

test(runtime): fix the stale orchestration context timestamp before the sync reads the clock - #35516

Merged
nwparker merged 1 commit into
mainfrom
nwparker/orchestration-stale-context-flake
Oct 29, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/orchestration-stale-context-flake

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

A test checks that an old, finished task is not shown as current. It made its "old" timestamp a moment too late, so on a busy machine the task looked fresh and the test failed. The test now makes the timestamp up front, before the code under test reads the clock.

What Changed

  • Before: "does not return stale completed orchestration context for renderer-synced terminal leaves" sometimes failed under load with expected { …(1) } to be undefined. It failed shard 5/5 on fix(wsl): session history reads never boot a stopped WSL distro (E9) #35367, which is unrelated, and fails on main locally in 1 of 6 runs under CPU load.
  • After: the test passes 8 of 8 times under the same load. It also passes with a 5 ms delay injected into the mock.

How it broke: the mock built completed_at (now − window − 1 ms) at the moment the code under test called it. The code captures its own now earlier, when the sync starts. If 1 ms or more passed between the two, the row was at most exactly the window old. The code counts that as recent.

The fix computes the timestamp once, before the sync. The product code is unchanged.

Why

Fixing the timestamp before the clock read removes the race completely.

  • A larger margin, such as one minute, would only make the race less likely.
  • Fake timers would add global clock state for a single value.

To confirm the cause: with a temporary 5 ms busy-wait inside the mock, the old test fails every run and the new one passes every run.

Linked Issue

N/A (internal flake; failing run 40788108475).

Visual Proof

N/A: test-only change, no UI or behavior change.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Results (macOS):

  • pnpm test src/main/runtime/orca-runtime.test.ts: 1499 passed, 3 skipped.
  • The single test 8 times under 8 CPU-bound processes: 8/8 pass. The same loop on main: 1/6 fail.
  • Also passed: pnpm tc, pnpm run typecheck:ci, pnpm run check:code-quality:changed, the anti-slop oxlint, and ast-grep.

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Test-only change; no security, platform, SSH, mobile, compatibility, or performance impact.

Flag-off: test-only change; no runtime behavior.
User-risk: none; no product code changes.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…he sync reads the clock

The mock built completed_at when the projection called it, after the
projection captured now. With 1 ms or more between the two, the
"stale" row was within the freshness window and the test failed under
load.
@nwparker

Copy link
Copy Markdown
Contributor Author

STATUS: ready for review at ea65cbc. Test-only flake fix. Reproduced on main under load (1/6 fail); with the fix, 8/8 pass under load and the whole orca-runtime.test.ts file passes.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] This test-only change appears safe to merge.

Summary

Fixes a flaky test by computing staleCompletedAt before syncWindowGraph reads the clock.

  • The stale-dispatch test sets its completion time before the sync starts.

Reviews (1) · Last reviewed commit: "test(runtime): fix the stale orchestrati..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cb1d27b1-d2e9-49fa-b20c-fa8394735871
Commits

Reviewing files that changed from the base of the PR and between 7827925 and ea65cbc.

Files selected for processing: 1
  • src/main/runtime/orca-runtime-tests/lineage-and-scan-cache-part-06.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Walkthrough

The stale-completed-dispatch test now computes its completion timestamp before synchronization and reuses it in the mocked dispatch. The test still checks that the renderer-synced terminal leaf has no orchestration context.

Priority: Low

Merge Risk: Minimal · up to ea65c

This test-only fix removes the timing flake without introducing production behavior changes.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly identifies the test-only fix: computing the stale orchestration timestamp before synchronization reads the clock.
Description check Passed The description is complete and explains the race, the test change, the rationale, validation results, scope, and checklist status. It marks the linked issue as N/A for an internal test flake, which i…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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.
Full details: Description check

Explanation

The description is complete and explains the race, the test change, the rationale, validation results, scope, and checklist status. It marks the linked issue as N/A for an internal test flake, which is consistent with the stated context.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@nwparker
nwparker merged commit b117789 into main Oct 29, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant