Skip to content

fix: harden adaptive replay evidence - #2

Closed
hhh2210 wants to merge 2 commits into
adaptive-replay-harnessfrom
codex/adaptive-replay-proof-fixes
Closed

fix: harden adaptive replay evidence#2
hhh2210 wants to merge 2 commits into
adaptive-replay-harnessfrom
codex/adaptive-replay-proof-fixes

Conversation

@hhh2210

@hhh2210 hhh2210 commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • Split legacy traces at deadline-overrun gaps so replay does not synthesize timer ticks across long unobserved spans.
  • Separate counterfactual replay advances from recorded live schedule events. The live audit now checks payloads, menu linkage, accepted-event multiplicity, ambiguous legacy comparisons, and a full-precision schedule lead.
  • Add an offline activity-cap candidate with causal signal reconstruction, active-delay compliance metrics, and focused regression coverage.
  • Update the existing adaptive refresh decision record with the bounded local result and its limitations.
  • Isolate the Claude keychain ownership test from both real keychain reader paths so the full test shard is deterministic.

Scope and non-goals

This PR targets the fork's adaptive-replay-harness branch. It does not change the production AdaptiveRefreshPolicy, make Adaptive the default, or feed coding activity into the running app's policy. The activity candidate exists only in offline replay.

The raw trace stays local. The PR contains aggregate results, the trace record count, and its SHA-256, but no transcript content, paths, project names, or account data.

Replay evidence

Frozen input: 1,780 records, SHA-256 b1e4aa33180b7c177293eb9ed16b45e24e026d259600fba2b1b67b931b904f0b.

The legacy heuristic produced 28 observed segments and excluded 26.10 hours after recorded timer deadlines. That excluded time is only "unobserved"; the heuristic cannot distinguish sleep or reboot from a long refresh or event-loop stall.

Policy Simulated refreshes Per observed 24h Simulated advances Unconstrained active over 5m Menu staleness p50 / p95
Current adaptive 694 143.47 53 4 / 145 142s / 1093s
Activity-cap candidate 696 143.88 53 0 / 145 139s / 1093s
Fixed 5m 1383 285.90 0 0 / 99 150s / 281s

On this snapshot, current adaptive schedules 49.8% fewer batches than fixed 5m. The candidate adds two simulated refreshes and removes four active-delay violations. It does not improve p95 menu staleness.

The frozen trace predates timerAdvanceEvaluated: it contains 46 legacy timerAdvanced events and zero evaluation records, so it cannot validate accepted/rejected live comparisons. Simulated advances are counterfactual and are not compared by count with recorded advances.

After packaging commit 105a9f16, the live trace recorded two schedule evaluations: one accepted and one rejected. The recorded-schedule audit reported zero payload, decision, menu-link, multiplicity, or ambiguity errors. The accepted evaluation had one matching timerAdvanced; the rejected evaluation had none.

Privacy and runtime boundary

  • Trace recording remains off by default and local-only.
  • Coding activity is stat-only metadata. The recorder does not read transcript contents or store file paths.
  • Existing trace fields remain optional so legacy JSONL lines still decode.
  • The production refresh policy and provider execution paths are unchanged.

Validation

  • make check
  • DYLD_FRAMEWORK_PATH="$PWD/.build/out/Products/Debug" OS_ACTIVITY_MODE=disable make test (553 selections, 47/47 groups)
  • DYLD_FRAMEWORK_PATH="$PWD/.build/out/Products/Debug" swift test --filter 'RecordedScheduleAuditTests|CodingActivityReplayPolicyTests|ReplayTraceSegmentationTests|AdaptiveRefreshTraceRecordingTests|AdaptiveReplayEngineTests' (36 tests in 5 suites)
  • swift build --product AdaptiveReplayCLI
  • ./Scripts/package_app.sh debug
  • codesign --verify --deep --strict CodexBar.app
  • Packaged CodexGitCommit=105a9f16; installed process stayed running and CodexBarCLI config validate returned Config: OK
  • Exact-head live recorded-schedule audit: 2 evaluations, 1 accepted, 0 mismatches, 0 ambiguous comparisons

Limitations

  • The aggregate result is from one machine and one local trace.
  • Legacy gap segmentation is a deadline-based heuristic, not lifecycle telemetry.
  • Replay uses a zero-service-time policy clock; real provider refresh duration still affects the live schedule.
  • The candidate changes few decisions and leaves p95 unchanged. This evidence does not support a production or default-policy change.

Related

Follow-up to steipete/CodexBar#1861. Updates the decision record introduced in steipete/CodexBar#1739.

Copilot AI review requested due to automatic review settings July 10, 2026 05:07

Copilot AI 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.

Pull request overview

This PR hardens the fork-only adaptive replay harness by (1) segmenting legacy traces to avoid synthesizing timer ticks across long unobserved gaps, (2) auditing recorded live schedule evaluations separately from counterfactual replay advances, and (3) adding an offline “coding activity cap” candidate plus metrics/tests to support evidence gathering without changing production policy behavior.

Changes:

  • Add legacy gap segmentation and a segmented replay path that reports excluded wall time and segment counts.
  • Introduce timerAdvanceEvaluated trace records + RecordedScheduleAuditor to validate live schedule comparisons (payload, menu linkage, multiplicity, ambiguity, sub-second lead).
  • Add coding-activity signal plumbed into replay input/metrics and a fork-only CodingActivityAdaptivePolicy, with focused regression tests and updated docs/CLI output.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Tests/CodexBarTests/ReplayTraceSegmentationTests.swift Adds regression coverage for gap segmentation behavior and segmented rate math.
Tests/CodexBarTests/RecordedScheduleAuditTests.swift Adds coverage for live schedule audit rules (legacy vs evaluated, linkage, multiplicity, fractional lead).
Tests/CodexBarTests/CodingActivityReplayPolicyTests.swift Adds replay-only coverage for the activity-cap policy and compliance counters.
Tests/CodexBarTests/ClaudeOAuthCredentialsStoreCLIStorageOwnershipTests.swift Updates test overrides to isolate Claude keychain ownership deterministically.
Tests/CodexBarTests/AdaptiveRefreshTraceRecordingTests.swift Updates app-side trace recording expectations to include evaluations + accepted-only advances.
Sources/CodexBar/UsageStore.swift Records every schedule evaluation and only records timerAdvanced when accepted.
Sources/CodexBar/AdaptiveRefreshTraceRecording.swift Adds recordTimerAdvanceEvaluation(...) writer entrypoint.
Sources/AdaptiveReplayKit/ReplayTraceSegmentation.swift Implements deadline-overrun gap segmentation + segmented replay aggregation.
Sources/AdaptiveReplayKit/ReplayPolicy.swift Extends replay inputs with lastCodingActivityAt and derives activity age.
Sources/AdaptiveReplayKit/ReplayMetrics.swift Adds activity compliance and segmentation-related metrics + staleness helper init.
Sources/AdaptiveReplayKit/ReplayEngine.swift Adds activity signal reconstruction, compliance counting, and staleness sample plumbing.
Sources/AdaptiveReplayKit/RecordedScheduleAudit.swift Adds the standalone recorded-schedule audit and mismatch accounting.
Sources/AdaptiveReplayKit/README.md Documents segmentation, evaluation vs advances, and recorded-schedule auditing.
Sources/AdaptiveReplayKit/CandidatePolicies.swift Adds the fork-only coding-activity capped adaptive candidate.
Sources/AdaptiveReplayKit/AdaptiveRefreshTrace.swift Extends trace schema with timerAdvanceEvaluated and lead/acceptance metadata.
Sources/AdaptiveReplayCLI/main.swift Adds CLI segmentation controls, activity/comparison reporting, and audit output.
docs/predictive-refresh-policy.md Updates decision record status and appends local replay evidence/limitations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +67 to +69
if let last = currentRecords.last {
segments.append(ReplayTraceSegment(records: currentRecords, start: currentStart, end: last.timestamp))
}
Comment on lines +5 to +7
public struct CodingActivityAdaptivePolicy: ReplayPolicy, Sendable {
public let name = "adaptive-activity-cap"
public let advancesOnInteraction = true
Comment on lines +241 to 244
private static func lastActivity(_ samples: [ActivityObservation], at time: Date) -> Date? {
guard let index = self.lastIndex(samples.map(\.timestamp), atOrBefore: time) else { return nil }
return samples[index].lastCodingActivityAt
}
@hhh2210

hhh2210 commented Jul 10, 2026

Copy link
Copy Markdown
Owner Author

Superseded by the upstream Draft RFC: steipete#2029. Closing this fork-internal PR.

@hhh2210 hhh2210 closed this Jul 10, 2026
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.

2 participants