{
  "summary": "Own-delivery custody should be attached to the existing per-session InputWriter FIFO and finalized only after successful physical writes, with translation-origin tags applied before enqueue. Current checkout has KeyCmd::Text, not Write, and no separate typeahead/post-commit delivery path. Controller-floor flushes must remain explicitly non-delivery. No files changed or validation commands run.",
  "files": [
    {
      "path": ".worktrees/300-input-acceptance/crates/spt-daemon/src/broker.rs",
      "description": "HostedSession/InputWriter and physical writer seam: 4109–4277; controller floor flush: 4588–4598; translation construction: 4630–4697; settle probe: 4757–4783; text chunking: 4843–4859; sequence application: 4884–4944; worker/re-drive: 4952–5182; writer construction: 8314–8320; controller input: 8746–8848."
    },
    {
      "path": ".worktrees/300-input-acceptance/crates/spt-daemon/src/translation.rs",
      "description": "Command forms 64–79; exact key-to-byte mapping 93–155; controller-only InjectFloor state 169–217; stdout JSON decode 276–293; binary stdin write (not PTY delivery) 309–317."
    },
    {
      "path": ".worktrees/300-input-acceptance/crates/spt-term/src/pty.rs",
      "description": "Shared writer handle 191–196 and physical SessionSurface::write_input 236–240 establish locking and success/partial-failure limits."
    },
    {
      "path": ".worktrees/300-input-acceptance/docs/INPUT-PROVENANCE-CONTRACT.md",
      "description": "Section 8 explicitly requires exclusion using bytes core actually wrote, not payload shape."
    }
  ],
  "architecture": "Translation commands and controller input share one bounded, nonblocking InputWriter FIFO. The lone broker input_writer drains raw Vec<u8> records into PtySession::write_input; origin and sequence metadata are currently absent. Translation floor buffering separates controller bytes during injection, but does not retain delivery history. The InputWriter survives translation respawn and therefore is the minimal session-lifetime custody owner.",
  "report": "## Concrete minimal recording seam\n\nChange the internal InputRecord representation from raw Vec<u8> to a tagged record identifying ordinary/controller/control bytes versus translation-delivery bytes, with a per-delivery/attempt identity and sequence boundaries where needed. Keep the existing FIFO and single physical writer. Attach a small session-local shared delivery ledger to InputWriter, accessible through HostedSession.input; do not put it on Translation, because build_translation replaces that child/state on respawn while reusing the existing InputWriter (4630–4697).\n\nTag delivery at drive_one_sequence's Key and Text branches. Preserve exact ordered bytes, including text split across chunk records and mapped key bytes; retain Text-versus-Key information so semantic candidates can be related to their actual byte source rather than guessing from event-envelope shape. In input_writer, record successful writes only after SessionSurface::write_input returns Ok. A dropped enqueue, disconnected writer, or failed write must not create a claim that the whole delivery landed. Propagate/retain an attempt-invalid marker if any tagged chunk fails enqueue or write; otherwise later successful chunks must not accidentally certify the omitted full payload. Existing bool enqueue results are currently ignored at all production callsites.\n\nA commit marker must be ordered in the same FIFO if used to finalize a full sequence, before flushing controller input. It writes no PTY bytes. Do not silently treat a dropped commit marker as a completed record. However, commit-only publication has a receipt race: Enter can cause USER_INPUT before the binary emits commit or the writer processes its marker. Successful text/submit boundaries need to become visible incrementally rather than relying solely on a future commit. There remains a narrower interval between a physical write making input visible to the harness and the writer publishing successful completion; resolving that without delaying input/receipt is not proven by the existing API. Do not mark enqueued bytes as successful to conceal this interval.\n\n## Every production broker enqueue/write site\n\n| Location | Bytes | Custody |\n|---|---|---|\n| broker.rs:4907–4910, drive_one_sequence Key | key_to_bytes result | Translation delivery; record exact successful bytes with sequence identity. Includes Enter/CR and choreography/control keys. Unknown key emits nothing. |\n| broker.rs:4912–4916 → 4843–4846, Text / enqueue_text_chunked | UTF-8 text split by chunk_text | Translation delivery; accumulate successful ordered chunks without assuming one chunk equals one submission. |\n| broker.rs:4923–4926, Commit | None | Logical terminator only; currently any parsed Commit, including commit:false, ends the sequence. Does not establish successful enqueue/write. |\n| broker.rs:4593, flush_inject_floor | Controller bytes buffered while floor held | Never own delivery. Same helper runs after commit, timeout, disconnect, and event-send failure. |\n| broker.rs:4769, settle_before_inject | INJECT_SETTLE_PROBE | Core terminal readiness control, not peer-message text; keep separate from delivery candidates. |\n| broker.rs:8818, dispatch_input journaled branch | Decoded InputReq bytes | Ordinary input, not own translation delivery. Includes human, RC, shell/system and legacy paths. |\n| broker.rs:8843, dispatch_input unjournaled branch | Decoded InputReq bytes | Same non-delivery classification. |\n| broker.rs:4274–4277, input_writer | All accepted FIFO records | Only broker physical write call; classify before this convergence, confirm success here. |\n\nThe broker's single write_input caller is not the sole physical writer in all of spt-term: PtySession::shared_writer (pty.rs:191–196) is cloned for drain DSR auto-answer. Those terminal replies serialize on the same underlying writer but are not peer-message delivery. Hooking all low-level writer traffic would capture unrelated protocol bytes and lose origin discrimination.\n\n## Post-commit, release, typeahead and retry\n\nIn this inspected checkout, KeyCmd has Key, Text, Delay, Commit (translation.rs:64–79); there is no Write variant. Targeted search followed by a broader crates search found no typeahead/post_commit implementation. The available equivalent is InjectFloor.buffer: it contains controller-origin input exclusively, taken by take_or_release in a loop and enqueued after the injected commands (translation.rs:169–217; broker.rs:4588–4598). This is human/input custody, not an extension of the core delivery.\n\nAfter Commit, drive_one_sequence immediately flushes/releases and returns. It does not apply remaining commands as post-commit delivery. run_inject_worker drains/discards any pending cmd_rx records before the next event (5002–5005). An actual echo retry calls drive_one_sequence again (5019–5068), so instrumenting its two translated byte branches covers re-drive without another write seam. Timed-out/disconnected attempts may already have written bytes; committed status alone does not describe whether a submission occurred. A queued EVENT or successful child.send is even earlier and is not delivery proof.\n\n## Existing normalization and state\n\nThere is no delivery-to-USER_INPUT normalizer in these target files. Text passes from serde JSON string to text.into_bytes unchanged; chunk_text preserves concatenation exactly. TranslationChild trims the outer JSON line, not the decoded text value (276–293). key_to_bytes trims/lowercases the key name and maps enter/return/cr to CR, newline/lf to LF, named terminal keys to CSI and ctrl chords to control bytes (93–155). These are command decoding rules, not evidence that a reported payload retained terminal framing.\n\nBracketed paste wrapping is explicitly deferred in broker.rs:694–696 and 750–754. A broader search finds wrap_bracketed_paste in crates/spt/src/rc.rs:651–667, but that wraps controller clipboard input and is not a delivery normalizer. No existing stripping of ESC[200~/ESC[201~ or CR-to-LF conversion was found in the delivery path. Any new exact-byte-derived report comparison normalization must be stated as an added comparison rule, not reused existing behavior. Do not broadly trim whitespace, strip payload-looking wrappers or match a prefix.\n\nThe existing sent_text Vec (4899, 4915; SeqOutcome at 4865–4875) concatenates Text commands before enqueue, excludes all Keys, and is used solely for echo checking. It is therefore neither a complete actual byte record nor proof of successful writes. echo_verified (781–786) checks only a bounded text head in output; echo_verify_after (4812–4835) may assume success when output is absent. Neither is suitable authority for full-byte custody. InputWriter.backpressure only reports queue pressure. InjectFloor holds a boolean and controller Vec. Worker-local respooled_once/strikes serve retry bookkeeping, not provenance.\n\n## Lock ordering\n\n- dispatch_input clones input/translation/log under sessions, releases sessions, then checks controller under log, releases log, sends the content-free child ping, and separately locks floor for buffer_if_held (8746–8804).\n- flush_inject_floor calls take_or_release under floor and releases it before enqueue (4588–4598). Preserve this; never record these bytes as delivery just because they were emitted by the inject worker.\n- drive_one_sequence opens floor under a short lock, releases it before child.send and all enqueue operations. TranslationChild::send holds only its stdin mutex during the binary write.\n- input_writer currently takes no sessions/log/floor lock. PtySession::write_input takes its private writer mutex, executes write_all and flush, and returns (pty.rs:236–240).\n- Recommended ledger locking is after the physical call returns and only for short in-memory updates; lookup clones the session's input handle before consulting the ledger. Avoid acquiring sessions/log/floor from the writer and never hold a ledger mutex across a potentially wedged PTY write.\n\n## Proof limits\n\nThis is static source mapping only, as requested; no builds/tests/validation or runtime experiments were performed. write_input Ok establishes write_all plus flush completed, not that the terminal/harness accepted the same semantic payload. An Err can occur after a partial write, or after write_all succeeded but flush failed; the current Result exposes no committed byte count. Exact custody for those partial/error bytes requires a deeper write-accounting API, not a broker-only assumption. Terminal editing keys, stash/restore, bracketed paste interpretation and downstream text transformations can make raw stream bytes differ from reported submission text. Full command-byte recording preserves evidence but is not a general terminal editor emulator. Byte equality also cannot distinguish a later human deliberately submitting text identical to a prior core delivery; session-local exact-byte exclusion has that intrinsic ceiling. No adapter changes or token mechanism are necessary for the recommended recording seam."
}
