Repository navigation
Measure selected native acquisition in its own input lifetime - #3605
Merged
Merged
Conversation
trissim
marked this pull request as ready for review
October 29, 2026 14:59
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
debt-src at cbce7b5, every finding: |
trissim
force-pushed
the
work/p947-input-measurements
branch
from
October 29, 2026 15:14
5729c80 to
48b3026
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three commits; twelve production modules and one test import; +163 / -109 lines. Selected acquisition diagnostics go from one recipient-lifetime counter borrowed across inputs to one fresh
PublicationMeasurementsper reservedPrivateSendClaim. Ten selected cursor-measurement accesses are removed; zero selectedNativeStartupinstances borrow cursor counters. Cursor-lifetime observation counters remain withCursorDelivery.This is P947's authorized parent-side measurement dependency, not a latency optimization or completion of the performance target. No tests, application/provider inputs, probes, installation, native JS/build/pin, SQL/schema or proof changes were performed.
Evidence motivating the repair
Original idle input 38559 had at least 820.077 ms (unrounded 820.076777 ms) after
native_openreturned and before writer join could start. Kernel-write completion was 835.511940–850.947103 ms after that return. Acquisition itself was 117.132108 ms, including 14.015580 ms spawning; none of that establishes RPC readiness.These are retained measurements and parent-only bounds, not a prediction that all of that time can be removed. The busy control's 10.312 seconds belongs to its already-running model request and is not targeted or interrupted here.
Before / after owners and lifetimes
PrivateSendClaim.reservePrivateSendClaim.execute,_start_onceCursorDeliveryNativeSession.acquire_nativeUnboundToolTransport.bind_processfor both real callers: genericNativeSession.runandTrackedTurnSession.completeTrackedTurnSession.execute/complete_write_fencedRequestObservationsPublicationMeasurementsdeclarationpublication_measurements.py; all consumers import it directly, while diagnostics imports the real report argument ownersNo new family, worker, timing framework, receipt, phase, database row, send authority, readiness wait or retry.
NativeStartup.native_processis a diagnostic observation copied fromnative.proc.identity, never a permission check.NoProcessmeans acquisition did not return a child; it does not assert that a failed spawn had no external side effect. The process identity remains meaningful after the child's resources close.Span meanings and limits
All parent observations use
time.monotonic_ns(); worker bodies capture their clocks inside their worker, not around scheduling alone. ExistingPublicationMeasurementsgainsfirst_started_ns/last_finished_nswhile retaining count/total/max and the maximum's original endpoints. First/last cover observed bodies, including exceptional exits, not an acknowledgment or proof of delivery.input_reservation_binding: completeCoordination.run_asyncawait.input_reservation_binding_worker: the actual reservation and exact prompt binding callback; the outer-only portions also include coordinator connection/transaction work, not just scheduling. A failed reservation/binding retains existing failure/no-replay behavior and does not construct a claim/report.selected_registry_snapshot/_worker: awaited registry acquisition versus actual callback execution.native_launch_selection/_worker: awaited existing launch selection versus actual worker execution.native_openandnative_spawn: unchanged distinct acquisition/spawn operations; spawn remains nested where applicable and is absent on actual reuse. Neither establishes native RPC readiness.native_process_binding: actualbind_processawait, including listener startup; shared at the existing acquisition owner, not a selected-only copy.draft_publication_acquisition: await of existing worker entry intoDraftRow.publication;draft_publication_worker: actualExitStack.enter_contextbody. Neither includes the draft's subsequent lifetime or retirement.prompt_writer_join: existing owner-loop call through serialization, writer startup and joined completion. Existingclaim_wait,prompt_locksand the grant operations remain distinct and nested.prompt_write_loop: one interval around the whole OS-write loop after the one-use grant. It includes partial writes, retries of a nonblocking syscall after readiness waits, loop bookkeeping and cancellation/deadline checks. Existing nestedraw_pipe_writecounters retain individual syscall resource meaning; a failed/nonblocking syscall is still an observed syscall, not bytes-delivered proof. An exceptional outer interval is not a successful write; unchanged failure classification owns that answer.native_child_retirement: unchanged cleanup interval. Finalrecord_acquisition_progressremains after the tracked session's resources and writer have been joined/closed; retained-child cleanup does not mean a reused idle process was killed. The final report can therefore follow first context by the rest of the normal turn.Nested spans must not be summed as disjoint costs. First/last permit the actual surrounding scheduling gaps to be inspected without cumulative deltas or borrowing earlier maxima. No measurement changes a fence, timeout budget, token, write ordering, cancellation, UNKNOWN/known-not-written classification, or replay rule.
Dependency correction and complete report contract
The second typing correction exposed an actual import cycle:
diagnostics -> turn_lease.NativeCapture -> coordination_session -> diagnostics.PublicationMeasurements. The failed cold-import traceback is retained inp947-report-types-import.log; the unpublished failure was removed before pushing. Root's clean correction c64ac3904658 authorized fixing that dependency at its existing owner.Moved the single existing
PublicationMeasurementsclass topublication_measurements.py, which imports only stdlib declarations. All fields and method bodies remain AST-identical; the existingoperationandmeasuringmethods now declare their return contracts (AbstractContextManager[None]andIterator[None]). No new timing class, wrapper, alias, compatibility export, logger, schema or store.Migrated every consumer directly: coordination_session, cursor_publication, diagnostics, native_child, native_prompt_send, native_startup, private_send_claim, turn_progress and the existing native-send test. The native-child type import is now a normal runtime import of the dependency-light owner. The test has only an import-location change, with no test execution or changed behavior.
The full report contract is now:
All argument owners are actual runtime imports. The earlier callback-only check missed the added parameter on this existing function; the final check enumerates added parameters as well as added definitions against main. The added
native_processparameter is typed, as are all three callbacks and both relocated methods. No newTYPE_CHECKING, cast,Any, ignore or forwarding wrapper.Final evidence:
p947-measurement-move-before.json/-after.json: 1,193 → 1,194 modules, one class → one class, 8 → 9 direct defining imports (diagnostics becomes a consumer), zero old defining imports, zero parse omissions. All 1,194 final source hashes match. Dataclass fields and method bodies are unchanged.p947-measurement-final-check.log: seven separate fresh processes cold-import publication_measurements, diagnostics, coordination_session, turn_lease, native_startup, private_send_claim and tracked_turn successfully. Import order cannot conceal the original cycle.Typed-contract correction after send-back
The initial delivery omitted return annotations on the three newly added worker callbacks. Imports and parsing did not prove their typed contracts; that was my miss under
disallow_untyped_defs.snapshot_registry() -> RegistrySnapshotselect_launch() -> NativePiRpcLaunchacquire_draft() -> DraftPublicationDraftRow.publication(cls, root: Path, input_id: InputId) -> Iterator[DraftPublication], soExitStack.enter_contextretains the actual result type.All three new definitions were enumerated against current main with NRA, including parameter/return annotations. Runtime owner imports and the producer's complete signature resolve through declaration introspection. No new
TYPE_CHECKINGimports,cast,Any, ignores or wrappers. Timing and send bodies are unchanged by this correction. No mypy, pytest, application or provider run is claimed.Targeted reproof:
p947-type-contracts.jsonandp947-types-corrected-check.logretain all seven changed file hashes, the three new definitions, concrete producer parameters/result and zero parse omissions. They superseded the initial inventory's hashes at the callback-correction checkpoint. The final declaration/import move is covered byp947-measurement-move-after.json; earlier artifacts remain dated source observations, not current-hash claims.Source inventory and deletion evidence
Retained prior map:
latency-owner-ast.jsonplus the 19-file installed-source trace. Fresh before/after evidence uses NRAModuleSyntaxIndex, covering 1,193 modules under allsrc,tests,tools, zero parse omissions; 358 → 383 syntactic reference sites. Counts are source leads, not repair scores or dynamic dispatch proof.Artifacts in
/home/ts/.cache/agent-scratch/awareness-schema/:p947-source-before.json,p947-source-after.json: source hashes, declarations/inheritance/imports, writes and producer/consumer reference sites, with lexical owners.p947-source-proof.json/.log: all 1,193 after-inventory hashes matched the initial source checkpoint; one reservation factory; zero selected startup cursor borrows; one acquisition-report consumer. Removing only the added write-loop timing context made_write_fenced's AST exactly equal to that main. These are retained original observations, not assertions that changed-file hashes stayed equal after the typed-contract correction.p947-source-validation.log: six changed modules import successfully;git diff --checkpasses. No pytest, ratchet, app or provider run.Syntactic names/attributes do not resolve arbitrary dynamic imports or callbacks. Existing partials, worker callbacks, the two generic acquisition consumers, independent/selected launch implementations and cleanup lifetimes were read semantically. Native dependency relationships are retained from the prior trace; native sources are unchanged and outside this checkpoint. One-shot inventory/proof executables are retired before delivery, with their hashes retained in the result record.
Deleted authority mistake: IDEN-3 — fact: timing belongs to this selected input; at the former
PrivateSendClaim.executestartup/report and_start_oncecounters; derive: the existing claim's reservation lifetime; by: one claim-ownedPublicationMeasurements, passed unchanged to every selected consumer. No counter reset, clone or snapshot subtraction.Concurrent work
Checked #3572, #3566 and #3538 before edits. Claude confirmed no unpublished changes in these acquisition/writer files. #3572's read-basis/context-refusal changes overlap
private_send_claim.py,tracked_turn.pyandbackend.py; they are independent semantic changes to preserve, not replace. Neither the read-basis authority nor those branches/worktrees were edited. This branch was rebased onto current main before the corrected delivery; conflicting semantic changes from the outstanding PRs must still be preserved when they integrate.Root-owned validation and remaining gaps
Root reported the combined eight real-pipe/admission/UNKNOWN safety controls passed on the preceding head. Their bodies and timing behavior are unchanged by the declaration/import correction, so those controls were not repeated. Root owns hosted gates, installation and one fresh installed nonce input joined to its first original model context. Source equivalence and cold imports are not installed qualification.
Still absent and deliberately outside this checkpoint: native RPC-reader-ready, native prompt entry, message construction timestamps; following input's
StreamWriter.writeis enqueue, not kernel write; provider receipt/token production and historical send-time eligibility. Following transport is unchanged. The measured dominant parent span must choose the eventual optimization; P947 remains OPEN.Assumed: existing
PublicationMeasurementsremains diagnostic-only; actual process identity is available when acquisition returns (as existing native progress reporting already requires); root performs runtime and installed qualification before any performance or live-readiness claim.