Skip to content

feat(environment): time browser scenario records so scenario environments learn a write clock - #6967

Merged
morluto merged 8 commits into
morluto:mainfrom
earakely-scale:feat/scenario-request-timing
Oct 24, 2026
Merged

morluto merged 8 commits into
morluto:mainfrom
earakely-scale:feat/scenario-request-timing

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Browser scenario captures record no request times, so every record a scenario projects is untimed. The
environment-state view then reads a scenario in record order and learns no write clock. Any update whose response
carries a modification time the application sets is withheld as unexplained-change, however carefully it is recorded,
while a HAR of the same session serves it with a clock rule. This was the main gap left in building environments from a
prompt (#6946), where the agent records with a browser scenario: Linkding's and Homebox's edits never served.

This PR records the times and uses them:

  1. Scenario network events carry times:
    • request events get observed_at, when REA observed the request;
    • request-finished and request-failed events get the browser's own started_at and elapsed_ms, which
      Playwright reports once a request ends.
  2. Scenario records are timed as HAR entries are: the browser's start (falling back to observed_at) and its
    duration. A timed scenario gets the recorded-start-time timeline and a write clock.
  3. Comparisons ignore the times: a committed built-in rule, ignore_network_request_timing.

On the same recordings built with and without their times, prompt-recorded Linkding serves 4 writes instead of 1, and
Homebox 3 instead of 2. The Linkding bundle with timed records passes all three of the application's write tasks with
both eval models; the earlier prompt-built Linkding bundles passed none. No capture serves fewer writes with times, and
captures made before this change read exactly as before.

Part of #4933 (agent-environment projection, serving and export).

Problem and expected behavior

  • A scenario capture should time its records as a HAR does, so the state can order and overlap them and learn the clock
    an application's modification times follow.
  • Captures recorded before the change must keep parsing and projecting identically.
  • Scenario comparisons must not report a change because two runs took different times.

Change and scope

  • Events (src/domain/browserScenarioCaptureValues.ts, src/browser/network/PlaywrightScenarioNetwork.ts):
    • optional observed_at on request events;
    • optional started_at and elapsed_ms on request-finished and request-failed events, from Playwright's
      request.timing() (startTime > 0, responseEnd >= 0);
    • the strings are charged to the event budgets like other metadata.
  • Records (src/domain/analysisView/scenarioCaptureRecords.ts):
    • startedDateTime comes from the transaction's single finished or failed started_at, else from observed_at;
    • time comes from its elapsed_ms, or 0 without one;
    • a limitation names the sources.
    • A capture with any untimed request keeps record order, as a HAR with an untimed entry does.
  • Comparison (src/domain/browserScenarioNetworkComparison.ts, browserScenarioDiffValues.ts):
    • the three fields are dropped before fingerprinting;
    • the new built-in rule joins the normalization commitment, so normalization digests differ from earlier
      comparisons (documented, as the storage rule's change was).
  • Docs and spec: the scenario contract's network evidence and comparison sections, the environment docs'
    browser-scenario section, and docs/specs/agent-environments/scenario-timing/.

Not included:

  • re-timing older captures;
  • changes to HAR captures or to how the state uses times;

Contract and boundary impact

  • Semantic owner and earliest changed stage: browser scenario capture events (src/browser/network), scenario
    records for the environment views (src/domain/analysisView), and scenario comparison (src/domain).
  • Contribution scope fit and linked maintainer decision: within the existing scenario-capture and environment
    boundaries. It observes timing the browser already reports; no new target interaction.
  • CLI and MCP/tool-catalog contract:
    • capture_browser_scenario output events gain three optional fields;
    • compare_web_captures gains one built-in normalization rule, so built_in_rules now lists 11.
  • Provider, bridge, target-format, or platform compatibility: Playwright launch and connect.
  • Evidence, artifact, provenance, or reconstruction contract:
    • New scenario Evidence carries the fields. REA versions before this change refuse it, because the event schemas are
      strict; consumers pinned to an older rea-agents cannot read scenario captures made with this one.
    • Earlier Evidence parses and projects byte-identically.
  • Target selection, authority, upstream behavior, and cleanup details: unchanged.
  • Generated metadata, package, or installation impact: output schema additions and packaged skill version 49.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

The same capture with and without its times. Each capture was recorded with this branch, then built as recorded and
with its times removed (the Evidence sealed again as the provider seals it):

Capture Records Writes served without / with times
Linkding, agent-recorded from a prompt 60 1 / 4
Linkding, agent-recorded from a prompt (again) 65 3 / 3
Homebox, agent-recorded from a prompt 263 2 / 3
Homebox, agent-recorded from a prompt (again) 275 2 / 2
Pinry, its published scenario re-recorded 568 0 / 0 (1 clock rule learned)
PhotoPrism, its published scenario re-recorded 273 2 / 2 (2 clock rules learned)
  • What times unlock: Linkding's bookmark and bundle edits and Homebox's tag edit are served only with times, because
    their responses carry server-set modification times. PhotoPrism's served album create now stamps CreatedAt and
    UpdatedAt from the clock instead of replaying the recorded values.
  • When they don't help: the second Linkding and Homebox recordings gain nothing, because their gaps are elsewhere
    (unconfirmed, contradicted).
  • How the prompt-recorded captures were made: with a local, unpushed build of this branch merged with feat(environment): build agent environments from a prompt #6946, for its
    request action. Claude Code recorded each app from a one-paragraph prompt on Ubuntu VMs (snap Chromium 155).
  • Write evals:
    • The timed Linkding bundle passes all 3 write tasks with fireworks_ai/gpt-oss-120b and
      fireworks_ai/glm-5p3-flash. Counts are relative to its own state, which holds active and archived bookmarks as
      two types.
    • Homebox passes 2/2 with gpt-oss and 1/2 with GLM (GLM deleted the wrong item).

Stale environments, not republished. Pinry and PhotoPrism are the oldest published environments recorded as
scenarios (0.1.0, replay only). I re-recorded both with this branch and rebuilt them with the publishing pipeline:

App Published 0.1.0 Rebuilt
Pinry 12 tools, replay, retrieval 6/6 and 6/6 12 tools, state and clock, no writes served; retrieval 6/6 and 4/6
PhotoPrism 13 tools, replay, retrieval 10/10 and 10/10 14 tools, state and clock, album create and rename served; retrieval 8/10 and 5/10
  • Neither improves, so I did not update them on Hugging Face.
  • The drops are not from timing: timed and untimed states are identical in every view those tasks read.
  • PhotoPrism: its album list is answered from the state in name order, while the recorded answer that generated the
    task listed another album first. That is a list-order gap in state serving, worth its own issue.
  • Pinry: GLM's two misses are tool calls rejected for numeric limit/offset, under the same tool schemas as the
    published version.

Review. An independent review rebuilt the branch and tried to refute it.

  • Confirmed:

    • views byte-identical for the three published scenario captures on main and this branch;
    • comparisons alike with and without times, including against an untimed capture;
    • each duration taken only from its own transaction;
    • both fields charged to the budgets.
  • Fixed:

    • Records now start at the browser's own start. The provider's observation trailed it by up to 36 ms while other
      responses were read, and mixed two clocks in one interval.
    • Docs now give the fallback's lag, the older-reader refusal and the digest change.
    • Tests now cover the fallbacks, partly untimed captures and comparisons with untimed captures.
  • Tests added:

    • the collector stamps observed_at, started_at and elapsed_ms, and omits what the browser does not report;
    • records prefer the browser's start and fall back for a request that never ended or ended twice;
    • a timed scenario of the book session learns the same clock and verdicts as its HAR, while an untimed or partly
      untimed one keeps record order;
    • comparisons ignore the times, including against an untimed capture;
    • the real-Chrome network lane asserts every request and finished request is timed.
  • User-visible CLI/MCP output: from a real Chrome capture with this branch (a page that PATCHes /api/items/1),
    the transaction's request and completion events now carry:

    {"kind":"request","transaction_id":"request-2","method":"PATCH","observed_at":"2026-10-24T12:19:32.578Z"}
    {"kind":"request-finished","transaction_id":"request-2","started_at":"2026-10-24T12:19:32.576Z","elapsed_ms":0.981}

    Its scenario record takes startedDateTime: "2026-10-24T12:19:32.576Z" and time: 0.981, and a comparison lists
    ignore_network_request_timing among normalization.built_in_rules.

  • Remaining proof gaps:

    • a request that never ends has no browser start, so its record starts at the provider's observation, with no
      duration;
    • captures from before this change stay untimed until re-recorded.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

Current integration: 374436f, macOS with pinned Node v24.22.1.

  • npm run check: passed, including build, typecheck, format, lint, module boundaries, and architecture guards.
  • Timing, comparison, scenario-record, skill-publication, and verifier-ownership workflows: 7 files, 90 tests passed. This includes all three packaged-verifier tests that failed in the earlier CI run.
  • Coverage and actual MCP schema/client workflows: 3 files, 23 tests passed.
  • npm run docs:check: passed, including 9 documentation tests.
  • npm run verify:browser:network in real Chrome: 10 timed requests, 9 timed completions, CLI and MCP paths verified, no remaining owned descendants. Connected-browser verification remains outside this local lane.

Merged current main to inherit the shared command-ownership and source-loader fixes. The environment skill and coverage wording now distinguish fully timed scenarios from older or partly untimed captures; the packaged skill version is 49.

The earlier application recordings and model evaluations are documented above and in the verification document; they were not rerun during this integration. Hosted CI passed at 374436f, including all eight test shards, real-browser, agentenv, the native package baseline, and the required CI gate.

Compatibility, safety, and release

  • Breaking changes or migration steps: none for callers. Older REA versions refuse new scenario captures, so a
    consumer reading scenario Evidence needs this version or later.
  • Real Hopper/Ghidra, browser, or OS coverage: real Chrome on macOS; snap Chromium 155 on Ubuntu 24.04.
  • Package or release metadata impact: packaged skill version 49 for the updated timing guidance.
  • Security, privacy, process, or containment review: the new fields are times only; no values from the page.

Author readiness

Human owner: @earakely-scale

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code

earakely-scale and others added 6 commits October 23, 2026 23:12
…ng they took

Request events carry observed_at, the wall-clock time the provider observed
the request start, and finished or failed events carry the browser's
elapsed_ms when it reports one. Both are optional, so earlier captures still
parse, and scenario comparisons leave them out as a committed built-in rule.
The real-Chrome network lane checks every request and finished response is
timed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s a write clock

Scenario records take startedDateTime from when each request was observed and
time from the browser's duration, as HAR entries are timed. A timed scenario
of the book session learns the same clock and serves the same writes as its
HAR; an untimed one keeps record order and learns no clock, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… records

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… start

The provider observes a request up to tens of milliseconds after the browser
starts it while it reads other responses, so a record starting then and
ending after the browser's duration mixed two clocks. Finished and failed
events now carry the browser's started_at, records prefer it and fall back to
observed_at, and comparisons drop it too. Tests cover the fallback for a
request that never ended or ended twice, a partly untimed capture keeping
record order, comparing an untimed capture with a timed one, and the
real-Chrome lane checks every finished request carries the browser's start
and duration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and older readers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Gates, the real-Chrome lane, prompt-recorded and re-recorded published
scenario captures built with and without their times, the stale published
environments left unrepublished, and the review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale marked this pull request as ready for review October 24, 2026 12:12
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 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 🔄 Running since 2026-10-24T14:05:16.143093Z 374436f New commits
ℹ️ 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.

@greptile-apps

greptile-apps Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The PR appears safe to merge, with no new blocking issue found.

Summary

Browser scenarios now record request times and use them to build timed environment records.

  • New scenario captures give environment records browser-based request times.
  • Scenario comparisons leave request times out of network fingerprints.

No new actionable correctness, security, or repository-rule issue was established. earakely-scale documents and accepts the fallback for unfinished requests because the browser has not reported their start or duration.

Review was source-only; tests were not run. Whether another PR supersedes this one could not be checked because GitHub authentication was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Browser request events] --> B[Capture request times]
  B --> C[Scenario Evidence]
  C --> D[Project transaction records]
  D --> E[Use browser start or observed start]
  E --> F[Environment timeline and write clock]
  C --> G[Remove request timing fields]
  G --> H[Compare transaction fingerprints]
Loading

Reviews (3) · Last reviewed commit: "fix(environment): integrate scenario tim..." · Reviewed by Greptile

Comment thread src/domain/browserScenarioDiff.test.ts Resolved
…mparison test

The comparison test's captures had no finished or failed events, so dropping
started_at and elapsed_ms from them went untested. The captures now end one
request and fail the other, the test asserts both carry times, compares them
shifted by seven seconds and against an untimed capture, and a control shows
a changed failure on a timed completion is still reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale

earakely-scale commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Review round at ae275203:

  • Greptile (completion times untested): fixed in ae275203. The comparison test now has a finished and a failed request carrying started_at and elapsed_ms. It compares captures whose three times all differ, compares an untimed capture with a timed one, and has a control that a changed failure on a timed completion is still reported. Greptile re-reviewed at 5/5 with no findings.

  • CI: at ae275203 the failures (test shard 1's packagedWasmVerifierOwnership tests and the agentenv lane's lingering verifier) were shared with main. After morluto's merge of main (374436ff), every check passes, including all eight shards, real-browser and agentenv.

  • Readiness: the owner and declarations are filled; [Design] Project captures into an environment manifest, serve it over streamable HTTP, export agent-environment bundles #4933 is linked; representative output now comes from a real Chrome capture.

  • Codex: re-requested on ae275203; it found no issues.

@earakely-scale

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: ae27520361

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@morluto
morluto merged commit 69f99c5 into morluto:main Oct 24, 2026
45 checks passed
@morluto morluto mentioned this pull request Oct 25, 2026
3 tasks done
@morluto morluto added the enhancement New feature or request label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants