Skip to content

feat(camofox): give scheduled agents a durable browser identity - #386

Closed
leonardoag2026-beep wants to merge 3 commits into
NousResearch:mainfrom
leonardoag2026-beep:feat/camofox-agent-identity
Closed

leonardoag2026-beep wants to merge 3 commits into
NousResearch:mainfrom
leonardoag2026-beep:feat/camofox-agent-identity

Conversation

@leonardoag2026-beep

@leonardoag2026-beep leonardoag2026-beep commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What

A cron job is an agent that outlives one run, but its browser identity did not. Cron sessions run
under cron:<job_id>:<execution_id>, and the execution id is new on every fire, so the same job
minted a different Camofox userId each time: the tab the previous fire left was unreachable and its
cookies were gone. With managed_persistence: true the job instead fell back to the profile-scoped
identity, sharing one cookie jar with every other task in the profile — the opposite failure, since a
job that logs in should not hand those cookies to unrelated work.

This adds a durable rung keyed to the agent rather than to the task, behind an opt-in setting:

browser:
  camofox:
    durable_agent_identity: true   # default: false
cron:<job_id>:<execution_id>  ->  agent key   cron:<job_id>
                              ->  user_id     hermes_ag_<uuid5(state dir, agent key)[:12]>
                              ->  session_key agent_<uuid5(...)[:16]>

Derived, never stored, so it cannot drift or duplicate across processes. Every fire lands in the same
profile with the logins the previous fire left. One-off tasks (interactive chats, subagents) never
join a job's profile; an explicit CAMOFOX_USER_ID / browser.camofox.user_id still wins; tab
adoption stays the user's own choice (adopt_existing_tab) instead of being forced.

Teardown: hermes camofox identity <job_id>

Closes the live session through DELETE /sessions/<userId>, after hermes cron remove. It does not
touch the on-disk profile: the Camofox server owns that directory and exposes no route that deletes
one, so the README documents the manual cleanup rather than rebuilding the server's private
sha256(user_id)[:32] layout and deleting it.

Stacked on #255

Rebased onto #255 (beac51d): #255 makes the ephemeral identity reproducible per task, this adds the
durable rung above it. git merge-tree against current main is clean; the diff also carries #255's
commit until it lands, and I will rebase --onto main once it does.

Tests

camofox/tests/test_camofox_sessions.py::TestDurableAgentIdentity — 9 new:

  • the same job keeps one identity across two executions, and it is neither the profile-scoped nor the
    task-scoped one
  • off by default: a cron fire under managed_persistence: true is untouched
  • two jobs never share a profile
  • a one-off task (subagent-*, cron: with no id) gets no durable identity
  • a durable identity does not force tab adoption
  • the end of a fire keeps the session (no DELETE), so the next fire adopts the same tab
  • without the opt-in, end-of-session cleanup still closes the session
  • forget_agent_identity issues exactly DELETE /sessions/<userId> and does no filesystem work
  • teardown against an unreachable server does not raise

Full plugin suite against current core main (f578714e0): 106 passed. The same file on #255's
head: 97 passed, with 6 of the 9 new tests failing there.

Verified end to end against a live camofox-browser server, one process per fire: two fires of one job
resolved to the same userId and the same adopted tab, and a cookie set in fire 1 was still there in
fire 2 — after fire 1's end-of-session cleanup. A second job resolved to a different userId; with
the setting off the same job kept the profile identity and no agent profile was created.

browser_navigate succeeded, then every following call failed with No browser session. The session map is process-local: wherever calls do not share that process, each call minted a fresh random userId, so the tab the previous call opened was invisible to the next one.

Derive the ephemeral userId from (state dir, task_id) instead of uuid4, so every call in the same task resolves to the same browser user, and allow tab adoption for that reproducible identity. Unkeyed calls keep a random id, so they never collapse onto one shared profile.

Closes NousResearch#215.
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for this. A per-job browser identity for scheduled agents is a useful idea. Three things need to change before it can merge:

  1. Make it opt-in. As written, get_session gives every cron job a durable identity and forces adopt=True even when managed_persistence is off, which is the default. Today default cron fires are ephemeral. After this PR, every cron job keeps cookies on disk without anyone opting in, teardown is manual, and orphaned profiles pile up. Please gate it behind managed_persistence or a new plugin setting that defaults to off.
  2. Don't delete a path built from the server's internals. camofox_profile_dir rebuilds the Camofox server's private sha256(user_id)[:32] directory layout (plus CAMOFOX_PROFILE_DIR) and then deletes that directory. If the server ever changes its layout, that delete hits the wrong path. Please tear the identity down through the server's API instead. If the server has no API for that, leave the directory in place and document the manual cleanup.
  3. Rebase over fix(camofox): make the ephemeral browser identity reproducible per task #255. The two PRs conflict in camofox_client.py; git merge-tree reports a CONFLICT.

The tests look good: 107 pass on this head, and 3 of the new ones fail on main as they should.

@leonardoag2026-beep
leonardoag2026-beep force-pushed the feat/camofox-agent-identity branch from 0feaaba to 6ac2bb5 Compare November 15, 2026 02:16
@leonardoag2026-beep

Copy link
Copy Markdown
Contributor Author

Rebased onto #255 and reworked — all three addressed.

1. Opt-in. New browser.camofox.durable_agent_identity, default false, config-only (no env
var, matching how managed_persistence is read). With it off, get_session never asks for an agent
identity, so a cron fire behaves exactly as before — profile-scoped when managed_persistence is on,
task-scoped otherwise — and there is a test pinning that. adopt=True is no longer forced either:
the durable identity only makes adoption possible, and it still obeys adopt_existing_tab.

While implementing that I found a sibling of the same bug: soft_cleanup decided "keep the session
alive" from managed_persistence/external override alone, so with the feature on and persistence off
the end-of-session cleanup would have closed the job's session anyway and the next fire would have
had no tab to adopt. It now keeps a durable agent's session too, with a test.

2. No more deleting a path built from the server's internals. camofox_profile_dir is gone, with
its hashlib/shutil imports and the CAMOFOX_PROFILE_DIR reconstruction. forget_agent_identity
now does one thing: DELETE /sessions/<userId>, plus dropping the in-process entries, and reports
session_closed. The profile directory is left in place, and both the README and the CLI say so —
including that closing a session checkpoints state rather than erasing it, so the manual step is
real and not only theoretical.

3. Rebased over #255. git merge-tree against current main is clean. The branch now sits on
beac51d, so the PR also carries #255's commit until it lands; I will rebase --onto main once it
merges.

Tests: 106 passed against current core main (f578714e0); the same file on #255's head gives 97
passed with 6 of the 9 new tests failing there. End to end against a live camofox-browser server, one
process per fire: two fires of one job resolved to the same userId and adopted the same tab, and a
cookie set in fire 1 was still there in fire 2 after fire 1's end-of-session cleanup. A second job got
a different userId, and with the setting off the same job kept the profile identity.

teknium1 and others added 2 commits November 19, 2026 04:04
…g_tab

NousResearch#255 made the per-task userId reproducible, but the rebuilt session entry
only re-adopted the tab when adopt_existing_tab was set, so the default
config still answered 'No browser session' after navigate in another
process (NousResearch#215). A task-scoped userId only ever holds this task's tabs, so
the rebuild always looks for one; the per-call adopt_existing_tab gate is
unchanged (a tab gone after a restart is still recreated).
A cron job outlives one run, but its browser identity did not: cron sessions
run under cron:<job_id>:<execution_id> and the execution id is new on every
fire, so each fire minted a different userId — the tab the previous fire left
was unreachable and its cookies were gone. With managed_persistence the job
instead fell back to the profile-scoped jar, sharing cookies with every other
task in the profile.

With browser.camofox.durable_agent_identity (default off) the identity comes
from the job id — the stable half of the task id — so every fire resolves to
the same Camofox profile with the logins the previous fire left:

  cron:<job_id>:<execution_id>  ->  agent key  cron:<job_id>
                                ->  user_id    hermes_ag_<uuid5(...)[:12]>
                                ->  session_key agent_<uuid5(...)[:16]>

Derived, not stored, so it cannot drift or duplicate across processes.
Opt-in because it puts a job's cookies on disk and those profiles outlive the
job; one-off tasks (interactive chats, subagents) never join a job's profile,
and tab adoption stays the user's own choice (adopt_existing_tab).

Teardown is `hermes camofox identity <job_id>`, after `hermes cron remove`:
it closes the live session through DELETE /sessions/<userId>. The on-disk
profile belongs to the Camofox server, which exposes no route that deletes
one, so Hermes no longer rebuilds and removes the server's private
sha256(user_id)[:32] directory; the README documents the manual cleanup.

Rebased onto NousResearch#255, which makes the ephemeral identity reproducible per task.
@teknium1

Copy link
Copy Markdown
Contributor

Thank you @leonardoag2026-beep! This landed on main through #451, with your authorship kept; tip 269ddcb. To get it now: hermes plugins install NousResearch/hermes-official-plugins#<plugin> --force; hermes plugins update follows once the catalog pin moves (in progress).

@teknium1 teknium1 closed this Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-decision Awaiting an owner policy or product decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants