warn when a session can't be saved, instead of failing silently

Found while chasing an anomalous benchmark rerun: under a sandbox that
blocks writes outside its workspace (codex exec's default), 'oc open'
still renders fine but its session save throws, and the bare catch {}
swallowed it completely. The next 'oc do' then resolves against whatever
session last saved successfully, silently, with no sign the state is
stale. In one repro this served a Hacker News agent a Yahoo Finance page
under 'oc do 5' and it answered from that instead of erroring, which is
how a multi-step task ballooned to 250k tokens without a single wrong
tool call visible in the log.

This does not fix the staleness itself, that needs a design for detecting
a save failure across separate 'oc open' and 'oc do' invocations. It makes
the failure visible on stderr instead of invisible, which is the cheap
half of 'fail loud and cheap' and better than nothing while the real fix
gets designed. Verified manually against an unwritable OC_HOME; cli.js's
main() always calls the network fetcher, so an automated test here would
need fetch-mocking infrastructure this project has none of yet, and none
of cli.js has test coverage today.
This commit is contained in:
only-cli
2026-08-19 08:34:27 -04:00
parent 9873b7f492
commit 943192351a
+8 -2
View File
@@ -41,11 +41,17 @@ budget left behind without fetching it again. State lives in ~/.only-cli
// A rendered page has to be remembered or its [3] means nothing to the next
// command. Saving state must never break a render, so a home directory that
// cannot be written costs the agent `do`, `read`, and `next`, and nothing else.
// cannot be written costs the agent `do`, `read`, and `next`, and nothing
// else, but silently: a sandbox that blocks the write leaves `do` resolving
// against whatever session last saved successfully, possibly from an
// unrelated page, with no sign anything is wrong. So the failure still prints,
// on stderr where it costs nothing until something breaks.
const remember = (page, name, cursor) => {
try {
saveSession(name, sessionFromPage(page, loadSession(name), { cursor }));
} catch {}
} catch (err) {
console.error(`oc: warning: could not save session '${name}' (${err.message}), 'do'/'read'/'next' may act on stale state`);
}
};
// What browsing costs without this tool is the raw page HTML in context.