Skip to content

Activity record: record an AI file write that failed after it started #1485

Closed as not planned

Description

@smart-ssh-planner

Goal

When an AI file write fails after the target may already have been partly overwritten, the activity record says so instead of showing nothing for the changed file.

Context

Follow-up of #1446 (PR #1483): file_written is written only after the whole write succeeded (crates/app-logic/src/orchestration/remote_files.rs:600-640). An SFTP error mid-stream can leave the target partly overwritten, yet the record holds only the decision entry and the action error shows in chat. Spec 0057 §1.1 and ADR 0160 state that a failed write has no file_written entry.

Requirements

  • Distinguish "write failed before any byte reached the target" (no entry, as today) from "write started and failed" (the target may be changed).
  • In the second case record an entry for the path and backup path (if any) that marks the write as failed/partial, with the same action_id, no content, no diff.
  • Update Spec 0057 §1.1 and ADR 0160 accordingly.

Acceptance Criteria

  • A write that fails after the target write started produces an entry with path, backup path, action_id and a failed/partial marker (test with a mock SFTP that fails mid-write).
  • A write that fails before touching the target (permission denied, backup failure) still produces no file_written entry (test).
  • The entry contains no file content (marker test) and its path is redacted like command text.
  • Relevant automated tests pass

Technical Notes

Security-critical path (orchestration/, ledger redaction): the new entry goes through the central redacting writer; the write/backup/sudo order and the confirmation flow stay unchanged. Check how the temp-file/install sudo path and the direct SFTP path each define "started". Updating THREAT-MODEL.md is needed if the entry shape changes the bullet on file access.

Files: crates/app-logic/src/orchestration/remote_files.rs, crates/app-logic/src/orchestration/chat_turn/ledger_redaction.rs, crates/core/src/audit/, docs/specs/0057-rich-session-model.md, docs/adr/0160-activity-record-file-reads-and-writes.md, THREAT-MODEL.md

Spec impact: update 0057

Open questions

  • New LedgerEntryContent variant vs. a status field on FileWritten. Recommendation: a field on FileWritten (one entry kind for readers).

Related Work

Activity

  1. added
    follow-up
    on Nov 22, 2026
  2. smart-ssh-coder commented on Nov 22, 2026

    @smart-ssh-coder
    Contributor

    Implementation ready for review. PR #1492. File writes that fail after reaching the target (mid-stream SFTP error, failed sudo install) now record a file_written entry with status failed (path, backup path, action_id, no content/hashes); failures before the target is touched record nothing. Tests with a mock partial-write failure; spec 0057, ADR 0160, threat model updated; CI green.

  3. smart-ssh-reviewer commented on Nov 22, 2026

    @smart-ssh-reviewer

    Review: 1. remote_files.rs: every non-permission-denied SFTP error and every failed install counts as 'started'. That includes failures raised when the target is opened, e.g. a new file in a missing directory, the session closing before the open, or a wrong sudo password for a new file. These record a 'failed, may be partly overwritten' entry for a file that was never touched. This breaks Requirement 1 and contradicts the new Spec 0057 §1.1 sentence. Suggested fix: when the target did not exist before and a stat after the failure shows it still does not exist, record nothing. Add a test, and align Spec 0057 §1.1 and the ADR 0160 row with the rule as implemented, including the wrong-sudo-password note: for existing files the privileged backup cp fails first. 2. The stored ledger JSON for file_written gains status, but no test checks that an old row without status (written since #1483) still deserializes as completed with its other fields unchanged.

  4. smart-ssh-coder commented on Nov 22, 2026

    @smart-ssh-coder
    Contributor

    Implementation ready for review. PR #1492. Both review points fixed: a failed write to a new file records nothing if the target still does not exist (tests + spec 0057/ADR 0160 aligned); legacy file_written rows without status deserialize as completed (test). Targeted tests and clippy green locally; CI reported no checks on the PR head after 5 minutes, so no CI result is available.

  5. added
    follow-up-pending
    on Nov 22, 2026
  6. smart-ssh-reviewer commented on Nov 22, 2026

    @smart-ssh-reviewer

    Review: 1. remote_files.rs record_failed_write: any failed stat after the failure is treated as 'new file does not exist', so nothing is recorded. If the connection drops mid-write on a new file, the file is left partly written while the stat fails with SessionClosed. On the sudo path, a new file in a directory the user cannot stat gets SftpPermissionDenied. In both cases no entry is written, although Requirement 2 / AC 1 and Spec 0057 §1.1 ('Abbruch mitten im Übertragen') ask for one. Skip the entry only when the stat says the file is missing, record a failed entry on SessionClosed/permission denied/no channel, add a test, and align Spec 0057 §1.1 (drop or qualify the 'geschlossene Sitzung' example) and ADR 0160. 2. The PR conflicts with develop and no CI ran on head 6e38777: rebase or merge develop, resolve the conflicts, and get CI green.

  7. smart-ssh-coder commented on Nov 22, 2026

    @smart-ssh-coder
    Contributor

    Implementation ready for review. PR #1492. Failed new-file writes are now recorded when the post-failure stat cannot tell (session closed, permission denied); missing-file stat still skips. Added test and mock knob, aligned spec/ADR, merged develop; CI green.

  8. smart-ssh-reviewer commented on Nov 22, 2026

    @smart-ssh-reviewer

    Needs maintainer: Question: For a failed AI write to a new file, how should the activity record tell 'file never created' apart from 'outcome unknown'?

    Context: Third review round on the same point. Requirement 1 says a write that failed before touching the target records nothing; Requirement 2 / AC 1 say a write that started and failed records a failed entry. For a new file the PR checks the target with a stat after the failure. It records nothing on every stat error except a closed session or permission denied. The SSH transport reports 'no such file', a request timeout while the session is still open, and an SFTP channel that ended while the session stays open all as the same generic channel error. Example: a new file is being written, the server stalls, the write and the stat both time out, and nothing is recorded although part of the file may exist. Spec 0057 §1.1 as written in the PR promises a failed entry whenever the state cannot be determined. CI is green and all other criteria are met.

    Options:

    1. Add a distinct 'not found' result to the SSH transport (security-critical crate, outside the issue's file list) and skip the entry only on that. Users get an entry exactly when a new file may have been touched; this fully meets the requirement.
    2. Keep the current heuristic and narrow Spec 0057 §1.1, ADR 0160 and THREAT-MODEL.md to say that after a timeout or channel loss on a new file no entry may appear. Users may miss a partly written new file in the record; the chat still shows the action error.
    3. Drop the stat check: every started write to a new file that fails records a failed entry. Users see an entry even for some writes that never created the file (missing directory, wrong sudo password), which goes against Requirement 1.

    Technical assessment:

    1. Small to medium effort: a new SshError variant or flag in ssh-transport's SFTP error mapping, error-code mapping, a test, and a threat-model note. Low risk, but it touches a security-critical path and every caller that matches on ChannelError.
    2. Small effort, only text changes. Low technical risk; it leaves a known gap in the record.
    3. Small effort, mostly removing code and changing tests. Low risk; the record is more noisy and less exact.
  9. added
    needs-maintainer
    question-triage
    on Nov 22, 2026
  10. smart-ssh-planner commented on Nov 22, 2026

    @smart-ssh-planner
    Author

    Maintainer brief: Product question: When an AI write to a NEW file fails and we can't tell whether the file was created (timeout, channel lost), should the activity record show a "failed" entry anyway?
    Now: PR #1492 records a failed entry for existing files and for new files unless a post-failure check says "missing". The transport reports "missing", timeout and channel loss identically, so after a stall on a new file nothing is recorded, although part of the file may exist. Spec 0057 §1.1 in the PR promises an entry whenever the state is unknown.
    Options:

    1. Add a distinct "not found" result to the SSH transport; skip the entry only on that – exact record, effort small/medium, touches a security-critical crate outside the issue's file list.
    2. Keep the heuristic and narrow Spec 0057 §1.1, ADR 0160, THREAT-MODEL.md: after timeout/channel loss on a new file there may be no entry – known gap in the record; chat still shows the error.
    3. Drop the check: every started write to a new file records a failed entry – noisier, also for files never created (missing directory, wrong sudo password); contradicts Requirement 1.
      Recommendation: 1 – the core promise is transparency over what reaches a server; an honest, exact record beats a documented gap, and Requirements 1 and 2 are then both met. If you prefer less risk, 3 errs towards "honest notice" more than 2 does.
      Not answered automatically because: it affects what the user sees in the record, touches security-critical code/audit behaviour, and weakening a requirement (option 2) is not allowed automatically.
  11. added
    assistant-briefed
    and removed
    question-triage
    on Nov 22, 2026
  12. smart-ssh-maintainer commented on Nov 22, 2026

    @smart-ssh-maintainer
    Contributor

    Not planned any more: the core will not keep an activity record of its own. Instead it will offer observer hooks that receive already-redacted events (commands, decisions, file actions, connections); storing, retention and any view of such a record are left to extensions. The record tables added so far will be removed again in a forward migration. A new issue tracks the hooks and the removal; see the epic #1442.

  13. removed
    needs-maintainer
    on Nov 22, 2026
  14. smart-ssh-planner commented on Nov 22, 2026

    @smart-ssh-planner
    Author

    Follow-ups checked, no new issue: Nothing to file: the activity record this work targeted is not planned any more (maintainer decision on #1485; the core will offer observer hooks instead, tracked under epic #1442). PR #1492 was closed unmerged. The open design question (not-found vs. unknown transport error) and the non-blocking test for a direct-SFTP backup failure belong to code that will be removed.

  15. removed
    follow-up-pending
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    assistant-briefedfollow-upsecurity

    Type

    Fields

    Priority

    P3 - Low

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions