Skip to content

sminos: MW5 image and PDF intake — the media RPC, a synthetic native Read (1.15.0) - #400

Merged
SSFSKIM merged 2 commits into
mainfrom
desk-ctl-mw5
Oct 26, 2026
Merged

SSFSKIM merged 2 commits into
mainfrom
desk-ctl-mw5

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

This is MW5 of the desk control surface (MAWS spec docs/doperpowers/specs/2026-10-22-desk-control-surface-design.md, Plan of Work, the machine-side wave). It adds image and PDF intake: images and PDFs the person attaches at the desk reach the session as a native Read. It bumps sminos to 1.15.0.

What it builds

  • Daemon RPC media (sminos_rpc.py, new sminos_media.py). It takes {attachments: [{name, mediaType, data}]}.
    • Shape check: 1–4 attachments, a PNG, JPEG, GIF, WebP or PDF each, matched by the bytes' signature. Base64 is strict. Duplicate names are allowed, since names are only for display.
    • The bridge must take media, otherwise unsupported.
    • Where the files go: <realpath(live cwd)>/.claude/desk-uploads/<session>/<upload>.<i>.<ext>. The cwd comes from the bridge's read status, so a /cd is followed.
    • The upload root and file names are noted on the ledger claim before the first byte is written.
    • Writes walk directories by dir_fd with O_NOFOLLOW and create files with O_CREAT|O_EXCL|O_NOFOLLOW at 0600. A link anywhere on the path refuses the upload. Saving the same bytes again succeeds; different bytes are refused.
    • **/.claude/desk-uploads/ is added to the repository's common info/exclude.
    • The bridge op is posted next. The RPC answers {upload, root, paths, state: queued} only once the bridge holds the upload. If the bridge refuses it, the files are removed, either at once or on the reconcile after a restart.
    • Restarts are handled by trace, rearm (by upload) and the child's kept end.
    • The daemon's bridge duty sweeps upload roots, which are recorded in daemon/uploads/<sid>.json, once a session has been quiet for a day.
  • Bridge (new sminos/hooks/mods/bridge-media.tsx, routed from bridge.tsx):
    • The upload is kept in $.state before the bridge answers.
    • On the next main-loop step, a turn.step hook claims one attachment. It streams a short prelude and a native Read tool call of the file, then stop: tool_use, without calling next. The engine then runs the Read under the session's ordinary permissions, so the next request carries an image or document block.
    • Each attachment moves through these states: pending → claimed → read → forwarded, or ends failed or aborted.
    • Aborts: Esc or step close gives cancelled, turn end gives turn ended, and a reload that finds a claim with no result gives indeterminate after reload.
    • An idle session gets one wake (asUser).
    • DX5 media events ({id, phase, attachments, t}) are relayed by the child as DX4 op with rpc = upload. They are deduplicated by (upload, index, state), and the end is kept under the nonce.
  • Capabilities: controls.media is available, and ops lists media.

Validation Evidence

  • Full sminos suite: with-slot.sh bash sminos/tests/run-sminos-tests.sh → all 2417 assertions passed.

  • Mods: bash sminos/tests/mods/run.sh → 569 pass (RED before: 556 pass, 13 fail, every MW5 case plus the controls list). tests/mods/typecheck.sh --lay exits 0.

  • Child: bash sminos/tests/test-bridge-control.sh → all 171 bridge control assertions passed (RED: 5 of 171 failed).

  • Daemon: python3 sminos/tests/test_rpcs.py → Ran 115 tests … OK. Ten of these are MW5 tests: a link in the path, duplicate names, a restart between save and acceptance, a restart between acceptance and answer, and a refusal with its files removed both at once and after a restart. RED: FAILED (failures=8, errors=1). python3 sminos/tests/test_media.py → Ran 11 tests … OK.

  • CI: ci-gate from the worktree → GREEN, 9/9 gates PASS (repo-checks, sminos-mods, mods, shell-lint, mods-types, sminos, issue-tracker, board-api, sminos-suites) on 9b6eecb (https://github.com/SSFSKIM/doperpowers/actions/runs/40332888104)

  • Live check. Setup:

    • Claude Code 2.1.310, fully isolated: fresh HOME, CLAUDE_CONFIG_DIR and SMINOS_HOME under /private/tmp, env -i, throwaway git checkouts.
    • A recording stub on 127.0.0.1 with a dummy key, so there is no inference.
    • The daemon's own path runs in-process: sminos_rpc.Rpcs with each RPC sealed as a browser seals it, and the bridge's events relayed by sminos_requests as DX4 op.

    Every case passed:

    • Idle PNG and whole PDF: answered queued with the root and paths. Both attachments ended forwarded. The wake turn's first request held the image and document blocks (sha256 matches). git status stayed clean. Repeating the same RPC was answered from the ledger, with one Read each. After a /cd before the upload, the root was under the new cwd. After a /cd between the save and the Read, the Read raised a request, and an allow from the desk produced forwarded.
    • Busy: an upload during a running Bash call was read within that turn, with no wake. An upload while an end_turn was in flight produced one wake.
    • Deny (an ask rule): the request stayed pending until the desk denied it, then the attachment ended failed with the deny text as its reason. No request carried the image.
    • A stand-in plugin beneath that answers the step: forwarded, and no request carried the image.
    • Esc mid-step: aborted (cancelled before the Read ran), and the wake was dropped. The second attachment was read in the person's next turn, and the first was never retried.
    • Reload with an attachment pending: forwarded after the reload. Reload with an attachment claimed: aborted (indeterminate after reload), never streamed. Reloads never land mid-turn on the built code, so this claim was staged with a probe copy that keeps it; the reconciliation under test is the built module's.
  • First live launch: the engine refused to load the module because $ was passed into a function expression. The unit tests and typecheck had both passed it. The fix was in place before the commit, and the rule is logged in the friction tracker (Friction tracker (moved to ~/.claude/friction-tracker/doperpowers/) #304).

Open concern: a whole PDF's document block on a session served through the Codex gateway fails the next request. This is a known gateway limitation (friction tracker #304) and was not measured here.

The MAWS half (protocol types, the fake machine's mw5 producer, spec Decision Log): SSFSKIM/MAWS#174

Review fix wave (0e4c8c7)

  • Walks start at /. Saving, removing and sweeping open every path component from / without following a link. They keep directory descriptors through the cleanup. Before this, a removal days later could follow a link that an ancestor had since become, and delete a file in another tree.
  • Rollback is scoped. A refused save removes only the files this upload created, or found already holding its own bytes. A file already at an upload's filename is opened O_NONBLOCK|O_NOFOLLOW and must be a regular file, so a FIFO can no longer block the save.
  • info/exclude is written through the same walk. A linked info, a linked exclude, or one that is not a regular file is refused. The refusal is logged and the upload goes on.
  • Wrong JSON types are bad-shape. A mediaType of the wrong type (a list or object) was raising TypeError.
  • The idle wake re-checks after its await. It stays armed through the await. Before submitting, it checks again that no turn has started and that something is still pending.

Validation:

  • test_media.py: 19 OK. RED before the fix: 2 failures, 5 errors, among them the other tree's file deleted and a FIFO blocking until the alarm.
  • test_rpcs.py: 117 OK. RED before the fix (m5 tests): 2 failures, 1 error, among them both foreign files deleted and TypeError: unhashable type: 'list'.
  • Mods: 570 pass. RED before the fix: 1 failure, the wake submitted into a running turn. tests/mods/typecheck.sh --lay: exit 0.
  • Full sminos suite: all 2417 assertions passed.
  • The live idle case, re-run on the fixed code: every check passed, verdict pass.
  • ci-gate on 0e4c8c7: GREEN, 9/9 (https://github.com/SSFSKIM/doperpowers/actions/runs/40340920154).

Residue

  • Media op replay for a reconnecting browser. The hub's putOp keeps command ops only, so a media op's states are relayed live. A browser that connects mid-upload sees only the later states. This needs its own approval and a hub change, so decide it with the web half.
  • A whole PDF on a Codex-gateway session. A whole-PDF document block in a tool result fails the next request on a session served through the local gateway to Codex (friction tracker Friction tracker (moved to ~/.claude/friction-tracker/doperpowers/) #304). It was not measured against MW5's Read. The candidate fix is to read PDFs with pages or to refuse application/pdf on such sessions, decided after a measurement.

Sminos-Session: desk-sminos-orchestrator#b4948247 (doperpowers on macbook)

…Read (1.15.0)

The daemon's `media` RPC checks 1-4 attachments (name, type against the
bytes' signature, strict base64, `queued-turn`, no `text`), reads the
session's live working directory from its bridge, keeps the root and file
names on the claim, and saves each file under
`<cwd>/.claude/desk-uploads/<session>/<nonce>.<n>.<ext>` through a walk that
follows no link (exclusive, 0600; a link or another file's bytes refuse
it). `**/.claude/desk-uploads/` goes in the repository's common
info/exclude; each root is recorded and swept, following no link, by the
bridge kept file's rule. The bridge is handed the upload and the RPC is
answered `queued` only once it holds it; a refusal removes the files. A
restart between save and acceptance is `interrupted`; one after acceptance
is answered from the child's kept answer.

The bridge (bridge-media.tsx) keeps each upload in `$.state`; at a
main-loop step with one pending, it claims an attachment (a generated
tool-use id kept before anything is yielded), checks it still lands inside
its root, and streams the prelude and a native Read of the pinned path
without calling `next`. Each attachment is read, forwarded, aborted (Esc,
a turn's end, a reload that finds no result) or failed, said as a `media`
event owed until the child took it; the child relays each once by
(upload, index, state), with the upload as `rpc`, and keeps the end beside
the answer; the daemon relays them as DX4 `op`. An idle upload is woken for
after 2 s, and a turn that ends with one pending wakes once. `media` turns
available in `controls`.

Sminos-Session: desk-sminos-orchestrator#b4948247 (doperpowers on macbook)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 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 ✅ Completed 2026-10-26T13:59:30.872548Z 9b6eecb PR opened
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b6eecb751

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sminos/hooks/mods/bridge-media.tsx Outdated
Comment on lines +398 to +400
state.after(MEDIA_WAKE_MS, () => {
if (state.mediaWake.armed !== armed) {
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Invalidate pending media when the session is cleared

If the person runs /clear while an upload is pending—for example, during this two-second wake delay—the upload survives into the new conversation. The session.end handler and switchSession() call forgetLive(), but that function clears neither state.media nor state.mediaWake. Consequently, this timer can wake the replacement session, and its next main-loop step reads files attached to the previous session; subsequent media events also go through the replacement session's child. Abort or discard the old session's pending intake and invalidate its wake when switching sessions.

Useful? React with 👍 / 👎.

Comment on lines +99 to +100
if a.get("mediaType") not in TYPES:
return "attachment %d's mediaType is one of %s" % (i, ", ".join(TYPES))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate the media type before dictionary membership

An authenticated media RPC containing an attachment with mediaType: [] or mediaType: {} raises TypeError here instead of returning a shape refusal. This is reachable through shape('media', ...) during Rpcs.receive() on the uplink's main thread, where only Refused is caught; the uplink loop does not catch TypeError either, so one malformed upload terminates the uplink and disrupts all session traffic until it restarts. Check that mediaType is a string before looking it up in TYPES.

Useful? React with 👍 / 👎.

…clude, the wake re-check

- Saving, removing and sweeping an upload walk every component from / without
  following a link, keeping directory descriptors through the cleanup: a link an
  ancestor became since never leads a removal into another tree.
- A refused save removes only the files the upload created or found holding its
  own bytes; a collision is opened non-blocking and must be a regular file.
- info/exclude is written through the same walk; a linked or irregular one is
  refused, logged, and the upload goes on.
- mediaType of any other JSON type is bad-shape, not a TypeError.
- The idle wake stays armed through its await and re-checks the turn and the
  pending work before it submits.

Sminos-Session: desk-sminos-orchestrator#b4948247 (doperpowers on macbook)
@SSFSKIM
SSFSKIM merged commit 68a8974 into main Oct 26, 2026
11 checks passed
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.

1 participant