Skip to content

test(app-server): settle context usage before comparing exports - #1937

Merged
zerob13 merged 2 commits into
mainfrom
dimagent/timeline-export-settle
Nov 20, 2026
Merged

zerob13 merged 2 commits into
mainfrom
dimagent/timeline-export-settle

Conversation

@zerob13

@zerob13 zerob13 commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

timeline_export::timeline_export_reads_a_live_product_home_and_its_copies no longer races the context usage write. Refs #1919.

The test waits for the child branch to be idle, copies the live database, then exports the copy and the live database and expects equal output. ContextUsage can still append a context-usage/recovered fact after the branch is idle. When that lands between the copy and the live export, the live export holds one more event (99 against 98) and the comparison fails. The test now reads session.context.usage on both branches before copying, which waits for that write.

This failed on the Linux verification trial (run 44684351971, verify (linux)), where the extra event was the child branch's context-usage/recovered at sequence 20. It is not Linux-specific: it reproduces on macOS under load.

Test-only; no product behaviour changes.

Design rule checklist

All plugin design rules are n/a: the change is one wait in an App Server flow test.

Documentation

  • No accepted ADR is modified or deleted.
  • No other module's design is changed.
  • Delivery status is not added to an ADR, index or roadmap.

No document describes this test's synchronisation.

Verification

On macOS, the single test run six at a time beside 20 CPU-bound processes:

Failed
Before 1 of 12 (the same extra context-usage/recovered event as on Linux)
After 0 of 60

Without load it passed 22 of 22 before the change, so the "after" figure is evidence, not proof, that the read closes the window. cargo fmt --all -- --check --config error_on_line_overflow=true passed.

The export flow copies the live database and then exports both. The
branch is idle by then, but ContextUsage may still append its
`context-usage/recovered` fact, so the live export can hold one event
the copy lacks. Reading `session.context.usage` on both branches first
waits for that write.

Seen on the Linux verification trial (run 44684351971); reproduced
locally 1 of 12 under CPU load, 0 of 60 with the read.

Refs #1919

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review at 6b5e6ae6 (origin/main 499d5906).

The PR adds a synchronization point to timeline_export_reads_a_live_product_home_and_its_copies. After the child branch is idle, the test reads session.context.usage on main and the child before copying the live database, so the backup and the live export are compared after ContextUsage has settled its pending context-usage/recovered write. The change is seven test lines; no product code or contract changes.

Verdict: APPROVE.

session.context.usage reaches ContextPreparation::usage (crates/dim-agent-capabilities/src/context_preparation.rs:870-876) and ContextUsage::read(None) (crates/dim-agent-capabilities/src/context_usage.rs:984-996), which waits for covered >= through; with this test's ready configuration and no history recount, the wait condition also requires saved_through >= relevant_through (:1145-1154). advance consumes the branch's sources and saves them (crates/dim-agent-capabilities/src/context_usage/sources.rs:681-731), and save appends the context-usage/recovered batch and awaits its publication before setting saved_through (crates/dim-agent-capabilities/src/context_usage.rs:1206-1245). The two reads are therefore barriers for the pending writes on their branches. The referenced trial run 44684351971 at 88a9777f failed verify (linux) in Run compiled workspace tests; the failing test was timeline_export::timeline_export_reads_a_live_product_home_and_its_copies at the export equality assertion (timeline_export.rs:404, now :411). The test passes at this head.

Optional P3: the test now depends on a synchronization behavior that the contract does not state.

Problem. The new reads are a barrier, but the public description says session.context.usage writes nothing and does not promise that it waits for a pending save (docs/design/plugins/ContextCompaction.md:56,982; crates/dim-agent-capabilities/src/context_preparation.rs:870). The implementation does wait today.

Failure scenario. A future change makes the query return the in-memory estimate without waiting for saved_through, or a maintainer removes the two reads as unused. The original race returns, and the failure appears only under load, which is hard to attribute to this test.

Evidence. crates/dim-agent-capabilities/src/context_usage.rs:984-996,1145-1154,1206-1245; crates/dim-agent-capabilities/src/context_usage/sources.rs:681-731.

Fix. Add a short comment at the loop explaining that the reads wait for the usage owner to save its pending result, or state the settlement guarantee in the contract. This is not blocking.

Verification:

  • git diff --check origin/main...HEAD: clean.
  • git merge-tree --write-tree HEAD origin/main: clean (1f6ea13e).
  • cargo fmt --all -- --check --config error_on_line_overflow=true: passed.
  • node scripts/adr-check.mjs --base origin/main: passed (1 changed file).
  • cargo test --locked -p dim-app-server --test transport_flow timeline_export::timeline_export_reads_a_live_product_home_and_its_copies -- --exact: 1 passed, 682 filtered out, finished in 5.93s.
  • CI at 6b5e6ae6: changes and dependencies pass; verify is queued; web, windows-cli and acp-registry skip.
  • I did not rerun the 60-run load experiment. The PR reports 0 of 60 failures with the read and 1 of 12 without it.

No existing reviews or inline threads; no inline comments.

Verdict: APPROVE.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at head 6b5e6ae.

The fix is the right kind of wait: it reads session.context.usage on the root and the child branch before copying, so whatever the owner still owes — here the child's context-usage/recovered fact — has been written by the time the copy is taken and the live export cannot hold one more event than the copy. Waiting on the owner's own read instead of sleeping, polling a file or widening the comparison is what makes this a fix rather than a slower test, and the comment on the failure (extra event at sequence 20, reproduces under load on macOS too) is the evidence that it was a race and not a platform bug.

It is also correctly a one-file test change: nothing in the product is adjusted to make a test observation easier.

verify and ci-ok failed on this head, at the architecture check and before any test ran:

web/src/chat-ui/WebChatTimeline.vue:34: `"main"` names neither the root nor the default branch;
  write `ROOT_BRANCH_ID` or `DEFAULT_BRANCH_ID`, or name the use in `UNRELATED`
web/src/chat-ui/WebChatTimeline.vue:328: same

That file is main's, not this PR's, and the hit at 34 is variant?: "main" | "panel" — a render variant. It is the same repository-wide red I described on #1920 and #1881; main has had no green run since 574861f3. Renaming the variant ("inline" / "panel") is the smallest fix and needs no UNRELATED entry. Note the irony worth stating: this PR exists because verify went red on a flaky test, and it cannot go green for a different, global reason.

Not approving while a required check is red.

Non-blocking: none.

@codoggy codoggy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary

I reviewed the merge-base diff for 49a5a9553c89cda117331c19a0f3c8088c8603ad, focusing on whether the export test can take its SQLite backup before the child’s usage record is published. I found no blocking issues in that scope.

Checks: Static inspection: timeline_export.rs:400–411 waits for a successful session.context.usage read on both the root and child before taking the backup, and still compares the complete live and backup exports. Unlike waiting for the turn to go idle, the usage read waits for the branch boundary; the usage worker waits for the recovered record’s publication before marking it saved (context_usage.rs:989–996,1238–1244). No production code changed. CI: changes and dependencies passed; verify had not reported a result when checked. Tests not run locally.

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.

4 participants