Repository navigation
sminos: MW5 image and PDF intake — the media RPC, a synthetic native Read (1.15.0) - #400
Conversation
…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)
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| state.after(MEDIA_WAKE_MS, () => { | ||
| if (state.mediaWake.armed !== armed) { | ||
| return |
There was a problem hiding this comment.
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 👍 / 👎.
| if a.get("mediaType") not in TYPES: | ||
| return "attachment %d's mediaType is one of %s" % (i, ", ".join(TYPES)) |
There was a problem hiding this comment.
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)
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
media(sminos_rpc.py, newsminos_media.py). It takes{attachments: [{name, mediaType, data}]}.media, otherwiseunsupported.<realpath(live cwd)>/.claude/desk-uploads/<session>/<upload>.<i>.<ext>. The cwd comes from the bridge'sread status, so a/cdis followed.dir_fdwithO_NOFOLLOWand create files withO_CREAT|O_EXCL|O_NOFOLLOWat 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 commoninfo/exclude.{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.trace,rearm(by upload) and the child's kept end.daemon/uploads/<sid>.json, once a session has been quiet for a day.sminos/hooks/mods/bridge-media.tsx, routed frombridge.tsx):$.statebefore the bridge answers.turn.stephook claims one attachment. It streams a short prelude and a nativeReadtool call of the file, thenstop: tool_use, without callingnext. The engine then runs the Read under the session's ordinary permissions, so the next request carries animageordocumentblock.asUser).mediaevents ({id, phase, attachments, t}) are relayed by the child as DX4opwithrpc = upload. They are deduplicated by(upload, index, state), and the end is kept under the nonce.controls.mediais available, andopslistsmedia.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 --layexits 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-gatefrom 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:
HOME,CLAUDE_CONFIG_DIRandSMINOS_HOMEunder/private/tmp,env -i, throwaway git checkouts.sminos_rpc.Rpcswith each RPC sealed as a browser seals it, and the bridge's events relayed bysminos_requestsas DX4op.Every case passed:
queuedwith the root and paths. Both attachments endedforwarded. The wake turn's first request held theimageanddocumentblocks (sha256 matches).git statusstayed clean. Repeating the same RPC was answered from the ledger, with one Read each. After a/cdbefore the upload, the root was under the new cwd. After a/cdbetween the save and the Read, the Read raised a request, and an allow from the desk producedforwarded.end_turnwas in flight produced one wake.failedwith the deny text as its reason. No request carried the image.forwarded, and no request carried the image.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.forwardedafter 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
documentblock 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
mw5producer, spec Decision Log): SSFSKIM/MAWS#174Review fix wave (0e4c8c7)
/. 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.O_NONBLOCK|O_NOFOLLOWand must be a regular file, so a FIFO can no longer block the save.info/excludeis written through the same walk. A linkedinfo, a linkedexclude, or one that is not a regular file is refused. The refusal is logged and the upload goes on.bad-shape. AmediaTypeof the wrong type (a list or object) was raisingTypeError.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 andTypeError: unhashable type: 'list'.tests/mods/typecheck.sh --lay: exit 0.all 2417 assertions passed.verdict pass.ci-gateon 0e4c8c7: GREEN, 9/9 (https://github.com/SSFSKIM/doperpowers/actions/runs/40340920154).Residue
putOpkeeps command ops only, so amediaop'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.documentblock 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 withpagesor to refuseapplication/pdfon such sessions, decided after a measurement.Sminos-Session: desk-sminos-orchestrator#b4948247 (doperpowers on macbook)