Skip to content

Commit dc735c0

Browse files
committed
fix(install): migrate v0.10.8 OpenCode agent profiles on upgrade (DeusData#2264)
Upgrading from v0.10.8 to v0.11.0 on a machine with OpenCode reported all three OpenCode subagent profiles as "preserved modified profile" plus an op=agent_install error each, and the activation stopped ("one or more agent configurations failed; the published/current executable was kept"), although nobody had edited those files. Root cause: DeusData#1933 (v0.11.0) added the tool_search / tool_search_regex permissions to the rendered OpenCode profile. Install and uninstall recognise a profile as ours only when it matches the current rendering or one of the known released renderings (the other access mode, the v0.9.1-rc.1 Codex shape, the pre-tier Verify file). The v0.10.8 OpenCode shape was not in that set, so cbm_text_migrate_owned_document classified the untouched v0.10.8 files as user-modified. Reproduced end to end: install with the v0.10.8 release binary, then install with v0.11.0/main, into an isolated HOME; the three profiles are 1729/1880/1910 bytes, the same sizes as in the report. cbm_render_graph_profile_opencode_v0108() renders the pre-DeusData#1933 shape (both access modes), and install/uninstall now list it as a released rendering, so those files are upgraded in place and uninstall removes them as owned. A profile the user actually edited is still preserved. The released-list assembly that install and uninstall duplicated moves into one helper, and the two legacy renderers share one implementation (cli.c drops three raw free sites; the memory-core baseline is tightened 173 -> 170). The Codex and OpenCode op=mcp_install errors in the same report do not reproduce from a pristine v0.10.8 config and depend on the reporter's own config.toml / opencode.json; they are not addressed here. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 9d65f4c commit dc735c0

5 files changed

Lines changed: 204 additions & 62 deletions

File tree

‎scripts/memory-core-baseline.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal/cbm/sqlite_writer.c 74
1717
src/cli/activation_transaction.c 80
1818
src/cli/agent_clients.c 73
1919
src/cli/agent_profiles.c 7
20-
src/cli/cli.c 173
20+
src/cli/cli.c 170
2121
src/cli/client_adapter.c 3
2222
src/cli/config_edit_path.c 2
2323
src/cli/config_json_like.c 142

‎src/cli/agent_profiles.c‎

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,23 @@ static bool append_codex_profile(profile_buffer_t *buffer, cbm_graph_tier_t tier
498498
profile_buffer_append(buffer, "]\n");
499499
}
500500

501+
/* before_tool_search reproduces the v0.10.8 rendering: #1933 (v0.11.0) added
502+
* the tool_search / tool_search_regex permissions, and install/uninstall
503+
* must still recognise the older bytes as ours (#2264). */
504+
static bool append_opencode_profile(profile_buffer_t *buffer, cbm_graph_tier_t tier,
505+
cbm_graph_access_t access, const char *prompt,
506+
bool before_tool_search) {
507+
return profile_buffer_append(buffer, "---\ndescription: ") &&
508+
profile_buffer_append(buffer, profile_description(tier, access)) &&
509+
profile_buffer_append(buffer, "\nmode: subagent\npermission:\n \"*\": deny\n read: "
510+
"allow\n grep: allow\n glob: allow\n") &&
511+
(before_tool_search ||
512+
profile_buffer_append(buffer, " tool_search: allow\n tool_search_regex: allow\n")) &&
513+
(access != CBM_GRAPH_ACCESS_DIRECT ||
514+
append_permission_mcp_tools(buffer, CBM_GRAPH_DIALECT_OPENCODE, tier)) &&
515+
profile_buffer_append(buffer, "---\n") && profile_buffer_append(buffer, prompt);
516+
}
517+
501518
static bool render_profile_text(profile_buffer_t *buffer, cbm_graph_profile_dialect_t dialect,
502519
cbm_graph_tier_t tier, cbm_graph_access_t access,
503520
const char *binary_path, const char *prompt) {
@@ -547,17 +564,7 @@ static bool render_profile_text(profile_buffer_t *buffer, cbm_graph_profile_dial
547564
}
548565
return true;
549566
case CBM_GRAPH_DIALECT_OPENCODE:
550-
if (!profile_buffer_append(buffer, "---\ndescription: ") ||
551-
!profile_buffer_append(buffer, description) ||
552-
!profile_buffer_append(
553-
buffer, "\nmode: subagent\npermission:\n \"*\": deny\n read: allow\n grep: "
554-
"allow\n glob: allow\n tool_search: allow\n tool_search_regex: "
555-
"allow\n") ||
556-
(direct && !append_permission_mcp_tools(buffer, dialect, tier)) ||
557-
!profile_buffer_append(buffer, "---\n") || !profile_buffer_append(buffer, prompt)) {
558-
return false;
559-
}
560-
return true;
567+
return append_opencode_profile(buffer, tier, access, prompt, false);
561568
case CBM_GRAPH_DIALECT_KILO:
562569
if (!profile_buffer_append(buffer, "---\ndescription: ") ||
563570
!profile_buffer_append(buffer, description) ||
@@ -711,21 +718,34 @@ char *cbm_render_graph_profile(cbm_graph_profile_dialect_t dialect, cbm_graph_ti
711718
return profile_buffer_finish(&buffer);
712719
}
713720

714-
char *cbm_render_graph_profile_codex_rc1(cbm_graph_tier_t tier) {
715-
if (!tier_valid(tier)) {
721+
/* A released-but-superseded rendering, kept only so install/uninstall can
722+
* recognise and migrate files an older release wrote. */
723+
static char *render_released_profile(cbm_graph_profile_dialect_t dialect, cbm_graph_tier_t tier,
724+
cbm_graph_access_t access) {
725+
if (!tier_valid(tier) || !access_valid(access)) {
716726
return NULL;
717727
}
718-
char *prompt = cbm_render_graph_prompt(tier, CBM_GRAPH_ACCESS_DIRECT);
728+
char *prompt = cbm_render_graph_prompt(tier, access);
719729
if (!prompt) {
720730
return NULL;
721731
}
722732
profile_buffer_t buffer;
723733
profile_buffer_init(&buffer);
724-
bool ok = append_codex_profile(&buffer, tier, CBM_GRAPH_ACCESS_DIRECT, NULL, prompt, true);
734+
bool ok = dialect == CBM_GRAPH_DIALECT_OPENCODE
735+
? append_opencode_profile(&buffer, tier, access, prompt, true)
736+
: append_codex_profile(&buffer, tier, access, NULL, prompt, true);
725737
free(prompt);
726738
if (!ok) {
727739
profile_buffer_discard(&buffer);
728740
return NULL;
729741
}
730742
return profile_buffer_finish(&buffer);
731743
}
744+
745+
char *cbm_render_graph_profile_opencode_v0108(cbm_graph_tier_t tier, cbm_graph_access_t access) {
746+
return render_released_profile(CBM_GRAPH_DIALECT_OPENCODE, tier, access);
747+
}
748+
749+
char *cbm_render_graph_profile_codex_rc1(cbm_graph_tier_t tier) {
750+
return render_released_profile(CBM_GRAPH_DIALECT_CODEX, tier, CBM_GRAPH_ACCESS_DIRECT);
751+
}

‎src/cli/agent_profiles.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ char *cbm_render_graph_profile(cbm_graph_profile_dialect_t dialect, cbm_graph_ti
6060
* so install/uninstall can recognize and migrate those files. */
6161
char *cbm_render_graph_profile_codex_rc1(cbm_graph_tier_t tier);
6262

63+
/* v0.10.8 OpenCode rendering (before the tool_search permissions of #1933),
64+
* kept so install/uninstall can recognize and migrate those files (#2264). */
65+
char *cbm_render_graph_profile_opencode_v0108(cbm_graph_tier_t tier, cbm_graph_access_t access);
66+
6367
/* Vibe stores the behavioral prompt separately from its TOML agent definition.
6468
* Other integrations may also use this as the canonical contract text. */
6569
char *cbm_render_graph_prompt(cbm_graph_tier_t tier, cbm_graph_access_t access);

‎src/cli/cli.c‎

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8717,6 +8717,54 @@ static cbm_graph_access_t cbm_tiered_profile_set_access(cbm_tiered_profile_set_t
87178717
: CBM_GRAPH_ACCESS_HANDOFF;
87188718
}
87198719

8720+
/* Every earlier rendering of one tier's profile that install/uninstall must
8721+
* still recognise as ours: the other access mode, the v0.9.1-rc.1 Codex
8722+
* shape, the pre-tier Verify file, and the v0.10.8 OpenCode shape (#2264). */
8723+
typedef struct {
8724+
char *owned[4];
8725+
size_t owned_count;
8726+
const char *content[5];
8727+
size_t count;
8728+
} tiered_released_profiles_t;
8729+
8730+
static void tiered_released_profiles_keep(tiered_released_profiles_t *released, char *rendered) {
8731+
if (rendered) {
8732+
released->owned[released->owned_count++] = rendered;
8733+
released->content[released->count++] = rendered;
8734+
}
8735+
}
8736+
8737+
static void tiered_released_profiles_collect(cbm_tiered_profile_set_t profiles,
8738+
cbm_graph_tier_t tier, cbm_graph_access_t access,
8739+
tiered_released_profiles_t *released) {
8740+
memset(released, 0, sizeof(*released));
8741+
cbm_graph_access_t alternate_access =
8742+
access == CBM_GRAPH_ACCESS_DIRECT ? CBM_GRAPH_ACCESS_HANDOFF : CBM_GRAPH_ACCESS_DIRECT;
8743+
tiered_released_profiles_keep(
8744+
released,
8745+
cbm_render_graph_profile(profiles.dialect, tier, alternate_access, profiles.binary_path));
8746+
if (profiles.dialect == CBM_GRAPH_DIALECT_CODEX && access == CBM_GRAPH_ACCESS_DIRECT) {
8747+
tiered_released_profiles_keep(released, cbm_render_graph_profile_codex_rc1(tier));
8748+
}
8749+
if (profiles.dialect == CBM_GRAPH_DIALECT_OPENCODE) {
8750+
tiered_released_profiles_keep(released,
8751+
cbm_render_graph_profile_opencode_v0108(tier, access));
8752+
tiered_released_profiles_keep(
8753+
released, cbm_render_graph_profile_opencode_v0108(tier, alternate_access));
8754+
}
8755+
if (tier == CBM_GRAPH_TIER_VERIFY && profiles.legacy_verify_content) {
8756+
released->content[released->count++] = profiles.legacy_verify_content;
8757+
}
8758+
}
8759+
8760+
static void tiered_released_profiles_free(tiered_released_profiles_t *released) {
8761+
for (size_t i = 0U; i < released->owned_count; i++) {
8762+
free(released->owned[i]);
8763+
}
8764+
released->owned_count = 0U;
8765+
released->count = 0U;
8766+
}
8767+
87208768
static void install_tiered_agent_profiles(cbm_tiered_profile_set_t profiles, bool dry_run) {
87218769
cbm_graph_access_t access = cbm_tiered_profile_set_access(profiles);
87228770
for (int value = 0; value < (int)CBM_GRAPH_TIER_COUNT; value++) {
@@ -8740,30 +8788,13 @@ static void install_tiered_agent_profiles(cbm_tiered_profile_set_t profiles, boo
87408788
record_agent_config_error(false, profiles.label, "agent_render", path);
87418789
continue;
87428790
}
8743-
cbm_graph_access_t alternate_access =
8744-
access == CBM_GRAPH_ACCESS_DIRECT ? CBM_GRAPH_ACCESS_HANDOFF : CBM_GRAPH_ACCESS_DIRECT;
8745-
char *alternate = cbm_render_graph_profile(profiles.dialect, tier, alternate_access,
8746-
profiles.binary_path);
8747-
char *codex_rc1 =
8748-
profiles.dialect == CBM_GRAPH_DIALECT_CODEX && access == CBM_GRAPH_ACCESS_DIRECT
8749-
? cbm_render_graph_profile_codex_rc1(tier)
8750-
: NULL;
8751-
const char *released[3];
8752-
size_t released_count = 0U;
8753-
if (alternate) {
8754-
released[released_count++] = alternate;
8755-
}
8756-
if (codex_rc1) {
8757-
released[released_count++] = codex_rc1;
8758-
}
8759-
if (tier == CBM_GRAPH_TIER_VERIFY && profiles.legacy_verify_content) {
8760-
released[released_count++] = profiles.legacy_verify_content;
8761-
}
8762-
int result = prepare_config_parent(path)
8763-
? cbm_text_migrate_owned_document(path, current, released, released_count)
8764-
: CLI_ERR;
8765-
free(codex_rc1);
8766-
free(alternate);
8791+
tiered_released_profiles_t released;
8792+
tiered_released_profiles_collect(profiles, tier, access, &released);
8793+
int result =
8794+
prepare_config_parent(path)
8795+
? cbm_text_migrate_owned_document(path, current, released.content, released.count)
8796+
: CLI_ERR;
8797+
tiered_released_profiles_free(&released);
87678798
free(current);
87688799
if (result != CLI_OK) {
87698800
if (result > CLI_OK) {
@@ -8795,28 +8826,11 @@ static void uninstall_tiered_agent_profiles(cbm_tiered_profile_set_t profiles, b
87958826
record_agent_config_error(true, profiles.label, "agent_render", path);
87968827
continue;
87978828
}
8798-
cbm_graph_access_t alternate_access =
8799-
access == CBM_GRAPH_ACCESS_DIRECT ? CBM_GRAPH_ACCESS_HANDOFF : CBM_GRAPH_ACCESS_DIRECT;
8800-
char *alternate = cbm_render_graph_profile(profiles.dialect, tier, alternate_access,
8801-
profiles.binary_path);
8802-
char *codex_rc1 =
8803-
profiles.dialect == CBM_GRAPH_DIALECT_CODEX && access == CBM_GRAPH_ACCESS_DIRECT
8804-
? cbm_render_graph_profile_codex_rc1(tier)
8805-
: NULL;
8806-
const char *released[3];
8807-
size_t released_count = 0U;
8808-
if (alternate) {
8809-
released[released_count++] = alternate;
8810-
}
8811-
if (codex_rc1) {
8812-
released[released_count++] = codex_rc1;
8813-
}
8814-
if (tier == CBM_GRAPH_TIER_VERIFY && profiles.legacy_verify_content) {
8815-
released[released_count++] = profiles.legacy_verify_content;
8816-
}
8817-
int result = cbm_text_remove_owned_document_any(path, current, released, released_count);
8818-
free(codex_rc1);
8819-
free(alternate);
8829+
tiered_released_profiles_t released;
8830+
tiered_released_profiles_collect(profiles, tier, access, &released);
8831+
int result =
8832+
cbm_text_remove_owned_document_any(path, current, released.content, released.count);
8833+
tiered_released_profiles_free(&released);
88208834
free(current);
88218835
if (result < CLI_OK) {
88228836
record_agent_config_error(true, profiles.label, "agent_uninstall", path);

‎tests/test_cli.c‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7412,6 +7412,109 @@ TEST(cli_tiered_codex_profiles_migrate_preserve_and_uninstall) {
74127412
PASS();
74137413
}
74147414

7415+
/* The OpenCode subagent profile as v0.10.8 wrote it: today's rendering minus
7416+
* the tool_search / tool_search_regex permission lines #1933 added in
7417+
* v0.11.0. Derived by deleting exactly those lines, so the test states the
7418+
* released bytes without going through any production legacy renderer. */
7419+
static char *opencode_profile_before_tool_search(cbm_graph_tier_t tier) {
7420+
char *current =
7421+
cbm_render_graph_profile(CBM_GRAPH_DIALECT_OPENCODE, tier, CBM_GRAPH_ACCESS_DIRECT, NULL);
7422+
if (!current) {
7423+
return NULL;
7424+
}
7425+
const char *const added[] = {" tool_search: allow\n", " tool_search_regex: allow\n"};
7426+
for (size_t i = 0U; i < sizeof(added) / sizeof(added[0]); i++) {
7427+
char *at = strstr(current, added[i]);
7428+
if (!at) {
7429+
free(current);
7430+
return NULL;
7431+
}
7432+
size_t len = strlen(added[i]);
7433+
memmove(at, at + len, strlen(at + len) + 1U);
7434+
}
7435+
return current;
7436+
}
7437+
7438+
/* #2264: upgrading v0.10.8 -> v0.11.0 reported all three OpenCode profiles
7439+
* as "preserved modified profile" + op=agent_install errors and stopped the
7440+
* activation, although nobody had edited them: the release render changed
7441+
* and the previous render was not recognised as ours. */
7442+
TEST(cli_tiered_opencode_profiles_migrate_v0108_render) {
7443+
char tmpdir[256];
7444+
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-tiered-opencode-XXXXXX");
7445+
if (!cbm_mkdtemp(tmpdir))
7446+
FAIL("cbm_mkdtemp failed");
7447+
7448+
const char *const env_names[] = {
7449+
"HOME", "PATH", "CODEX_HOME", "QWEN_HOME", "COPILOT_HOME",
7450+
"CLINE_DATA_DIR", "KIRO_HOME", "OPENCODE_CONFIG", "OPENCODE_CONFIG_DIR"};
7451+
char *saved_env[sizeof(env_names) / sizeof(env_names[0])];
7452+
for (size_t i = 0U; i < sizeof(env_names) / sizeof(env_names[0]); i++) {
7453+
saved_env[i] = save_test_env(env_names[i]);
7454+
cbm_unsetenv(env_names[i]);
7455+
}
7456+
cbm_setenv("HOME", tmpdir, 1);
7457+
cbm_setenv("PATH", tmpdir, 1);
7458+
7459+
char agents_dir[512];
7460+
snprintf(agents_dir, sizeof(agents_dir), "%s/.config/opencode/agents", tmpdir);
7461+
test_mkdirp(agents_dir);
7462+
char paths[CBM_GRAPH_TIER_COUNT][640];
7463+
bool seeded = true;
7464+
for (int t = 0; t < (int)CBM_GRAPH_TIER_COUNT; t++) {
7465+
cbm_graph_tier_t tier = (cbm_graph_tier_t)t;
7466+
snprintf(paths[t], sizeof(paths[t]), "%s/%s.md", agents_dir, cbm_graph_tier_slug(tier));
7467+
char *old = opencode_profile_before_tool_search(tier);
7468+
seeded = seeded && old != NULL;
7469+
if (old) {
7470+
write_test_file(paths[t], old);
7471+
free(old);
7472+
}
7473+
}
7474+
7475+
char installed_binary[640];
7476+
snprintf(installed_binary, sizeof(installed_binary), "%s/.local/bin/codebase-memory-mcp",
7477+
tmpdir);
7478+
int install_rc = cbm_install_agent_configs(tmpdir, installed_binary, false, false);
7479+
bool migrated = true;
7480+
for (int t = 0; t < (int)CBM_GRAPH_TIER_COUNT; t++) {
7481+
char *after = read_test_file_alloc(paths[t]);
7482+
migrated = migrated && after && strstr(after, " tool_search: allow\n") &&
7483+
strstr(after, " tool_search_regex: allow\n");
7484+
free(after);
7485+
}
7486+
7487+
/* Uninstall must also recognise the v0.10.8 bytes as ours. */
7488+
for (int t = 0; t < (int)CBM_GRAPH_TIER_COUNT; t++) {
7489+
char *old = opencode_profile_before_tool_search((cbm_graph_tier_t)t);
7490+
if (old) {
7491+
write_test_file(paths[t], old);
7492+
free(old);
7493+
}
7494+
}
7495+
char *argv[] = {"uninstall", "--yes"};
7496+
int uninstall_rc = cli_test_cmd_uninstall(2, argv);
7497+
bool removed = true;
7498+
struct stat state;
7499+
for (int t = 0; t < (int)CBM_GRAPH_TIER_COUNT; t++) {
7500+
removed = removed && stat(paths[t], &state) != 0;
7501+
}
7502+
7503+
for (size_t i = 0U; i < sizeof(env_names) / sizeof(env_names[0]); i++) {
7504+
restore_test_env(env_names[i], saved_env[i]);
7505+
}
7506+
test_rmdir_r(tmpdir);
7507+
if (!seeded)
7508+
FAIL("v0.10.8 OpenCode profile bytes could not be derived");
7509+
ASSERT_EQ(install_rc, 0);
7510+
if (!migrated)
7511+
FAIL("v0.10.8 OpenCode profiles must be upgraded in place, not preserved as modified");
7512+
ASSERT_EQ(uninstall_rc, 0);
7513+
if (!removed)
7514+
FAIL("uninstall must remove v0.10.8 OpenCode profiles as owned");
7515+
PASS();
7516+
}
7517+
74157518
TEST(cli_tiered_vibe_installs_matching_agent_prompt_sets) {
74167519
char tmpdir[256];
74177520
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-tiered-vibe-XXXXXX");
@@ -16428,6 +16531,7 @@ SUITE(cli) {
1642816531
RUN_TEST(cli_warp_installs_shared_skill_without_mcp_or_permissions);
1642916532
RUN_TEST(cli_owned_durable_profiles_preserve_user_files);
1643016533
RUN_TEST(cli_tiered_codex_profiles_migrate_preserve_and_uninstall);
16534+
RUN_TEST(cli_tiered_opencode_profiles_migrate_v0108_render);
1643116535
RUN_TEST(cli_tiered_vibe_installs_matching_agent_prompt_sets);
1643216536
RUN_TEST(cli_tiered_grok_installs_profiles_and_withholds_hooks);
1643316537
RUN_TEST(cli_grok_mcp_preserves_foreign_table);

0 commit comments

Comments
 (0)