multica-ai/multica · error

parse config.toml shell environment expressions: %w

Error message

parse config.toml shell environment expressions: %w

What it means

After iterating expressions with the toml/unstable parser to locate shell_environment_policy byte ranges, parser.Error() reports a parse failure the iteration surfaced. The stable decode in step one passed, so this indicates an inconsistency the iterative parser rejects — e.g. constructs valid at decode time but malformed at expression level.

Source

Thrown at server/internal/daemon/execenv/codex_shell_env.go:181

			if isCodexShellEnvPolicyPath(keys) {
				r, err := tomlTableHeaderLineRange(content, expr)
				if err != nil {
					return nil, err
				}
				ranges = append(ranges, r)
			}
		case unstable.KeyValue:
			fullKey := make([]string, 0, len(currentTable)+len(keys))
			fullKey = append(fullKey, currentTable...)
			fullKey = append(fullKey, keys...)
			if isCodexShellEnvPolicyPath(fullKey) {
				start := int(expr.Raw.Offset)
				ranges = append(ranges, tomlByteRange{start: start, end: start + int(expr.Raw.Length)})
			}
		}
	}
	if err := parser.Error(); err != nil {
		return nil, fmt.Errorf("parse config.toml shell environment expressions: %w", err)
	}
	return removeTOMLByteRanges(content, ranges)
}

func tomlNodeKeys(node *unstable.Node) []string {
	it := node.Key()
	keys := make([]string, 0, 4)
	for it.Next() {
		keys = append(keys, string(it.Node().Data))
	}
	return keys
}

func isCodexShellEnvPolicyPath(keys []string) bool {
	if len(keys) > 0 && keys[0] == shellEnvironmentPolicyKey {
		return true
	}
	return len(keys) >= 3 && keys[0] == "profiles" && keys[2] == shellEnvironmentPolicyKey

View on GitHub (pinned to 2c0912b6ec)

Solutions

  1. Simplify the formatting of the user's config.toml (normalize quoting/key style) and retry
  2. Delete the managed-range-containing sections and let the daemon rewrite them
  3. Report the config sample if it decodes with toml.Unmarshal but fails here
Defensive patterns

Strategy: fallback

Try / catch

stripped, err := stripUserShellEnvPolicy(content)
if err != nil && strings.Contains(err.Error(), "shell environment expressions") {
	// stable decode passed but iterative parse failed: fall back to
	// regenerating the file from decoded values instead of byte surgery
	stripped, err = regenerateFromDecoded(content)
}

Prevention

When it happens

Trigger: Exotic-but-decodable TOML (mixed key styles, odd whitespace) that the unstable parser flags mid-iteration; a parser/library version mismatch in behavior.

Common situations: Machine-generated config.toml from third-party tools; TOML library upgrade changing parser strictness.

Related errors


AI-assisted analysis of multica-ai/multica@2c0912b6ec (2026-08-15). Data as JSON: /api/errors/650729e939d77107. Report an issue: GitHub.